/******************schema xsd*****************************/
<xsd:complexType name="Service">
<xsd:sequence>
<xsd:element name="serviceId" type="xsd:decimal"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="available" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" name="roles"
type="this:Role"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Role">
<xsd:sequence>
<xsd:element name="roleId" type="xsd:decimal"/>
<xsd:element name="serviceId" type="xsd:decimal"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="available" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
/**************configuration file ********************/
<Command name="qryAllServices" SQL="select CCP_SERVICE.SERVICE_ID,
CCP_SERVICE.NAME,CCP_SERVICE.AVAILABLE,CCP_ROLE.ROLE_ID,CCP_ROLE.NAME,CCP_ROLE.AVAILABLE
from CCP_SERVICE INNER JOIN CCP_ROLE on
CCP_SERVICE.SERVICE_ID=CCP_ROLE.SERVICE_ID" kind="Select">
<ResultDescriptor columnName="SERVICE_ID" tableName="CCP_SERVICE"
columnType="commonj.sdo.Decimal"/>
<ResultDescriptor columnName="NAME" tableName="CCP_SERVICE"
columnType="commonj.sdo.String"/>
<ResultDescriptor columnName="AVAILABLE" tableName="CCP_SERVICE"
columnType="commonj.sdo.String"/>
<ResultDescriptor columnName="ROLE_ID" tableName="CCP_ROLE"
columnType="commonj.sdo.Decimal"/>
<ResultDescriptor columnName="NAME" tableName="CCP_ROLE" columnType="
commonj.sdo.String"/>
<ResultDescriptor columnName="AVAILABLE" tableName="CCP_ROLE"
columnType="commonj.sdo.String"/>
</Command>
<Table tableName="CCP_SERVICE" typeName="Service">
<Column columnName="SERVICE_ID" propertyName="serviceId"
primaryKey="true" />
<Column columnName="NAME" propertyName="name"/>
<Column columnName="AVAILABLE"
propertyName="available"/>
</Table>
<Table tableName="CCP_ROLE" typeName="Role">
<Column columnName="ROLE_ID" propertyName="roleId"
primaryKey="true"/>
<Column columnName="SERVICE_ID" propertyName="serviceId"/>
<Column columnName="NAME" propertyName="name"/>
<Column columnName="AVAILABLE"
propertyName="available"/>
</Table>
/***************************java src code ****************************/
Connection conn=dataSource.getConnection();
conn.setAutoCommit(false);
DAS das=DAS.FACTORY.createDAS(new
ClassPathResource(schemaConfig).getInputStream(),conn);
Command command=das.getCommand(commandName);
if(param!=null) command.setParameter(1,param);
DataObject root=command.executeQuery();
List services=root.getList("Service");
System.out.println(services.size());
for(int i=0;i<services.size();i++){
Service obj=(Service)services.get(i);
System.out.println(obj.getServiceId());
List roles=obj.getRoles();
System.out.println("role size"+roles.size());
for(int j=0;j<roles.size();j++){
Role role=(Role)roles.get(i);
System.out.println(role.getName());
}
//here is add a new role into CCP_ROLE table
Role newRole=UserFactory.INSTANCE.createRole();
newRole.setRoleId(new BigDecimal(1));
newRole.setName("test2322");
newRole.setAvailable("1");
newRole.setServiceId(new BigDecimal(14));
roles.add(newRole);
}
das.applyChanges(root);
**********************************************************************
Question: CCP_SERVICE and CCP_ROLE is one to many relationship by SERVICE_ID
column. when I need to
add a new role of a service, tuscany should add a new role
record into CCP_ROLE, however, it produces
a SQL:
update CCP_SERVICE set roles = ? where SERVICE_ID = ?
My god!!!