Package org.apache.ddlutils.model

Examples of org.apache.ddlutils.model.Reference


    {
        Identity identity = new Identity(fk.getForeignTable(), getFKName(owningTable, fk));

        for (int idx = 0; idx < fk.getReferenceCount(); idx++)
        {
            Reference reference = (Reference)fk.getReference(idx);
            Object    value     = bean.get(reference.getLocalColumnName());

            if (value == null)
            {
                return null;
            }
            identity.setColumnValue(reference.getForeignColumnName(), value);
        }
        return identity;
    }
View Full Code Here


        }
        if (fk != null)
        {
            for (int idx = 0; idx < fk.getReferenceCount(); idx++)
            {
                Reference curRef       = fk.getReference(idx);
                Column    sourceColumn = curRef.getLocalColumn();
                Column    targetColumn = curRef.getForeignColumn();

                bean.set(sourceColumn.getName(), identity.getColumnValue(targetColumn.getName()));
            }
        }
    }
View Full Code Here

                fk.setForeignTableName(fkRs.getString(3));
                for (int idx = 0; idx < 16; idx++)
                {
                    short     fkColIdx = fkRs.getShort(5 + idx + idx);
                    short     pkColIdx = fkRs.getShort(6 + idx + idx);
                    Reference ref      = new Reference();

                    if (fkColIdx == 0)
                    {
                        break;
                    }

                    prepStmt.setInt(1, localTableId);
                    prepStmt.setShort(2, fkColIdx);

                    ResultSet colRs = prepStmt.executeQuery();

                    if (colRs.next())
                    {
                        ref.setLocalColumnName(colRs.getString(1));
                    }
                    colRs.close();

                    prepStmt.setInt(1, remoteTableId);
                    prepStmt.setShort(2, pkColIdx);

                    colRs = prepStmt.executeQuery();

                    if (colRs.next())
                    {
                        ref.setForeignColumnName(colRs.getString(1));
                    }
                    colRs.close();

                    fk.addReference(ref);
                }
View Full Code Here

            fk = new ForeignKey(fkName);
            fk.setForeignTableName((String)values.get("PKTABLE_NAME"));
            knownFks.put(fkName, fk);
        }

        Reference ref = new Reference();

        ref.setForeignColumnName((String)values.get("PKCOLUMN_NAME"));
        ref.setLocalColumnName((String)values.get("FKCOLUMN_NAME"));
        if (values.containsKey("KEY_SEQ"))
        {
            ref.setSequenceValue(((Short)values.get("KEY_SEQ")).intValue());
        }
        fk.addReference(ref);
    }
View Full Code Here

                    {
                        boolean found = false;

                        for (int curRefIdx = 0; !found && (curRefIdx < curRefs.size()); curRefIdx++)
                        {
                            Reference curRef = (Reference)curRefs.get(curRefIdx);

                            if ((caseMatters  && refs[refIdx].equals(curRef)) ||
                                (!caseMatters && refs[refIdx].equalsIgnoreCase(curRef)))
                            {
                                curRefs.remove(curRefIdx);
View Full Code Here

        assertEquals(someTable.getName(),
                     fk.getForeignTableName());
        assertEquals(1,
                     fk.getReferenceCount());

        Reference ref = fk.getFirstReference();

        assertEquals(fkColumn,
                     ref.getLocalColumn());
        assertEquals("Some_ID",
                     ref.getLocalColumnName());
        assertEquals(pkColumn,
                     ref.getForeignColumn());
        assertEquals("ID",
                     ref.getForeignColumnName());

        assertEquals(
            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX + "\">\n" +
            "  <database name=\"test\">\n" +
            "    <table name=\"SomeTable\" description=\"Some table\">\n" +
View Full Code Here

        assertEquals("A",
                     fk.getForeignTableName());
        assertEquals(1,
                     fk.getReferenceCount());

        Reference ref = fk.getFirstReference();

        assertEquals(table.getColumn(1),
                     ref.getLocalColumn());
        assertEquals("parentId",
                     ref.getLocalColumnName());
        assertEquals(table.getColumn(0),
                     ref.getForeignColumn());
        assertEquals("id",
                     ref.getForeignColumnName());

        Index index = table.getIndex(0);

        assertNull(index.getName());
        assertTrue(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());

        IndexColumn indexColumn = index.getColumn(0);

        assertEquals("name",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        // table B
       
        table = model.getTable(1);

        assertEquals("B",
                     table.getName());
        assertEquals("Table B",
                     table.getDescription());
        assertEquals(0, table.getAutoIncrementColumns().length);
        assertEquals(3,
                     table.getColumnCount());
        assertEquals(2,
                     table.getForeignKeyCount());
        assertEquals(1,
                     table.getIndexCount());

        column = table.getColumn(0);

        assertEquals("id",
                     column.getName());
        assertEquals("TIMESTAMP",
                     column.getType());
        assertEquals(Types.TIMESTAMP,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertTrue(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The primary key of table B",
                     column.getDescription());

        column = table.getColumn(1);

        assertEquals("aid",
                     column.getName());
        assertEquals("INTEGER",
                     column.getType());
        assertEquals(Types.INTEGER,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The field for the foreign key towards A",
                     column.getDescription());

        column = table.getColumn(2);

        assertEquals("cid",
                     column.getName());
        assertEquals("CHAR",
                     column.getType());
        assertEquals(Types.CHAR,
                     column.getTypeCode());
        assertEquals("32",
                     column.getSize());
        assertEquals(32,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The field for the foreign key towards C",
                     column.getDescription());

        fk = table.getForeignKey(0);

        assertNull(fk.getName());
        assertEquals(model.getTable(0),
                     fk.getForeignTable());
        assertEquals("A",
                     fk.getForeignTableName());
        assertEquals(1,
                     fk.getReferenceCount());

        ref = fk.getFirstReference();

        assertEquals(table.getColumn(1),
                     ref.getLocalColumn());
        assertEquals("aid",
                     ref.getLocalColumnName());
        assertEquals(model.getTable(0).getColumn(0),
                     ref.getForeignColumn());
        assertEquals("id",
                     ref.getForeignColumnName());

        fk = table.getForeignKey(1);

        assertNull(fk.getName());
        assertEquals(model.getTable(2),
                     fk.getForeignTable());
        assertEquals("C",
                     fk.getForeignTableName());
        assertEquals(1,
                     fk.getReferenceCount());

        ref = fk.getFirstReference();

        assertEquals(table.getColumn(2),
                     ref.getLocalColumn());
        assertEquals("cid",
                     ref.getLocalColumnName());
        assertEquals(model.getTable(2).getColumn(0),
                     ref.getForeignColumn());
        assertEquals("id",
                     ref.getForeignColumnName());

        index = table.getIndex(0);

        assertNull(index.getName());
        assertFalse(index.isUnique());
View Full Code Here

    t.setName(table.getName());
    return null;
  }

  private Reference getReference(Field field) {
    Reference reference = new Reference();
    Column localColumn = new Column();
    localColumn.setName(field.getName());
    reference.setLocalColumn(localColumn);
    reference.setLocalColumnName(field.getName());

    Column foreignColumn = new Column();
    foreignColumn.setName(field.getLinkToTargetField());
    reference.setForeignColumn(foreignColumn);
    reference.setForeignColumnName(field.getLinkToTargetField());
//    reference.setLocalColumn(localColumn);
//    reference.setForeignColumn(foreignColumn)
    return reference;
  }
View Full Code Here

            // --------------------------

            if ( columnDefinition.mReferenced != null && !columns.mVersioned ) {

                ForeignKey foreignKey = new ForeignKey();
                Reference reference = new Reference();
                String referencedTableName = columnDefinition.mReferenced.substring(
                        0, columnDefinition.mReferenced.indexOf("(")
                );
                String referencedColumnName = columnDefinition.mReferenced.substring(
                        columnDefinition.mReferenced.indexOf("(") + 1,
                        columnDefinition.mReferenced.indexOf(")")
                );
                org.apache.ddlutils.model.Table referencedTable = pDb.findTable(referencedTableName);
                String fkName = (t.getName()
                                 + c.getName()
                                 + "FK"
                                 + referencedTableName
                                 + referencedColumnName);


                foreignKey.setName(fkName);

                if ( referencedTable != null ) {
                    Column referencedColumn = referencedTable.findColumn(referencedColumnName);
                    if ( referencedTable.getName().equals(t.getName())
                         && pRepository.isLoggingDebug()
                         && referencedColumn.getName().equals(c.getName()) ) {
                        if ( pRepository.isLoggingDebug() ) {
                            pRepository.logDebug(
                                    "Skipping foreign key constraint, table and column are the same. Table.Column="
                                    + referencedTableName
                                    + "."
                                    + referencedColumnName
                            );
                        }
                    } else {
                        reference.setForeignColumn(referencedColumn);
                        reference.setLocalColumn(c);
                        foreignKey.addReference(reference);
                        foreignKey.setForeignTable(referencedTable);
                        // try to find existing fk
                        ForeignKey existingKey = t.findForeignKey(foreignKey);
                        // don't add this fk if the name is already used
View Full Code Here

TOP

Related Classes of org.apache.ddlutils.model.Reference

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.