Package org.apache.cayenne.test.jdbc

Examples of org.apache.cayenne.test.jdbc.TableHelper


    protected void setUpAfterInjection() throws Exception {
        dbHelper.deleteAll("MT_TABLE2");
        dbHelper.deleteAll("MT_TABLE1");
        dbHelper.deleteAll("MT_TABLE3");

        tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
        tMtTable1.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1");

        tMtTable2 = new TableHelper(dbHelper, "MT_TABLE2");
        tMtTable2.setColumns("TABLE2_ID", "TABLE1_ID", "GLOBAL_ATTRIBUTE");

        tMtTable3 = new TableHelper(dbHelper, "MT_TABLE3");
        tMtTable3.setColumns("TABLE3_ID", "BINARY_COLUMN", "CHAR_COLUMN", "INT_COLUMN");
    }
View Full Code Here


        dbHelper.deleteAll("IV1_ROOT");
    }

    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]);
View Full Code Here

        assertNull(rootData[2]);
    }

    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(1, 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]);

        Object[] subdata = ivSub1Table.select();
        assertEquals(2, subdata.length);
        assertEquals(data[0], subdata[0]);
        assertNull(subdata[1]);

        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]);

        subdata = ivSub1Table.select();
        assertEquals(2, subdata.length);
        assertEquals(data[0], subdata[0]);
        assertEquals("BdE2", subdata[1]);
    }
View Full Code Here

        assertEquals("BdE2", subdata[1]);
    }

    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]);
    }
View Full Code Here

        assertEquals("3DQa", subsubdata[1]);
    }

    public void testSelectQuery_SuperSub() 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");

        // insert
        ivRootTable.insert(1, "xROOT", null);
        ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
        ivSub1Table.insert(2, "xSUB1");

        SelectQuery query = new SelectQuery(IvRoot.class);
        List<IvRoot> results = context.performQuery(query);

        assertEquals(2, results.size());
View Full Code Here

        assertEquals("IvSub1", sub1.getDiscriminator());
    }

    public void testSelectQuery_DeepAndWide() 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_NAME");

        TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
        ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");

        // insert
        ivRootTable.insert(1, "xROOT", null);

        ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
        ivSub1Table.insert(2, "xSUB1");

        ivRootTable.insert(3, "xSUB1_SUB1_ROOT", "IvSub1Sub1");
        ivSub1Table.insert(3, "xSUB1_SUB1_SUBROOT");
        ivSub1Sub1Table.insert(3, "xSUB1_SUB1");

        ivRootTable.insert(4, "xROOT_SUB2", "IvSub2");
        ivSub2Table.insert(4, "xSUB2");

        SelectQuery query = new SelectQuery(IvRoot.class);
View Full Code Here

        assertEquals("xSUB2", sub2.getSub2Name());
    }

    public void testSelectQuery_MiddleLeaf() 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_NAME");

        TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
        ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");

        // insert
        ivRootTable.insert(1, "xROOT", null);

        ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
        ivSub1Table.insert(2, "xSUB1");

        ivRootTable.insert(3, "xSUB1_SUB1_ROOT", "IvSub1Sub1");
        ivSub1Table.insert(3, "xSUB1_SUB1_SUBROOT");
        ivSub1Sub1Table.insert(3, "xSUB1_SUB1");

        ivRootTable.insert(4, "xROOT_SUB2", "IvSub2");
        ivSub2Table.insert(4, "xSUB2");

        SelectQuery query = new SelectQuery(IvSub1.class);
View Full Code Here

        assertEquals("xSUB1_SUB1", sub1Sub1.getSub1Sub1Name());
    }

    public void testDelete_Mix() 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_NAME");

        TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
        ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");

        // insert
        ivRootTable.insert(1, "xROOT", null);

        ivRootTable.insert(2, "xSUB1_ROOT", "IvSub1");
        ivSub1Table.insert(2, "xSUB1");

        ivRootTable.insert(3, "xSUB1_SUB1_ROOT", "IvSub1Sub1");
        ivSub1Table.insert(3, "xSUB1_SUB1_SUBROOT");
        ivSub1Sub1Table.insert(3, "xSUB1_SUB1");

        ivRootTable.insert(4, "xROOT_SUB2", "IvSub2");
        ivSub2Table.insert(4, "xSUB2");

        SelectQuery query = new SelectQuery(IvRoot.class);

        List<IvRoot> results = context.performQuery(query);

        assertEquals(4, results.size());
        Map<String, IvRoot> resultTypes = new HashMap<String, IvRoot>();

        for (IvRoot result : results) {
            resultTypes.put(result.getClass().getName(), result);
        }

        assertEquals(4, resultTypes.size());

        IvRoot root = resultTypes.get(IvRoot.class.getName());
        context.deleteObject(root);

        IvSub1 sub1 = (IvSub1) resultTypes.get(IvSub1.class.getName());
        context.deleteObject(sub1);

        context.commitChanges();

        assertEquals(2, ivRootTable.getRowCount());
        assertEquals(1, ivSub1Table.getRowCount());
        assertEquals(1, ivSub1Sub1Table.getRowCount());
        assertEquals(1, ivSub2Table.getRowCount());

        results = context.performQuery(query);
        assertEquals(2, results.size());
    }
View Full Code Here

        assertEquals(2, results.size());
    }

    public void testSelectQuery_AttributeOverrides() throws Exception {

        TableHelper iv1RootTable = new TableHelper(dbHelper, "IV1_ROOT");
        iv1RootTable.setColumns("ID", "NAME", "DISCRIMINATOR");

        TableHelper iv1Sub1Table = new TableHelper(dbHelper, "IV1_SUB1");
        iv1Sub1Table.setColumns("ID", "SUB1_NAME");

        // insert
        iv1RootTable.insert(1, "xROOT", null);
        iv1RootTable.insert(2, "xSUB1_ROOT", "Iv1Sub1");
        iv1Sub1Table.insert(2, "xSUB1");

        SelectQuery query = new SelectQuery(Iv1Root.class);
        List<Iv1Root> results = context.performQuery(query);

        assertEquals(2, results.size());
View Full Code Here

        dbHelper.deleteAll("ARTIST_GROUP");
        dbHelper.deleteAll("ARTIST");
        dbHelper.deleteAll("COMPOUND_FK_TEST");
        dbHelper.deleteAll("COMPOUND_PK_TEST");

        tArtist = new TableHelper(dbHelper, "ARTIST");
        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");

        tPainting = new TableHelper(dbHelper, "PAINTING");
        tPainting.setColumns(
                "PAINTING_ID",
                "ARTIST_ID",
                "PAINTING_TITLE",
                "ESTIMATED_PRICE");

        tCompoundPk = new TableHelper(dbHelper, "COMPOUND_PK_TEST");
        tCompoundPk.setColumns("KEY1", "KEY2");

        tCompoundFk = new TableHelper(dbHelper, "COMPOUND_FK_TEST");
        tCompoundFk.setColumns("PKEY", "F_KEY1", "F_KEY2");
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.test.jdbc.TableHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.