use of org.hibernate.metadata.ClassMetadata in project head by mifos.
the class InterceptHelper method populateAndMergeValueForObjectsOfTypeMasterDataEntityInCollections.
private void populateAndMergeValueForObjectsOfTypeMasterDataEntityInCollections(Object obj, String state, String name) {
Class clazz = getClazz(obj);
ClassMetadata customMeta = StaticHibernateUtil.getSessionFactory().getClassMetadata(clazz);
setPrimaryKeyValueForCollectionTypeAndMerge(customMeta, obj, name, state);
}
use of org.hibernate.metadata.ClassMetadata in project head by mifos.
the class InterceptHelper method readFurtherMetaForCollectionType.
private void readFurtherMetaForCollectionType(Object obj, String firstName, String state) {
Class l = getClazz(obj);
ClassMetadata customMeta = StaticHibernateUtil.getSessionFactory().getClassMetadata(l);
Object[] propertyValues = customMeta.getPropertyValues(obj, EntityMode.POJO);
String[] propertyNames = customMeta.getPropertyNames();
Type[] propertyTypes = customMeta.getPropertyTypes();
setPrimaryKeyValueForCollectionType(customMeta, obj, firstName.concat(customMeta.getIdentifierPropertyName()), state);
for (int i = 0; i < propertyNames.length; i++) {
if (!propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && !propertyTypes[i].isCollectionType()) {
if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
String name = firstName.concat(propertyNames[i]);
logger.debug("i readFurtherMetaForCollectionType : " + name + " : " + propertyValues[i]);
String oldValue = getOldValueToKey(initialValues, name);
if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
if (!oldValue.equals("")) {
initialValues.put(name, value.concat(",").concat(oldValue));
} else {
initialValues.put(name, value);
}
} else {
if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
if (!oldValue.equals("")) {
initialValues.put(name, ((Calendar) propertyValues[i]).getTime().toString().concat(",").concat(oldValue));
} else {
initialValues.put(name, ((Calendar) propertyValues[i]).getTime());
}
} else if (!(propertyValues[i] instanceof Calendar) && !(propertyValues[i] instanceof Date) && propertyValues[i] != null) {
if (!oldValue.equals("")) {
initialValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
} else {
initialValues.put(name, propertyValues[i]);
}
} else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
if (!oldValue.equals("")) {
try {
Date date = (Date) propertyValues[i];
initialValues.put(name, DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()).toString().concat(",").concat(oldValue));
} catch (Exception e) {
initialValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
}
} else {
try {
Date date = (Date) propertyValues[i];
initialValues.put(name, DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()));
} catch (Exception e) {
initialValues.put(name, propertyValues[i].toString());
}
}
} else {
if (!oldValue.equals("")) {
initialValues.put(name, oldValue);
} else {
initialValues.put(name, propertyValues[i]);
}
}
}
String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
if (columnName != null && !columnName.equals("")) {
columnNames.put(name, columnName);
} else {
columnNames.put(name, propertyNames[i]);
}
} else {
String name = firstName.concat(propertyNames[i].toString());
logger.debug("c readFurtherMetaForCollectionType : " + name + " : " + propertyValues[i]);
String oldValue = getOldValueToKey(changedValues, name);
if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
if (!value.equals("")) {
changedValues.put(name, value.concat(",").concat(oldValue));
} else {
changedValues.put(name, oldValue);
}
} else {
if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
if (!oldValue.equals("")) {
changedValues.put(name, ((Calendar) propertyValues[i]).getTime().toString().concat(",").concat(oldValue));
} else {
changedValues.put(name, ((Calendar) propertyValues[i]).getTime());
}
} else if (!(propertyValues[i] instanceof Calendar) && !(propertyValues[i] instanceof Date) && propertyValues[i] != null) {
if (!oldValue.equals("")) {
changedValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
} else {
changedValues.put(name, propertyValues[i]);
}
} else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
if (!oldValue.equals("")) {
try {
Date date = (Date) propertyValues[i];
changedValues.put(name, DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()).toString().concat(",").concat(oldValue));
} catch (Exception e) {
changedValues.put(name, propertyValues[i].toString().concat(",").concat(oldValue));
}
} else {
try {
Date date = (Date) propertyValues[i];
changedValues.put(name, DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()));
} catch (Exception e) {
changedValues.put(name, propertyValues[i].toString());
}
}
} else {
if (!oldValue.equals("")) {
changedValues.put(name, oldValue);
} else {
changedValues.put(name, propertyValues[i]);
}
}
}
String columnName = AuditConfiguration.getColumnNameForPropertyName(entityName, name);
if (columnName != null && !columnName.equals("")) {
columnNames.put(name, columnName);
} else {
columnNames.put(name, propertyNames[i]);
}
}
}
if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && propertyValues[i] instanceof MasterDataEntity && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
populateValueForObjectsOfTypeMasterDataEntityInCollections(propertyValues[i], state, firstName.concat(propertyNames[i]));
}
if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
Object object = propertyValues[i];
if (object != null) {
if (object instanceof MeetingBO) {
MeetingBO meeting = (MeetingBO) object;
if (propertyNames[i].equalsIgnoreCase("meeting") && meeting.getMeetingId() != null) {
readMeetingCollection(meeting, propertyNames[i], state);
} else {
readFurtherMetaForCollectionType(object, propertyNames[i], state);
}
} else {
readFurtherMetaForCollectionType(object, propertyNames[i], state);
}
}
}
// Reading further component type
if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
Object obj1 = propertyValues[i];
if (obj1 != null) {
readComponenetTypeInCollectionTypeWithoutMerge(obj1, propertyNames[i], state, propertyTypes[i]);
}
}
}
}
use of org.hibernate.metadata.ClassMetadata in project head by mifos.
the class InterceptHelper method readAndMergeCollectionTypes.
private void readAndMergeCollectionTypes(Object obj, String firstName, String parentName, String state) {
Class l = getClazz(obj);
ClassMetadata customMeta = StaticHibernateUtil.getSessionFactory().getClassMetadata(l);
Object[] propertyValues = customMeta.getPropertyValues(obj, EntityMode.POJO);
String[] propertyNames = customMeta.getPropertyNames();
Type[] propertyTypes = customMeta.getPropertyTypes();
setPrimaryKeyValueForCollectionTypeAndMerge(customMeta, obj, firstName.concat(customMeta.getIdentifierPropertyName()), state);
for (int i = 0; i < propertyNames.length; i++) {
logger.debug("property Name : " + propertyNames[i] + " value : " + propertyValues[i]);
if (!propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && !propertyTypes[i].isCollectionType()) {
if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
String name = firstName.concat(propertyNames[i]);
logger.debug("i readFurtherMetaForCollectionType " + name + " value : " + propertyValues[i]);
if (isValueLoggable(propertyNames[i], firstName)) {
if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
if (initialArray.toString().trim().length() == 0 || initialArray.toString().endsWith(",")) {
initialArray.append(value);
} else if (value.trim().length() != 0) {
initialArray.append("-").append(value);
}
} else {
if (propertyValues[i] != null) {
if (initialArray.toString().trim().length() == 0 || initialArray.toString().endsWith(",")) {
initialArray.append(propertyValues[i]);
} else if (propertyValues[i].toString().trim().length() != 0) {
initialArray.append("-").append(propertyValues[i]);
}
}
}
}
} else {
String name = firstName.concat(propertyNames[i].toString());
logger.debug("c readFurtherMetaForCollectionType " + name + " value : " + propertyValues[i]);
if (isValueLoggable(propertyNames[i], firstName)) {
if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
if (changeArray.toString().trim().length() == 0 || changeArray.toString().endsWith(",")) {
changeArray.append(value);
} else if (value.trim().length() != 0) {
changeArray.append("-").append(value);
}
} else {
if (propertyValues[i] != null) {
if (changeArray.toString().trim().length() == 0 || changeArray.toString().endsWith(",")) {
changeArray.append(propertyValues[i]);
} else if (propertyValues[i].toString().trim().length() != 0) {
changeArray.append("-").append(propertyValues[i]);
}
}
}
}
}
}
if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && propertyValues[i] instanceof MasterDataEntity && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
populateAndMergeValueForObjectsOfTypeMasterDataEntityInCollections(propertyValues[i], state, firstName.concat(propertyNames[i]));
}
if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
Object object = propertyValues[i];
if (object != null) {
if (object instanceof MeetingBO) {
MeetingBO meeting = (MeetingBO) object;
if (propertyNames[i].equalsIgnoreCase("meeting") && meeting.getMeetingId() != null) {
readAndMergeMeetingCollection(meeting, propertyNames[i], state);
} else {
readAndMergeCollectionTypes(object, propertyNames[i], firstName, state);
}
} else {
readAndMergeCollectionTypes(object, propertyNames[i], firstName, state);
}
}
}
// Reading further component type
if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
Object obj1 = propertyValues[i];
if (obj1 != null) {
readComponenetTypeInCollectionTypeWithMerge(obj1, propertyNames[i], state, propertyTypes[i]);
}
}
}
}
use of org.hibernate.metadata.ClassMetadata in project yyl_example by Relucent.
the class HibernateTest method test3.
private static void test3(SessionFactory sessionFactory) {
System.out.println("--------------------------------------------------");
ClassMetadata metadata = sessionFactory.getClassMetadata(Table1.class);
System.out.println("EntityName: " + metadata.getMappedClass());
System.out.println("IdProperty: " + metadata.getIdentifierPropertyName());
for (String propertyName : metadata.getPropertyNames()) {
Type type = metadata.getPropertyType(propertyName);
System.out.println("Property: " + propertyName);
System.out.println(" isComponentType: " + type.isComponentType());
System.out.println(" isAnyType: " + type.isAnyType());
System.out.println(" isCollection: " + type.isCollectionType());
System.out.println(" isAssociationType: " + type.isAssociationType());
if (type instanceof AssociationType) {
AssociationType associationType = (AssociationType) type;
String associatedEntityName = associationType.getAssociatedEntityName((SessionFactoryImpl) sessionFactory);
ClassMetadata associatedClassMetadata = sessionFactory.getClassMetadata(associatedEntityName);
Class<?> mappedClass = associatedClassMetadata.getMappedClass();
System.out.println(" associatedClass: " + mappedClass);
} else {
System.out.println(" propertyClass: " + type.getReturnedClass());
}
System.out.println();
}
}
use of org.hibernate.metadata.ClassMetadata in project midpoint by Evolveum.
the class RUtil method fixCompositeIdentifierInMetaModel.
private static void fixCompositeIdentifierInMetaModel(SessionFactory sessionFactory, Class clazz) {
ClassMetadata classMetadata = sessionFactory.getClassMetadata(clazz);
if (classMetadata instanceof AbstractEntityPersister) {
AbstractEntityPersister persister = (AbstractEntityPersister) classMetadata;
EntityMetamodel model = persister.getEntityMetamodel();
IdentifierProperty identifier = model.getIdentifierProperty();
try {
Field field = IdentifierProperty.class.getDeclaredField("hasIdentifierMapper");
field.setAccessible(true);
field.set(identifier, true);
field.setAccessible(false);
} catch (Exception ex) {
throw new SystemException("Attempt to fix entity meta model with hack failed, reason: " + ex.getMessage(), ex);
}
}
}
Aggregations