Package org.apache.torque

Examples of org.apache.torque.ForeignKeySchemaData


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

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(CompIntegerVarcharPkPeer.ID1);
        criteria.addAscendingOrderByColumn(CompIntegerVarcharPkPeer.ID2);
        List<CompIntegerVarcharPk> pkList
                = CompIntegerVarcharPkPeer.doSelect(criteria);
        assertEquals(3, pkList.size());
        assertEquals(
                testData.getCompositeIntegerVarcharPkList().get(0).getPrimaryKey(),
                pkList.get(0).getPrimaryKey());
        // check referencing lists are not initialized
        for (CompIntegerVarcharPk compIntegerVarcharPk : pkList)
        {
            assertFalse(compIntegerVarcharPk.isCompIntegerVarcharFksInitialized());
        }

        List<CompIntegerVarcharFk> referencingFkList
                = CompIntegerVarcharPkPeer.fillCompIntegerVarcharFks(
                        pkList);

        // returned list must contain compositeIntegerVarcharFk2,
        // compositeIntegerVarcharFk3a, compositeIntegerVarcharFk3b
        // where the order of the last two is undefined
        assertEquals(3, referencingFkList.size());
        assertEquals(
                testData.getCompositeIntegerVarcharFkList().get(0).getId(),
                referencingFkList.get(0).getId());
        assertTrue(
                referencingFkList.contains(
                        testData.getCompositeIntegerVarcharFkList().get(1)));
        assertTrue(
                referencingFkList.contains(
                        testData.getCompositeIntegerVarcharFkList().get(2)));

        // The second pk entry must reference compositeIntegerVarcharFk2
        // and the third pk entry must reference compositeIntegerVarcharFk3a
        // and compositeIntegerVarcharFk3b
        assertEquals(0, pkList.get(0).getCompIntegerVarcharFks().size());
        assertEquals(1, pkList.get(1).getCompIntegerVarcharFks().size());
        assertEquals(2, pkList.get(2).getCompIntegerVarcharFks().size());
        assertEquals(
                testData.getCompositeIntegerVarcharFkList().get(0),
                pkList.get(1).getCompIntegerVarcharFks().get(0));
        assertTrue(
                pkList.get(2).getCompIntegerVarcharFks().contains(
                        testData.getCompositeIntegerVarcharFkList().get(1)));
        assertTrue(
                pkList.get(2).getCompIntegerVarcharFks().contains(
                        testData.getCompositeIntegerVarcharFkList().get(2)));

        // The objects in the result list must be the same objects
        // as the referenced objects in the pk list
        assertSame(
                referencingFkList.get(0),
View Full Code Here


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

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(CompIntegerVarcharPkPeer.ID1);
        criteria.addAscendingOrderByColumn(CompIntegerVarcharPkPeer.ID2);
        List<CompIntegerVarcharPk> pkList
                = CompIntegerVarcharPkPeer.doSelect(criteria);
        assertEquals(3, pkList.size());
        assertEquals(
                testData.getCompositeIntegerVarcharPkList().get(0).getPrimaryKey(),
                pkList.get(0).getPrimaryKey());
        // check referencing lists are not initialized
        for (CompIntegerVarcharPk compIntegerVarcharPk : pkList)
        {
            assertFalse(compIntegerVarcharPk.isCompNonpkFksInitialized());
        }

        List<CompNonpkFk> referencingFkList
                = CompIntegerVarcharPkPeer.fillCompNonpkFks(pkList);

        // returned list must contain compositeNonpkFk1a,
        // compositeNonpkFk1b, compositeNonpkFk2
        // where the order of the first two is undefined
        assertEquals(3, referencingFkList.size());
        assertTrue(
                referencingFkList.contains(
                        testData.getCompositeNonpkFkList().get(0)));
        assertTrue(
                referencingFkList.contains(
                        testData.getCompositeNonpkFkList().get(1)));
        assertEquals(
                testData.getCompositeNonpkFkList().get(2).getId(),
                referencingFkList.get(2).getId());

        // The first pk entry must reference compositeNonpkFk1a and
        // compositeNonpkFk1b and the second pk entry must reference
        // compositeNonpkFk2
        assertEquals(2, pkList.get(0).getCompNonpkFks().size());
        assertEquals(1, pkList.get(1).getCompNonpkFks().size());
        assertEquals(0, pkList.get(2).getCompNonpkFks().size());
        assertTrue(
                pkList.get(0).getCompNonpkFks().contains(
                        testData.getCompositeNonpkFkList().get(0)));
        assertTrue(
                pkList.get(0).getCompNonpkFks().contains(
                        testData.getCompositeNonpkFkList().get(1)));
        assertEquals(
                testData.getCompositeNonpkFkList().get(2),
                pkList.get(1).getCompNonpkFks().get(0));

        // The objects in the result list must be the same objects
        // as the referenced objects in the pk list
        assertSame(
View Full Code Here

     * with the current database state.
     */
    public void testReferencingObjectRefill() throws TorqueException
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        Criteria criteria = new Criteria();
        criteria.and(OIntegerPkPeer.NAME, "oIntegerPk2");
        List<OIntegerPk> pkList = OIntegerPkPeer.doSelect(criteria);
        assertEquals(1, pkList.size());
        OIntegerPk pkObject = pkList.get(0);
        assertEquals(
                testData.getOIntegerPkList().get(1).getId(),
                pkList.get(0).getId());

        NullableOIntegerFk changedFkObject
                = pkObject.getNullableOIntegerFks().get(0);
        changedFkObject.setName("nullableOIntegerFk2Modified");
View Full Code Here

     * Tests that the chunk size -1 works for referencing objects.
     */
    public void testReferencingObjectChunkSizeMinusOne() throws TorqueException
    {
        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(PIntegerPkPeer.ID);
        List<PIntegerPk> pkList = PIntegerPkPeer.doSelect(criteria);
        assertEquals(3, pkList.size());
        assertEquals(
                testData.getPIntegerPkList().get(0).getId(),
                pkList.get(0).getId());
        // check referencing lists are not initialized
        for (PIntegerPk pIntegerPk : pkList)
        {
            assertFalse(pIntegerPk.isRequiredPIntegerFksInitialized());
        }

        List<RequiredPIntegerFk> referencingFkList
                = PIntegerPkPeer.fillRequiredPIntegerFks(pkList, -1);

        // check all referencing lists are initialized
        for (PIntegerPk pIntegerPk : pkList)
        {
            assertTrue(pIntegerPk.isRequiredPIntegerFksInitialized());
        }
        // returned list must contain requiredPIntegerFk2,
        // requiredPIntegerFk3a, requiredPIntegerFk3b
        // where the last two can be exchanged
        assertEquals(3, referencingFkList.size());
        assertEquals(
                testData.getRequiredPIntegerFkList().get(0).getId(),
                referencingFkList.get(0).getId());
        assertTrue(
                referencingFkList.contains(
                        testData.getRequiredPIntegerFkList().get(1)));
        assertTrue(
                referencingFkList.contains(
                        testData.getRequiredPIntegerFkList().get(2)));

        // The second pk entry must reference requiredPIntegerFk2
        // and the third pk entry must reference requiredPIntegerFk3a
        // and requiredPIntegerFk3b
        assertEquals(0, pkList.get(0).getRequiredPIntegerFks().size());
        assertEquals(1, pkList.get(1).getRequiredPIntegerFks().size());
        assertEquals(2, pkList.get(2).getRequiredPIntegerFks().size());
        assertEquals(
                testData.getRequiredPIntegerFkList().get(0),
                pkList.get(1).getRequiredPIntegerFks().get(0));
        assertTrue(
                pkList.get(2).getRequiredPIntegerFks().contains(
                        testData.getRequiredPIntegerFkList().get(1)));
        assertTrue(
                pkList.get(2).getRequiredPIntegerFks().contains(
                        testData.getRequiredPIntegerFkList().get(2)));

        // The objects in the result list must be the same objects
        // as the referenced objects in the pk list
        assertSame(
                referencingFkList.get(0),
View Full Code Here

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

        NullableOIntegerFk toDelete
            = testData.getNullableOIntegerFkList().get(0);
        int preDeleteId = toDelete.getId();

        // check that four entries are in the NullableOIntegerFk table
        List<NullableOIntegerFk> nullableOIntegerFkList
                = getNullableOIntegerFkList();
View Full Code Here

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

        NullableOIntegerFk toDelete
            = testData.getNullableOIntegerFkList().get(0);
        toDelete.setId(toDelete.getId() - 1);
        int preDeleteId = toDelete.getId();

        // check that four entries are in the NullableOIntegerFk table
        List<NullableOIntegerFk> nullableOIntegerFkList
View Full Code Here

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

        NullableOIntegerFk toDelete
            = testData.getNullableOIntegerFkList().get(0);
        toDelete.setName("nullableOIntegerFk2Changed");
        int preDeleteId = toDelete.getId();

        // check that isDeleted() is false before deletion
        assertFalse(toDelete.isDeleted());
View Full Code Here

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

        List<NullableOIntegerFk> toDelete
            = new ArrayList<NullableOIntegerFk>();
        toDelete.add(testData.getNullableOIntegerFkList().get(0));
        toDelete.add(testData.getNullableOIntegerFkList().get(2));
        List<Integer> preDeleteIds = new ArrayList<Integer>();
        preDeleteIds.add(toDelete.get(0).getId());
        preDeleteIds.add(toDelete.get(1).getId());

        // check that isDeleted() is false before deletion
View Full Code Here

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

        List<NullableOIntegerFk> toDelete
            = new ArrayList<NullableOIntegerFk>();
        toDelete.add(testData.getNullableOIntegerFkList().get(0));
        toDelete.add(testData.getNullableOIntegerFkList().get(2));
        toDelete.get(0).setId(toDelete.get(0).getId() - 1);
        int preDeleteId = toDelete.get(0).getId();

        // check that isDeleted() is false before deletion
        assertFalse(toDelete.get(0).isDeleted());
View Full Code Here

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

        NullableOIntegerFk toDelete
            = testData.getNullableOIntegerFkList().get(0);
        int preDeleteId = toDelete.getId();

        // check that four entries are in the NullableOIntegerFk table
        List<NullableOIntegerFk> nullableOIntegerFkList
                = getNullableOIntegerFkList();
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.