Example usage for org.hibernate.type ComponentType getReturnedClass

List of usage examples for org.hibernate.type ComponentType getReturnedClass

Introduction

In this page you can find the example usage for org.hibernate.type ComponentType getReturnedClass.

Prototype

public Class getReturnedClass() 

Source Link

Usage

From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java

License:Apache License

private Type getPropertyType(ComponentType componentType, String property) {
    property = propertyResolver.getPropertyName(componentType.getReturnedClass(), property);
    int propertyIndex = componentType.getPropertyIndex(property);
    return componentType.getSubtypes()[propertyIndex];
}

From source file:org.atemsource.atem.impl.hibernate.HibernateMetaDataRepository.java

License:Apache License

public HibernateEntityType createComponentType(ComponentType type) {

    HibernateEntityType entityType = (HibernateEntityType) nameToEntityTypes.get(type.getName());
    if (entityType != null) {
        return entityType;
    }/*w w  w.jav  a2s.com*/
    entityType = new HibernateComponentType();
    entityType.setEntityClass(type.getReturnedClass());
    entityType.setCode(type.getName());

    nameToEntityTypes.put(type.getName(), entityType);

    // TODO use subtypes

    MetaLogs.LOG.debug("Initializing properties of " + type.getName() + "");
    Type[] propertyTypes = type.getSubtypes();// (Type[]) ReflectionUtils.getField(type, "propertyTypes");
    int index = 0;
    List<Attribute> attributes = new ArrayList<Attribute>();
    for (String propertyName : type.getPropertyNames()) {
        Type propertyType = propertyTypes[index];
        index++;
        PropertyDescriptor propertyDescriptor = PropertyDescriptor.createInstance(type.getReturnedClass(),
                propertyName);
        if (propertyDescriptor == null) {
            continue;
        }
        if (propertyDescriptor.getReadMethod() != null) {
            for (AttributeType attributeType : attributeTypes) {
                if (attributeType.canCreate(propertyDescriptor, propertyType, sessionFactory)) {
                    Attribute attribute = attributeType.create(validationMetaData, entityType,
                            getEntityTypeCreationContext(), propertyDescriptor, propertyType, sessionFactory);
                    attributes.add(attribute);
                    MetaLogs.LOG.debug(
                            "added property " + attribute.getCode() + " to " + propertyType.getName() + "");
                    break;
                }
            }
        }

    }

    entityType.setAttributes(attributes);
    attacheServicesToEntityType(entityType);

    entityTypes.add(entityType);
    classToEntityTypes.put(entityType.getEntityClass(), entityType);

    return entityType;
}