Example usage for org.hibernate.type ComponentType getName

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

Introduction

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

Prototype

@Override
    public String getName() 

Source Link

Usage

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;
    }/*from  ww  w .j av 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;
}