Search in sources :

Example 1 with IValue

use of org.jboss.tools.hibernate.runtime.spi.IValue 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 2 with IValue

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

the class ElementsFactory method processExpand.

protected void processExpand(ExpandableShape shape) {
    Object element = shape.getOrmElement();
    if (!(element instanceof IProperty)) {
        return;
    }
    OrmShape s = null;
    IProperty property = (IProperty) element;
    if (!property.isComposite()) {
        final IConfiguration config = getConfig();
        // 
        IValue v = property.getValue();
        IType type = UtilTypeExtract.getTypeUsingExecContext(v, getConsoleConfig());
        if (type != null && type.isEntityType()) {
            Object clazz = config != null ? config.getClassMapping(type.getAssociatedEntityName()) : null;
            if (clazz instanceof IPersistentClass && ((IPersistentClass) clazz).isInstanceOfRootClass()) {
                IPersistentClass rootClass = (IPersistentClass) clazz;
                s = getOrCreatePersistentClass(rootClass, null);
                if (shouldCreateConnection(shape, s)) {
                    connections.add(new Connection(shape, s));
                }
            } else if (clazz instanceof IPersistentClass && ((IPersistentClass) clazz).isInstanceOfSubclass()) {
                s = getOrCreatePersistentClass(((IPersistentClass) clazz).getRootClass(), null);
            }
        }
    } else {
        s = getOrCreatePersistentClass(getService().newSpecialRootClass(property), null);
        if (shouldCreateConnection(shape, s)) {
            connections.add(new Connection(shape, s));
        }
        createConnections(s, getOrCreateDatabaseTable(property.getValue().getTable()));
    }
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IType(org.jboss.tools.hibernate.runtime.spi.IType)

Example 3 with IValue

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

the class ElementsFactory method getOrCreateAssociationClass.

protected OrmShape getOrCreateAssociationClass(IProperty property) {
    OrmShape classShape = null;
    IValue component = property.getValue().getElement();
    if (component == null) {
        return classShape;
    }
    if (component.getAssociatedClass().isInstanceOfRootClass()) {
        classShape = getOrCreatePersistentClass(component.getAssociatedClass(), null);
        if (classShape == null) {
            classShape = createShape(component.getAssociatedClass());
        }
        OrmShape tableShape = elements.get(Utils.getTableName(component.getAssociatedClass().getTable()));
        if (tableShape == null) {
            tableShape = getOrCreateDatabaseTable(component.getAssociatedClass().getTable());
        }
        createConnections(classShape, tableShape);
        if (shouldCreateConnection(classShape, tableShape)) {
            connections.add(new Connection(classShape, tableShape));
        }
    }
    return classShape;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue)

Example 4 with IValue

use of org.jboss.tools.hibernate.runtime.spi.IValue 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 5 with IValue

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

the class OrmImageMap method getImageName.

/**
 * the image name for hierarchy:
 * Property
 * @param field
 * @return
 */
public static String getImageName(IProperty field, final ConsoleConfiguration cfg) {
    // $NON-NLS-1$
    String str = "Image_PersistentFieldSimple";
    if (field == null) {
        return str;
    }
    final IPersistentClass persistentClass = field.getPersistentClass();
    if (persistentClass != null && persistentClass.getVersion() == field) {
        // $NON-NLS-1$
        str = "Image_PersistentFieldSimple_version";
    } else if (persistentClass != null && persistentClass.getIdentifierProperty() == field) {
        // $NON-NLS-1$
        str = "Image_PersistentFieldSimple_id";
    } else if (field.getValue() != null) {
        final IValue value = field.getValue();
        if (value.isOneToMany()) {
            // $NON-NLS-1$
            str = "Image_PersistentFieldOne-to-many";
        } else if (value.isOneToOne()) {
            // $NON-NLS-1$
            str = "Image_PersistentFieldOne-to-one";
        } else if (value.isManyToOne()) {
            // $NON-NLS-1$
            str = "Image_PersistentFieldMany-to-one";
        } else if (value.isAny()) {
            // $NON-NLS-1$
            str = "Image_PersistentFieldAny";
        } else {
            IType type = UtilTypeExtract.getTypeUsingExecContext(value, cfg);
            if (type != null && type.isCollectionType()) {
                if (value.isPrimitiveArray()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_primitive_array";
                } else if (value.isArray()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_array";
                } else if (value.isList()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_list";
                } else if (value.isSet()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_set";
                } else if (value.isMap()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_map";
                } else if (value.isBag()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_bag";
                } else if (value.isIdentifierBag()) {
                    // $NON-NLS-1$
                    str = "Image_Collection_idbag";
                } else {
                    // $NON-NLS-1$
                    str = "Image_Collection";
                }
            }
        }
    } else if ("parent".equals(field.getName())) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        str = "Image_PersistentFieldParent";
    }
    return str;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IType(org.jboss.tools.hibernate.runtime.spi.IType)

Aggregations

IValue (org.jboss.tools.hibernate.runtime.spi.IValue)144 Test (org.junit.Test)105 SimpleValue (org.hibernate.mapping.SimpleValue)68 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)59 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)40 Bag (org.hibernate.mapping.Bag)20 Set (org.hibernate.mapping.Set)20 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)20 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)17 IdentifierBag (org.hibernate.mapping.IdentifierBag)16 KeyValue (org.hibernate.mapping.KeyValue)16 RootClass (org.hibernate.mapping.RootClass)16 Value (org.hibernate.mapping.Value)16 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)13 Collection (org.hibernate.mapping.Collection)8 Component (org.hibernate.mapping.Component)8 List (org.hibernate.mapping.List)8 PersistentClass (org.hibernate.mapping.PersistentClass)8 PrimitiveArray (org.hibernate.mapping.PrimitiveArray)8 Table (org.hibernate.mapping.Table)8