List of usage examples for org.hibernate.type CompositeType getPropertyValue
Object getPropertyValue(Object component, int index, SharedSessionContractImplementor session) throws HibernateException;
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 ww . j a v a 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) {// w w w . j a va 2s. 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); } }