db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/schema ojbtest-schema.xml
Date Wed, 12 Mar 2003 18:38:35 GMT
arminw      2003/03/12 10:38:35

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/broker ReferenceTest.java
               src/schema ojbtest-schema.xml
  Log:
  add new test case to demonstrate
  post "Interesting (failing)
  scenario of FKs/PKs in PB" on user-list
  
  Revision  Changes    Path
  1.53      +64 -0     db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- repository_junit.xml	12 Mar 2003 09:29:00 -0000	1.52
  +++ repository_junit.xml	12 Mar 2003 18:38:35 -0000	1.53
  @@ -3339,6 +3339,70 @@
       </class-descriptor>
   
       <class-descriptor
  +        class="org.apache.ojb.broker.ReferenceTest$RepositoryFK"
  +        table="REF_REPOSITORY_FK">
  +
  +        <field-descriptor
  +         name="repId"
  +         column="REP_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +         name="refId"
  +         column="REF_FK"
  +         primarykey="true"
  +         jdbc-type="INTEGER"
  +        />
  +
  +        <field-descriptor
  +         name="refAId"
  +         column="REFA_FK"
  +         primarykey="true"
  +         jdbc-type="INTEGER"
  +        />
  +
  +        <field-descriptor
  +         name="refBId"
  +         column="REFB_FK"
  +         primarykey="true"
  +         jdbc-type="INTEGER"
  +        />
  +
  +        <reference-descriptor
  +            name="ref"
  +            class-ref="org.apache.ojb.broker.ReferenceTest$Reference"
  +            proxy="false"
  +            auto-retrieve="true"
  +            auto-update="true"
  +            auto-delete="true">
  +                <foreignkey field-ref="refId"/>
  +        </reference-descriptor>
  +
  +        <reference-descriptor
  +            name="refA"
  +            class-ref="org.apache.ojb.broker.ReferenceTest$ReferenceA"
  +            proxy="false"
  +            auto-retrieve="true"
  +            auto-update="true"
  +            auto-delete="true">
  +                <foreignkey field-ref="refAId"/>
  +        </reference-descriptor>
  +
  +        <reference-descriptor
  +            name="refB"
  +            class-ref="org.apache.ojb.broker.ReferenceTest$ReferenceB"
  +            proxy="true"
  +            auto-retrieve="true"
  +            auto-update="true"
  +            auto-delete="true">
  +                <foreignkey field-ref="refBId"/>
  +        </reference-descriptor>
  +    </class-descriptor>
  +
  +    <class-descriptor
           class="org.apache.ojb.broker.ReferenceTest$Reference"
           table="REF_REFERENCE">
   
  
  
  
  1.3       +97 -1     db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java
  
  Index: ReferenceTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ReferenceTest.java	8 Mar 2003 21:48:32 -0000	1.2
  +++ ReferenceTest.java	12 Mar 2003 18:38:35 -0000	1.3
  @@ -154,6 +154,63 @@
           assertEquals("Wrong number of References", 0, result.size());
       }
   
  +    /**
  +     * This test does the same as the {@link #testRepositoryFKStore},
  +     * but the used mapping data differ.
  +     * {@link RepositoryFK} defines all the reference fields as
  +     * primary key in field-descriptors. Further on the used
  +     * database table declares the reference fields as PK too.
  +     * Based on a user post:
  +     * > The following fails to be stored by PersistenceBroker:
  +        >
  +        > I have a class ACL which has two primary keys: objectId and userFK, and
  +        > userFK is also a foreign key tied to a reference of type User. If I do
  +        this:
  +        >
  +        > persistentBroker.beginTransaction();
  +        > ACL acl = new ACL();
  +        > acl.setObjectId( 100 );
  +        > acl.setUser( currentUser );
  +        > persistentBroker.store(acl);
  +        > persistentBroker.commitTransaction();
  +        >
  +        > Acl will not be saved. The reason seems to be because in the storeToDb()
  +        > method of the PersistentBroker, there first comes an assertion of the
  +        > PrimaryKeys and afterwards comes the assignment of all the foreign keys.
  +        In
  +        > the scenario above the assertion of the primary keys will fail, because
  +        the
  +        > userFK has not been assigned yet, so we have an incomplete set of primary
  +        > keys. This does work with the ODMG layer, probably because of a different
  +        > sequence of events during the storing of the object.
  +        >
  +        > I wonder if there should be a check whether a primary key is shared by the
  +        > foreign key and allow that assignment before the assertion of the primary
  +        > keys is performed. Any ideas?
  +        >
  +        > Cheers,
  +        > --Bill.
  +     */
  +    public void testRepositoryFKStore()
  +    {
  +        String referenceNamePrefix = "testReferenceStore"+System.currentTimeMillis();
  +        RepositoryFK[] repository = prepareRepositoryFK(referenceNamePrefix);
  +
  +        broker.beginTransaction();
  +        broker.store(repository[0]);
  +        broker.store(repository[1]);
  +        broker.store(repository[2]);
  +        broker.commitTransaction();
  +
  +        Identity oid = new Identity(repository[0], broker);
  +        RepositoryFK repFK = (RepositoryFK) broker.getObjectByIdentity(oid);
  +
  +        assertNotNull("We should found a RepositoryFK object, but doesn't.", repFK);
  +        assertNotNull(repFK.getRef());
  +        assertNotNull(repFK.getRefA());
  +        assertNotNull(repFK.getRefB());
  +    }
  +
       private Repository[] prepareRepository(String referenceNamePrefix)
       {
           Reference[] ref = new Reference[]{
  @@ -187,7 +244,38 @@
           return new Repository[]{repository, repository2, repository3};
       }
   
  +    private RepositoryFK[] prepareRepositoryFK(String referenceNamePrefix)
  +    {
  +        Reference[] ref = new Reference[]{
  +            new Reference(referenceNamePrefix + "ref_1"),
  +            new Reference(referenceNamePrefix + "ref_2"),
  +            new Reference(referenceNamePrefix + "ref_3")};
  +        ReferenceA[] refA = new ReferenceA[]{
  +            new ReferenceA(referenceNamePrefix + "refA_1", "a1"),
  +            new ReferenceA(referenceNamePrefix + "refA_2", "a2"),
  +            new ReferenceA(referenceNamePrefix + "refA_3", "a3")};
  +        ReferenceB[] refB = new ReferenceB[]{
  +            new ReferenceB(referenceNamePrefix + "refB_1", "b1"),
  +            new ReferenceB(referenceNamePrefix + "refB_2", "b2"),
  +            new ReferenceB(referenceNamePrefix + "refB_3", "b3")};
  +
  +        RepositoryFK repository = new RepositoryFK();
  +        repository.setRef(ref[0]);
  +        repository.setRefA(refA[0]);
  +        repository.setRefB(refB[0]);
   
  +        RepositoryFK repository2 = new RepositoryFK();
  +        repository2.setRef(ref[1]);
  +        repository2.setRefA(refA[1]);
  +        repository2.setRefB(refB[1]);
  +
  +        RepositoryFK repository3 = new RepositoryFK();
  +        repository3.setRef(ref[2]);
  +        repository3.setRefA(refA[2]);
  +        repository3.setRefB(refB[2]);
  +
  +        return new RepositoryFK[]{repository, repository2, repository3};
  +    }
   
   
   
  @@ -250,6 +338,14 @@
           {
               this.repId = repId;
           }
  +    }
  +
  +    /**
  +     * Used for test case using FK on DB level
  +     */
  +    public static class RepositoryFK extends Repository
  +    {
  +
       }
   
       public static interface ReferenceIF
  
  
  
  1.29      +8 -0      db-ojb/src/schema/ojbtest-schema.xml
  
  Index: ojbtest-schema.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- ojbtest-schema.xml	12 Mar 2003 09:29:01 -0000	1.28
  +++ ojbtest-schema.xml	12 Mar 2003 18:38:35 -0000	1.29
  @@ -598,6 +598,14 @@
           <column name="NAME" type="VARCHAR" size="100"/>
       </table>
   
  +    <table name="REF_REPOSITORY_FK">
  +        <column name="REP_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="REF_FK" type="INTEGER" primaryKey="true"/>
  +        <column name="REFA_FK" type="INTEGER" primaryKey="true"/>
  +        <column name="REFB_FK" type="INTEGER" primaryKey="true"/>
  +        <column name="NAME" type="VARCHAR" size="100"/>
  +    </table>
  +
       <table name="REF_REFERENCE">
           <column name="REF_ID" required="true" primaryKey="true" type="INTEGER"/>
           <column name="NAME" type="VARCHAR" size="100"/>
  
  
  

Mime
View raw message