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