Example usage for org.hibernate.type CompositeType getPropertyNames

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

Introduction

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

Prototype

String[] getPropertyNames();

Source Link

Document

Get the names 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 ww w .  ja va  2s.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);/*w  w w.jav a 2  s. com*/

    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  a  va 2  s .  co  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:edu.northwestern.bioinformatics.studycalendar.service.auditing.AuditEventFactory.java

License:BSD License

private void addComponentValues(AuditEvent event, CompositeType propertyType, String propertyName,
        Object previousState, Object currentState) {
    Object[] componentPrevState = getComponentState(propertyType, previousState);
    Object[] componentCurState = getComponentState(propertyType, currentState);

    if (ignoreStates(componentPrevState, componentCurState)) {
        return;/*from  w  ww. j av a  2  s.c  o  m*/
    } else {
        int index = componentCurState == null ? componentPrevState.length : componentCurState.length;
        for (int i = 0; i < index; i++) {
            String compPropertyName = propertyName.concat(".").concat(propertyType.getPropertyNames()[i]);
            if (componentPrevState != null && componentCurState != null) {
                if (!ComparisonTools.nullSafeEquals(componentCurState[i], componentPrevState[i])) {
                    event.addValue(new DataAuditEventValue(compPropertyName, scalarValue(componentPrevState[i]),
                            scalarValue(componentCurState[i])));
                }
            } else {
                event.addValue(new DataAuditEventValue(compPropertyName,
                        componentPrevState == null ? null : scalarValue(componentPrevState[i]),
                        componentCurState == null ? null : scalarValue(componentCurState[i])));
            }
        }
    }
}

From source file:gov.nih.nci.cabig.ctms.audit.AuditInterceptorImpl.java

License:BSD License

private List<DataAuditEventValue> decomposeComponent(final CompositeType propertyType,
        final String propertyName, final Object previousState, final Object currentState) {
    Object[] componentPrevState = previousState == null ? null
            : propertyType.getPropertyValues(previousState, ENTITY_MODE);
    Object[] componentCurState = currentState == null ? null
            : propertyType.getPropertyValues(currentState, ENTITY_MODE);
    List<Integer> differences = findDifferences(componentCurState, componentPrevState, null);
    List<DataAuditEventValue> values = new ArrayList<DataAuditEventValue>(differences.size());
    for (Integer index : differences) {
        String compPropertyName = propertyName + '.' + propertyType.getPropertyNames()[index];
        values.add(new DataAuditEventValue(compPropertyName,
                previousState == null ? null : scalarAuditableValue(componentPrevState[index]),
                currentState == null ? null : scalarAuditableValue(componentCurState[index])));
    }/*from  w  w w.  j  a  v a 2s .  c o m*/
    return values;
}