use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass 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;
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass 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()));
}
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class ElementsFactory method getOrCreateDatabaseTable.
@SuppressWarnings("rawtypes")
protected OrmShape getOrCreateDatabaseTable(ITable databaseTable) {
OrmShape tableShape = null;
if (databaseTable != null) {
tableShape = getShape(databaseTable);
if (tableShape == null) {
tableShape = createShape(databaseTable);
final IConfiguration config = getConfig();
if (config != null) {
Iterator iterator = config.getClassMappings();
while (iterator.hasNext()) {
Object clazz = iterator.next();
if (clazz instanceof IPersistentClass && ((IPersistentClass) clazz).isInstanceOfRootClass()) {
IPersistentClass cls = (IPersistentClass) clazz;
if (databaseTable.equals(cls.getTable())) {
// create persistent class shape only for RootClass,
// which has same table reference
getOrCreatePersistentClass(cls, null);
}
}
}
}
}
}
return tableShape;
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class OrmDiagram method getPropertyValue.
@Override
public Object getPropertyValue(Object propertyId) {
Object res = null;
if (PROPERTY_NAME.equals(propertyId)) {
res = getDiagramName();
} else if (PROPERTY_WIDTH.equals(propertyId)) {
res = Integer.valueOf(width).toString();
} else if (PROPERTY_HEIGHT.equals(propertyId)) {
res = Integer.valueOf(height).toString();
} else if (PROPERTY_ZOOM.equals(propertyId)) {
res = Double.valueOf(zoom).toString();
} else if (PROPERTY_ITEMS.equals(propertyId)) {
res = Integer.valueOf(elements.size()).toString();
} else if (PROPERTY_ENTITIES.equals(propertyId)) {
int nEntities = 0;
Iterator<OrmShape> it = elements.values().iterator();
while (it.hasNext()) {
final OrmShape shape = it.next();
Object ormElement = shape.getOrmElement();
if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfRootClass()) {
nEntities++;
}
}
res = Integer.valueOf(nEntities).toString();
} else if (PROPERTY_TABLES.equals(propertyId)) {
int nTables = 0;
Iterator<OrmShape> it = elements.values().iterator();
while (it.hasNext()) {
final OrmShape shape = it.next();
Object ormElement = shape.getOrmElement();
if (ormElement instanceof ITable) {
nTables++;
}
}
res = Integer.valueOf(nTables).toString();
} else if (PROPERTY_INVISIBLE.equals(propertyId)) {
int nInvisible = 0;
Iterator<OrmShape> it = elements.values().iterator();
while (it.hasNext()) {
final OrmShape shape = it.next();
if (!shape.isVisible()) {
nInvisible++;
}
}
res = Integer.valueOf(nInvisible).toString();
}
if (res == null) {
res = super.getPropertyValue(propertyId);
}
return toEmptyStr(res);
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class OrmDiagram method recreateChildren.
public void recreateChildren() {
deleteChildren();
elements.clear();
connections.clear();
StringBuilder errorMessage = new StringBuilder();
IConfiguration config = getConfig(errorMessage);
final ElementsFactory factory = new ElementsFactory(consoleConfigName, elements, connections);
for (int i = 0; i < roots.size(); i++) {
IPersistentClass rc = roots.get(i);
if (rc != null) {
factory.getOrCreatePersistentClass(rc, null);
}
}
updateChildrenList();
factory.createChildren(this);
factory.createForeingKeyConnections();
updateChildrenList();
if (getChildrenNumber() == 0) {
String error = DiagramViewerMessages.MessageShape_warning;
if (config != null) {
if (consoleConfigName != null && consoleConfigName.length() > 0) {
error = consoleConfigName;
// $NON-NLS-1$
error += ": ";
error += DiagramViewerMessages.Diagram_no_items_or_incorrect_state;
}
}
if (errorMessage.length() > 0) {
error = errorMessage.toString();
}
addChild(new MessageShape(error, getConsoleConfigName()));
}
}
Aggregations