Search in sources :

Example 11 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class AbstractPropertyMapping method initComponentPropertyPaths.

protected void initComponentPropertyPaths(final String path, final CompositeType type, final String[] columns, final String[] columnReaders, final String[] columnReaderTemplates, String[] formulaTemplates, final Mapping factory) throws MappingException {
    Type[] types = type.getSubtypes();
    String[] properties = type.getPropertyNames();
    int begin = 0;
    for (int i = 0; i < properties.length; i++) {
        String subpath = extendPath(path, properties[i]);
        try {
            int length = types[i].getColumnSpan(factory);
            String[] columnSlice = ArrayHelper.slice(columns, begin, length);
            String[] columnReaderSlice = ArrayHelper.slice(columnReaders, begin, length);
            String[] columnReaderTemplateSlice = ArrayHelper.slice(columnReaderTemplates, begin, length);
            String[] formulaSlice = formulaTemplates == null ? null : ArrayHelper.slice(formulaTemplates, begin, length);
            initPropertyPaths(subpath, types[i], columnSlice, columnReaderSlice, columnReaderTemplateSlice, formulaSlice, factory);
            begin += length;
        } catch (Exception e) {
            throw new MappingException("bug in initComponentPropertyPaths", e);
        }
    }
}
Also used : EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) MappingException(org.hibernate.MappingException) QueryException(org.hibernate.QueryException) MappingException(org.hibernate.MappingException)

Example 12 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class PojoEntityTuplizer method buildProxyFactory.

@Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
    // determine the id getter and setter methods from the proxy interface (if any)
    // determine all interfaces needed by the resulting proxy
    /*
		 * We need to preserve the order of the interfaces they were put into the set, since javassist will choose the
		 * first one's class-loader to construct the proxy class with. This is also the reason why HibernateProxy.class
		 * should be the last one in the order (on JBossAS7 its class-loader will be org.hibernate module's class-
		 * loader, which will not see the classes inside deployed apps.  See HHH-3078
		 */
    Set<Class> proxyInterfaces = new java.util.LinkedHashSet<Class>();
    Class mappedClass = persistentClass.getMappedClass();
    Class proxyInterface = persistentClass.getProxyInterface();
    if (proxyInterface != null && !mappedClass.equals(proxyInterface)) {
        if (!proxyInterface.isInterface()) {
            throw new MappingException("proxy must be either an interface, or the class itself: " + getEntityName());
        }
        proxyInterfaces.add(proxyInterface);
    }
    if (mappedClass.isInterface()) {
        proxyInterfaces.add(mappedClass);
    }
    Iterator<Subclass> subclasses = persistentClass.getSubclassIterator();
    while (subclasses.hasNext()) {
        final Subclass subclass = subclasses.next();
        final Class subclassProxy = subclass.getProxyInterface();
        final Class subclassClass = subclass.getMappedClass();
        if (subclassProxy != null && !subclassClass.equals(subclassProxy)) {
            if (!subclassProxy.isInterface()) {
                throw new MappingException("proxy must be either an interface, or the class itself: " + subclass.getEntityName());
            }
            proxyInterfaces.add(subclassProxy);
        }
    }
    proxyInterfaces.add(HibernateProxy.class);
    Iterator properties = persistentClass.getPropertyIterator();
    Class clazz = persistentClass.getMappedClass();
    while (properties.hasNext()) {
        Property property = (Property) properties.next();
        Method method = property.getGetter(clazz).getMethod();
        if (method != null && Modifier.isFinal(method.getModifiers())) {
            LOG.gettersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
        }
        method = property.getSetter(clazz).getMethod();
        if (method != null && Modifier.isFinal(method.getModifiers())) {
            LOG.settersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
        }
    }
    Method idGetterMethod = idGetter == null ? null : idGetter.getMethod();
    Method idSetterMethod = idSetter == null ? null : idSetter.getMethod();
    Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idGetterMethod);
    Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idSetterMethod);
    ProxyFactory pf = buildProxyFactoryInternal(persistentClass, idGetter, idSetter);
    try {
        pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod, proxySetIdentifierMethod, persistentClass.hasEmbeddedIdentifier() ? (CompositeType) persistentClass.getIdentifier().getType() : null);
    } catch (HibernateException he) {
        LOG.unableToCreateProxyFactory(getEntityName(), he);
        pf = null;
    }
    return pf;
}
Also used : Subclass(org.hibernate.mapping.Subclass) ProxyFactory(org.hibernate.proxy.ProxyFactory) HibernateException(org.hibernate.HibernateException) Method(java.lang.reflect.Method) MappingException(org.hibernate.MappingException) Iterator(java.util.Iterator) PersistentClass(org.hibernate.mapping.PersistentClass) Property(org.hibernate.mapping.Property) CompositeType(org.hibernate.type.CompositeType)

Example 13 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class SimpleEmbeddableOverriddenConverterTest method testSimpleConvertOverrides.

/**
	 * Test outcome of annotations exclusively.
	 */
@Test
public void testSimpleConvertOverrides() {
    final EntityPersister ep = sessionFactory().getEntityPersister(Person.class.getName());
    CompositeType homeAddressType = assertTyping(CompositeType.class, ep.getPropertyType("homeAddress"));
    Type homeAddressCityType = findCompositeAttributeType(homeAddressType, "city");
    assertTyping(StringType.class, homeAddressCityType);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) CompositeType(org.hibernate.type.CompositeType) StringType(org.hibernate.type.StringType) Type(org.hibernate.type.Type) CompositeType(org.hibernate.type.CompositeType) Test(org.junit.Test)

Example 14 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class DefaultRefreshEventListener method evictCachedCollections.

private void evictCachedCollections(Type[] types, Serializable id, EventSource source) throws HibernateException {
    for (Type type : types) {
        if (type.isCollectionType()) {
            CollectionPersister collectionPersister = source.getFactory().getMetamodel().collectionPersister(((CollectionType) type).getRole());
            if (collectionPersister.hasCache()) {
                final CollectionRegionAccessStrategy cache = collectionPersister.getCacheAccessStrategy();
                final Object ck = cache.generateCacheKey(id, collectionPersister, source.getFactory(), source.getTenantIdentifier());
                final SoftLock lock = cache.lockItem(source, ck, null);
                source.getActionQueue().registerProcess(new AfterTransactionCompletionProcess() {

                    @Override
                    public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
                        cache.unlockItem(session, ck, lock);
                    }
                });
                cache.remove(source, ck);
            }
        } else if (type.isComponentType()) {
            CompositeType actype = (CompositeType) type;
            evictCachedCollections(actype.getSubtypes(), id, source);
        }
    }
}
Also used : CollectionType(org.hibernate.type.CollectionType) CompositeType(org.hibernate.type.CompositeType) Type(org.hibernate.type.Type) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) AfterTransactionCompletionProcess(org.hibernate.action.spi.AfterTransactionCompletionProcess) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) CollectionRegionAccessStrategy(org.hibernate.cache.spi.access.CollectionRegionAccessStrategy) SoftLock(org.hibernate.cache.spi.access.SoftLock) CompositeType(org.hibernate.type.CompositeType)

Example 15 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class JoinWalker method walkCollectionTree.

/**
	 * For a collection role, return a list of associations to be fetched by outerjoin
	 */
private void walkCollectionTree(final QueryableCollection persister, final String alias, final PropertyPath path, final int currentDepth) throws MappingException {
    if (persister.isOneToMany()) {
        walkEntityTree((OuterJoinLoadable) persister.getElementPersister(), alias, path, currentDepth);
    } else {
        Type type = persister.getElementType();
        if (type.isAssociationType()) {
            // a many-to-many;
            // decrement currentDepth here to allow join across the association table
            // without exceeding MAX_FETCH_DEPTH (i.e. the "currentDepth - 1" bit)
            AssociationType associationType = (AssociationType) type;
            String[] aliasedLhsColumns = persister.getElementColumnNames(alias);
            String[] lhsColumns = persister.getElementColumnNames();
            // if the current depth is 0, the root thing being loaded is the
            // many-to-many collection itself.  Here, it is alright to use
            // an inner join...
            boolean useInnerJoin = currentDepth == 0;
            final JoinType joinType = getJoinType(associationType, persister.getFetchMode(), path, persister.getTableName(), lhsColumns, !useInnerJoin, currentDepth - 1, //operations which cascade as far as the collection also cascade to collection elements
            null);
            addAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, path, currentDepth - 1, joinType);
        } else if (type.isComponentType()) {
            walkCompositeElementTree((CompositeType) type, persister.getElementColumnNames(), persister, alias, path, currentDepth);
        }
    }
}
Also used : EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) JoinType(org.hibernate.sql.JoinType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) AssociationType(org.hibernate.type.AssociationType) JoinType(org.hibernate.sql.JoinType) CompositeType(org.hibernate.type.CompositeType)

Aggregations

CompositeType (org.hibernate.type.CompositeType)32 Type (org.hibernate.type.Type)22 AssociationType (org.hibernate.type.AssociationType)12 EntityType (org.hibernate.type.EntityType)11 EntityPersister (org.hibernate.persister.entity.EntityPersister)7 JoinType (org.hibernate.sql.JoinType)6 CollectionType (org.hibernate.type.CollectionType)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 MappingException (org.hibernate.MappingException)3 QueryException (org.hibernate.QueryException)3 ExpandingCompositeQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace)3 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)3 HashSet (java.util.HashSet)2 HibernateException (org.hibernate.HibernateException)2 TypedValue (org.hibernate.engine.spi.TypedValue)2 CompositePropertyMapping (org.hibernate.loader.plan.build.internal.spaces.CompositePropertyMapping)2 ExpandingEntityQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingEntityQuerySpace)2 AssociationKey (org.hibernate.persister.walking.spi.AssociationKey)2 AttributeDefinition (org.hibernate.persister.walking.spi.AttributeDefinition)2