Package org.apache.torque

Examples of org.apache.torque.ForeignKeySchemaData


     * @throws Exception if the test fails
     */
    public void testSetAndSaveModifiedReferencedObject() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        OIntegerPk oIntegerPk = testData.getOIntegerPkList().get(2);
        oIntegerPk.setName("modified");
        List<NullableOIntegerFk> fkList = new ArrayList<NullableOIntegerFk>();
        fkList.add(testData.getNullableOIntegerFkList().get(1));

        OIntegerPkPeer.setAndSaveNullableOIntegerFks(
                oIntegerPk,
                fkList);

View Full Code Here


     * @throws Exception if the test fails
     */
    public void testSetAndSavePkIntegerForeignKey() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        OIntegerPk oIntegerPk = testData.getOIntegerPkList().get(2);
        List<NullableOIntegerFk> fkList = new ArrayList<NullableOIntegerFk>();
        // object already associated to this object
        fkList.add(testData.getNullableOIntegerFkList().get(1));
        // object already associated to another object
        fkList.add(testData.getNullableOIntegerFkList().get(0));
        // object not associated yet
        fkList.add(testData.getNullableOIntegerFkList().get(3));
        // new object
        NullableOIntegerFk newNullableOIntegerFk = new NullableOIntegerFk();
        newNullableOIntegerFk.setName("newNullableOIntegerFk");
        fkList.add(newNullableOIntegerFk);

        OIntegerPkPeer.setAndSaveNullableOIntegerFks(
                oIntegerPk,
                fkList);

        List<NullableOIntegerFk> cachedFks
                = oIntegerPk.getNullableOIntegerFks();
        assertEquals(4, cachedFks.size());
        assertEquals(
                testData.getNullableOIntegerFkList().get(1).getId(),
                cachedFks.get(0).getId());
        assertEquals(
                oIntegerPk.getId(),
                cachedFks.get(0).getFk());
        assertEquals(
                testData.getNullableOIntegerFkList().get(1).getName(),
                cachedFks.get(0).getName());
        assertEquals(
                testData.getNullableOIntegerFkList().get(0).getId(),
                cachedFks.get(1).getId());
        assertEquals(
                oIntegerPk.getId(),
                cachedFks.get(1).getFk());
        assertEquals(
                testData.getNullableOIntegerFkList().get(0).getName(),
                cachedFks.get(1).getName());
        assertEquals(
                testData.getNullableOIntegerFkList().get(3).getId(),
                cachedFks.get(2).getId());
        assertEquals(
                oIntegerPk.getId(),
                cachedFks.get(2).getFk());
        assertEquals(
                testData.getNullableOIntegerFkList().get(3).getName(),
                cachedFks.get(2).getName());
        assertEquals(
                newNullableOIntegerFk.getId(),
                cachedFks.get(3).getId());
        assertEquals(
View Full Code Here

     * @throws Exception if the test fails
     */
    public void testSetAndSaveNonpkIntegerForeignKey() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        OIntegerPk oIntegerPk = testData.getOIntegerPkList().get(0);
        List<NonPkOIntegerFk> fkList = new ArrayList<NonPkOIntegerFk>();
        // object already associated to this object
        fkList.add(testData.getNonPkOIntegerFkList().get(1));
        // object already associated to another object
        fkList.add(testData.getNonPkOIntegerFkList().get(2));
        // object not associated yet
        fkList.add(testData.getNonPkOIntegerFkList().get(3));
        // new object
        NonPkOIntegerFk newNonPkOIntegerFk = new NonPkOIntegerFk();
        newNonPkOIntegerFk.setName("newNonPkOIntegerFk");
        fkList.add(newNonPkOIntegerFk);

        OIntegerPkPeer.setAndSaveNonPkOIntegerFks(
                oIntegerPk,
                fkList);

        List<NonPkOIntegerFk> cachedFks
                = oIntegerPk.getNonPkOIntegerFks();
        assertEquals(4, cachedFks.size());
        assertEquals(
                testData.getNonPkOIntegerFkList().get(1).getId(),
                cachedFks.get(0).getId());
        assertEquals(
                oIntegerPk.getIntegerColumn(),
                cachedFks.get(0).getFk());
        assertEquals(
                testData.getNonPkOIntegerFkList().get(1).getName(),
                cachedFks.get(0).getName());
        assertEquals(
                testData.getNonPkOIntegerFkList().get(2).getId(),
                cachedFks.get(1).getId());
        assertEquals(
                oIntegerPk.getIntegerColumn(),
                cachedFks.get(1).getFk());
        assertEquals(
                testData.getNonPkOIntegerFkList().get(2).getName(),
                cachedFks.get(1).getName());
        assertEquals(
                testData.getNonPkOIntegerFkList().get(3).getId(),
                cachedFks.get(2).getId());
        assertEquals(
                oIntegerPk.getIntegerColumn(),
                cachedFks.get(2).getFk());
        assertEquals(
                testData.getNonPkOIntegerFkList().get(3).getName(),
                cachedFks.get(2).getName());
        assertEquals(
                newNonPkOIntegerFk.getId(),
                cachedFks.get(3).getId());
        assertEquals(
View Full Code Here

     * @throws Exception if the test fails
     */
    public void testSetAndSaveCompositePkIntegerForeignKey() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        CompIntegerVarcharPk compIntegerVarcharPk
                = testData.getCompositeIntegerVarcharPkList().get(2);
        List<CompIntegerVarcharFk> fkList
                = new ArrayList<CompIntegerVarcharFk>();
        // object already associated to this object
        fkList.add(testData.getCompositeIntegerVarcharFkList().get(1));
        // object already associated to another object
        fkList.add(testData.getCompositeIntegerVarcharFkList().get(0));
        // object not associated yet
        fkList.add(testData.getCompositeIntegerVarcharFkList().get(3));
        // new object
        CompIntegerVarcharFk newCompIntegerVarcharFk
                = new CompIntegerVarcharFk();
        newCompIntegerVarcharFk.setName("newCompositeIntegerVarcharFk");
        fkList.add(newCompIntegerVarcharFk);

        CompIntegerVarcharPkPeer.setAndSaveCompIntegerVarcharFks(
                    compIntegerVarcharPk,
                    fkList);

        List<CompIntegerVarcharFk> cachedFks
                = compIntegerVarcharPk.getCompIntegerVarcharFks();
        assertEquals(4, cachedFks.size());
        assertEquals(
                testData.getCompositeIntegerVarcharFkList().get(1).getId(),
                cachedFks.get(0).getId());
        assertEquals(
                compIntegerVarcharPk.getId1(),
                cachedFks.get(0).getFk1());
        assertEquals(
                compIntegerVarcharPk.getId2(),
                cachedFks.get(0).getFk2());
        assertEquals(
                testData.getCompositeIntegerVarcharFkList().get(1).getName(),
                cachedFks.get(0).getName());
        assertEquals(
                testData.getCompositeIntegerVarcharFkList().get(0).getId(),
                cachedFks.get(1).getId());
        assertEquals(
                compIntegerVarcharPk.getId1(),
                cachedFks.get(1).getFk1());
        assertEquals(
                compIntegerVarcharPk.getId2(),
                cachedFks.get(1).getFk2());
        assertEquals(
                testData.getCompositeIntegerVarcharFkList().get(0).getName(),
                cachedFks.get(1).getName());
        assertEquals(
                testData.getCompositeIntegerVarcharFkList().get(3).getId(),
                cachedFks.get(2).getId());
        assertEquals(
                compIntegerVarcharPk.getId1(),
                cachedFks.get(2).getFk1());
        assertEquals(
                compIntegerVarcharPk.getId2(),
                cachedFks.get(2).getFk2());
        assertEquals(
                testData.getCompositeIntegerVarcharFkList().get(3).getName(),
                cachedFks.get(2).getName());
        assertEquals(
                newCompIntegerVarcharFk.getId(),
                cachedFks.get(3).getId());
        assertEquals(
View Full Code Here

     * @throws Exception if the test fails
     */
    public void testSetAndSaveCompositePkOtherFk() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        OIntegerPk oIntegerPk = testData.getOIntegerPkList().get(0);
        List<CompPkOtherFk> fkList = new ArrayList<CompPkOtherFk>();
        // object already associated to this object
        fkList.add(testData.getCompositePkOtherFkList().get(0));
        // object already associated to another object
        fkList.add(testData.getCompositePkOtherFkList().get(2));
        // new object
        CompPkOtherFk newCompPkOtherFk = new CompPkOtherFk();
        newCompPkOtherFk.setName("newCompPkOtherFk");
        newCompPkOtherFk.setId1(42);
        newCompPkOtherFk.setId2("new");
        fkList.add(newCompPkOtherFk);

        OIntegerPkPeer.setAndSaveCompPkOtherFks(
                    oIntegerPk,
                    fkList);

        List<CompPkOtherFk> cachedFks = oIntegerPk.getCompPkOtherFks();
        assertEquals(3, cachedFks.size());
        assertEquals(
                testData.getCompositePkOtherFkList().get(0).getId1(),
                cachedFks.get(0).getId1());
        assertEquals(
                testData.getCompositePkOtherFkList().get(0).getId2(),
                cachedFks.get(0).getId2());
        assertEquals(
                oIntegerPk.getId(),
                cachedFks.get(0).getFk());
        assertEquals(
                testData.getCompositePkOtherFkList().get(0).getName(),
                cachedFks.get(0).getName());
        assertEquals(
                testData.getCompositePkOtherFkList().get(2).getId1(),
                cachedFks.get(1).getId1());
        assertEquals(
                testData.getCompositePkOtherFkList().get(2).getId2(),
                cachedFks.get(1).getId2());
        assertEquals(
                oIntegerPk.getId(),
                cachedFks.get(1).getFk());
        assertEquals(
                testData.getCompositePkOtherFkList().get(2).getName(),
                cachedFks.get(1).getName());
        assertEquals(
                newCompPkOtherFk.getId1(),
                cachedFks.get(2).getId1());
        assertEquals(
View Full Code Here

     * @throws Exception if the test fails
     */
    public void testSetAndSaveCompositePkContainsFk() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        OIntegerPk oIntegerPk = testData.getOIntegerPkList().get(0);
        List<CompPkContainsFk> fkList = new ArrayList<CompPkContainsFk>();
        // object already associated to this object
        fkList.add(testData.getCompositePkContainsFkList().get(0));
        // new object
        CompPkContainsFk newCompPkContainsFk = new CompPkContainsFk();
        newCompPkContainsFk.setName("newCompPkContainsFk");
        newCompPkContainsFk.setId2("new");
        fkList.add(newCompPkContainsFk);

        OIntegerPkPeer.setAndSaveCompPkContainsFks(
                    oIntegerPk,
                    fkList);

        List<CompPkContainsFk> cachedFks = oIntegerPk.getCompPkContainsFks();
        assertEquals(2, cachedFks.size());
        assertEquals(
                oIntegerPk.getId(),
                cachedFks.get(0).getId1());
        assertEquals(
                testData.getCompositePkContainsFkList().get(0).getId2(),
                cachedFks.get(0).getId2());
        assertEquals(
                testData.getCompositePkContainsFkList().get(0).getName(),
                cachedFks.get(0).getName());
        assertEquals(
                oIntegerPk.getId(),
                cachedFks.get(1).getId1());
        assertEquals(
                newCompPkContainsFk.getId2(),
                cachedFks.get(1).getId2());
        assertEquals(
                newCompPkContainsFk.getName(),
                cachedFks.get(1).getName());

        // check database
        List<CompPkContainsFk> expectedInDb
                = new ArrayList<CompPkContainsFk>(cachedFks);
        expectedInDb.add(testData.getCompositePkContainsFkList().get(2));
        ForeignKeySchemaData.assertCompositePkContainsFksInDatabaseEquals(
                expectedInDb);
    }
View Full Code Here

     * @throws Exception if the test fails
     */
    public void testSetAndSaveModifiedReferencingObject() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        OIntegerPk oIntegerPk = testData.getOIntegerPkList().get(2);
        List<NullableOIntegerFk> fkList = new ArrayList<NullableOIntegerFk>();
        // copy object already associated to this object
        NullableOIntegerFk alreadyAssociated
                = testData.getNullableOIntegerFkList().get(1).copy();
        // id does not get copied, set manually
        alreadyAssociated.setId(
                testData.getNullableOIntegerFkList().get(1).getId());
        alreadyAssociated.setName("modifiedName");
        alreadyAssociated.setNew(true); // saving must also work with wrong new flag
        alreadyAssociated.setModified(false); // saving must work without the modified flag
        fkList.add(alreadyAssociated);

        OIntegerPkPeer.setAndSaveNullableOIntegerFks(
                oIntegerPk,
                fkList);

        List<NullableOIntegerFk> cachedFks
                = oIntegerPk.getNullableOIntegerFks();
        assertEquals(1, cachedFks.size());
        assertEquals(
                testData.getNullableOIntegerFkList().get(1).getId(),
                cachedFks.get(0).getId());
        assertEquals(
                oIntegerPk.getId(),
                cachedFks.get(0).getFk());
        assertEquals(
                "modifiedName",
                cachedFks.get(0).getName());

        // check database
        List<NullableOIntegerFk>expectedInDb
                = new ArrayList<NullableOIntegerFk>();
        expectedInDb.addAll(cachedFks);
        expectedInDb.add(testData.getNullableOIntegerFkList().get(0));
        expectedInDb.add(testData.getNullableOIntegerFkList().get(3));
        ForeignKeySchemaData.assertNullableOIntegerFksInDatabaseEquals(
                expectedInDb);
    }
View Full Code Here

     * @throws Exception if a database error occurs.
     */
    public void testFillReferencedPrimitiveIntegerKey() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(
                RequiredPIntegerFkPeer.ID);
        List<RequiredPIntegerFk> fkList
                = RequiredPIntegerFkPeer.doSelect(criteria);
        assertEquals(3, fkList.size());
        assertEquals(
                testData.getRequiredPIntegerFkList().get(0).getId(),
                fkList.get(0).getId());
        // TODO check that NullableIntFkList entries have not yet
        //      loaded their referenced intPk object

        List<PIntegerPk> referencedPkList
                = RequiredPIntegerFkPeer.fillPIntegerPks(
                        fkList);
        // TODO check that NullableIntFkList entries have now
        //      loaded their referenced intPk object

        // returned list must contain intPk2, intPk3, intPk3
        // and the last 2 objects must not be the same objects
        assertEquals(3, referencedPkList.size());
        assertEquals(
                testData.getPIntegerPkList().get(1).getId(),
                referencedPkList.get(0).getId());
        assertEquals(
                testData.getPIntegerPkList().get(2).getId(),
                referencedPkList.get(1).getId());
        assertEquals(
                testData.getPIntegerPkList().get(2).getId(),
                referencedPkList.get(2).getId());
        assertNotSame(
                referencedPkList.get(1),
                referencedPkList.get(2));

        // the fk list must reference intPk2, intPk3, intPk3
        // and the last 2 referenced objects must not be the same objects
        assertEquals(
                testData.getPIntegerPkList().get(1),
                fkList.get(0).getPIntegerPk());
        assertEquals(
                testData.getPIntegerPkList().get(2),
                fkList.get(1).getPIntegerPk());
        assertEquals(
                testData.getPIntegerPkList().get(2),
                fkList.get(2).getPIntegerPk());
        assertNotSame(
                fkList.get(1).getPIntegerPk(),
                fkList.get(2).getPIntegerPk());

View Full Code Here

     * @throws Exception if a database error occurs.
     */
    public void testFillReferencedObjectIntegerKey() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(
                NullableOIntegerFkPeer.ID);
        List<NullableOIntegerFk> fkList
                = NullableOIntegerFkPeer.doSelect(criteria);
        assertEquals(4, fkList.size());
        assertEquals(
                testData.getNullableOIntegerFkList().get(0).getId(),
                fkList.get(0).getId());
        // TODO check that fkList entries have not yet
        //      loaded its referenced intPk object

        List<OIntegerPk> referencedPkList
                = NullableOIntegerFkPeer.fillOIntegerPks(
                        fkList);

        // returned list must contain intPk2, intPk3, intPk3
        // and the last 2 objects must not be the same objects
        assertEquals(3, referencedPkList.size());
        assertEquals(
                testData.getOIntegerPkList().get(1).getId(),
                referencedPkList.get(0).getId());
        assertEquals(
                testData.getOIntegerPkList().get(2).getId(),
                referencedPkList.get(1).getId());
        assertEquals(
                testData.getOIntegerPkList().get(2).getId(),
                referencedPkList.get(2).getId());
        assertNotSame(
                referencedPkList.get(1),
                referencedPkList.get(2));

        // the fk list must reference intPk2, intPk3, intPk3
        // and the last 2 referenced objects must not be the same objects
        assertEquals(
                testData.getOIntegerPkList().get(1),
                fkList.get(0).getOIntegerPk());
        assertEquals(
                testData.getOIntegerPkList().get(2),
                fkList.get(1).getOIntegerPk());
        assertEquals(
                testData.getOIntegerPkList().get(2),
                fkList.get(2).getOIntegerPk());
        assertNotSame(
                fkList.get(1).getOIntegerPk(),
                fkList.get(2).getOIntegerPk());

View Full Code Here

     * @throws Exception if a database error occurs.
     */
    public void testFillReferencedNonPrimaryKey() throws Exception
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(
                NonPkOIntegerFkPeer.ID);
        List<NonPkOIntegerFk> fkList
                = NonPkOIntegerFkPeer.doSelect(criteria);
        assertEquals(4, fkList.size());
        assertEquals(
                testData.getNonPkOIntegerFkList().get(0).getId(),
                fkList.get(0).getId());
        // TODO check that fkList entries have not yet
        //      loaded its referenced intPk object

        List<OIntegerPk> referencedPkList
                = NonPkOIntegerFkPeer.fillOIntegerPks(
                        fkList);

        // returned list must contain intPk1, intPk1, intPk2
        // and the first 2 objects must not be the same objects
        assertEquals(3, referencedPkList.size());
        assertEquals(
                testData.getOIntegerPkList().get(0).getId(),
                referencedPkList.get(0).getId());
        assertEquals(
                testData.getOIntegerPkList().get(0).getId(),
                referencedPkList.get(1).getId());
        assertEquals(
                testData.getOIntegerPkList().get(1).getId(),
                referencedPkList.get(2).getId());
        assertNotSame(
                referencedPkList.get(0),
                referencedPkList.get(1));

        // the fk list must reference intPk1, intPk1, intPk2
        // and the first 2 referenced objects must not be the same objects
        assertEquals(
                testData.getOIntegerPkList().get(0),
                fkList.get(0).getOIntegerPk());
        assertEquals(
                testData.getOIntegerPkList().get(0),
                fkList.get(1).getOIntegerPk());
        assertEquals(
                testData.getOIntegerPkList().get(1),
                fkList.get(2).getOIntegerPk());
        assertNotSame(
                fkList.get(0).getOIntegerPk(),
                fkList.get(1).getOIntegerPk());

View Full Code Here

TOP

Related Classes of org.apache.torque.ForeignKeySchemaData

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.