Search in sources :

Example 1 with IProperty

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

the class AbstractHQLCompletionProposalFacade method getProperty.

@Override
public IProperty getProperty() {
    IProperty result = null;
    Object targetProperty = Util.invokeMethod(getTarget(), "getProperty", new Class[] {}, new Object[] {});
    if (targetProperty != null) {
        result = getFacadeFactory().createProperty(targetProperty);
    }
    return result;
}
Also used : IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty)

Example 2 with IProperty

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

the class SpecialRootClassFacadeImpl method getMetadataBuildingContext.

private static MetadataBuildingContext getMetadataBuildingContext(IProperty property) {
    Property target = (Property) ((IFacade) property).getTarget();
    PersistentClass pc = target.getPersistentClass();
    MetadataBuildingContext result = null;
    try {
        Field field = PersistentClass.class.getDeclaredField("metadataBuildingContext");
        field.setAccessible(true);
        result = (MetadataBuildingContext) field.get(pc);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        throw new RuntimeException("Problem while trying to retrieve MetadataBuildingContext from field", e);
    }
    return result;
}
Also used : Field(java.lang.reflect.Field) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) Property(org.hibernate.mapping.Property) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 3 with IProperty

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

the class ElementsFactory method createShape.

protected OrmShape createShape(Object ormElement) {
    OrmShape ormShape = null;
    if (ormElement instanceof IProperty) {
        IPersistentClass specialRootClass = getService().newSpecialRootClass((IProperty) ormElement);
        String key = Utils.getName(specialRootClass.getEntityName());
        ormShape = elements.get(key);
        if (null == ormShape) {
            ormShape = new SpecialOrmShape(specialRootClass, consoleConfigName);
            elements.put(key, ormShape);
        }
    } else {
        String key = Utils.getName(ormElement);
        ormShape = elements.get(key);
        if (null == ormShape) {
            ormShape = new OrmShape(ormElement, consoleConfigName);
            elements.put(key, ormShape);
        }
    }
    return ormShape;
}
Also used : IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 4 with IProperty

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

use of org.jboss.tools.hibernate.runtime.spi.IProperty 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)

Aggregations

IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)93 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)53 Property (org.hibernate.mapping.Property)40 Test (org.junit.Test)33 RootClass (org.hibernate.mapping.RootClass)27 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)20 PersistentClass (org.hibernate.mapping.PersistentClass)18 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)12 SimpleValue (org.hibernate.mapping.SimpleValue)12 AbstractPropertyFacade (org.jboss.tools.hibernate.runtime.common.AbstractPropertyFacade)12 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)12 FileNotFoundException (java.io.FileNotFoundException)9 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)9 Component (org.hibernate.mapping.Component)8 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)8 IEditorPart (org.eclipse.ui.IEditorPart)7 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)7 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 Mappings (org.hibernate.cfg.Mappings)6 PartInitException (org.eclipse.ui.PartInitException)5