Search in sources :

Example 6 with IForeignKey

use of org.jboss.tools.hibernate.runtime.spi.IForeignKey in project jbosstools-hibernate by jbosstools.

the class ElementsFactory method createForeingKeyConnections.

@SuppressWarnings("unchecked")
public void createForeingKeyConnections() {
    // do clone cause elements could be changed during iteration!
    HashMap<String, OrmShape> elementsTmp = (HashMap<String, OrmShape>) elements.clone();
    Iterator<OrmShape> it = elementsTmp.values().iterator();
    while (it.hasNext()) {
        final OrmShape shape = it.next();
        Object ormElement = shape.getOrmElement();
        if (ormElement instanceof ITable) {
            ITable databaseTable = (ITable) ormElement;
            Iterator<IForeignKey> itFK = databaseTable.getForeignKeyIterator();
            while (itFK.hasNext()) {
                final IForeignKey fk = itFK.next();
                ITable referencedTable = fk.getReferencedTable();
                final OrmShape referencedShape = getOrCreateDatabaseTable(referencedTable);
                // 
                Iterator<IColumn> itColumns = fk.columnIterator();
                while (itColumns.hasNext()) {
                    IColumn col = itColumns.next();
                    Shape shapeColumn = shape.getChild(col);
                    Iterator<IColumn> itReferencedColumns = null;
                    if (fk.isReferenceToPrimaryKey()) {
                        itReferencedColumns = (Iterator<IColumn>) referencedTable.getPrimaryKey().columnIterator();
                    } else {
                        itReferencedColumns = (Iterator<IColumn>) fk.getReferencedColumns().iterator();
                    }
                    while (itReferencedColumns != null && itReferencedColumns.hasNext()) {
                        IColumn colReferenced = itReferencedColumns.next();
                        Shape shapeReferencedColumn = referencedShape.getChild(colReferenced);
                        if (shouldCreateConnection(shapeColumn, shapeReferencedColumn)) {
                            connections.add(new Connection(shapeColumn, shapeReferencedColumn));
                        }
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) IForeignKey(org.jboss.tools.hibernate.runtime.spi.IForeignKey) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ITable(org.jboss.tools.hibernate.runtime.spi.ITable)

Example 7 with IForeignKey

use of org.jboss.tools.hibernate.runtime.spi.IForeignKey in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateForeignKey.

@Test
public void testCreateForeignKey() {
    ForeignKey foreignKey = new ForeignKey();
    IForeignKey facade = facadeFactory.createForeignKey(foreignKey);
    Assert.assertSame(foreignKey, ((IFacade) facade).getTarget());
}
Also used : IForeignKey(org.jboss.tools.hibernate.runtime.spi.IForeignKey) IForeignKey(org.jboss.tools.hibernate.runtime.spi.IForeignKey) ForeignKey(org.hibernate.mapping.ForeignKey) Test(org.junit.Test)

Example 8 with IForeignKey

use of org.jboss.tools.hibernate.runtime.spi.IForeignKey in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateForeignKey.

@Test
public void testCreateForeignKey() {
    ForeignKey foreignKey = new ForeignKey();
    IForeignKey facade = facadeFactory.createForeignKey(foreignKey);
    Assert.assertSame(foreignKey, ((IFacade) facade).getTarget());
}
Also used : IForeignKey(org.jboss.tools.hibernate.runtime.spi.IForeignKey) IForeignKey(org.jboss.tools.hibernate.runtime.spi.IForeignKey) ForeignKey(org.hibernate.mapping.ForeignKey) Test(org.junit.Test)

Example 9 with IForeignKey

use of org.jboss.tools.hibernate.runtime.spi.IForeignKey in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateForeignKey.

@Test
public void testCreateForeignKey() {
    ForeignKey foreignKey = new ForeignKey();
    IForeignKey facade = facadeFactory.createForeignKey(foreignKey);
    Assert.assertSame(foreignKey, ((IFacade) facade).getTarget());
}
Also used : IForeignKey(org.jboss.tools.hibernate.runtime.spi.IForeignKey) ForeignKey(org.hibernate.mapping.ForeignKey) IForeignKey(org.jboss.tools.hibernate.runtime.spi.IForeignKey) Test(org.junit.Test)

Aggregations

IForeignKey (org.jboss.tools.hibernate.runtime.spi.IForeignKey)9 ForeignKey (org.hibernate.mapping.ForeignKey)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)1 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)1 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)1