Search in sources :

Example 16 with ComponentType

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);
    }
}
Also used : ComponentType(org.hibernate.type.ComponentType) ValueGeneration(org.hibernate.tuple.ValueGeneration)

Example 17 with ComponentType

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;
}
Also used : CollectionType(org.hibernate.type.CollectionType) ComponentType(org.hibernate.type.ComponentType) MaterializedNClobType(org.hibernate.type.MaterializedNClobType) MaterializedClobType(org.hibernate.type.MaterializedClobType) MapType(org.hibernate.type.MapType) RevisionType(org.hibernate.envers.RevisionType) Type(org.hibernate.type.Type) ComponentType(org.hibernate.type.ComponentType) CollectionType(org.hibernate.type.CollectionType) MaterializedNClobType(org.hibernate.type.MaterializedNClobType) MaterializedClobType(org.hibernate.type.MaterializedClobType) MapType(org.hibernate.type.MapType)

Example 18 with ComponentType

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]);
                        }
                    }
                }
            }
        }
    }
}
Also used : ComponentType(org.hibernate.type.ComponentType) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject)

Example 19 with ComponentType

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]);
            }
        }
    }
}
Also used : ComponentType(org.hibernate.type.ComponentType) Calendar(java.util.Calendar) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) Date(java.util.Date)

Example 20 with ComponentType

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());
}
Also used : RootClass(org.hibernate.mapping.RootClass) ComponentType(org.hibernate.type.ComponentType) ComponentMetamodel(org.hibernate.tuple.component.ComponentMetamodel) ClassType(org.hibernate.type.ClassType) Component(org.hibernate.mapping.Component) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Aggregations

ComponentType (org.hibernate.type.ComponentType)22 Component (org.hibernate.mapping.Component)9 Type (org.hibernate.type.Type)9 Test (org.junit.Test)9 RootClass (org.hibernate.mapping.RootClass)8 ComponentMetamodel (org.hibernate.tuple.component.ComponentMetamodel)8 ClassType (org.hibernate.type.ClassType)8 IType (org.jboss.tools.hibernate.runtime.spi.IType)8 ManyToOneType (org.hibernate.type.ManyToOneType)5 MetadataSources (org.hibernate.boot.MetadataSources)4 MetadataBuilderImpl (org.hibernate.boot.internal.MetadataBuilderImpl)4 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)4 MetadataBuildingOptions (org.hibernate.boot.spi.MetadataBuildingOptions)4 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 CollectionType (org.hibernate.type.CollectionType)3 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 OneToOneType (org.hibernate.type.OneToOneType)2