Example usage for org.hibernate.mapping Property getValue

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

Introduction

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

Prototype

public Value getValue() 

Source Link

Usage

From source file:org.jooq.meta.extensions.jpa.AttributeConverterExtractor.java

License:Apache License

@SuppressWarnings("unchecked")
final Map<Name, AttributeConverter<?, ?>> extract() {
    Map<Name, AttributeConverter<?, ?>> result = new LinkedHashMap<>();

    initEntityManagerFactory();/* w  ww.  ja  v  a  2 s  .  c  o  m*/
    for (PersistentClass persistentClass : meta.getEntityBindings()) {
        Table table = persistentClass.getTable();

        Iterator<Property> propertyIterator = persistentClass.getPropertyIterator();

        propertyLoop: while (propertyIterator.hasNext()) {
            Property property = propertyIterator.next();
            Type type = property.getValue().getType();

            if (type instanceof AttributeConverterTypeAdapter) {
                AttributeConverter<?, ?> converter = ((AttributeConverterTypeAdapter<?>) type)
                        .getAttributeConverter().getConverterBean().getBeanInstance();
                Iterator<Column> columnIterator = property.getColumnIterator();

                if (columnIterator.hasNext()) {
                    Column column = columnIterator.next();

                    if (columnIterator.hasNext()) {
                        log.info("AttributeConverter", "Cannot apply AttributeConverter of property " + property
                                + " on several columns.");
                        continue propertyLoop;
                    }

                    result.put(name(table.getCatalog(), table.getSchema(), table.getName(), column.getName()),
                            converter);
                }
            }
        }
    }

    return result;
}

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   www .j a v a  2s  . c  om*/
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.sparkcommerce.openadmin.server.dao.DynamicEntityDaoImpl.java

License:Apache License

protected void buildComponentProperties(Class<?> targetClass, ForeignKey foreignField,
        ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties,
        MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> fields, String idProperty,
        Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields,
        String configurationKey, String ceilingEntityFullyQualifiedClassname, String propertyName, Type type,
        Class<?> returnedClass, List<Class<?>> parentClasses, Boolean isParentExcluded, String prefix) {
    String[] componentProperties = ((ComponentType) type).getPropertyNames();
    List<String> componentPropertyNames = Arrays.asList(componentProperties);
    Type[] componentTypes = ((ComponentType) type).getSubtypes();
    List<Type> componentPropertyTypes = Arrays.asList(componentTypes);
    String tempPrefix = "";
    int pos = prefix.indexOf(".");
    if (pos > 0 && pos < prefix.length() - 1) {
        //only use part of the prefix if it's more than one layer deep
        tempPrefix = prefix.substring(pos + 1, prefix.length());
    }/*from  w  ww .j  a  v a  2 s . c  o m*/
    Map<String, FieldMetadata> componentPresentationAttributes = metadata
            .getFieldPresentationAttributes(targetClass, returnedClass, this, tempPrefix + propertyName + ".");
    if (isParentExcluded) {
        for (String key : componentPresentationAttributes.keySet()) {
            LOG.debug("buildComponentProperties:Excluding " + key + " because the parent was excluded");
            componentPresentationAttributes.get(key).setExcluded(true);
        }
    }
    PersistentClass persistentClass = getPersistentClass(targetClass.getName());
    Property property;
    try {
        property = persistentClass.getProperty(propertyName);
    } catch (MappingException e) {
        property = persistentClass.getProperty(prefix + propertyName);
    }
    Iterator componentPropertyIterator = ((org.hibernate.mapping.Component) property.getValue())
            .getPropertyIterator();
    List<Property> componentPropertyList = new ArrayList<Property>();
    while (componentPropertyIterator.hasNext()) {
        componentPropertyList.add((Property) componentPropertyIterator.next());
    }
    Map<String, FieldMetadata> newFields = new HashMap<String, FieldMetadata>();
    buildProperties(targetClass, foreignField, additionalForeignFields, additionalNonPersistentProperties,
            mergedPropertyType, componentPresentationAttributes, componentPropertyList, newFields,
            componentPropertyNames, componentPropertyTypes, idProperty, populateManyToOneFields, includeFields,
            excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname, parentClasses,
            propertyName + ".", isParentExcluded, true);
    Map<String, FieldMetadata> convertedFields = new HashMap<String, FieldMetadata>();
    for (String key : newFields.keySet()) {
        convertedFields.put(propertyName + "." + key, newFields.get(key));
    }
    fields.putAll(convertedFields);
}

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();
    }//w  w w  .ja  va 2  s .c o  m
    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  .ja  va  2  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;
}

From source file:org.wicketopia.persistence.hibernate.decorator.HibernatePropertyDecorator.java

License:Apache License

public void decorate(PropertyMetaData propertyMetaData) {
    WicketopiaPropertyFacet facet = WicketopiaPropertyFacet.get(propertyMetaData);
    final PersistentClass classMapping = findClassMapping(propertyMetaData.getBeanMetaData());
    if (classMapping != null) {
        final Property property = classMapping.getProperty(propertyMetaData.getPropertyDescriptor().getName());

        if (property == null) {
            return;
        } else if (!(property.getValue() instanceof SimpleValue)) {
            facet.setIgnored(true);//w w  w. j  a  va  2s. c  o m
        } else if (ignoreIdentifiers && property.equals(classMapping.getIdentifierProperty())) {
            facet.setIgnored(true);
        } else if (property.equals(classMapping.getVersion())) {
            facet.setIgnored(true);
        }

        if (!property.isOptional()) {
            facet.setRequired(Context.ALL_CONTEXTS, true);
        }
    }
}

From source file:org.wintersleep.codeviz.uml.model.HibernateModelFactory.java

License:Apache License

private void addRelations(CodeModel model) throws ClassNotFoundException {
    Iterator<PersistentClass> pci = configuration.getClassMappings();
    while (pci.hasNext()) {
        PersistentClass persistentClass = pci.next();
        final ModelClass mc = model.findModelClass(persistentClass.getMappedClass());
        Iterator<Property> pi = persistentClass.getPropertyIterator();
        while (pi.hasNext()) {
            Property property = pi.next();
            System.out.println(property);
            Value value = property.getValue();
            if (value instanceof ToOne) {
                ToOne toOne = (ToOne) value;
                ModelClass toClass = model.findModelClass(Class.forName(toOne.getReferencedEntityName()));
                RelationEndpoint fromEndpoint = new RelationEndpoint(mc, property.getName());
                fromEndpoint.setMinCardinality(toOne.isNullable() ? 0 : 1);
                RelationEndpoint toEndpoint = new RelationEndpoint(toClass, toOne.getReferencedPropertyName());
                toEndpoint.setMinCardinality(0);
                toEndpoint.setMaxCardinality(RelationEndpoint.MANY_CARDINALITY);
                if (value instanceof OneToOne) {
                    fromEndpoint.setMaxCardinality(1);
                } else if (value instanceof ManyToOne) {
                    fromEndpoint.setMaxCardinality(1);
                }/*w  ww  . ja  v  a  2  s.co m*/
                mc.addRelationTo(fromEndpoint, toEndpoint);
            } else if (value instanceof OneToMany) {
                OneToMany oneToMany = (OneToMany) value;
                oneToMany.getAssociatedClass();
                ModelClass toClass = model.findModelClass(oneToMany.getAssociatedClass().getMappedClass());
                RelationEndpoint fromEndpoint = new RelationEndpoint(mc, property.getName());
                fromEndpoint.setMinCardinality(0);
                fromEndpoint.setMaxCardinality(RelationEndpoint.MANY_CARDINALITY);
                RelationEndpoint toEndpoint = new RelationEndpoint(toClass, "TODO other");
                toEndpoint.setMinCardinality(oneToMany.isNullable() ? 0 : 1);
                toEndpoint.setMaxCardinality(1);
                mc.addRelationTo(fromEndpoint, toEndpoint);
            }
        }
    }
}

From source file:test.hibernate.ExecutionEnvironment.java

License:Open Source License

@SuppressWarnings("unchecked")
private void applyCacheSettings(Configuration configuration) {
    if (settings.getCacheConcurrencyStrategy() != null) {
        Iterator iter = configuration.getClassMappings();
        while (iter.hasNext()) {
            PersistentClass clazz = (PersistentClass) iter.next();
            Iterator props = clazz.getPropertyClosureIterator();
            boolean hasLob = false;
            while (props.hasNext()) {
                Property prop = (Property) props.next();
                if (prop.getValue().isSimpleValue()) {
                    String type = ((SimpleValue) prop.getValue()).getTypeName();
                    if ("blob".equals(type) || "clob".equals(type)) {
                        hasLob = true;//from ww w.j  a v  a 2s  .c  om
                    }
                    if (Blob.class.getName().equals(type) || Clob.class.getName().equals(type)) {
                        hasLob = true;
                    }
                }
            }
            if (!hasLob && !clazz.isInherited() && settings.overrideCacheStrategy()) {
                configuration.setCacheConcurrencyStrategy(clazz.getEntityName(),
                        settings.getCacheConcurrencyStrategy());
            }
        }
        iter = configuration.getCollectionMappings();
        while (iter.hasNext()) {
            Collection coll = (Collection) iter.next();
            configuration.setCollectionCacheConcurrencyStrategy(coll.getRole(),
                    settings.getCacheConcurrencyStrategy());
        }
    }
}

From source file:tools.xor.HibernateType.java

License:Apache License

@Override
public List<Type> getEmbeddableTypes() {
    List<Type> result = new ArrayList<Type>();

    Iterator<?> itr = getPropertyIterator();
    while (itr.hasNext()) {
        org.hibernate.mapping.Property property = (org.hibernate.mapping.Property) itr.next();
        if (property.getType().isComponentType()) {
            HibernateType type = new HibernateType(property.getType(), property.getValue());
            result.add(type);//  w  w w . j  a v a  2s. co m
        }
    }

    return result;
}