djencks 2004/10/28 17:21:30
Added: modules/core/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone
ABean.java ALocal.java ALocalHome.java BBean.java
BLocal.java BLocalHome.java
OneToOneCompoundPKTest.java OneToOneTest.java
Log:
Move the deployment classes ***ContainerBuilder to deployment. Drag most ofthe
testsuite along with them. Don't you wish we were on svn?
Revision Changes Path
1.1
openejb/modules/core/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/ABean.java
Index: ABean.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment.entity.cmp.cmr.onetoone;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import org.openejb.deployment.entity.cmp.cmr.CompoundPK;
/**
*
* @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:30 $
*/
public abstract class ABean implements EntityBean {
private EntityContext context;
// CMP
public abstract Integer getField1();
public abstract void setField1(Integer field1);
public abstract String getField2();
public abstract void setField2(String field2);
// CMR
public abstract BLocal getB();
public abstract void setB(BLocal b);
public Integer ejbCreate(Integer field1) throws CreateException {
setField1(field1);
return null;
}
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) {
context = ctx;
}
public void unsetEntityContext() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void ejbLoad() {
}
public void ejbStore() {
}
public void ejbRemove() throws RemoveException {
}
}
1.1
openejb/modules/core/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/ALocal.java
Index: ALocal.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment.entity.cmp.cmr.onetoone;
import javax.ejb.EJBLocalObject;
/**
*
* @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:30 $
*/
public interface ALocal extends EJBLocalObject {
// CMP
public Integer getField1();
public void setField1(Integer field1);
public String getField2();
public void setField2(String field2);
// CMR
public BLocal getB();
public void setB(BLocal b);
}
1.1
openejb/modules/core/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/ALocalHome.java
Index: ALocalHome.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment.entity.cmp.cmr.onetoone;
import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
import javax.ejb.FinderException;
import org.openejb.deployment.entity.cmp.cmr.CompoundPK;
/**
*
* @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:30 $
*/
public interface ALocalHome extends EJBLocalHome {
// Create
public ALocal create(Integer field1) throws CreateException;
public ALocal create(CompoundPK primaryKey) throws CreateException;
// Finder
public ALocal findByPrimaryKey(Integer primaryKey) throws FinderException;
public ALocal findByPrimaryKey(CompoundPK primaryKey) throws FinderException;
}
1.1
openejb/modules/core/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/BBean.java
Index: BBean.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment.entity.cmp.cmr.onetoone;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
/**
*
* @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:30 $
*/
public abstract class BBean implements EntityBean {
private EntityContext context;
// CMP
public abstract Integer getField1();
public abstract void setField1(Integer field1);
public abstract String getField2();
public abstract void setField2(String field2);
// CMR
public abstract ALocal getA();
public abstract void setA(ALocal b);
public Integer ejbCreate(Integer field1) throws CreateException {
setField1(field1);
return null;
}
public void ejbPostCreate(Integer field1) {
}
public void setEntityContext(EntityContext ctx) {
context = ctx;
}
public void unsetEntityContext() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void ejbLoad() {
}
public void ejbStore() {
}
public void ejbRemove() throws RemoveException {
}
}
1.1
openejb/modules/core/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/BLocal.java
Index: BLocal.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment.entity.cmp.cmr.onetoone;
import javax.ejb.EJBLocalObject;
/**
*
* @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:30 $
*/
public interface BLocal extends EJBLocalObject {
// CMP
public Integer getField1();
public void setField1(Integer field1);
public String getField2();
public void setField2(String field2);
// CMR
public ALocal getA();
public void setA(ALocal a);
}
1.1
openejb/modules/core/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/BLocalHome.java
Index: BLocalHome.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment.entity.cmp.cmr.onetoone;
import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
import javax.ejb.FinderException;
/**
*
* @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:30 $
*/
public interface BLocalHome extends EJBLocalHome {
// Create
public BLocal create(Integer field1) throws CreateException;
// Finder
public BLocal findByPrimaryKey(Integer primaryKey) throws FinderException;
}
1.1
openejb/modules/core/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/OneToOneCompoundPKTest.java
Index: OneToOneCompoundPKTest.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment.entity.cmp.cmr.onetoone;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.geronimo.transaction.context.ContainerTransactionContext;
import org.openejb.deployment.entity.cmp.cmr.AbstractCMRTest;
import org.openejb.deployment.entity.cmp.cmr.CompoundPK;
/**
*
* @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:30 $
*/
public class OneToOneCompoundPKTest extends AbstractCMRTest {
private ALocalHome ahome;
private ALocal a;
private BLocalHome bhome;
private BLocal b;
public void testAGetBExistingAB() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
ALocal a = ahome.findByPrimaryKey(new CompoundPK(new Integer(1), "value1"));
BLocal b = a.getB();
assertNotNull(b);
assertEquals(new Integer(11), b.getField1());
assertEquals("value11", b.getField2());
ctx.commit();
}
public void testBGetAExistingAB() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
BLocal b = bhome.findByPrimaryKey(new Integer(11));
ALocal a = b.getA();
assertNotNull(a);
assertEquals(new Integer(1), a.getField1());
assertEquals("value1", a.getField2());
ctx.commit();
}
private void assertStateDropExisting() throws Exception {
Connection c = ds.getConnection();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM B WHERE fka1 = 1 AND
fka2 = 'value1'");
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
rs.close();
s.close();
c.close();
}
/**
* TODO Disabled due to an Axion bug. It has been tested with another
* DB DataSource successfully.
*/
public void XtestASetBDropExisting() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
ALocal a = ahome.findByPrimaryKey(new CompoundPK(new Integer(1), "value1"));
a.setB(null);
ctx.commit();
assertStateDropExisting();
}
/**
* TODO Disabled due to an Axion bug. It has been tested with another
* DB DataSource successfully.
*/
public void XtestBSetADropExisting() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
BLocal b = bhome.findByPrimaryKey(new Integer(11));
b.setA(null);
ctx.commit();
assertStateDropExisting();
}
private ContainerTransactionContext prepareNewAB() throws Exception {
CompoundPK pkA = new CompoundPK(new Integer(2), "value2");
ContainerTransactionContext ctx = newTransactionContext();
a = ahome.create(pkA);
b = bhome.create(new Integer(22));
b.setField2("value22");
return ctx;
}
private void assertStateNewAB() throws Exception {
Connection c = ds.getConnection();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM A WHERE a1 = 2 AND a2 =
'value2'");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
rs.close();
rs = s.executeQuery("SELECT b1, b2 FROM B WHERE fka1 = 2 AND fka2 =
'value2'");
assertTrue(rs.next());
assertEquals(22, rs.getInt(1));
assertEquals("value22", rs.getString(2));
rs.close();
s.close();
c.close();
}
public void testASetBNewAB() throws Exception {
ContainerTransactionContext ctx = prepareNewAB();
a.setB(b);
ctx.commit();
assertStateNewAB();
}
public void testBSetANewAB() throws Exception {
ContainerTransactionContext ctx = prepareNewAB();
b.setA(a);
ctx.commit();
assertStateNewAB();
}
private ContainerTransactionContext prepareExistingBNewA() throws Exception {
CompoundPK pkA = new CompoundPK(new Integer(2), "value2");
ContainerTransactionContext ctx = newTransactionContext();
a = ahome.create(pkA);
b = bhome.findByPrimaryKey(new Integer(11));
return ctx;
}
private void assertStateExistingBNewA() throws Exception {
Connection c = ds.getConnection();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM A WHERE a1 = 2 AND a2 =
'value2'");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
rs.close();
rs = s.executeQuery("SELECT b1, b2 FROM B WHERE fka1 = 2 AND fka2 =
'value2'");
assertTrue(rs.next());
assertEquals(11, rs.getInt(1));
assertEquals("value11", rs.getString(2));
rs.close();
s.close();
c.close();
}
public void testASetBExistingBNewA() throws Exception {
ContainerTransactionContext ctx = prepareExistingBNewA();
a.setB(b);
ctx.commit();
assertStateExistingBNewA();
}
public void testBSetAExistingBNewA() throws Exception {
ContainerTransactionContext ctx = prepareExistingBNewA();
b.setA(a);
ctx.commit();
assertStateExistingBNewA();
}
private ContainerTransactionContext prepareExistingANewB() throws Exception {
CompoundPK pkA = new CompoundPK(new Integer(1), "value1");
ContainerTransactionContext ctx = newTransactionContext();
a = ahome.findByPrimaryKey(pkA);
b = bhome.create(new Integer(22));
b.setField2("value22");
return ctx;
}
private void assertStateExistingANewB() throws Exception {
Connection c = ds.getConnection();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM B WHERE fka1 = 1 AND
fka2 = 'value1'");
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
rs.close();
rs = s.executeQuery("SELECT b1, b2 FROM B WHERE fka1 = 1 AND fka2 =
'value1'");
assertTrue(rs.next());
assertEquals(22, rs.getInt(1));
assertEquals("value22", rs.getString(2));
rs.close();
s.close();
c.close();
}
/**
* TODO Disabled due to an Axion bug. It has been tested with another
* DB DataSource successfully.
* @see OneToOneTest for more details.
*/
public void XtestASetBExistingANewB() throws Exception {
ContainerTransactionContext ctx = prepareExistingANewB();
a.setB(b);
ctx.commit();
assertStateExistingANewB();
}
/**
* TODO Disabled due to an Axion bug. It has been tested with another
* DB DataSource successfully.
* @see OneToOneTest for more details.
*/
public void XtestBSetAExistingANewB() throws Exception {
ContainerTransactionContext ctx = prepareExistingANewB();
b.setA(a);
ctx.commit();
assertStateExistingANewB();
}
protected void setUp() throws Exception {
super.setUp();
ahome = (ALocalHome) super.ahome;
bhome = (BLocalHome) super.bhome;
}
protected void buildDBSchema(Connection c) throws Exception {
Statement s = c.createStatement();
try {
s.execute("DROP TABLE A");
} catch (SQLException e) {
// ignore
}
try {
s.execute("DROP TABLE B");
} catch (SQLException e) {
// ignore
}
s.execute("CREATE TABLE A(A1 INTEGER, A2 VARCHAR(50))");
s.execute("CREATE TABLE B(B1 INTEGER, B2 VARCHAR(50), FKA1 INTEGER, FKA2
VARCHAR(50))");
s.execute("INSERT INTO A(A1, A2) VALUES(1, 'value1')");
s.execute("INSERT INTO B(B1, B2, FKA1, FKA2) VALUES(11, 'value11', 1,
'value1')");
s.close();
c.close();
}
protected String getEjbJarDD() {
return "src/test-cmp/onetoone/compoundpk/ejb-jar.xml";
}
protected String getOpenEjbJarDD() {
return "src/test-cmp/onetoone/compoundpk/openejb-jar.xml";
}
protected EJBClass getA() {
return new EJBClass(ABean.class, ALocalHome.class, ALocal.class);
}
protected EJBClass getB() {
return new EJBClass(BBean.class, BLocalHome.class, BLocal.class);
}
}
1.1
openejb/modules/core/src/test/org/openejb/deployment/entity/cmp/cmr/onetoone/OneToOneTest.java
Index: OneToOneTest.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment.entity.cmp.cmr.onetoone;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.geronimo.transaction.context.ContainerTransactionContext;
import org.openejb.deployment.entity.cmp.cmr.AbstractCMRTest;
/**
*
* @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:30 $
*/
public class OneToOneTest extends AbstractCMRTest {
private ALocalHome ahome;
private ALocal a;
private BLocalHome bhome;
private BLocal b;
public void testAGetBExistingAB() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
ALocal a = ahome.findByPrimaryKey(new Integer(1));
BLocal b = a.getB();
assertNotNull(b);
assertEquals(new Integer(11), b.getField1());
assertEquals("value11", b.getField2());
ctx.commit();
}
public void testBGetAExistingAB() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
BLocal b = bhome.findByPrimaryKey(new Integer(11));
ALocal a = b.getA();
assertNotNull(a);
assertEquals(new Integer(1), a.getField1());
assertEquals("value1", a.getField2());
ctx.commit();
}
private void assertStateDropExisting() throws Exception {
Connection c = ds.getConnection();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM B WHERE fka1 = 1");
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
rs.close();
s.close();
c.close();
}
/**
* TODO Disabled due to an Axion bug. It has been tested with another
* DB DataSource successfully.
*/
public void XtestASetBDropExisting() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
ALocal a = ahome.findByPrimaryKey(new Integer(1));
a.setB(null);
ctx.commit();
assertStateDropExisting();
}
/**
* TODO Disabled due to an Axion bug. It has been tested with another
* DB DataSource successfully.
*/
public void XtestBSetADropExisting() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
BLocal b = bhome.findByPrimaryKey(new Integer(11));
b.setA(null);
ctx.commit();
assertStateDropExisting();
}
private ContainerTransactionContext prepareNewAB() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
a = ahome.create(new Integer(2));
a.setField2("value2");
b = bhome.create(new Integer(22));
b.setField2("value22");
return ctx;
}
private void assertStateNewAB() throws Exception {
Connection c = ds.getConnection();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT a2 FROM A WHERE a1 = 2");
assertTrue(rs.next());
assertEquals("value2", rs.getString(1));
rs.close();
rs = s.executeQuery("SELECT b1, b2 FROM B WHERE fka1 = 2");
assertTrue(rs.next());
assertEquals(22, rs.getInt(1));
assertEquals("value22", rs.getString(2));
rs.close();
s.close();
c.close();
}
public void testASetBNewAB() throws Exception {
ContainerTransactionContext ctx = prepareNewAB();
a.setB(b);
ctx.commit();
assertStateNewAB();
}
public void testBSetANewAB() throws Exception {
ContainerTransactionContext ctx = prepareNewAB();
b.setA(a);
ctx.commit();
assertStateNewAB();
}
private ContainerTransactionContext prepareExistingBNewA() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
a = ahome.create(new Integer(2));
a.setField2("value2");
b = bhome.findByPrimaryKey(new Integer(11));
return ctx;
}
private void assertStateExistingBNewA() throws Exception {
Connection c = ds.getConnection();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT a2 FROM A WHERE a1 = 2");
assertTrue(rs.next());
assertEquals("value2", rs.getString(1));
rs.close();
rs = s.executeQuery("SELECT b1, b2 FROM B WHERE fka1 = 2");
assertTrue(rs.next());
assertEquals(11, rs.getInt(1));
assertEquals("value11", rs.getString(2));
rs.close();
s.close();
c.close();
}
public void testASetBExistingBNewA() throws Exception {
ContainerTransactionContext ctx = prepareExistingBNewA();
a.setB(b);
ctx.commit();
assertStateExistingBNewA();
}
public void testBSetAExistingBNewA() throws Exception {
ContainerTransactionContext ctx = prepareExistingBNewA();
b.setA(a);
ctx.commit();
assertStateExistingBNewA();
}
private ContainerTransactionContext prepareExistingANewB() throws Exception {
ContainerTransactionContext ctx = newTransactionContext();
a = ahome.findByPrimaryKey(new Integer(1));
b = bhome.create(new Integer(22));
b.setField2("value22");
return ctx;
}
private void assertStateExistingANewB() throws Exception {
Connection c = ds.getConnection();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM B WHERE fka1 = 1");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
rs.close();
rs = s.executeQuery("SELECT b1, b2 FROM B WHERE fka1 = 1");
assertTrue(rs.next());
assertEquals(22, rs.getInt(1));
assertEquals("value22", rs.getString(2));
rs.close();
s.close();
c.close();
}
/**
* TODO Disabled due to an Axion bug. It has been tested with another
* DB DataSource successfully.
*/
public void XtestASetBExistingANewB() throws Exception {
// The following PrepareStatement does not set to null fka
// PreparedStatement ps = null;
// ps = c.prepareStatement("UPDATE B SET value = CASE WHEN ? THEN ? ELSE value
END, fka = CASE WHEN ? THEN ? ELSE fka END WHERE b1 = ?");
// ps.setBoolean(1, false);
// ps.setString(2, "");
// ps.setBoolean(3, true);
// ps.setNull(4);
// ps.setInt(5, 1);
// ps.execute();
ContainerTransactionContext ctx = prepareExistingANewB();
a.setB(b);
ctx.commit();
assertStateExistingANewB();
}
/**
* TODO Disabled due to an Axion bug. It has been tested with another
* DB DataSource successfully.
*/
public void XtestBSetAExistingANewB() throws Exception {
ContainerTransactionContext ctx = prepareExistingANewB();
b.setA(a);
ctx.commit();
assertStateExistingANewB();
}
protected void setUp() throws Exception {
super.setUp();
ahome = (ALocalHome) super.ahome;
bhome = (BLocalHome) super.bhome;
}
protected void buildDBSchema(Connection c) throws Exception {
Statement s = c.createStatement();
try {
s.execute("DROP TABLE A");
} catch (SQLException e) {
// ignore
}
try {
s.execute("DROP TABLE B");
} catch (SQLException e) {
// ignore
}
s.execute("CREATE TABLE A(A1 INTEGER, A2 VARCHAR(50))");
s.execute("CREATE TABLE B(B1 INTEGER, B2 VARCHAR(50), FKA1 INTEGER)");
s.execute("INSERT INTO A(A1, A2) VALUES(1, 'value1')");
s.execute("INSERT INTO B(B1, B2, FKA1) VALUES(11, 'value11', 1)");
s.close();
c.close();
}
protected String getEjbJarDD() {
return "src/test-cmp/onetoone/simplepk/ejb-jar.xml";
}
protected String getOpenEjbJarDD() {
return "src/test-cmp/onetoone/simplepk/openejb-jar.xml";
}
protected EJBClass getA() {
return new EJBClass(ABean.class, ALocalHome.class, ALocal.class);
}
protected EJBClass getB() {
return new EJBClass(BBean.class, BLocalHome.class, BLocal.class);
}
}