Example usage for org.hibernate.type CompositeType getSubtypes

List of usage examples for org.hibernate.type CompositeType getSubtypes

Introduction

In this page you can find the example usage for org.hibernate.type CompositeType getSubtypes.

Prototype

Type[] getSubtypes();

Source Link

Document

Get the types of the component properties

Usage

From source file:com.googlecode.hibernate.audit.listener.AuditSessionFactoryObserver.java

License:Open Source License

private AuditType initializeComponentAuditType(Session session, CompositeType type) {
    String auditTypeClassName = auditConfiguration.getExtensionManager().getAuditableInformationProvider()
            .getAuditTypeClassName(auditConfiguration.getMetadata(), type);

    AuditType componentAuditType = HibernateAudit.getAuditType(session, auditTypeClassName);
    if (componentAuditType == null) {
        componentAuditType = new AuditType();
        componentAuditType.setClassName(auditTypeClassName);
        componentAuditType.setType(AuditType.COMPONENT_TYPE);
        session.save(componentAuditType);
        updateMetaModel(session);//from w  ww . jav  a2 s . c  o  m
    }

    String[] componentPropertyNames = type.getPropertyNames();
    if (componentPropertyNames != null) {
        for (int i = 0; i < componentPropertyNames.length; i++) {
            AuditTypeField componentAuditField = initializeAuditField(session, auditTypeClassName,
                    componentAuditType, componentPropertyNames[i], type.getSubtypes()[i]);

        }
    }
    return componentAuditType;
}

From source file:com.googlecode.hibernate.audit.synchronization.work.AbstractAuditWorkUnit.java

License:Open Source License

protected ComponentObjectProperty processComponentValue(Session session, AuditConfiguration auditConfiguration,
        AuditEvent auditEvent, AuditObject auditObject, String entityName, Object entity, String propertyName,
        Object component, CompositeType componentType) {
    AuditTypeField auditField = HibernateAudit.getAuditField(session,
            auditConfiguration.getExtensionManager().getAuditableInformationProvider()
                    .getAuditTypeClassName(auditConfiguration.getMetadata(), entityName),
            propertyName);//from w w  w.j a va 2 s .  co  m

    ComponentObjectProperty property = new ComponentObjectProperty();
    property.setAuditObject(auditObject);
    property.setAuditField(auditField);
    property.setIndex(null);
    if (component != null) {
        property.setAuditType(HibernateAudit.getAuditType(session,
                auditConfiguration.getExtensionManager().getAuditableInformationProvider()
                        .getAuditTypeClassName(auditConfiguration.getMetadata(), componentType)));
    }

    ComponentAuditObject targetComponentAuditObject = null;

    if (component != null) {
        targetComponentAuditObject = new ComponentAuditObject();
        targetComponentAuditObject.setAuditEvent(auditEvent);
        targetComponentAuditObject.setParentAuditObject(auditObject);
        AuditType auditType = HibernateAudit.getAuditType(session,
                auditConfiguration.getExtensionManager().getAuditableInformationProvider()
                        .getAuditTypeClassName(auditConfiguration.getMetadata(), componentType));
        targetComponentAuditObject.setAuditType(auditType);

        for (int i = 0; i < componentType.getPropertyNames().length; i++) {
            String componentPropertyName = componentType.getPropertyNames()[i];

            Type componentPropertyType = componentType.getSubtypes()[i];
            Object componentPropertyValue = componentType.getPropertyValue(component, i,
                    (SessionImplementor) session);

            processProperty(session, auditConfiguration, auditEvent, component, componentPropertyName,
                    componentPropertyValue, componentPropertyType, targetComponentAuditObject);
        }
    }
    property.setTargetComponentAuditObject(targetComponentAuditObject);

    return property;
}

From source file:com.googlecode.hibernate.audit.synchronization.work.AbstractCollectionAuditWorkUnit.java

License:Open Source License

protected void processElement(Session session, AuditConfiguration auditConfiguration, Object entityOwner,
        Object element, Type elementType, String propertyName, long index, EntityAuditObject auditObject,
        AuditEvent auditEvent) {//from   w  w  w . j av a2  s.c o  m

    AuditTypeField auditField = HibernateAudit
            .getAuditField(session,
                    auditConfiguration.getExtensionManager().getAuditableInformationProvider()
                            .getAuditTypeClassName(auditConfiguration.getMetadata(), getEntityName()),
                    propertyName);
    AuditObjectProperty property = null;

    if (elementType.isEntityType()) {
        Serializable id = null;

        if (element != null) {
            id = session.getSessionFactory()
                    .getClassMetadata(((EntityType) elementType).getAssociatedEntityName())
                    .getIdentifier(element, (SessionImplementor) session);
        }

        property = new EntityObjectProperty();
        property.setAuditObject(auditObject);
        property.setAuditField(auditField);
        property.setIndex(new Long(index));
        ((EntityObjectProperty) property).setTargetEntityId(
                auditConfiguration.getExtensionManager().getPropertyValueConverter().toString(null, id));
    } else if (elementType.isComponentType()) {
        CompositeType componentType = (CompositeType) elementType;

        property = new ComponentObjectProperty();
        property.setAuditObject(auditObject);
        property.setAuditField(auditField);
        property.setIndex(new Long(index));
        ComponentAuditObject targetComponentAuditObject = null;

        if (element != null) {
            targetComponentAuditObject = new ComponentAuditObject();
            targetComponentAuditObject.setAuditEvent(auditEvent);
            targetComponentAuditObject.setParentAuditObject(auditObject);
            AuditType auditComponentType = HibernateAudit.getAuditType(session,
                    auditConfiguration.getExtensionManager().getAuditableInformationProvider()
                            .getAuditTypeClassName(auditConfiguration.getMetadata(), elementType));
            targetComponentAuditObject.setAuditType(auditComponentType);

            for (int j = 0; j < componentType.getPropertyNames().length; j++) {
                String componentPropertyName = componentType.getPropertyNames()[j];

                Type componentPropertyType = componentType.getSubtypes()[j];
                Object componentPropertyValue = componentType.getPropertyValue(element, j,
                        (SessionImplementor) session);

                processProperty(session, auditConfiguration, auditEvent, element, componentPropertyName,
                        componentPropertyValue, componentPropertyType, targetComponentAuditObject);
            }
        }
        ((ComponentObjectProperty) property).setTargetComponentAuditObject(targetComponentAuditObject);
    } else if (elementType.isCollectionType()) {
        // collection of collections
    } else {

        property = new SimpleObjectProperty();
        property.setAuditObject(auditObject);
        property.setAuditField(auditField);
        property.setIndex(new Long(index));
        ((SimpleObjectProperty) property).setValue(
                auditConfiguration.getExtensionManager().getPropertyValueConverter().toString(null, element));
    }

    if (property != null) {
        AuditType auditType = null;
        if (element != null) {
            auditType = HibernateAudit.getAuditType(session, element.getClass().getName());
            if (auditType == null) {
                // subclass that was not registered in the audit metadata - use the base class
                auditType = property.getAuditField().getFieldType();
            }
        }

        property.setAuditType(auditType);
        auditObject.getAuditObjectProperties().add(property);
    }
}

From source file:org.babyfish.hibernate.internal.ImplicitCollectionJoins.java

License:Open Source License

private boolean hasImplicitCollectionJoins0(CompositeType compositeType, Map<String, Boolean> contextMap) {
    Type[] subtypes = compositeType.getSubtypes();
    for (int i = subtypes.length - 1; i >= 0; i--) {
        Type subtype = subtypes[i];
        if (compositeType.getFetchMode(i) == FetchMode.JOIN) {
            if (subtype.isCollectionType()) { //find collection with {fetch = "join"}
                return true;
            }//from  w  w w. j  a  va2  s .  c o m
            if (subtype instanceof AssociationType) {
                String childEntityName = ((AssociationType) subtype).getAssociatedEntityName(this.factory);
                if (this.hasImplicitCollectionJoins0(childEntityName, contextMap)) {
                    return true;
                }
            }
        } else if (subtype instanceof CompositeType) {
            if (this.hasImplicitCollectionJoins0((CompositeType) subtype, contextMap)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.eulerframework.web.core.extend.hibernate5.InExpressionX.java

License:Apache License

@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
    final ArrayList<TypedValue> list = new ArrayList<TypedValue>();
    final Type type = criteriaQuery.getTypeUsingProjection(criteria, propertyName);
    if (type.isComponentType()) {
        final CompositeType compositeType = (CompositeType) type;
        final Type[] subTypes = compositeType.getSubtypes();
        for (Object value : values) {
            for (int i = 0; i < subTypes.length; i++) {
                final Object subValue = value == null ? null
                        : compositeType.getPropertyValues(value, EntityMode.POJO)[i];
                list.add(new TypedValue(subTypes[i], subValue));
            }/*from  w  w  w. j  a  va  2 s .  co m*/
        }
    } else {
        for (Object value : values) {
            list.add(new TypedValue(type, value));
        }
    }

    return list.toArray(new TypedValue[list.size()]);
}