gdamour     2005/05/17 11:49:38

  Modified:    
modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone
                        BBean.java BLocal.java BLocalHome.java
                        OneToOneCompoundPKTest.java OneToOneTest.java
  Log:

  Support mapping of CMP fields to foreign key columns.
  
  When such a CMP field is fetched, the engine actually sources the value
  from the CMR field defining the foreign key column. In other words, the
  values of such CMP fields always mirror the values of the associated CMR
  field.
  
  Also, the implementation does not allow for the update of such CMP fields
  as its breaks the CMR relationship contract.
  
  Revision  Changes    Path
  1.2       +19 -2     
openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/BBean.java
  
  Index: BBean.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/BBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BBean.java        10 Nov 2004 01:35:12 -0000      1.1
  +++ BBean.java        17 May 2005 15:49:38 -0000      1.2
  @@ -52,6 +52,8 @@
   import javax.ejb.EntityContext;

   import javax.ejb.RemoveException;

   

  +import org.openejb.deployment.entity.cmp.cmr.CompoundPK;

  +

   /**

    *

    * @version $Revision$ $Date$

  @@ -66,7 +68,13 @@
   

       public abstract String getField2();

       public abstract void setField2(String field2);

  -    

  +

  +    public abstract Integer getField3();

  +    public abstract void setField3(Integer field3);

  +

  +    public abstract String getField4();

  +    public abstract void setField4(String field4);

  +

       // CMR

       public abstract ALocal getA();

       public abstract void setA(ALocal b);

  @@ -77,6 +85,15 @@
       }

   

       public void ejbPostCreate(Integer field1) {

  +    }

  +

  +    public CompoundPK ejbCreate(CompoundPK primaryKey)  throws 
CreateException {

  +        setField1(primaryKey.field1);

  +        setField2(primaryKey.field2);

  +        return null;

  +    }

  +

  +    public void ejbPostCreate(CompoundPK primaryKey) {

       }

   

       public void setEntityContext(EntityContext ctx) {

  
  
  
  1.2       +8 -2      
openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/BLocal.java
  
  Index: BLocal.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/BLocal.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BLocal.java       10 Nov 2004 01:35:12 -0000      1.1
  +++ BLocal.java       17 May 2005 15:49:38 -0000      1.2
  @@ -61,7 +61,13 @@
   

       public String getField2();

       public void setField2(String field2);

  -    

  +

  +    public Integer getField3();

  +    public void setField3(Integer field3);

  +

  +    public String getField4();

  +    public void setField4(String field4);

  +

       // CMR

       public ALocal getA();

       public void setA(ALocal a);

  
  
  
  1.2       +5 -2      
openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/BLocalHome.java
  
  Index: BLocalHome.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/BLocalHome.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BLocalHome.java   10 Nov 2004 01:35:12 -0000      1.1
  +++ BLocalHome.java   17 May 2005 15:49:38 -0000      1.2
  @@ -51,6 +51,8 @@
   import javax.ejb.EJBLocalHome;

   import javax.ejb.FinderException;

   

  +import org.openejb.deployment.entity.cmp.cmr.CompoundPK;

  +

   

   /**

    *

  @@ -60,8 +62,9 @@
   

       // Create

       public BLocal create(Integer field1) throws CreateException;

  +    public BLocal create(CompoundPK primaryKey) throws CreateException;

   

       // Finder

       public BLocal findByPrimaryKey(Integer primaryKey) throws 
FinderException;

  -

  +    public BLocal findByPrimaryKey(CompoundPK primaryKey) throws 
FinderException;

   }

  
  
  
  1.4       +32 -7     
openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/OneToOneCompoundPKTest.java
  
  Index: OneToOneCompoundPKTest.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/OneToOneCompoundPKTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- OneToOneCompoundPKTest.java       1 Mar 2005 23:34:39 -0000       1.3
  +++ OneToOneCompoundPKTest.java       17 May 2005 15:49:38 -0000      1.4
  @@ -53,6 +53,8 @@
   import java.sql.SQLException;

   import java.sql.Statement;

   

  +import javax.ejb.EJBException;

  +

   import org.apache.geronimo.transaction.context.TransactionContext;

   import org.openejb.deployment.entity.cmp.cmr.AbstractCMRTest;

   import org.openejb.deployment.entity.cmp.cmr.CompoundPK;

  @@ -79,7 +81,7 @@
   

       public void testBGetAExistingAB() throws Exception {

           TransactionContext ctx = newTransactionContext();

  -        BLocal b = bhome.findByPrimaryKey(new Integer(11));

  +        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), 
"value11"));

           ALocal a = b.getA();

           assertNotNull(a);

           assertEquals(new Integer(1), a.getField1());

  @@ -117,7 +119,7 @@
        */

       public void XtestBSetADropExisting() throws Exception {

           TransactionContext ctx = newTransactionContext();

  -        BLocal b = bhome.findByPrimaryKey(new Integer(11));

  +        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), 
"value11"));

           b.setA(null);

           ctx.commit();

   

  @@ -129,8 +131,7 @@
   

           TransactionContext ctx = newTransactionContext();

           a = ahome.create(pkA);

  -        b = bhome.create(new Integer(22));

  -        b.setField2("value22");

  +        b = bhome.create(new CompoundPK(new Integer(22), "value22"));

           return ctx;

       }

   

  @@ -172,7 +173,7 @@
   

           TransactionContext ctx = newTransactionContext();

           a = ahome.create(pkA);

  -        b = bhome.findByPrimaryKey(new Integer(11));

  +        b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), 
"value11"));

           return ctx;

       }

       

  @@ -288,7 +289,7 @@
   

       public void testCascadeDelete() throws Exception {

           TransactionContext ctx = newTransactionContext();

  -        BLocal b = bhome.findByPrimaryKey(new Integer(11));

  +        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), 
"value11"));

           b.remove();

           ctx.commit();

   

  @@ -302,6 +303,30 @@
           c.close();

       }

       

  +    public void testCMPMappedToForeignKeyColumn() throws Exception {

  +        TransactionContext ctx = newTransactionContext();

  +        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), 
"value11"));

  +

  +        Integer field3 = b.getField3();

  +        assertEquals(((CompoundPK) b.getA().getPrimaryKey()).field1, field3);

  +

  +        String field4 = b.getField4();

  +        assertEquals(((CompoundPK) b.getA().getPrimaryKey()).field2, field4);

  +        ctx.commit();

  +    }

  +    

  +    public void testSetCMPMappedToForeignKeyColumn() throws Exception {

  +        TransactionContext ctx = newTransactionContext();

  +        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), 
"value11"));

  +

  +        try {

  +            b.setField3(new Integer(13));

  +            fail("Cannot set the value of a CMP field mapped to a foreign 
key column.");

  +        } catch (EJBException e) {

  +        }

  +        ctx.commit();

  +    }

  +

       protected void setUp() throws Exception {

           super.setUp();

           

  
  
  
  1.4       +24 -1     
openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/OneToOneTest.java
  
  Index: OneToOneTest.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/OneToOneTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- OneToOneTest.java 1 Mar 2005 23:34:39 -0000       1.3
  +++ OneToOneTest.java 17 May 2005 15:49:38 -0000      1.4
  @@ -53,6 +53,8 @@
   import java.sql.SQLException;

   import java.sql.Statement;

   

  +import javax.ejb.EJBException;

  +

   import org.apache.geronimo.transaction.context.TransactionContext;

   import org.openejb.deployment.entity.cmp.cmr.AbstractCMRTest;

   

  @@ -303,6 +305,27 @@
           rs.close();

           s.close();

           c.close();

  +    }

  +    

  +    public void testCMPMappedToForeignKeyColumn() throws Exception {

  +        TransactionContext ctx = newTransactionContext();

  +        BLocal b = bhome.findByPrimaryKey(new Integer(11));

  +

  +        Integer field3 = b.getField3();

  +        assertEquals(b.getA().getPrimaryKey(), field3);

  +        ctx.commit();

  +    }

  +

  +    public void testSetCMPMappedToForeignKeyColumn() throws Exception {

  +        TransactionContext ctx = newTransactionContext();

  +        BLocal b = bhome.findByPrimaryKey(new Integer(11));

  +

  +        try {

  +            b.setField3(new Integer(13));

  +            fail("Cannot set the value of a CMP field mapped to a foreign 
key column.");

  +        } catch (EJBException e) {

  +        }

  +        ctx.commit();

       }

   

       protected void setUp() throws Exception {

  
  
  

Reply via email to