use of org.hibernate.type.ComponentType in project hibernate-orm by hibernate.
the class AbstractEntityPersister method isValueGenerationRequired.
private boolean isValueGenerationRequired(NonIdentifierAttribute attribute, GenerationTiming matchTiming) {
if (attribute.getType() instanceof ComponentType) {
final ComponentType type = (ComponentType) attribute.getType();
final ValueGeneration[] propertyValueGenerationStrategies = type.getPropertyValueGenerationStrategies();
for (int i = 0; i < propertyValueGenerationStrategies.length; i++) {
if (isReadRequired(propertyValueGenerationStrategies[i], matchTiming)) {
return true;
}
}
return false;
} else {
return isReadRequired(attribute.getValueGenerationStrategy(), matchTiming);
}
}
use of org.hibernate.type.ComponentType in project hibernate-orm by hibernate.
the class ValidityAuditStrategy method isNonIdentifierWhereConditionsRequired.
private boolean isNonIdentifierWhereConditionsRequired(String entityName, String propertyName, SessionImplementor session) {
final Type propertyType = session.getSessionFactory().getMetamodel().entityPersister(entityName).getPropertyType(propertyName);
if (propertyType.isCollectionType()) {
final CollectionType collectionType = (CollectionType) propertyType;
final Type collectionElementType = collectionType.getElementType(session.getSessionFactory());
if (collectionElementType instanceof ComponentType) {
// required for Embeddables
return true;
} else if (collectionElementType instanceof MaterializedClobType || collectionElementType instanceof MaterializedNClobType) {
// for Map<> using @Lob annotations
return collectionType instanceof MapType;
}
}
return false;
}
use of org.hibernate.type.ComponentType in project head by mifos.
the class InterceptHelper method readComponenetTypeInCollectionTypeWithMerge.
private void readComponenetTypeInCollectionTypeWithMerge(Object obj, String firstName, String state, Type propertyType) {
ComponentType componentType = (ComponentType) propertyType;
Object[] propertyValues = componentType.getPropertyValues(obj, EntityMode.POJO);
String[] propertyNames = componentType.getPropertyNames();
for (int i = 0; i < propertyNames.length; i++) {
logger.debug("property Name : " + propertyNames[i] + " value : " + propertyValues[i]);
if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
String name = firstName.concat(propertyNames[i]);
logger.debug("i readComponenetTypeInCollectionTypeWithMerge " + 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 readComponenetTypeInCollectionTypeWithMerge " + 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]);
}
}
}
}
}
}
}
use of org.hibernate.type.ComponentType in project head by mifos.
the class InterceptHelper method readFurtherComponenetMeta.
private void readFurtherComponenetMeta(Object obj, String firstName, String state, Type propertyType) {
ComponentType componentType = (ComponentType) propertyType;
Object[] propertyValues = componentType.getPropertyValues(obj, EntityMode.POJO);
String[] propertyNames = componentType.getPropertyNames();
for (int i = 0; i < propertyNames.length; i++) {
if (state.equalsIgnoreCase(AuditConstants.TRANSACTIONBEGIN)) {
String name = firstName.concat(propertyNames[i]);
logger.debug("i setColumnValues " + name + " : " + propertyValues[i]);
if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
initialValues.put(name, value);
} else {
if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
initialValues.put(name, ((Calendar) propertyValues[i]).getTime());
} else if (propertyValues[i] instanceof byte[] && propertyValues[i] != null) {
initialValues.put(name, new String((byte[]) propertyValues[i]));
} else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
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 {
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]);
logger.debug("c setColumnValues " + name + " : " + propertyValues[i]);
if (AuditConfiguration.checkForPropertyName(entityName, name, localeId)) {
String value = AuditConfiguration.getValueOfCorrespondingId(entityName, name, propertyValues[i], localeId);
changedValues.put(name, value);
} else {
if (propertyValues[i] instanceof Calendar && propertyValues[i] != null) {
changedValues.put(name, ((Calendar) propertyValues[i]).getTime());
} else if (propertyValues[i] instanceof byte[] && propertyValues[i] != null) {
changedValues.put(name, new String((byte[]) propertyValues[i]));
} else if (propertyValues[i] instanceof Date && propertyValues[i] != null) {
Date date = (Date) propertyValues[i];
changedValues.put(name, DateUtils.getUserLocaleDate(locale, new java.sql.Date(date.getTime()).toString()));
} 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]);
}
}
}
}
use of org.hibernate.type.ComponentType in project jbosstools-hibernate by jbosstools.
the class TypeFacadeTest method testIsComponentType.
@Test
public void testIsComponentType() {
IType typeFacade = null;
ClassType classType = new ClassType();
typeFacade = FACADE_FACTORY.createType(classType);
Assert.assertFalse(typeFacade.isComponentType());
ComponentType componentType = new ComponentType(null, new ComponentMetamodel(new Component(null, new RootClass())));
typeFacade = FACADE_FACTORY.createType(componentType);
Assert.assertTrue(typeFacade.isComponentType());
}
Aggregations