Search in sources :

Example 66 with IValue

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

the class TypeVisitor method visit.

@Override
public boolean visit(SimpleType type) {
    ITypeBinding tb = type.resolveBinding();
    // Unresolved binding. Omit the property.
    if (tb == null)
        return false;
    ITypeBinding[] interfaces = Utils.getAllInterfaces(tb);
    IValue value = buildCollectionValue(interfaces);
    if (value != null) {
        // $NON-NLS-1$
        IValue element = buildSimpleValue("string");
        value.setElement(element);
        // TODO what to set?
        value.setCollectionTable(rootClass.getTable());
        buildProperty(value);
        if (value.isList()) {
            value.setIndex(service.newSimpleValue());
        } else if (value.isMap()) {
            IValue map_key = service.newSimpleValue();
            // FIXME: how to detect key-type here
            // $NON-NLS-1$
            map_key.setTypeName("string");
            value.setIndex(map_key);
        }
        // $NON-NLS-1$
        prop.setCascade("none");
    } else if (tb.isEnum()) {
        // $NON-NLS-1$
        value = buildSimpleValue("org.hibernate.type.EnumType");
        Properties typeParameters = new Properties();
        // $NON-NLS-1$
        typeParameters.put("enumClass", tb.getBinaryName());
        // $NON-NLS-1$
        typeParameters.put("type", java.sql.Types.VARCHAR);
        value.setTypeParameters(typeParameters);
        buildProperty(value);
    } else if (ref != null) /*&& ref.fullyQualifiedName.indexOf('$') < 0*/
    {
        IValue sValue = null;
        if (ref.refType == RefType.MANY2ONE) {
            sValue = service.newManyToOne(rootClass.getTable());
        } else if (ref.refType == RefType.ONE2ONE) {
            sValue = service.newOneToOne(rootClass);
        } else if (ref.refType == RefType.UNDEF) {
            sValue = service.newOneToOne(rootClass);
        } else {
            // OneToMany and ManyToMany must be a collection
            throw new IllegalStateException(ref.refType.toString());
        }
        IColumn column = service.newColumn(varName.toUpperCase());
        sValue.addColumn(column);
        sValue.setTypeName(tb.getBinaryName());
        sValue.setFetchModeJoin();
        sValue.setReferencedEntityName(ref.fullyQualifiedName);
        buildProperty(sValue);
        // $NON-NLS-1$
        prop.setCascade("none");
    } else {
        value = buildSimpleValue(tb.getBinaryName());
        buildProperty(value);
    }
    return super.visit(type);
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) Properties(java.util.Properties)

Example 67 with IValue

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

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

the class PropertyViewAdapter method createSingleEndedEnityAssociations.

private void createSingleEndedEnityAssociations() {
    try {
        // TODO: we need the consoleconfiguration here to know the exact types
        IValue value = property.getValue();
        if (value != null && value.isCollection()) {
            if (!value.isInverse() && value.getElement().isOneToMany()) {
                IValue oneToMany = value.getElement();
                String entityName = oneToMany.getAssociatedClass().getEntityName();
                PersistentClassViewAdapter target = configuration.getPersistentClassViewAdapter(entityName);
                PropertyAssociationViewAdapter pava = new PropertyAssociationViewAdapter(clazz, this, target);
                this.addSourceAssociation(pava);
                target.addTargetAssociation(pava);
            }
        } else if (property.getType().isEntityType()) {
            IType et = (IType) property.getType();
            PersistentClassViewAdapter target = configuration.getPersistentClassViewAdapter(et.getAssociatedEntityName());
            PropertyAssociationViewAdapter pava = new PropertyAssociationViewAdapter(clazz, this, target);
            this.addSourceAssociation(pava);
            target.addTargetAssociation(pava);
        }
    } catch (Exception he) {
        HibernateConsolePlugin.getDefault().logWarning(he);
    }
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IType(org.jboss.tools.hibernate.runtime.spi.IType)

Example 69 with IValue

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

Example 70 with IValue

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

the class AbstractValueFacade method getElement.

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

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