Search in sources :

Example 16 with TableHelper

use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.

the class PrimitiveAttributesIT method testSelect.

@Test
public void testSelect() throws Exception {
    TableHelper tPrimitives = new TableHelper(dbHelper, "PRIMITIVES_TEST");
    tPrimitives.setColumns("ID", "BOOLEAN_COLUMN", "INT_COLUMN", "CHAR_COLUMN");
    tPrimitives.insert(1, true, -100, String.valueOf('a')).insert(2, false, 0, String.valueOf('~')).insert(3, true, Integer.MAX_VALUE, String.valueOf('Z'));
    List<PrimitivesTestEntity> result = ObjectSelect.query(PrimitivesTestEntity.class).orderBy(PrimitivesTestEntity.INT_COLUMN.asc()).select(context);
    assertEquals(3, result.size());
    assertEquals(-100, result.get(0).getIntColumn());
    assertEquals('a', result.get(0).getCharColumn());
    assertTrue(result.get(0).isBooleanColumn());
    assertEquals(0, result.get(1).getIntColumn());
    assertEquals('~', result.get(1).getCharColumn());
    assertFalse(result.get(1).isBooleanColumn());
    assertEquals(Integer.MAX_VALUE, result.get(2).getIntColumn());
    assertEquals('Z', result.get(2).getCharColumn());
    assertTrue(result.get(2).isBooleanColumn());
}
Also used : PrimitivesTestEntity(org.apache.cayenne.testdo.primitive.PrimitivesTestEntity) TableHelper(org.apache.cayenne.test.jdbc.TableHelper) Test(org.junit.Test)

Example 17 with TableHelper

use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.

the class VerticalInheritanceIT method testInsert_Root.

@Test
public void testInsert_Root() throws Exception {
    TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
    ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
    assertEquals(0, ivRootTable.getRowCount());
    IvRoot root = context.newObject(IvRoot.class);
    root.setName("XyZ");
    root.getObjectContext().commitChanges();
    assertEquals(1, ivRootTable.getRowCount());
    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]);
}
Also used : TableHelper(org.apache.cayenne.test.jdbc.TableHelper) Test(org.junit.Test)

Example 18 with TableHelper

use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.

the class VerticalInheritanceIT method testInsertWithRelationship.

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

Example 19 with TableHelper

use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.

the class VerticalInheritanceIT method testInsert_Sub1Sub1.

@Test
public void testInsert_Sub1Sub1() 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");
    TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
    ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
    IvSub1Sub1 sub1Sub1 = context.newObject(IvSub1Sub1.class);
    sub1Sub1.setName("XyZN");
    sub1Sub1.setSub1Name("mDA");
    sub1Sub1.setSub1Sub1Name("3DQa");
    sub1Sub1.getObjectContext().commitChanges();
    assertEquals(1, ivRootTable.getRowCount());
    assertEquals(1, ivSub1Table.getRowCount());
    assertEquals(1, ivSub1Sub1Table.getRowCount());
    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[] subdata = ivSub1Table.select();
    assertEquals(2, subdata.length);
    assertEquals(data[0], subdata[0]);
    assertEquals("mDA", subdata[1]);
    Object[] subsubdata = ivSub1Sub1Table.select();
    assertEquals(2, subsubdata.length);
    assertEquals(data[0], subsubdata[0]);
    assertEquals("3DQa", subsubdata[1]);
}
Also used : TableHelper(org.apache.cayenne.test.jdbc.TableHelper) Test(org.junit.Test)

Example 20 with TableHelper

use of org.apache.cayenne.test.jdbc.TableHelper in project cayenne by apache.

the class VerticalInheritanceIT method testCountEjbqlQuery.

@Test
public void testCountEjbqlQuery() 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");
    TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
    ivSub2Table.setColumns("ID", "SUB2_ATTR", "SUB2_NAME");
    // Root, IvSub1, IvSub2
    ivRootTable.insert(1, "root1", "");
    ivRootTable.insert(2, "sub11", "IvSub1");
    ivSub1Table.insert(2, "sub_name1_1");
    ivRootTable.insert(3, "sub21", "IvSub2");
    ivRootTable.insert(4, "sub22", "IvSub2");
    ivSub2Table.insert(3, "attr1", "sub_name2_1");
    ivSub2Table.insert(4, "attr2", "sub_name2_2");
    EJBQLQuery query1 = new EJBQLQuery("SELECT COUNT(a) FROM IvRoot a");
    assertEquals(Collections.singletonList(4L), context.performQuery(query1));
    EJBQLQuery query2 = new EJBQLQuery("SELECT COUNT(a) FROM IvSub1 a");
    assertEquals(Collections.singletonList(1L), context.performQuery(query2));
    EJBQLQuery query3 = new EJBQLQuery("SELECT COUNT(a) FROM IvSub2 a");
    assertEquals(Collections.singletonList(2L), context.performQuery(query3));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) TableHelper(org.apache.cayenne.test.jdbc.TableHelper) Test(org.junit.Test)

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