use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.
the class ElementsFactory method createConnections.
@SuppressWarnings("rawtypes")
private boolean createConnections(ExpandableShape persistentClass, ExpandableShape dbTable) {
boolean res = false;
if (persistentClass == null || dbTable == null) {
return res;
}
IProperty parentProperty = null;
if (persistentClass.getOrmElement() instanceof IPersistentClass && ((IPersistentClass) persistentClass.getOrmElement()).isInstanceOfSpecialRootClass()) {
parentProperty = ((IPersistentClass) persistentClass.getOrmElement()).getParentProperty();
}
Iterator<Shape> itFields = persistentClass.getChildrenIterator();
Set<Shape> processed = new HashSet<Shape>();
while (itFields.hasNext()) {
final Shape shape = itFields.next();
Object element = shape.getOrmElement();
if (!(element instanceof IProperty && parentProperty != element)) {
continue;
}
IValue value = ((IProperty) element).getValue();
Iterator iterator = value.getColumnIterator();
while (iterator.hasNext()) {
Object o = iterator.next();
if (!(o instanceof IColumn)) {
continue;
}
IColumn dbColumn = (IColumn) o;
Iterator<Shape> itColumns = dbTable.getChildrenIterator();
while (itColumns.hasNext()) {
final Shape shapeCol = itColumns.next();
if (processed.contains(shapeCol)) {
continue;
}
if (shape.equals(shapeCol)) {
continue;
}
Object ormElement = shapeCol.getOrmElement();
// $NON-NLS-1$
String name2 = "";
if (ormElement instanceof IColumn) {
IColumn dbColumn2 = (IColumn) ormElement;
name2 = dbColumn2.getName();
} else if (ormElement instanceof IProperty) {
IProperty property2 = (IProperty) ormElement;
name2 = property2.getName();
}
if (dbColumn.getName().equals(name2)) {
if (shouldCreateConnection(shape, shapeCol)) {
connections.add(new Connection(shape, shapeCol));
res = true;
}
processed.add(shapeCol);
}
}
}
}
return res;
}
use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.
the class ElementsFactory method refreshComponentReferences.
protected void refreshComponentReferences(ComponentShape componentShape) {
IProperty property = (IProperty) componentShape.getOrmElement();
IValue v = property.getValue();
if (!v.isCollection()) {
return;
}
IValue collection = v;
IValue component = collection.getElement();
Shape csChild0 = null, csChild1 = null;
Iterator<Shape> tmp = componentShape.getChildrenIterator();
if (tmp.hasNext()) {
csChild0 = tmp.next();
}
if (tmp.hasNext()) {
csChild1 = tmp.next();
}
OrmShape childShape = null;
if (component.isComponent()) {
childShape = elements.get(component.getComponentClassName());
if (childShape == null) {
childShape = getOrCreateComponentClass(property);
}
IValue value = (IValue) csChild0.getOrmElement();
OrmShape tableShape = getOrCreateDatabaseTable(value.getTable());
if (tableShape != null) {
Iterator<IColumn> it = value.getColumnIterator();
while (it.hasNext()) {
IColumn el = it.next();
Shape shape = tableShape.getChild(el);
if (shouldCreateConnection(csChild0, shape)) {
connections.add(new Connection(csChild0, shape));
}
}
}
if (shouldCreateConnection(csChild1, childShape)) {
connections.add(new Connection(csChild1, childShape));
}
} else if (collection.isOneToMany()) {
childShape = getOrCreateAssociationClass(property);
if (childShape != null) {
if (shouldCreateConnection(csChild1, childShape)) {
connections.add(new Connection(csChild1, childShape));
}
OrmShape keyTableShape = getOrCreateDatabaseTable(collection.getKey().getTable());
Iterator<IColumn> it = collection.getKey().getColumnIterator();
while (it.hasNext()) {
Object el = it.next();
if (el instanceof IColumn) {
IColumn col = (IColumn) el;
Shape shape = keyTableShape.getChild(col);
if (shouldCreateConnection(csChild0, shape)) {
connections.add(new Connection(csChild0, shape));
}
}
}
}
} else {
// this is case: if (collection.isMap() || collection.isSet())
childShape = getOrCreateDatabaseTable(collection.getCollectionTable());
if (childShape != null) {
Iterator<IColumn> it = ((IValue) csChild0.getOrmElement()).getColumnIterator();
while (it.hasNext()) {
Object el = it.next();
if (el instanceof IColumn) {
IColumn col = (IColumn) el;
Shape shape = childShape.getChild(col);
if (shouldCreateConnection(csChild0, shape)) {
connections.add(new Connection(csChild0, shape));
}
}
}
it = ((IValue) csChild1.getOrmElement()).getColumnIterator();
while (it.hasNext()) {
Object el = it.next();
if (el instanceof IColumn) {
IColumn col = (IColumn) el;
Shape shape = childShape.getChild(col);
if (shouldCreateConnection(csChild1, shape)) {
connections.add(new Connection(csChild1, shape));
}
}
}
}
}
}
use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.
the class ElementsFactory method getOrCreateComponentClass.
protected OrmShape getOrCreateComponentClass(IProperty property) {
OrmShape classShape = null;
if (property == null) {
return classShape;
}
IValue value = property.getValue();
if (value.isCollection()) {
IValue component = value.getElement();
if (component != null) {
classShape = createShape(property);
OrmShape tableShape = elements.get(Utils.getTableName(component.getTable()));
if (tableShape == null) {
tableShape = getOrCreateDatabaseTable(component.getTable());
}
createConnections(classShape, tableShape);
if (shouldCreateConnection(classShape, tableShape)) {
connections.add(new Connection(classShape, tableShape));
}
Shape parentShape = ((SpecialOrmShape) classShape).getParentShape();
if (parentShape != null) {
OrmShape parentClassShape = elements.get(Utils.getName(((IProperty) parentShape.getOrmElement()).getPersistentClass().getEntityName()));
if (shouldCreateConnection(parentShape, parentClassShape)) {
connections.add(new Connection(parentShape, parentClassShape));
}
}
}
} else if (value.isComponent()) {
classShape = elements.get(value.getComponentClassName());
if (classShape == null) {
classShape = createShape(property);
}
}
return classShape;
}
use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.
the class Shape method getPropertyValue.
/**
* Return the property value for the given propertyId, or null.
* <p>The property view uses the IDs from the IPropertyDescriptors array
* to obtain the value of the corresponding properties.</p>
* @see #descriptors
* @see #getPropertyDescriptors()
*/
@Override
public Object getPropertyValue(Object propertyId) {
Object res = null;
IColumn col = null;
if (getOrmElement() instanceof IColumn) {
col = (IColumn) getOrmElement();
}
IProperty prop = null;
if (getOrmElement() instanceof IProperty) {
prop = (IProperty) getOrmElement();
}
if (prop != null) {
if (PROPERTY_NAME.equals(propertyId)) {
res = prop.getName();
} else if (PROPERTY_TYPE.equals(propertyId)) {
IValue value = prop.getValue();
if (value.isComponent()) {
res = value.toString();
} else {
IType type = getTypeUsingExecContext(value);
if (type != null) {
res = type.getAssociatedEntityName();
}
}
} else if (PROPERTY_VALUE.equals(propertyId)) {
res = prop.getValue().toString();
} else if (PROPERTY_CLASS.equals(propertyId)) {
if (prop.getPersistentClass() != null) {
res = prop.getPersistentClass().getClassName();
}
} else if (PROPERTY_SELECT.equals(propertyId)) {
res = Boolean.valueOf(prop.isSelectable()).toString();
} else if (PROPERTY_INSERT.equals(propertyId)) {
res = Boolean.valueOf(prop.isInsertable()).toString();
} else if (PROPERTY_UPDATE.equals(propertyId)) {
res = Boolean.valueOf(prop.isUpdateable()).toString();
} else if (PROPERTY_CASCADE.equals(propertyId)) {
res = prop.getCascade();
} else if (PROPERTY_LAZY.equals(propertyId)) {
res = Boolean.valueOf(prop.isLazy()).toString();
} else if (PROPERTY_OPTIONAL.equals(propertyId)) {
res = Boolean.valueOf(prop.isOptional()).toString();
} else if (PROPERTY_NATURAL_IDENTIFIER.equals(propertyId)) {
res = Boolean.valueOf(prop.isNaturalIdentifier()).toString();
} else if (PROPERTY_OPTIMISTIC_LOCKED.equals(propertyId)) {
res = Boolean.valueOf(prop.isOptimisticLocked()).toString();
}
} else if (col != null) {
if (PROPERTY_NAME.equals(propertyId)) {
res = col.getName();
} else if (PROPERTY_TYPE.equals(propertyId)) {
String sqlType = col.getSqlType();
if (sqlType == null) {
getOrmDiagram().getLabelProvider().updateColumnSqlType(col);
sqlType = col.getSqlType();
}
StringBuffer name = new StringBuffer();
if (sqlType != null) {
name.append(sqlType.toUpperCase());
name.append(HibernateUtils.getTable(col) != null && HibernateUtils.isPrimaryKey(col) ? " PK" : // $NON-NLS-1$ //$NON-NLS-2$
"");
name.append(HibernateUtils.getTable(col) != null && HibernateUtils.isForeignKey(col) ? " FK" : // $NON-NLS-1$ //$NON-NLS-2$
"");
}
res = name.toString();
} else if (PROPERTY_VALUE.equals(propertyId)) {
res = col.getValue().toString();
} else if (PROPERTY_NULLABLE.equals(propertyId)) {
res = Boolean.valueOf(col.isNullable()).toString();
} else if (PROPERTY_UNIQUE.equals(propertyId)) {
res = Boolean.valueOf(col.isUnique()).toString();
}
}
if (res == null) {
res = super.getPropertyValue(propertyId);
}
return toEmptyStr(res);
}
use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.
the class SpecialOrmShape method initModel.
/**
* creates children of the shape,
*/
@Override
protected void initModel() {
IPersistentClass rootClass = (IPersistentClass) getOrmElement();
IProperty identifierProperty = rootClass.getIdentifierProperty();
if (identifierProperty != null) {
addChild(new Shape(identifierProperty, getConsoleConfigName()));
}
IPersistentClass src = (IPersistentClass) getOrmElement();
if (src.getParentProperty() != null) {
Shape bodyOrmShape = new Shape(src.getParentProperty(), getConsoleConfigName());
addChild(bodyOrmShape);
parentShape = bodyOrmShape;
}
Iterator<IProperty> iterator = rootClass.getPropertyIterator();
while (iterator.hasNext()) {
IProperty field = iterator.next();
IValue v = field.getValue();
IType type = getTypeUsingExecContext(v);
Shape bodyOrmShape = null;
if (type != null && type.isEntityType()) {
bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
} else if (type != null && type.isCollectionType()) {
bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
} else {
bodyOrmShape = new Shape(field, getConsoleConfigName());
}
addChild(bodyOrmShape);
}
}
Aggregations