use of org.jboss.tools.hibernate.runtime.spi.ITable 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.ITable 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.ITable in project jbosstools-hibernate by jbosstools.
the class OrmShape method initModel.
/**
* creates children of the shape,
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void initModel() {
Object ormElement = getOrmElement();
if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfRootClass()) {
IPersistentClass rootClass = (IPersistentClass) ormElement;
IProperty identifierProperty = rootClass.getIdentifierProperty();
if (identifierProperty != null) {
addChild(new Shape(identifierProperty, getConsoleConfigName()));
}
IValue identifier = rootClass.getIdentifier();
if (identifier != null && identifier.isComponent()) {
IValue component = identifier;
if (component.isEmbedded()) {
Iterator<IProperty> iterator = identifier.getPropertyIterator();
while (iterator.hasNext()) {
IProperty property = iterator.next();
addChild(new Shape(property, getConsoleConfigName()));
}
}
}
Iterator<IProperty> iterator = rootClass.getPropertyIterator();
while (iterator.hasNext()) {
IProperty field = iterator.next();
if (!field.isBackRef()) {
if (!field.isComposite()) {
final IValue val = field.getValue();
Shape bodyOrmShape = null;
if (val.isSimpleValue() && val.isTypeSpecified()) {
bodyOrmShape = new Shape(field, getConsoleConfigName());
} else {
if (val.isCollection()) {
bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
} else {
IType type = getTypeUsingExecContext(val);
if (type != null && type.isEntityType()) {
bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
} else {
bodyOrmShape = new Shape(field, getConsoleConfigName());
}
}
}
addChild(bodyOrmShape);
} else {
Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
addChild(bodyOrmShape);
}
}
}
} else if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfSubclass()) {
IPersistentClass rootClass = ((IPersistentClass) ormElement).getRootClass();
IProperty identifierProperty = rootClass.getIdentifierProperty();
if (identifierProperty != null) {
addChild(new Shape(identifierProperty, getConsoleConfigName()));
}
IValue identifier = rootClass.getIdentifier();
if (identifier.isComponent()) {
Iterator<IProperty> iterator = identifier.getPropertyIterator();
while (iterator.hasNext()) {
IProperty property = iterator.next();
addChild(new Shape(property, getConsoleConfigName()));
}
}
Iterator<IProperty> iterator = rootClass.getPropertyIterator();
while (iterator.hasNext()) {
IProperty field = iterator.next();
if (!field.isBackRef()) {
if (!field.isComposite()) {
IValue fieldValue = field.getValue();
boolean typeIsAccessible = true;
if (fieldValue.isSimpleValue() && fieldValue.isTypeSpecified()) {
try {
field.getValue().getType();
} catch (Exception e) {
typeIsAccessible = false;
}
}
Shape bodyOrmShape = null;
if (typeIsAccessible && field.getValue().isSimpleValue()) {
bodyOrmShape = new Shape(field, getConsoleConfigName());
} else if (typeIsAccessible && field.getValue().getType().isEntityType()) {
bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
} else if (typeIsAccessible && field.getValue().getType().isCollectionType()) {
bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
} else {
bodyOrmShape = new Shape(field, getConsoleConfigName());
}
addChild(bodyOrmShape);
} else {
Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
addChild(bodyOrmShape);
}
}
}
Iterator<IProperty> iter = ((IPersistentClass) ormElement).getPropertyIterator();
while (iter.hasNext()) {
IProperty property = iter.next();
if (!property.isBackRef()) {
if (!property.isComposite()) {
boolean typeIsAccessible = true;
IValue propertyValue = property.getValue();
if (propertyValue.isSimpleValue() && propertyValue.isTypeSpecified()) {
try {
property.getValue().getType();
} catch (Exception e) {
typeIsAccessible = false;
}
}
Shape bodyOrmShape = null;
if (typeIsAccessible && property.getValue().getType().isEntityType()) {
bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
} else if (typeIsAccessible && property.getValue().getType().isCollectionType()) {
bodyOrmShape = new ComponentShape(property, getConsoleConfigName());
} else {
bodyOrmShape = new Shape(property, getConsoleConfigName());
}
addChild(bodyOrmShape);
} else {
Shape bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
addChild(bodyOrmShape);
}
}
}
} else if (ormElement instanceof ITable) {
Iterator iterator = ((ITable) getOrmElement()).getColumnIterator();
while (iterator.hasNext()) {
IColumn column = (IColumn) iterator.next();
Shape bodyOrmShape = new Shape(column, getConsoleConfigName());
addChild(bodyOrmShape);
}
}
}
use of org.jboss.tools.hibernate.runtime.spi.ITable in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newTable.
@Override
public ITable newTable(String name) {
Table target = new Table(name);
target.setPrimaryKey(new PrimaryKey(target));
return facadeFactory.createTable(target);
}
use of org.jboss.tools.hibernate.runtime.spi.ITable in project jbosstools-hibernate by jbosstools.
the class ShapeShowAction method canPerformAction.
private boolean canPerformAction() {
boolean res = false;
if (getSelectedObjects().isEmpty()) {
return res;
}
Iterator<?> it = getSelectedObjects().iterator();
while (it.hasNext() && !res) {
Object firstElement = it.next();
Object obj = null;
if (firstElement instanceof OrmEditPart) {
obj = ((OrmEditPart) firstElement).getModel();
} else if (firstElement instanceof AbstractTreeEditPart) {
obj = ((AbstractTreeEditPart) firstElement).getModel();
}
if (null != obj && obj instanceof OrmShape) {
OrmShape ormShape = (OrmShape) obj;
Object ormElement = ormShape.getOrmElement();
if (ormElement instanceof IPersistentClass || ormElement instanceof ITable) {
if (!ormShape.isVisible()) {
res = true;
}
}
}
}
return res;
}
Aggregations