Search in sources :

Example 6 with ITable

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

the class ElementsFactory method getOrCreatePersistentClass.

@SuppressWarnings({ "rawtypes" })
protected OrmShape getOrCreatePersistentClass(IPersistentClass persistentClass, ITable componentClassDatabaseTable) {
    OrmShape classShape = null;
    if (persistentClass == null) {
        return classShape;
    }
    OrmShape shape = null;
    classShape = getShape(persistentClass.getEntityName());
    if (classShape == null) {
        classShape = createShape(persistentClass);
    }
    if (componentClassDatabaseTable == null && persistentClass.getTable() != null) {
        componentClassDatabaseTable = persistentClass.getTable();
    }
    if (componentClassDatabaseTable != null) {
        shape = getShape(componentClassDatabaseTable);
        if (shape == null) {
            shape = getOrCreateDatabaseTable(componentClassDatabaseTable);
        }
        createConnections(classShape, shape);
        if (shouldCreateConnection(classShape, shape)) {
            connections.add(new Connection(classShape, shape));
        }
    }
    IPersistentClass rc = persistentClass;
    Iterator iter = rc.getSubclassIterator();
    while (iter.hasNext()) {
        Object element = iter.next();
        if (element instanceof IPersistentClass && ((IPersistentClass) element).isInstanceOfSubclass()) {
            IPersistentClass subclass = (IPersistentClass) element;
            OrmShape subclassShape = getShape(subclass);
            if (subclassShape == null) {
                subclassShape = createShape(subclass);
            }
            if (((IPersistentClass) element).isJoinedSubclass()) {
                ITable jcTable = ((IPersistentClass) element).getTable();
                OrmShape jcTableShape = getOrCreateDatabaseTable(jcTable);
                createConnections(subclassShape, jcTableShape);
                if (shouldCreateConnection(subclassShape, jcTableShape)) {
                    connections.add(new Connection(subclassShape, jcTableShape));
                }
            } else {
                createConnections(subclassShape, shape);
                if (shouldCreateConnection(subclassShape, shape)) {
                    connections.add(new Connection(subclassShape, shape));
                }
            }
            OrmShape ownerTableShape = getOrCreateDatabaseTable(((IPersistentClass) element).getRootTable());
            createConnections(subclassShape, ownerTableShape);
            Iterator<IJoin> joinIterator = subclass.getJoinIterator();
            while (joinIterator.hasNext()) {
                IJoin join = joinIterator.next();
                Iterator<IProperty> iterator = join.getPropertyIterator();
                while (iterator.hasNext()) {
                    IProperty property = iterator.next();
                    OrmShape tableShape = getOrCreateDatabaseTable(property.getValue().getTable());
                    createConnections(subclassShape, tableShape);
                }
            }
        }
    }
    IValue identifier = persistentClass.getIdentifier();
    if (identifier != null && identifier.isComponent()) {
        if (identifier.getComponentClassName() != null && !identifier.getComponentClassName().equals(identifier.getOwner().getEntityName())) {
            OrmShape componentClassShape = elements.get(identifier.getComponentClassName());
            if (componentClassShape == null && persistentClass.isInstanceOfRootClass()) {
                componentClassShape = getOrCreateComponentClass(persistentClass.getIdentifierProperty());
                Shape idPropertyShape = classShape.getChild(persistentClass.getIdentifierProperty());
                if (shouldCreateConnection(idPropertyShape, componentClassShape)) {
                    connections.add(new Connection(idPropertyShape, componentClassShape));
                }
                OrmShape tableShape = getOrCreateDatabaseTable(identifier.getTable());
                if (componentClassShape != null) {
                    createConnections(componentClassShape, tableShape);
                }
            }
        }
    }
    Iterator<IJoin> joinIterator = persistentClass.getJoinIterator();
    while (joinIterator.hasNext()) {
        IJoin join = (IJoin) joinIterator.next();
        Iterator<IProperty> iterator = join.getPropertyIterator();
        while (iterator.hasNext()) {
            IProperty property = iterator.next();
            OrmShape tableShape = getOrCreateDatabaseTable(property.getValue().getTable());
            createConnections(classShape, tableShape);
        }
    }
    return classShape;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) Iterator(java.util.Iterator) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IJoin(org.jboss.tools.hibernate.runtime.spi.IJoin) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 7 with ITable

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

the class OrmDiagram method getPropertyValue.

@Override
public Object getPropertyValue(Object propertyId) {
    Object res = null;
    if (PROPERTY_NAME.equals(propertyId)) {
        res = getDiagramName();
    } else if (PROPERTY_WIDTH.equals(propertyId)) {
        res = Integer.valueOf(width).toString();
    } else if (PROPERTY_HEIGHT.equals(propertyId)) {
        res = Integer.valueOf(height).toString();
    } else if (PROPERTY_ZOOM.equals(propertyId)) {
        res = Double.valueOf(zoom).toString();
    } else if (PROPERTY_ITEMS.equals(propertyId)) {
        res = Integer.valueOf(elements.size()).toString();
    } else if (PROPERTY_ENTITIES.equals(propertyId)) {
        int nEntities = 0;
        Iterator<OrmShape> it = elements.values().iterator();
        while (it.hasNext()) {
            final OrmShape shape = it.next();
            Object ormElement = shape.getOrmElement();
            if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfRootClass()) {
                nEntities++;
            }
        }
        res = Integer.valueOf(nEntities).toString();
    } else if (PROPERTY_TABLES.equals(propertyId)) {
        int nTables = 0;
        Iterator<OrmShape> it = elements.values().iterator();
        while (it.hasNext()) {
            final OrmShape shape = it.next();
            Object ormElement = shape.getOrmElement();
            if (ormElement instanceof ITable) {
                nTables++;
            }
        }
        res = Integer.valueOf(nTables).toString();
    } else if (PROPERTY_INVISIBLE.equals(propertyId)) {
        int nInvisible = 0;
        Iterator<OrmShape> it = elements.values().iterator();
        while (it.hasNext()) {
            final OrmShape shape = it.next();
            if (!shape.isVisible()) {
                nInvisible++;
            }
        }
        res = Integer.valueOf(nInvisible).toString();
    }
    if (res == null) {
        res = super.getPropertyValue(propertyId);
    }
    return toEmptyStr(res);
}
Also used : Iterator(java.util.Iterator) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Point(org.eclipse.draw2d.geometry.Point)

Example 8 with ITable

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

the class OrmShape method initModel.

/**
 * creates children of the shape,
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void initModel() {
    Object ormElement = getOrmElement();
    if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfRootClass()) {
        IPersistentClass rootClass = (IPersistentClass) ormElement;
        IProperty identifierProperty = rootClass.getIdentifierProperty();
        if (identifierProperty != null) {
            addChild(new Shape(identifierProperty, getConsoleConfigName()));
        }
        IValue identifier = rootClass.getIdentifier();
        if (identifier != null && identifier.isComponent()) {
            IValue component = identifier;
            if (component.isEmbedded()) {
                Iterator<IProperty> iterator = identifier.getPropertyIterator();
                while (iterator.hasNext()) {
                    IProperty property = iterator.next();
                    addChild(new Shape(property, getConsoleConfigName()));
                }
            }
        }
        Iterator<IProperty> iterator = rootClass.getPropertyIterator();
        while (iterator.hasNext()) {
            IProperty field = iterator.next();
            if (!field.isBackRef()) {
                if (!field.isComposite()) {
                    final IValue val = field.getValue();
                    Shape bodyOrmShape = null;
                    if (val.isSimpleValue() && val.isTypeSpecified()) {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    } else {
                        if (val.isCollection()) {
                            bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
                        } else {
                            IType type = getTypeUsingExecContext(val);
                            if (type != null && type.isEntityType()) {
                                bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                            } else {
                                bodyOrmShape = new Shape(field, getConsoleConfigName());
                            }
                        }
                    }
                    addChild(bodyOrmShape);
                } else {
                    Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                    addChild(bodyOrmShape);
                }
            }
        }
    } else if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfSubclass()) {
        IPersistentClass rootClass = ((IPersistentClass) ormElement).getRootClass();
        IProperty identifierProperty = rootClass.getIdentifierProperty();
        if (identifierProperty != null) {
            addChild(new Shape(identifierProperty, getConsoleConfigName()));
        }
        IValue identifier = rootClass.getIdentifier();
        if (identifier.isComponent()) {
            Iterator<IProperty> iterator = identifier.getPropertyIterator();
            while (iterator.hasNext()) {
                IProperty property = iterator.next();
                addChild(new Shape(property, getConsoleConfigName()));
            }
        }
        Iterator<IProperty> iterator = rootClass.getPropertyIterator();
        while (iterator.hasNext()) {
            IProperty field = iterator.next();
            if (!field.isBackRef()) {
                if (!field.isComposite()) {
                    IValue fieldValue = field.getValue();
                    boolean typeIsAccessible = true;
                    if (fieldValue.isSimpleValue() && fieldValue.isTypeSpecified()) {
                        try {
                            field.getValue().getType();
                        } catch (Exception e) {
                            typeIsAccessible = false;
                        }
                    }
                    Shape bodyOrmShape = null;
                    if (typeIsAccessible && field.getValue().isSimpleValue()) {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    } else if (typeIsAccessible && field.getValue().getType().isEntityType()) {
                        bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                    } else if (typeIsAccessible && field.getValue().getType().isCollectionType()) {
                        bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
                    } else {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    }
                    addChild(bodyOrmShape);
                } else {
                    Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                    addChild(bodyOrmShape);
                }
            }
        }
        Iterator<IProperty> iter = ((IPersistentClass) ormElement).getPropertyIterator();
        while (iter.hasNext()) {
            IProperty property = iter.next();
            if (!property.isBackRef()) {
                if (!property.isComposite()) {
                    boolean typeIsAccessible = true;
                    IValue propertyValue = property.getValue();
                    if (propertyValue.isSimpleValue() && propertyValue.isTypeSpecified()) {
                        try {
                            property.getValue().getType();
                        } catch (Exception e) {
                            typeIsAccessible = false;
                        }
                    }
                    Shape bodyOrmShape = null;
                    if (typeIsAccessible && property.getValue().getType().isEntityType()) {
                        bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
                    } else if (typeIsAccessible && property.getValue().getType().isCollectionType()) {
                        bodyOrmShape = new ComponentShape(property, getConsoleConfigName());
                    } else {
                        bodyOrmShape = new Shape(property, getConsoleConfigName());
                    }
                    addChild(bodyOrmShape);
                } else {
                    Shape bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
                    addChild(bodyOrmShape);
                }
            }
        }
    } else if (ormElement instanceof ITable) {
        Iterator iterator = ((ITable) getOrmElement()).getColumnIterator();
        while (iterator.hasNext()) {
            IColumn column = (IColumn) iterator.next();
            Shape bodyOrmShape = new Shape(column, getConsoleConfigName());
            addChild(bodyOrmShape);
        }
    }
}
Also used : IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IType(org.jboss.tools.hibernate.runtime.spi.IType) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Iterator(java.util.Iterator) ITable(org.jboss.tools.hibernate.runtime.spi.ITable)

Example 9 with ITable

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

the class ServiceImpl method newTable.

@Override
public ITable newTable(String name) {
    Table target = new Table(name);
    target.setPrimaryKey(new PrimaryKey(target));
    return facadeFactory.createTable(target);
}
Also used : ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) PrimaryKey(org.hibernate.mapping.PrimaryKey)

Example 10 with ITable

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

the class ShapeShowAction method canPerformAction.

private boolean canPerformAction() {
    boolean res = false;
    if (getSelectedObjects().isEmpty()) {
        return res;
    }
    Iterator<?> it = getSelectedObjects().iterator();
    while (it.hasNext() && !res) {
        Object firstElement = it.next();
        Object obj = null;
        if (firstElement instanceof OrmEditPart) {
            obj = ((OrmEditPart) firstElement).getModel();
        } else if (firstElement instanceof AbstractTreeEditPart) {
            obj = ((AbstractTreeEditPart) firstElement).getModel();
        }
        if (null != obj && obj instanceof OrmShape) {
            OrmShape ormShape = (OrmShape) obj;
            Object ormElement = ormShape.getOrmElement();
            if (ormElement instanceof IPersistentClass || ormElement instanceof ITable) {
                if (!ormShape.isVisible()) {
                    res = true;
                }
            }
        }
    }
    return res;
}
Also used : OrmShape(org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape) AbstractTreeEditPart(org.eclipse.gef.editparts.AbstractTreeEditPart) OrmEditPart(org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Aggregations

ITable (org.jboss.tools.hibernate.runtime.spi.ITable)209 Table (org.hibernate.mapping.Table)180 Test (org.junit.Test)173 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)26 SimpleValue (org.hibernate.mapping.SimpleValue)24 Method (java.lang.reflect.Method)17 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)17 Column (org.hibernate.mapping.Column)16 PrimaryKey (org.hibernate.mapping.PrimaryKey)16 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)14 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)12 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)11 Connection (java.sql.Connection)8 Statement (java.sql.Statement)8 Collection (org.hibernate.mapping.Collection)8 KeyValue (org.hibernate.mapping.KeyValue)8 Set (org.hibernate.mapping.Set)8 ArrayList (java.util.ArrayList)7 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)7 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)7