我现在要讲一个服务注册到数据库中去,先简单说一下情况
因为一个服务有具体的名称,还有不同的服务类型(其实这里有两种类型,比如下面的soap_services,还有一个是rest_services,注册的时候可以选择注册的类型,然后跳转到具体的类型页面,提交相应的数据,这里提交的是XML的文档,我将它进行了解析,但是不知道如何完整的存到数据库里面去),同时还有若干个操作,每个操作又有若个个参数
我现在要用四张表来存储,第一个表里面只存服务的名称,第二个表里面存服务名称和描述,第三个表里面存储服务包含的操作名称,描述,第四个表里面存服务某一个具体操作的参数和描述(最后的两个表4_1和 4_2是并列的,因为每个服务的输入输出个数不一样,一张表无法解决)
具体的表是这样设计的
第一张表
[code="java"]
class CreateServices < ActiveRecord::Migration
def self.up
create_table :services do |t|
t.column :name, :string
t.column :user_id, :integer
t.column :updated_at, :datetime
t.column :created_at, :datetime
end
end
def self.down
drop_table :services
end
end
[/code]
第2张表
[code="java"]
class CreateSoapServices < ActiveRecord::Migration
def self.up
create_table :soap_services do |t|
t.column :name, :string
t.column :wsdl_location, :string
t.column :namespace, :string
t.column :description, :text
t.column :updated_at, :datetime
t.column :created_at, :datetime
end
end
def self.down
drop_table :soap_services
end
end
[/code]
第3张表
[code="java"]
class CreateSoapOperations < ActiveRecord::Migration
def self.up
create_table :soap_operations do |t|
t.column :name, :string
t.column :description, :text
t.column :soap_service_id, :integer
t.column :parameter_order, :string
t.column :parent_port_type, :string
t.column :soap_service_port_id, :integer
t.column :updated_at, :datetime
t.column :created_at, :datetime
end
end
def self.down
drop_table :soap_operations
end
end
[/code]
第4_1张表
[code="java"]
class CreateSoapInputs < ActiveRecord::Migration
def self.up
create_table :soap_inputs do |t|
t.column :name, :string
t.column :description, :text
t.column :soap_operation_id, :integer
t.column :computational_type, :string
t.column :computational_type_details, :text, :limit => 2.megabytes
t.column :min_occurs, :integer
t.column :max_occurs, :integer
t.column :updated_at, :datetime
t.column :created_at, :datetime
end
end
def self.down
drop_table :soap_inputs
end
end
[/code]
第4_2张表
[code="java"]
class CreateSoapOutputs < ActiveRecord::Migration
def self.up
create_table :soap_outputs do |t|
t.column :name, :string
t.column :description, :text
t.column :soap_operation_id, :integer
t.column :computational_type, :string
t.column :computational_type_details, :text, :limit => 2.megabytes
t.column :min_occurs, :integer
t.column :max_occurs, :integer
t.column :updated_at, :datetime
t.column :created_at, :datetime
end
end
def self.down
drop_table :soap_outputs
end
end
[/code]
提交的数据是在soap_services 的new页面中,如何能先将服务的名称存在第一张表里面,然后根据第二张表根据第一个表存储的id关联,同时能将数据存到其他相关的表格,麻烦了,刚刚接触这块,对数据库的知识也不是很懂!