use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.
the class VerticalInheritanceIT method testSelectQuery_SuperSub.
@Test
public void testSelectQuery_SuperSub() throws Exception {
TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR").setColumnTypes(Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
ivSub1Table.setColumns("ID", "SUB1_NAME");
// insert
ivRootTable.insert(1, "xROOT", null);
ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
ivSub1Table.insert(2, "xSUB1");
ObjectSelect<IvRoot> query = ObjectSelect.query(IvRoot.class);
List<IvRoot> results = context.select(query);
assertEquals(2, results.size());
// since we don't have ordering, need to analyze results in an order
// agnostic
// fashion
Map<String, IvRoot> resultTypes = new HashMap<>();
for (IvRoot result : results) {
resultTypes.put(result.getClass().getName(), result);
}
assertEquals(2, resultTypes.size());
IvRoot root = resultTypes.get(IvRoot.class.getName());
assertNotNull(root);
assertEquals("xROOT", root.getName());
assertNull(root.getDiscriminator());
IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
assertNotNull(sub1);
assertEquals("xSUB1_ROOT", sub1.getName());
assertEquals("IvSub1", sub1.getDiscriminator());
}
use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.
the class VerticalInheritanceIT method testInsert_Sub1.
@Test
public void testInsert_Sub1() throws Exception {
TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
ivSub1Table.setColumns("ID", "SUB1_NAME");
IvSub1 sub1 = context.newObject(IvSub1.class);
sub1.setName("XyZX");
sub1.getObjectContext().commitChanges();
assertEquals(1, ivRootTable.getRowCount());
assertEquals(0, ivSub1Table.getRowCount());
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();
IvSub1 sub11 = context.newObject(IvSub1.class);
sub11.setName("XyZXY");
sub11.setSub1Name("BdE2");
sub11.getObjectContext().commitChanges();
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]);
Object[] subdata = ivSub1Table.select();
assertEquals(2, subdata.length);
assertEquals(data[0], subdata[0]);
assertEquals("BdE2", subdata[1]);
}
use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.
the class SelectActionWithUnsupportedDistinctTypesIT method setUp.
@Before
public void setUp() throws Exception {
tProduct = new TableHelper(dbHelper, "PRODUCT");
tProduct.setColumns("ID", "LONGVARCHAR_COL");
tCustomer = new TableHelper(dbHelper, "CUSTOMER");
tCustomer.setColumns("ID", "LONGVARCHAR_COL");
tComposition = new TableHelper(dbHelper, "COMPOSITION");
tComposition.setColumns("BASE_ID", "CONTAINED_ID");
tOrders = new TableHelper(dbHelper, "ORDERS");
tOrders.setColumns("CUSTOMER_ID", "PRODUCT_ID");
}
use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.
the class VerticalInheritanceMultipleAttributesIT method setupTableHelpers.
@Before
public void setupTableHelpers() throws Exception {
ivOtherTable = new TableHelper(dbHelper, "IV_OTHER");
ivOtherTable.setColumns("ID", "NAME").setColumnTypes(Types.INTEGER, Types.VARCHAR);
ivBaseTable = new TableHelper(dbHelper, "IV_BASE");
ivBaseTable.setColumns("ID", "NAME", "TYPE").setColumnTypes(Types.INTEGER, Types.VARCHAR, Types.CHAR);
ivImplTable = new TableHelper(dbHelper, "IV_IMPL");
ivImplTable.setColumns("ID", "ATTR1", "ATTR2", "OTHER1_ID", "OTHER2_ID").setColumnTypes(Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER);
ivImplTable.deleteAll();
ivBaseTable.deleteAll();
ivOtherTable.deleteAll();
}
use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.
the class OptimisticLockingIT method setUp.
@Before
public void setUp() throws Exception {
tSimpleLockingTest = new TableHelper(dbHelper, "SIMPLE_LOCKING_TEST");
tSimpleLockingTest.setColumns("LOCKING_TEST_ID", "NAME", "DESCRIPTION", "INT_COLUMN_NOTNULL").setColumnTypes(Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER);
tRelLockingTest = new TableHelper(dbHelper, "REL_LOCKING_TEST");
tRelLockingTest.setColumns("REL_LOCKING_TEST_ID", "SIMPLE_LOCKING_TEST_ID", "NAME");
tLockingHelper = new TableHelper(dbHelper, "LOCKING_HELPER");
tLockingHelper.setColumns("LOCKING_HELPER_ID", "REL_LOCKING_TEST_ID", "NAME");
}
Aggregations