Search in sources :

Example 36 with IProperty

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

the class TypeVisitor method createHierarhyStructure.

/**
 * Replace <class> element on <joined-subclass> or <subclass>.
 * @param project
 * @param rootClasses
 * @return
 */
private Collection<IPersistentClass> createHierarhyStructure(IJavaProject project, Map<String, IPersistentClass> rootClasses) {
    IService service = getService(project);
    Map<String, IPersistentClass> pcCopy = new HashMap<String, IPersistentClass>();
    for (Map.Entry<String, IPersistentClass> entry : rootClasses.entrySet()) {
        pcCopy.put(entry.getKey(), entry.getValue());
    }
    for (Map.Entry<String, IPersistentClass> entry : pcCopy.entrySet()) {
        IPersistentClass pc = null;
        try {
            pc = getMappedSuperclass(project, pcCopy, entry.getValue());
            IPersistentClass subclass = null;
            if (pc != null) {
                if (pc.isAbstract()) {
                    subclass = service.newSingleTableSubclass(pc);
                    if (pc.isInstanceOfRootClass() && pc.getDiscriminator() == null) {
                        IValue discr = service.newSimpleValue();
                        // $NON-NLS-1$
                        discr.setTypeName("string");
                        // $NON-NLS-1$
                        discr.addColumn(service.newColumn("DISCR_COL"));
                        pc.setDiscriminator(discr);
                    }
                } else {
                    subclass = service.newJoinedSubclass(pc);
                }
            } else {
                pc = getMappedImplementedInterface(project, pcCopy, entry.getValue());
                if (pc != null) {
                    subclass = service.newSingleTableSubclass(pc);
                }
            }
            if (subclass != null) {
                IPersistentClass pastClass = pcCopy.get(entry.getKey());
                subclass.setClassName(pastClass.getClassName());
                subclass.setEntityName(pastClass.getEntityName());
                subclass.setDiscriminatorValue(StringHelper.unqualify(pastClass.getClassName()));
                subclass.setAbstract(pastClass.isAbstract());
                if (subclass.isInstanceOfJoinedSubclass()) {
                    subclass.setTable(service.newTable(StringHelper.unqualify(pastClass.getClassName()).toUpperCase()));
                    subclass.setKey(pc.getIdentifierProperty().getValue());
                }
                if (pastClass.getIdentifierProperty() != null) {
                    subclass.addProperty(pastClass.getIdentifierProperty());
                }
                Iterator<IProperty> it = pastClass.getPropertyIterator();
                while (it.hasNext()) {
                    subclass.addProperty(it.next());
                }
                entry.setValue(subclass);
            }
        } catch (JavaModelException e) {
            HibernateConsolePlugin.getDefault().log(e);
        }
    }
    return pcCopy.values();
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) HashMap(java.util.HashMap) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) HashMap(java.util.HashMap) Map(java.util.Map) IService(org.jboss.tools.hibernate.runtime.spi.IService) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 37 with IProperty

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

the class PersistentClassEditPart method getModelChildren.

protected List<PropertyViewAdapter> getModelChildren() {
    List<PropertyViewAdapter> list = new ArrayList<PropertyViewAdapter>();
    IProperty identifierProperty = getPersistentClass().getIdentifierProperty();
    if (identifierProperty != null) {
        list.add(new PropertyViewAdapter(getPersistentClassViewAdapter(), identifierProperty));
    }
    Iterator<IProperty> propertyIterator = getPersistentClass().getPropertyIterator();
    while (propertyIterator.hasNext()) {
        list.add(new PropertyViewAdapter(getPersistentClassViewAdapter(), propertyIterator.next()));
    }
    return list;
}
Also used : IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) ArrayList(java.util.ArrayList) PropertyViewAdapter(org.hibernate.eclipse.graph.model.PropertyViewAdapter)

Example 38 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 39 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 40 with IProperty

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

the class AbstractSpecialRootClassFacade method generate.

protected void generate() {
    if (property == null) {
        return;
    }
    IValue propVal = property.getValue();
    IValue component = null;
    if (propVal != null && propVal.isCollection()) {
        IValue collection = propVal;
        component = collection.getElement();
    } else if (propVal != null && propVal.isComponent()) {
        component = propVal;
    }
    if (component != null) {
        setClassName(component.getComponentClassName());
        setEntityName(component.getComponentClassName());
        IPersistentClass ownerClass = component.getOwner();
        if (component.getParentProperty() != null) {
            Object newProperty = Util.getInstance(getPropertyClassName(), getFacadeFactoryClassLoader());
            parentProperty = getFacadeFactory().createProperty(newProperty);
            parentProperty.setName(component.getParentProperty());
            parentProperty.setPersistentClass(ownerClass);
        }
        Iterator<IProperty> iterator = component.getPropertyIterator();
        while (iterator.hasNext()) {
            IProperty property = iterator.next();
            if (property != null) {
                addProperty(property);
            }
        }
    }
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

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