Search in sources :

Example 11 with TableHelper

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());
}
Also used : HashMap(java.util.HashMap) TableHelper(org.apache.cayenne.test.jdbc.TableHelper) Test(org.junit.Test)

Example 12 with TableHelper

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]);
}
Also used : TableHelper(org.apache.cayenne.test.jdbc.TableHelper) Test(org.junit.Test)

Example 13 with TableHelper

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");
}
Also used : TableHelper(org.apache.cayenne.test.jdbc.TableHelper) Before(org.junit.Before)

Example 14 with TableHelper

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();
}
Also used : TableHelper(org.apache.cayenne.test.jdbc.TableHelper) Before(org.junit.Before)

Example 15 with TableHelper

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");
}
Also used : TableHelper(org.apache.cayenne.test.jdbc.TableHelper) Before(org.junit.Before)

Aggregations

TableHelper (org.apache.cayenne.test.jdbc.TableHelper)175 Before (org.junit.Before)147 Test (org.junit.Test)19 HashMap (java.util.HashMap)5 DBHelper (org.apache.cayenne.test.jdbc.DBHelper)5 Date (java.util.Date)2 After (org.junit.After)2 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 DataRow (org.apache.cayenne.DataRow)1 ObjectContext (org.apache.cayenne.ObjectContext)1 MapQueryCache (org.apache.cayenne.cache.MapQueryCache)1 DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)1 OracleAdapter (org.apache.cayenne.dba.oracle.OracleAdapter)1 DefaultEventManager (org.apache.cayenne.event.DefaultEventManager)1 Expression (org.apache.cayenne.exp.Expression)1 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)1 SQLTemplate (org.apache.cayenne.query.SQLTemplate)1 CAY2666 (org.apache.cayenne.testdo.cay_2666.CAY2666)1 PrimitivesTestEntity (org.apache.cayenne.testdo.primitive.PrimitivesTestEntity)1