Example usage for org.hibernate.mapping RootClass getIdentifier

List of usage examples for org.hibernate.mapping RootClass getIdentifier

Introduction

In this page you can find the example usage for org.hibernate.mapping RootClass getIdentifier.

Prototype

@Override
    public KeyValue getIdentifier() 

Source Link

Usage

From source file:org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape.java

License:Open Source License

/**
 * creates children of the shape, // w  w w  .j  a v a  2 s  . co m
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void initModel() {
    Object ormElement = getOrmElement();
    if (ormElement instanceof RootClass) {
        RootClass rootClass = (RootClass) ormElement;
        Property identifierProperty = rootClass.getIdentifierProperty();
        if (identifierProperty != null) {
            addChild(new Shape(identifierProperty, getConsoleConfigName()));
        }

        KeyValue identifier = rootClass.getIdentifier();
        if (identifier instanceof Component) {
            Component component = (Component) identifier;
            if (component.isEmbedded()) {
                Iterator<Property> iterator = ((Component) identifier).getPropertyIterator();
                while (iterator.hasNext()) {
                    Property property = iterator.next();
                    addChild(new Shape(property, getConsoleConfigName()));
                }
            }
        }

        Iterator<Property> iterator = rootClass.getPropertyIterator();
        while (iterator.hasNext()) {
            Property field = iterator.next();
            if (!field.isBackRef()) {
                if (!field.isComposite()) {
                    final Value val = field.getValue();
                    Shape bodyOrmShape = null;
                    if (val.isSimpleValue() && !((SimpleValue) val).isTypeSpecified()) {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    } else {
                        if (val instanceof Collection) {
                            bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
                        } else {
                            Type 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 Subclass) {
        RootClass rootClass = ((Subclass) ormElement).getRootClass();

        Property identifierProperty = rootClass.getIdentifierProperty();
        if (identifierProperty != null) {
            addChild(new Shape(identifierProperty, getConsoleConfigName()));
        }

        KeyValue identifier = rootClass.getIdentifier();
        if (identifier instanceof Component) {
            Iterator<Property> iterator = ((Component) identifier).getPropertyIterator();
            while (iterator.hasNext()) {
                Property property = iterator.next();
                addChild(new Shape(property, getConsoleConfigName()));
            }
        }

        Iterator<Property> iterator = rootClass.getPropertyIterator();
        while (iterator.hasNext()) {
            Property field = iterator.next();
            if (!field.isBackRef()) {
                if (!field.isComposite()) {

                    boolean typeIsAccessible = true;
                    if (field.getValue().isSimpleValue()
                            && ((SimpleValue) field.getValue()).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<Property> iter = ((Subclass) ormElement).getPropertyIterator();
        while (iter.hasNext()) {
            Property property = iter.next();
            if (!property.isBackRef()) {
                if (!property.isComposite()) {

                    boolean typeIsAccessible = true;
                    if (property.getValue().isSimpleValue()
                            && ((SimpleValue) property.getValue()).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 Table) {
        Iterator iterator = ((Table) getOrmElement()).getColumnIterator();
        while (iterator.hasNext()) {
            Column column = (Column) iterator.next();
            Shape bodyOrmShape = new Shape(column, getConsoleConfigName());
            addChild(bodyOrmShape);
        }
    }
}