Great ; )
Adriano Crestani
On 10/24/07, Amita Vadhavkar <[EMAIL PROTECTED]> wrote:
>
> Thanks Adriano, as you have mentioned, there is a mapping available for
> Table<->Type and Column<->Property in
> <Table> element in DAS Config. So there is no need to duplicate it in
> <Relationship> and <KeyPair> and it
> can be referenced from <Table> when available. The logic used to fix the
> issue, such that, in case a <Table> entry is
> found in <Config>, it is used for the above mapping, else default behavior
> (typeName=tableName and propName=colName)
> is assumed.
>
> Based on this, I have modified:-
> 1) MappingWrapper.getRelationshipsByChildTable(name - SDO prop name) and
> 2) DatabaseObject.initialize() and get(parameter - SDO prop name)
>
> Also, added 2 test cases to
> RelationshipTests - testRelationshipTypesAndProperties() and
> testRelationshipWithProgrammaticConfig()
>
> The relevant JIRA is TUSCANY-1865.
>
> Regards,
> Amita
>
> On 10/23/07, Adriano Crestani <[EMAIL PROTECTED]> wrote:
> >
> > Hi Amita,
> >
> > On DAS C++ when a relationship is found, for example, between table
> A and
> > table B, it looks for their Table object in the Config, then, it it's
> > defined on the Config their type name can be retrieved using
> > tableA.getTypeName(). The same happens for the Column. It only assumes
> the
> > type name to be the table name if it's not defined on the Config.
> >
> > If you are saying that the methods below are always assuming the type
> name
> > being the table name, so I think they should be corrected.
> >
> > MappingWrapper-
> > getRelationshipByReference()
> > getRelationshipsByChildTable()
> >
> > DatabaseObject-
> > initialize()
> >
> > Regards,
> > Adriano Crestani
> >
> > On 10/23/07, Amita Vadhavkar <[EMAIL PROTECTED]> wrote:
> > >
> > > 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
> > >
> >
>