cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1397163 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java
Date Thu, 11 Oct 2012 17:01:05 GMT
Author: aadamchik
Date: Thu Oct 11 17:01:04 2012
New Revision: 1397163

URL: http://svn.apache.org/viewvc?rev=1397163&view=rev
Log:
CAY-1746 Two InsertBatchQueries generated for a single DbEntity insert when this DbEntity
has a flattened attribute and a flattened relationship

a test without subclass attribute ... this works

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java?rev=1397163&r1=1397162&r2=1397163&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java
Thu Oct 11 17:01:04 2012
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.cayenne.access;
 
+import java.sql.SQLException;
 import java.sql.Types;
 import java.util.HashMap;
 import java.util.List;
@@ -30,6 +31,8 @@ import org.apache.cayenne.test.jdbc.DBHe
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.inheritance.vertical.Iv1Root;
 import org.apache.cayenne.testdo.inheritance.vertical.Iv1Sub1;
+import org.apache.cayenne.testdo.inheritance.vertical.Iv2Sub1;
+import org.apache.cayenne.testdo.inheritance.vertical.Iv2X;
 import org.apache.cayenne.testdo.inheritance.vertical.IvRoot;
 import org.apache.cayenne.testdo.inheritance.vertical.IvSub1;
 import org.apache.cayenne.testdo.inheritance.vertical.IvSub1Sub1;
@@ -40,456 +43,486 @@ import org.apache.cayenne.unit.di.server
 @UseServerRuntime(ServerCase.INHERTITANCE_VERTICAL_PROJECT)
 public class VerticalInheritanceTest extends ServerCase {
 
-    @Inject
-    protected ObjectContext context;
+	@Inject
+	protected ObjectContext context;
 
-    @Inject
-    protected DBHelper dbHelper;
+	@Inject
+	protected DBHelper dbHelper;
 
-    @Override
-    protected void setUpAfterInjection() throws Exception {
+	@Override
+	protected void setUpAfterInjection() throws Exception {
 
-        dbHelper.deleteAll("IV_SUB1_SUB1");
-        dbHelper.deleteAll("IV_SUB1");
-        dbHelper.deleteAll("IV_SUB2");
-        dbHelper.deleteAll("IV_ROOT");
+		dbHelper.deleteAll("IV_SUB1_SUB1");
+		dbHelper.deleteAll("IV_SUB1");
+		dbHelper.deleteAll("IV_SUB2");
+		dbHelper.deleteAll("IV_ROOT");
 
-        dbHelper.deleteAll("IV1_SUB1");
-        dbHelper.deleteAll("IV1_ROOT");
-    }
+		dbHelper.deleteAll("IV1_SUB1");
+		dbHelper.deleteAll("IV1_ROOT");
 
-    public void testInsert_Root() throws Exception {
+		dbHelper.deleteAll("IV2_SUB1");
+		dbHelper.deleteAll("IV2_ROOT");
+		dbHelper.deleteAll("IV2_X");
+	}
 
-        TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
-        ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
+	public void testInsert_Root() throws Exception {
 
-        assertEquals(0, ivRootTable.getRowCount());
+		TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
+		ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
 
-        IvRoot root = context.newObject(IvRoot.class);
-        root.setName("XyZ");
-        root.getObjectContext().commitChanges();
+		assertEquals(0, ivRootTable.getRowCount());
 
-        assertEquals(1, ivRootTable.getRowCount());
+		IvRoot root = context.newObject(IvRoot.class);
+		root.setName("XyZ");
+		root.getObjectContext().commitChanges();
 
-        Object[] rootData = ivRootTable.select();
-        assertEquals(3, rootData.length);
-        assertTrue(rootData[0] instanceof Number);
-        assertTrue(((Number) rootData[0]).intValue() > 0);
-        assertEquals("XyZ", rootData[1]);
-        assertNull(rootData[2]);
-    }
+		assertEquals(1, ivRootTable.getRowCount());
 
-    public void testInsert_Sub1() throws Exception {
+		Object[] rootData = ivRootTable.select();
+		assertEquals(3, rootData.length);
+		assertTrue(rootData[0] instanceof Number);
+		assertTrue(((Number) rootData[0]).intValue() > 0);
+		assertEquals("XyZ", rootData[1]);
+		assertNull(rootData[2]);
+	}
 
-        TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
-        ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
+	public void testInsert_Sub1() throws Exception {
 
-        TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
-        ivSub1Table.setColumns("ID", "SUB1_NAME");
+		TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
+		ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
 
-        IvSub1 sub1 = context.newObject(IvSub1.class);
-        sub1.setName("XyZX");
-        sub1.getObjectContext().commitChanges();
+		TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
+		ivSub1Table.setColumns("ID", "SUB1_NAME");
 
-        assertEquals(1, ivRootTable.getRowCount());
-        assertEquals(1, ivSub1Table.getRowCount());
+		IvSub1 sub1 = context.newObject(IvSub1.class);
+		sub1.setName("XyZX");
+		sub1.getObjectContext().commitChanges();
 
-        Object[] data = ivRootTable.select();
-        assertEquals(3, data.length);
-        assertTrue(data[0] instanceof Number);
-        assertTrue(((Number) data[0]).intValue() > 0);
-        assertEquals("XyZX", data[1]);
-        assertEquals("IvSub1", data[2]);
+		assertEquals(1, ivRootTable.getRowCount());
+		assertEquals(1, ivSub1Table.getRowCount());
 
-        Object[] subdata = ivSub1Table.select();
-        assertEquals(2, subdata.length);
-        assertEquals(data[0], subdata[0]);
-        assertNull(subdata[1]);
+		Object[] data = ivRootTable.select();
+		assertEquals(3, data.length);
+		assertTrue(data[0] instanceof Number);
+		assertTrue(((Number) data[0]).intValue() > 0);
+		assertEquals("XyZX", data[1]);
+		assertEquals("IvSub1", data[2]);
 
-        ivSub1Table.deleteAll();
-        ivRootTable.deleteAll();
+		Object[] subdata = ivSub1Table.select();
+		assertEquals(2, subdata.length);
+		assertEquals(data[0], subdata[0]);
+		assertNull(subdata[1]);
 
-        IvSub1 sub11 = context.newObject(IvSub1.class);
-        sub11.setName("XyZXY");
-        sub11.setSub1Name("BdE2");
-        sub11.getObjectContext().commitChanges();
+		ivSub1Table.deleteAll();
+		ivRootTable.deleteAll();
 
-        data = ivRootTable.select();
-        assertEquals(3, data.length);
-        assertTrue(data[0] instanceof Number);
-        assertTrue(((Number) data[0]).intValue() > 0);
-        assertEquals("XyZXY", data[1]);
-        assertEquals("IvSub1", data[2]);
+		IvSub1 sub11 = context.newObject(IvSub1.class);
+		sub11.setName("XyZXY");
+		sub11.setSub1Name("BdE2");
+		sub11.getObjectContext().commitChanges();
 
-        subdata = ivSub1Table.select();
-        assertEquals(2, subdata.length);
-        assertEquals(data[0], subdata[0]);
-        assertEquals("BdE2", subdata[1]);
-    }
+		data = ivRootTable.select();
+		assertEquals(3, data.length);
+		assertTrue(data[0] instanceof Number);
+		assertTrue(((Number) data[0]).intValue() > 0);
+		assertEquals("XyZXY", data[1]);
+		assertEquals("IvSub1", data[2]);
 
-    public void testInsert_Sub2() throws Exception {
+		subdata = ivSub1Table.select();
+		assertEquals(2, subdata.length);
+		assertEquals(data[0], subdata[0]);
+		assertEquals("BdE2", subdata[1]);
+	}
 
-        TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
-        ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
+	public void testInsert_Sub2() throws Exception {
 
-        TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
-        ivSub2Table.setColumns("ID", "SUB2_NAME", "SUB2_ATTR");
+		TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
+		ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
 
-        IvSub2 sub2 = context.newObject(IvSub2.class);
-        sub2.setName("XyZX");
-        sub2.getObjectContext().commitChanges();
+		TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
+		ivSub2Table.setColumns("ID", "SUB2_NAME", "SUB2_ATTR");
 
-        assertEquals(1, ivRootTable.getRowCount());
-        assertEquals(1, ivSub2Table.getRowCount());
+		IvSub2 sub2 = context.newObject(IvSub2.class);
+		sub2.setName("XyZX");
+		sub2.getObjectContext().commitChanges();
 
-        Object[] data = ivRootTable.select();
-        assertEquals(3, data.length);
-        assertTrue(data[0] instanceof Number);
-        assertTrue(((Number) data[0]).intValue() > 0);
-        assertEquals("XyZX", data[1]);
-        assertEquals("IvSub2", data[2]);
+		assertEquals(1, ivRootTable.getRowCount());
+		assertEquals(1, ivSub2Table.getRowCount());
 
-        Object[] subdata = ivSub2Table.select();
-        assertEquals(3, subdata.length);
-        assertEquals(data[0], subdata[0]);
-        assertNull(subdata[1]);
-        assertNull(subdata[2]);
+		Object[] data = ivRootTable.select();
+		assertEquals(3, data.length);
+		assertTrue(data[0] instanceof Number);
+		assertTrue(((Number) data[0]).intValue() > 0);
+		assertEquals("XyZX", data[1]);
+		assertEquals("IvSub2", data[2]);
 
-        ivSub2Table.deleteAll();
-        ivRootTable.deleteAll();
+		Object[] subdata = ivSub2Table.select();
+		assertEquals(3, subdata.length);
+		assertEquals(data[0], subdata[0]);
+		assertNull(subdata[1]);
+		assertNull(subdata[2]);
 
-        IvSub2 sub21 = context.newObject(IvSub2.class);
-        sub21.setName("XyZXY");
-        sub21.setSub2Name("BdE2");
-        sub21.setSub2Attr("aTtR");
-        sub21.getObjectContext().commitChanges();
+		ivSub2Table.deleteAll();
+		ivRootTable.deleteAll();
 
-        data = ivRootTable.select();
-        assertEquals(3, data.length);
-        assertTrue(data[0] instanceof Number);
-        assertTrue(((Number) data[0]).intValue() > 0);
-        assertEquals("XyZXY", data[1]);
-        assertEquals("IvSub2", data[2]);
+		IvSub2 sub21 = context.newObject(IvSub2.class);
+		sub21.setName("XyZXY");
+		sub21.setSub2Name("BdE2");
+		sub21.setSub2Attr("aTtR");
+		sub21.getObjectContext().commitChanges();
 
-        subdata = ivSub2Table.select();
-        assertEquals(3, subdata.length);
-        assertEquals(data[0], subdata[0]);
-        assertEquals("BdE2", subdata[1]);
-        assertEquals("aTtR", subdata[2]);
+		data = ivRootTable.select();
+		assertEquals(3, data.length);
+		assertTrue(data[0] instanceof Number);
+		assertTrue(((Number) data[0]).intValue() > 0);
+		assertEquals("XyZXY", data[1]);
+		assertEquals("IvSub2", data[2]);
 
-        sub21.setSub2Attr("BUuT");
-        sub21.getObjectContext().commitChanges();
+		subdata = ivSub2Table.select();
+		assertEquals(3, subdata.length);
+		assertEquals(data[0], subdata[0]);
+		assertEquals("BdE2", subdata[1]);
+		assertEquals("aTtR", subdata[2]);
 
-        subdata = ivSub2Table.select();
-        assertEquals(3, subdata.length);
-        assertEquals(data[0], subdata[0]);
-        assertEquals("BdE2", subdata[1]);
-        assertEquals("BUuT", subdata[2]);
+		sub21.setSub2Attr("BUuT");
+		sub21.getObjectContext().commitChanges();
 
-        sub21.getObjectContext().deleteObjects(sub21);
-        sub21.getObjectContext().commitChanges();
+		subdata = ivSub2Table.select();
+		assertEquals(3, subdata.length);
+		assertEquals(data[0], subdata[0]);
+		assertEquals("BdE2", subdata[1]);
+		assertEquals("BUuT", subdata[2]);
 
-        assertEquals(0, ivRootTable.getRowCount());
-        assertEquals(0, ivSub2Table.getRowCount());
-    }
+		sub21.getObjectContext().deleteObjects(sub21);
+		sub21.getObjectContext().commitChanges();
 
-    public void testInsert_Sub1Sub1() throws Exception {
+		assertEquals(0, ivRootTable.getRowCount());
+		assertEquals(0, ivSub2Table.getRowCount());
+	}
 
-        TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
-        ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
+	public void testInsert_Sub1Sub1() throws Exception {
 
-        TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
-        ivSub1Table.setColumns("ID", "SUB1_NAME");
+		TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
+		ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
 
-        TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
-        ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
+		TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
+		ivSub1Table.setColumns("ID", "SUB1_NAME");
 
-        IvSub1Sub1 sub1Sub1 = context.newObject(IvSub1Sub1.class);
-        sub1Sub1.setName("XyZN");
-        sub1Sub1.setSub1Name("mDA");
-        sub1Sub1.setSub1Sub1Name("3DQa");
-        sub1Sub1.getObjectContext().commitChanges();
+		TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
+		ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
 
-        assertEquals(1, ivRootTable.getRowCount());
-        assertEquals(1, ivSub1Table.getRowCount());
-        assertEquals(1, ivSub1Sub1Table.getRowCount());
+		IvSub1Sub1 sub1Sub1 = context.newObject(IvSub1Sub1.class);
+		sub1Sub1.setName("XyZN");
+		sub1Sub1.setSub1Name("mDA");
+		sub1Sub1.setSub1Sub1Name("3DQa");
+		sub1Sub1.getObjectContext().commitChanges();
 
-        Object[] data = ivRootTable.select();
-        assertEquals(3, data.length);
-        assertTrue(data[0] instanceof Number);
-        assertTrue(((Number) data[0]).intValue() > 0);
-        assertEquals("XyZN", data[1]);
-        assertEquals("IvSub1Sub1", data[2]);
+		assertEquals(1, ivRootTable.getRowCount());
+		assertEquals(1, ivSub1Table.getRowCount());
+		assertEquals(1, ivSub1Sub1Table.getRowCount());
 
-        Object[] subdata = ivSub1Table.select();
-        assertEquals(2, subdata.length);
-        assertEquals(data[0], subdata[0]);
-        assertEquals("mDA", subdata[1]);
+		Object[] data = ivRootTable.select();
+		assertEquals(3, data.length);
+		assertTrue(data[0] instanceof Number);
+		assertTrue(((Number) data[0]).intValue() > 0);
+		assertEquals("XyZN", data[1]);
+		assertEquals("IvSub1Sub1", data[2]);
 
-        Object[] subsubdata = ivSub1Sub1Table.select();
-        assertEquals(2, subsubdata.length);
-        assertEquals(data[0], subsubdata[0]);
-        assertEquals("3DQa", subsubdata[1]);
-    }
+		Object[] subdata = ivSub1Table.select();
+		assertEquals(2, subdata.length);
+		assertEquals(data[0], subdata[0]);
+		assertEquals("mDA", subdata[1]);
 
-    public void testSelectQuery_SuperSub() throws Exception {
+		Object[] subsubdata = ivSub1Sub1Table.select();
+		assertEquals(2, subsubdata.length);
+		assertEquals(data[0], subsubdata[0]);
+		assertEquals("3DQa", subsubdata[1]);
+	}
 
-        TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
-        ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
-                Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
+	public void testSelectQuery_SuperSub() throws Exception {
 
-        TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
-        ivSub1Table.setColumns("ID", "SUB1_NAME");
+		TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
+		ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
+				Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
 
-        // insert
-        ivRootTable.insert(1, "xROOT", null);
-        ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
-        ivSub1Table.insert(2, "xSUB1");
+		TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
+		ivSub1Table.setColumns("ID", "SUB1_NAME");
 
-        SelectQuery query = new SelectQuery(IvRoot.class);
-        List<IvRoot> results = context.performQuery(query);
+		// insert
+		ivRootTable.insert(1, "xROOT", null);
+		ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
+		ivSub1Table.insert(2, "xSUB1");
 
-        assertEquals(2, results.size());
+		SelectQuery query = new SelectQuery(IvRoot.class);
+		List<IvRoot> results = context.performQuery(query);
 
-        // since we don't have ordering, need to analyze results in an order agnostic
-        // fashion
-        Map<String, IvRoot> resultTypes = new HashMap<String, IvRoot>();
+		assertEquals(2, results.size());
 
-        for (IvRoot result : results) {
-            resultTypes.put(result.getClass().getName(), result);
-        }
+		// since we don't have ordering, need to analyze results in an order
+		// agnostic
+		// fashion
+		Map<String, IvRoot> resultTypes = new HashMap<String, IvRoot>();
 
-        assertEquals(2, resultTypes.size());
+		for (IvRoot result : results) {
+			resultTypes.put(result.getClass().getName(), result);
+		}
 
-        IvRoot root = resultTypes.get(IvRoot.class.getName());
-        assertNotNull(root);
-        assertEquals("xROOT", root.getName());
-        assertNull(root.getDiscriminator());
+		assertEquals(2, resultTypes.size());
 
-        IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
-        assertNotNull(sub1);
-        assertEquals("xSUB1_ROOT", sub1.getName());
-        assertEquals("IvSub1", sub1.getDiscriminator());
-    }
+		IvRoot root = resultTypes.get(IvRoot.class.getName());
+		assertNotNull(root);
+		assertEquals("xROOT", root.getName());
+		assertNull(root.getDiscriminator());
 
-    public void testSelectQuery_DeepAndWide() throws Exception {
+		IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
+		assertNotNull(sub1);
+		assertEquals("xSUB1_ROOT", sub1.getName());
+		assertEquals("IvSub1", sub1.getDiscriminator());
+	}
 
-        TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
-        ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
-                Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
+	public void testSelectQuery_DeepAndWide() throws Exception {
 
-        TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
-        ivSub1Table.setColumns("ID", "SUB1_NAME");
+		TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
+		ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
+				Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
 
-        TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
-        ivSub2Table.setColumns("ID", "SUB2_NAME");
+		TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
+		ivSub1Table.setColumns("ID", "SUB1_NAME");
 
-        TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
-        ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
+		TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
+		ivSub2Table.setColumns("ID", "SUB2_NAME");
 
-        // insert
-        ivRootTable.insert(1, "xROOT", null);
+		TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
+		ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
 
-        ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
-        ivSub1Table.insert(2, "xSUB1");
+		// insert
+		ivRootTable.insert(1, "xROOT", null);
 
-        ivRootTable.insert(3, "xSUB1_SUB1_ROOT", "IvSub1Sub1");
-        ivSub1Table.insert(3, "xSUB1_SUB1_SUBROOT");
-        ivSub1Sub1Table.insert(3, "xSUB1_SUB1");
+		ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
+		ivSub1Table.insert(2, "xSUB1");
 
-        ivRootTable.insert(4, "xROOT_SUB2", "IvSub2");
-        ivSub2Table.insert(4, "xSUB2");
+		ivRootTable.insert(3, "xSUB1_SUB1_ROOT", "IvSub1Sub1");
+		ivSub1Table.insert(3, "xSUB1_SUB1_SUBROOT");
+		ivSub1Sub1Table.insert(3, "xSUB1_SUB1");
 
-        SelectQuery query = new SelectQuery(IvRoot.class);
-        List<IvRoot> results = context.performQuery(query);
+		ivRootTable.insert(4, "xROOT_SUB2", "IvSub2");
+		ivSub2Table.insert(4, "xSUB2");
 
-        assertEquals(4, results.size());
+		SelectQuery query = new SelectQuery(IvRoot.class);
+		List<IvRoot> results = context.performQuery(query);
 
-        // since we don't have ordering, need to analyze results in an order agnostic
-        // fashion
-        Map<String, IvRoot> resultTypes = new HashMap<String, IvRoot>();
+		assertEquals(4, results.size());
 
-        for (IvRoot result : results) {
-            resultTypes.put(result.getClass().getName(), result);
-        }
+		// since we don't have ordering, need to analyze results in an order
+		// agnostic
+		// fashion
+		Map<String, IvRoot> resultTypes = new HashMap<String, IvRoot>();
 
-        assertEquals(4, resultTypes.size());
+		for (IvRoot result : results) {
+			resultTypes.put(result.getClass().getName(), result);
+		}
 
-        IvRoot root = resultTypes.get(IvRoot.class.getName());
-        assertNotNull(root);
-        assertEquals("xROOT", root.getName());
-        assertNull(root.getDiscriminator());
+		assertEquals(4, resultTypes.size());
 
-        IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
-        assertNotNull(sub1);
-        assertEquals("xSUB1_ROOT", sub1.getName());
-        assertEquals("IvSub1", sub1.getDiscriminator());
+		IvRoot root = resultTypes.get(IvRoot.class.getName());
+		assertNotNull(root);
+		assertEquals("xROOT", root.getName());
+		assertNull(root.getDiscriminator());
 
-        IvSub1Sub1 sub1Sub1 = (IvSub1Sub1) resultTypes.get(IvSub1Sub1.class.getName());
-        assertNotNull(sub1Sub1);
-        assertEquals("xSUB1_SUB1_ROOT", sub1Sub1.getName());
-        assertEquals("IvSub1Sub1", sub1Sub1.getDiscriminator());
-        assertEquals("xSUB1_SUB1_SUBROOT", sub1Sub1.getSub1Name());
-        assertEquals("xSUB1_SUB1", sub1Sub1.getSub1Sub1Name());
+		IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
+		assertNotNull(sub1);
+		assertEquals("xSUB1_ROOT", sub1.getName());
+		assertEquals("IvSub1", sub1.getDiscriminator());
 
-        IvSub2 sub2 = (IvSub2) resultTypes.get(IvSub2.class.getName());
-        assertNotNull(sub2);
-        assertEquals("xROOT_SUB2", sub2.getName());
-        assertEquals("IvSub2", sub2.getDiscriminator());
-        assertEquals("xSUB2", sub2.getSub2Name());
-    }
+		IvSub1Sub1 sub1Sub1 = (IvSub1Sub1) resultTypes.get(IvSub1Sub1.class
+				.getName());
+		assertNotNull(sub1Sub1);
+		assertEquals("xSUB1_SUB1_ROOT", sub1Sub1.getName());
+		assertEquals("IvSub1Sub1", sub1Sub1.getDiscriminator());
+		assertEquals("xSUB1_SUB1_SUBROOT", sub1Sub1.getSub1Name());
+		assertEquals("xSUB1_SUB1", sub1Sub1.getSub1Sub1Name());
 
-    public void testSelectQuery_MiddleLeaf() throws Exception {
+		IvSub2 sub2 = (IvSub2) resultTypes.get(IvSub2.class.getName());
+		assertNotNull(sub2);
+		assertEquals("xROOT_SUB2", sub2.getName());
+		assertEquals("IvSub2", sub2.getDiscriminator());
+		assertEquals("xSUB2", sub2.getSub2Name());
+	}
 
-        TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
-        ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
-                Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
+	public void testSelectQuery_MiddleLeaf() throws Exception {
 
-        TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
-        ivSub1Table.setColumns("ID", "SUB1_NAME");
+		TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
+		ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
+				Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
 
-        TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
-        ivSub2Table.setColumns("ID", "SUB2_NAME");
+		TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
+		ivSub1Table.setColumns("ID", "SUB1_NAME");
 
-        TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
-        ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
+		TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
+		ivSub2Table.setColumns("ID", "SUB2_NAME");
 
-        // insert
-        ivRootTable.insert(1, "xROOT", null);
+		TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
+		ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
 
-        ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
-        ivSub1Table.insert(2, "xSUB1");
+		// insert
+		ivRootTable.insert(1, "xROOT", null);
 
-        ivRootTable.insert(3, "xSUB1_SUB1_ROOT", "IvSub1Sub1");
-        ivSub1Table.insert(3, "xSUB1_SUB1_SUBROOT");
-        ivSub1Sub1Table.insert(3, "xSUB1_SUB1");
+		ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
+		ivSub1Table.insert(2, "xSUB1");
 
-        ivRootTable.insert(4, "xROOT_SUB2", "IvSub2");
-        ivSub2Table.insert(4, "xSUB2");
+		ivRootTable.insert(3, "xSUB1_SUB1_ROOT", "IvSub1Sub1");
+		ivSub1Table.insert(3, "xSUB1_SUB1_SUBROOT");
+		ivSub1Sub1Table.insert(3, "xSUB1_SUB1");
 
-        SelectQuery query = new SelectQuery(IvSub1.class);
-        List<IvRoot> results = context.performQuery(query);
+		ivRootTable.insert(4, "xROOT_SUB2", "IvSub2");
+		ivSub2Table.insert(4, "xSUB2");
 
-        assertEquals(2, results.size());
+		SelectQuery query = new SelectQuery(IvSub1.class);
+		List<IvRoot> results = context.performQuery(query);
 
-        // since we don't have ordering, need to analyze results in an order agnostic
-        // fashion
-        Map<String, IvRoot> resultTypes = new HashMap<String, IvRoot>();
+		assertEquals(2, results.size());
 
-        for (IvRoot result : results) {
-            resultTypes.put(result.getClass().getName(), result);
-        }
+		// since we don't have ordering, need to analyze results in an order
+		// agnostic
+		// fashion
+		Map<String, IvRoot> resultTypes = new HashMap<String, IvRoot>();
 
-        assertEquals(2, resultTypes.size());
+		for (IvRoot result : results) {
+			resultTypes.put(result.getClass().getName(), result);
+		}
 
-        IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
-        assertNotNull(sub1);
-        assertEquals("xSUB1_ROOT", sub1.getName());
-        assertEquals("IvSub1", sub1.getDiscriminator());
+		assertEquals(2, resultTypes.size());
 
-        IvSub1Sub1 sub1Sub1 = (IvSub1Sub1) resultTypes.get(IvSub1Sub1.class.getName());
-        assertNotNull(sub1Sub1);
-        assertEquals("xSUB1_SUB1_ROOT", sub1Sub1.getName());
-        assertEquals("IvSub1Sub1", sub1Sub1.getDiscriminator());
-        assertEquals("xSUB1_SUB1_SUBROOT", sub1Sub1.getSub1Name());
-        assertEquals("xSUB1_SUB1", sub1Sub1.getSub1Sub1Name());
-    }
+		IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
+		assertNotNull(sub1);
+		assertEquals("xSUB1_ROOT", sub1.getName());
+		assertEquals("IvSub1", sub1.getDiscriminator());
 
-    public void testDelete_Mix() throws Exception {
+		IvSub1Sub1 sub1Sub1 = (IvSub1Sub1) resultTypes.get(IvSub1Sub1.class
+				.getName());
+		assertNotNull(sub1Sub1);
+		assertEquals("xSUB1_SUB1_ROOT", sub1Sub1.getName());
+		assertEquals("IvSub1Sub1", sub1Sub1.getDiscriminator());
+		assertEquals("xSUB1_SUB1_SUBROOT", sub1Sub1.getSub1Name());
+		assertEquals("xSUB1_SUB1", sub1Sub1.getSub1Sub1Name());
+	}
 
-        TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
-        ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
-                Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
+	public void testDelete_Mix() throws Exception {
 
-        TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
-        ivSub1Table.setColumns("ID", "SUB1_NAME");
+		TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
+		ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
+				Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
 
-        TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
-        ivSub2Table.setColumns("ID", "SUB2_NAME");
+		TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
+		ivSub1Table.setColumns("ID", "SUB1_NAME");
 
-        TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
-        ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
+		TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
+		ivSub2Table.setColumns("ID", "SUB2_NAME");
 
-        // insert
-        ivRootTable.insert(1, "xROOT", null);
+		TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
+		ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
 
-        ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
-        ivSub1Table.insert(2, "xSUB1");
+		// insert
+		ivRootTable.insert(1, "xROOT", null);
 
-        ivRootTable.insert(3, "xSUB1_SUB1_ROOT", "IvSub1Sub1");
-        ivSub1Table.insert(3, "xSUB1_SUB1_SUBROOT");
-        ivSub1Sub1Table.insert(3, "xSUB1_SUB1");
+		ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
+		ivSub1Table.insert(2, "xSUB1");
 
-        ivRootTable.insert(4, "xROOT_SUB2", "IvSub2");
-        ivSub2Table.insert(4, "xSUB2");
+		ivRootTable.insert(3, "xSUB1_SUB1_ROOT", "IvSub1Sub1");
+		ivSub1Table.insert(3, "xSUB1_SUB1_SUBROOT");
+		ivSub1Sub1Table.insert(3, "xSUB1_SUB1");
 
-        SelectQuery query = new SelectQuery(IvRoot.class);
+		ivRootTable.insert(4, "xROOT_SUB2", "IvSub2");
+		ivSub2Table.insert(4, "xSUB2");
 
-        List<IvRoot> results = context.performQuery(query);
+		SelectQuery query = new SelectQuery(IvRoot.class);
 
-        assertEquals(4, results.size());
-        Map<String, IvRoot> resultTypes = new HashMap<String, IvRoot>();
+		List<IvRoot> results = context.performQuery(query);
 
-        for (IvRoot result : results) {
-            resultTypes.put(result.getClass().getName(), result);
-        }
+		assertEquals(4, results.size());
+		Map<String, IvRoot> resultTypes = new HashMap<String, IvRoot>();
 
-        assertEquals(4, resultTypes.size());
+		for (IvRoot result : results) {
+			resultTypes.put(result.getClass().getName(), result);
+		}
 
-        IvRoot root = resultTypes.get(IvRoot.class.getName());
-        context.deleteObjects(root);
+		assertEquals(4, resultTypes.size());
 
-        IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
-        context.deleteObjects(sub1);
+		IvRoot root = resultTypes.get(IvRoot.class.getName());
+		context.deleteObjects(root);
 
-        context.commitChanges();
+		IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
+		context.deleteObjects(sub1);
 
-        assertEquals(2, ivRootTable.getRowCount());
-        assertEquals(1, ivSub1Table.getRowCount());
-        assertEquals(1, ivSub1Sub1Table.getRowCount());
-        assertEquals(1, ivSub2Table.getRowCount());
+		context.commitChanges();
 
-        results = context.performQuery(query);
-        assertEquals(2, results.size());
-    }
+		assertEquals(2, ivRootTable.getRowCount());
+		assertEquals(1, ivSub1Table.getRowCount());
+		assertEquals(1, ivSub1Sub1Table.getRowCount());
+		assertEquals(1, ivSub2Table.getRowCount());
 
-    public void testSelectQuery_AttributeOverrides() throws Exception {
+		results = context.performQuery(query);
+		assertEquals(2, results.size());
+	}
 
-        TableHelper iv1RootTable = new TableHelper(dbHelper, "IV1_ROOT");
-        iv1RootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
-                Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
+	public void testSelectQuery_AttributeOverrides() throws Exception {
 
-        TableHelper iv1Sub1Table = new TableHelper(dbHelper, "IV1_SUB1");
-        iv1Sub1Table.setColumns("ID", "SUB1_NAME");
+		TableHelper iv1RootTable = new TableHelper(dbHelper, "IV1_ROOT");
+		iv1RootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(
+				Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
 
-        // insert
-        iv1RootTable.insert(1, "xROOT", null);
-        iv1RootTable.insert(2, "xSUB1_ROOT", "Iv1Sub1");
-        iv1Sub1Table.insert(2, "xSUB1");
+		TableHelper iv1Sub1Table = new TableHelper(dbHelper, "IV1_SUB1");
+		iv1Sub1Table.setColumns("ID", "SUB1_NAME");
 
-        SelectQuery query = new SelectQuery(Iv1Root.class);
-        List<Iv1Root> results = context.performQuery(query);
+		// insert
+		iv1RootTable.insert(1, "xROOT", null);
+		iv1RootTable.insert(2, "xSUB1_ROOT", "Iv1Sub1");
+		iv1Sub1Table.insert(2, "xSUB1");
 
-        assertEquals(2, results.size());
+		SelectQuery query = new SelectQuery(Iv1Root.class);
+		List<Iv1Root> results = context.performQuery(query);
 
-        // since we don't have ordering, need to analyze results in an order agnostic
-        // fashion
-        Map<String, Iv1Root> resultTypes = new HashMap<String, Iv1Root>();
+		assertEquals(2, results.size());
 
-        for (Iv1Root result : results) {
-            resultTypes.put(result.getClass().getName(), result);
-        }
+		// since we don't have ordering, need to analyze results in an order
+		// agnostic
+		// fashion
+		Map<String, Iv1Root> resultTypes = new HashMap<String, Iv1Root>();
 
-        assertEquals(2, resultTypes.size());
+		for (Iv1Root result : results) {
+			resultTypes.put(result.getClass().getName(), result);
+		}
 
-        Iv1Root root = resultTypes.get(Iv1Root.class.getName());
-        assertNotNull(root);
-        assertEquals("xROOT", root.getName());
-        assertNull(root.getDiscriminator());
+		assertEquals(2, resultTypes.size());
 
-        Iv1Sub1 sub1 = (Iv1Sub1) resultTypes.get(Iv1Sub1.class.getName());
-        assertNotNull(sub1);
-        assertEquals("xSUB1", sub1.getName());
-    }
+		Iv1Root root = resultTypes.get(Iv1Root.class.getName());
+		assertNotNull(root);
+		assertEquals("xROOT", root.getName());
+		assertNull(root.getDiscriminator());
+
+		Iv1Sub1 sub1 = (Iv1Sub1) resultTypes.get(Iv1Sub1.class.getName());
+		assertNotNull(sub1);
+		assertEquals("xSUB1", sub1.getName());
+	}
+
+	public void testInsertWithRelationship() throws SQLException {
+		TableHelper xTable = new TableHelper(dbHelper, "IV2_X");
+		TableHelper rootTable = new TableHelper(dbHelper, "IV2_ROOT");
+		TableHelper sub1Table = new TableHelper(dbHelper, "IV2_SUB1");
+
+		assertEquals(0, xTable.getRowCount());
+		assertEquals(0, rootTable.getRowCount());
+		assertEquals(0, sub1Table.getRowCount());
+
+		Iv2Sub1 root = context.newObject(Iv2Sub1.class);
+		Iv2X x = context.newObject(Iv2X.class);
+		root.setX(x);
+
+		context.commitChanges();
+
+		assertEquals(1, xTable.getRowCount());
+		assertEquals(1, rootTable.getRowCount());
+		assertEquals(1, sub1Table.getRowCount());
+	}
 
 }



Mime
View raw message