Example usage for org.hibernate.mapping Property isComposite

List of usage examples for org.hibernate.mapping Property isComposite

Introduction

In this page you can find the example usage for org.hibernate.mapping Property isComposite.

Prototype

public boolean isComposite() 

Source Link

Usage

From source file:com.wavemaker.runtime.data.hibernate.DataServiceMetaData_Hib.java

License:Open Source License

@Override
public boolean isCompositeProperty(Class<?> c, String propertyName) {

    if (!isEntity(c)) {
        throw new DataServiceRuntimeException(c + " is not an entity");
    }// w w  w .  ja  va 2 s . c  o m

    RootClass rc = getRootClass(c);

    Property p = rc.getProperty(propertyName);

    return p.isComposite();
}

From source file:gov.nih.nci.protexpress.data.validator.UniqueConstraintValidator.java

License:BSD License

/**
 * {@inheritDoc}/*from   ww  w.  j  a  va 2 s.c o  m*/
 */
@SuppressWarnings("unchecked")
public void apply(Property property) {
    if (!property.isComposite()) { // currently not supporting composite columns
        Iterator<Column> iter = property.getColumnIterator();
        while (iter.hasNext()) {
            iter.next().setUnique(true);
        }
    }
}

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

License:Open Source License

/**
 * creates children of the shape, //  w ww  . j a  va2  s  .c o  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);
        }
    }
}

From source file:org.libreplan.business.common.LibrePlanClassValidator.java

License:Open Source License

/**
 * Retrieve the property by path in a recursive way, including IndetifierProperty in the loop
 * If propertyName is null or empty, the IdentifierProperty is returned
 *//*from   w w w  .ja v  a 2 s  .  c  o  m*/
public static Property findPropertyByName(PersistentClass associatedClass, String propertyName) {
    Property property = null;
    Property idProperty = associatedClass.getIdentifierProperty();
    String idName = idProperty != null ? idProperty.getName() : null;
    try {
        if (propertyName == null || propertyName.length() == 0 || propertyName.equals(idName)) {
            //default to id
            property = idProperty;
        } else {
            if (propertyName.indexOf(idName + ".") == 0) {
                property = idProperty;
                propertyName = propertyName.substring(idName.length() + 1);
            }
            StringTokenizer st = new StringTokenizer(propertyName, ".", false);
            while (st.hasMoreElements()) {
                String element = (String) st.nextElement();
                if (property == null) {
                    property = associatedClass.getProperty(element);
                } else {
                    if (!property.isComposite())
                        return null;
                    property = ((Component) property.getValue()).getProperty(element);
                }
            }
        }
    } catch (MappingException e) {
        try {
            //if we do not find it try to check the identifier mapper
            if (associatedClass.getIdentifierMapper() == null)
                return null;
            StringTokenizer st = new StringTokenizer(propertyName, ".", false);
            while (st.hasMoreElements()) {
                String element = (String) st.nextElement();
                if (property == null) {
                    property = associatedClass.getIdentifierMapper().getProperty(element);
                } else {
                    if (!property.isComposite())
                        return null;
                    property = ((Component) property.getValue()).getProperty(element);
                }
            }
        } catch (MappingException ee) {
            return null;
        }
    }
    return property;
}

From source file:org.teiid.spring.views.ViewBuilder.java

License:Apache License

@SuppressWarnings("unchecked")
String propertyName(Iterator<org.hibernate.mapping.Property> it,
        org.hibernate.mapping.Property identifierProperty, String colName) {
    if (identifierProperty != null && propertyMatches(identifierProperty, colName)) {
        return identifierProperty.getName();
    }//from   www.  ja  v  a 2 s.  com
    while (it.hasNext()) {
        org.hibernate.mapping.Property property = it.next();
        if (propertyMatches(property, colName)) {
            if (property.isComposite()) {
                Component comp = (Component) property.getValue();
                Iterator<org.hibernate.mapping.Property> compIt = comp.getPropertyIterator();
                return propertyName(compIt, null, colName);
            } else {
                return property.getName();
            }
        }
    }
    return null;
}

From source file:org.teiid.spring.views.ViewBuilder.java

License:Apache License

@SuppressWarnings("unchecked")
boolean propertyMatches(org.hibernate.mapping.Property property, String colName) {
    if (property.isComposite()) {
        Component comp = (Component) property.getValue();
        Iterator<org.hibernate.mapping.Property> compIt = comp.getPropertyIterator();
        while (compIt.hasNext()) {
            property = compIt.next();//from ww w. j a  v a2 s . c  o  m
            if (propertyMatches(property, colName)) {
                return true;
            }
        }
        return false;
    }
    Iterator<?> columnIterator = property.getColumnIterator();
    if (columnIterator.hasNext()) {
        org.hibernate.mapping.Column col = (org.hibernate.mapping.Column) columnIterator.next();
        assert !columnIterator.hasNext();
        if (col.getName().equals(colName)) {
            return true;
        }
    }
    return false;
}