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);
}
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();
}
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);
}
}
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);
}
}
}
}
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;
}
Aggregations