In RDB DAS, the config model has relationship definition as below:-
   <xsd:complexType name="Relationship">
      <xsd:sequence>
         <xsd:element  maxOccurs="unbounded" minOccurs="0" name="KeyPair"
            type="config:KeyPair"/>
      </xsd:sequence>
      <xsd:attribute name="name" type="xsd:string"/>
      <xsd:attribute name="primaryKeyTable" type="xsd:string"/>
      <xsd:attribute name="foreignKeyTable" type="xsd:string"/>
      <xsd:attribute name="many" type="xsd:boolean"/>
      <xsd:attribute name="keyRestricted" type="xsd:boolean"/>
   </xsd:complexType>


   <xsd:complexType name="KeyPair">
      <xsd:attribute name="primaryKeyColumn" type="xsd:string"/>
      <xsd:attribute name="foreignKeyColumn" type="xsd:string"/>
   </xsd:complexType>

So, it does not have a place to store Table<->Type and Column<->Property
mapping.

Also some methods below show that,they are always assuming TableName same as
TypeName and ColumnName same as PropertyName.
e.g.

MappingWrapper-
getRelationshipByReference()
getRelationshipsByChildTable()

DatabaseObject-
initialize()

Thus, in case the das config xml has defined different table/type and
column/property names and the tables have relationship,
the CUD operations based on relationship is not succeeding.

e.g. When a das config has -
_________________________________________________________________________
    <Table tableName="CUSTOMER" typeName="Customer">
        <Column columnName="ID" propertyName="ID" primaryKey="true"/>
        <Column columnName="LASTNAME" propertyName="lastName"/>
        <Column columnName="ADDRESS" propertyName="address"/>
    </Table>

    <Table tableName="ANORDER" typeName="AnOrder">
        <Column columnName="ID" propertyName="OrderId" primaryKey="true"/>
    </Table>

    <Relationship name="orders" primaryKeyTable="CUSTOMER"
        foreignKeyTable="ANORDER" many="true">
        <KeyPair primaryKeyColumn="ID" foreignKeyColumn="CUSTOMER_ID"/>
    </Relationship>
_________________________________________________________________________
The below test case results in AnOrder record in DB with CUSTOMER_ID null,
as the relationship is not properly picked.
_________________________________________________________________________________________________________
    public void testRelationshipTypesAndProperties1() throws Exception {
        //existing records
        DAS das = DAS.FACTORY.createDAS(getConfig("
CustomersOrdersConfigProps.xml"), getConnection());
        Command cmd = das.getCommand("customer and orders");
        cmd.setParameter("ID", new Integer(1));
        DataObject root = cmd.executeQuery();
        DataObject firstCustomer = root.getDataObject("Customer[ID=1]");
        System.out.println(XMLHelper.INSTANCE.save(firstCustomer,
"beforeInsertInDG", "beforeInsertInDG"));

        DataObject newOrder = root.createDataObject("AnOrder");
        newOrder.setInt("OrderId", 100);
        newOrder.setString("PRODUCT", "MyProd");

        firstCustomer.getList("orders").add(newOrder);

        System.out.println(XMLHelper.INSTANCE.save(firstCustomer,
"afterInsertInDG", "afterInsertInDG"));
        das.applyChanges(root);

        root = cmd.executeQuery();
        firstCustomer = root.getDataObject("Customer[ID=1]");
        System.out.println(XMLHelper.INSTANCE.save(firstCustomer, "fromDB",
"fromDB"));
    }
___________________________________________________________________________________________________________

Solution:
   <xsd:complexType name="Relationship">
      <xsd:sequence>
         <xsd:element  maxOccurs="unbounded" minOccurs="0" name="KeyPair"
            type="config:KeyPair"/>
      </xsd:sequence>
      <xsd:attribute name="name" type="xsd:string"/>
      <xsd:attribute name="primaryKeyTable" type="xsd:string"/>
      <xsd:attribute name="primaryKeyType" type="xsd:string"/>
      <xsd:attribute name="foreignKeyTable" type="xsd:string"/>
      <xsd:attribute name="foreignKeyType" type="xsd:string"/>
      <xsd:attribute name="many" type="xsd:boolean"/>
      <xsd:attribute name="keyRestricted" type="xsd:boolean"/>
   </xsd:complexType>

   <xsd:complexType name="KeyPair">
         <xsd:attribute name="primaryKeyColumn" type="xsd:string"/>
         <xsd:attribute name="primaryKeyColProperty" type="xsd:string"/>
         <xsd:attribute name="foreignKeyColumn" type="xsd:string"/>
         <xsd:attribute name="foreignKeyColProperty" type="xsd:string"/>
   </xsd:complexType>

and all relevant changes in code to support this config model.

Suggestions?

Regards,
Amita

Reply via email to