Package org.hibernate.persister.collection

Examples of org.hibernate.persister.collection.CollectionPersister


            .decode( model ) );
        accessStrategy = collectionRegion.buildAccessStrategy( accessType );
        entityAccessStrategies.put( cacheRegionName, accessStrategy );
        cacheAccess.addCacheRegion( cacheRegionName, collectionRegion );
      }
      CollectionPersister persister = persisterFactory.createCollectionPersister(
          cfg,
          model,
          accessStrategy,
          this
      ) ;
      collectionPersisters.put( model.getRole(), persister );
      tmpCollectionMetadata.put( model.getRole(), persister.getCollectionMetadata() );
      Type indexType = persister.getIndexType();
      if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) {
        String entityName = ( ( AssociationType ) indexType ).getAssociatedEntityName( this );
        Set roles = tmpEntityToCollectionRoleMap.get( entityName );
        if ( roles == null ) {
          roles = new HashSet();
          tmpEntityToCollectionRoleMap.put( entityName, roles );
        }
        roles.add( persister.getRole() );
      }
      Type elementType = persister.getElementType();
      if ( elementType.isAssociationType() && !elementType.isAnyType() ) {
        String entityName = ( ( AssociationType ) elementType ).getAssociatedEntityName( this );
        Set roles = tmpEntityToCollectionRoleMap.get( entityName );
        if ( roles == null ) {
          roles = new HashSet();
          tmpEntityToCollectionRoleMap.put( entityName, roles );
        }
        roles.add( persister.getRole() );
      }
    }
    collectionMetadata = Collections.unmodifiableMap( tmpCollectionMetadata );
    Iterator itr = tmpEntityToCollectionRoleMap.entrySet().iterator();
    while ( itr.hasNext() ) {
      final Map.Entry entry = ( Map.Entry ) itr.next();
      entry.setValue( Collections.unmodifiableSet( ( Set ) entry.getValue() ) );
    }
    collectionRolesByEntityParticipant = Collections.unmodifiableMap( tmpEntityToCollectionRoleMap );

    //Named Queries:
    this.namedQueryRepository = new NamedQueryRepository(
        cfg.getNamedQueries().values(),
        cfg.getNamedSQLQueries().values(),
        cfg.getSqlResultSetMappings().values(),
        toProcedureCallMementos( cfg.getNamedProcedureCallMap(), cfg.getSqlResultSetMappings() )
    );

    // after *all* persisters and named queries are registered
    for ( EntityPersister persister : entityPersisters.values() ) {
      persister.generateEntityDefinition();
    }

    for ( EntityPersister persister : entityPersisters.values() ) {
      persister.postInstantiate();
      registerEntityNameResolvers( persister );
    }
    for ( CollectionPersister persister : collectionPersisters.values() ) {
      persister.postInstantiate();
    }

    //JNDI + Serialization:

    name = settings.getSessionFactoryName();
View Full Code Here


    }
  }

  @Override
  public boolean containsCollection(String role, Serializable ownerIdentifier) {
    CollectionPersister p = sessionFactory.getCollectionPersister( role );
    return p.hasCache() &&
        p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( ownerIdentifier, p ) );
  }
View Full Code Here

        p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( ownerIdentifier, p ) );
  }

  @Override
  public void evictCollection(String role, Serializable ownerIdentifier) {
    CollectionPersister p = sessionFactory.getCollectionPersister( role );
    if ( p.hasCache() ) {
      if ( LOG.isDebugEnabled() ) {
        LOG.debugf(
            "Evicting second-level cache: %s",
            MessageHelper.collectionInfoString( p, ownerIdentifier, sessionFactory )
        );
      }
      CacheKey cacheKey = buildCacheKey( ownerIdentifier, p );
      p.getCacheAccessStrategy().evict( cacheKey );
    }
  }
View Full Code Here

    );
  }

  @Override
  public void evictCollectionRegion(String role) {
    CollectionPersister p = sessionFactory.getCollectionPersister( role );
    if ( p.hasCache() ) {
      if ( LOG.isDebugEnabled() ) {
        LOG.debugf( "Evicting second-level cache: %s", p.getRole() );
      }
      p.getCacheAccessStrategy().evictAll();
    }
  }
View Full Code Here

        );
        accessStrategy = collectionRegion.buildAccessStrategy( accessType );
        entityAccessStrategies.put( cacheRegionName, accessStrategy );
        cacheAccess.addCacheRegioncacheRegionName, collectionRegion );
      }
      CollectionPersister persister = serviceRegistry
          .getService( PersisterFactory.class )
          .createCollectionPersister( metadata, model, accessStrategy, this );
      collectionPersisters.put( model.getAttribute().getRole(), persister );
      tmpCollectionMetadata.put( model.getAttribute().getRole(), persister.getCollectionMetadata() );
      Type indexType = persister.getIndexType();
      if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) {
        String entityName = ( ( AssociationType ) indexType ).getAssociatedEntityName( this );
        Set<String> roles = tmpEntityToCollectionRoleMap.get( entityName );
        if ( roles == null ) {
          roles = new HashSet<String>();
          tmpEntityToCollectionRoleMap.put( entityName, roles );
        }
        roles.add( persister.getRole() );
      }
      Type elementType = persister.getElementType();
      if ( elementType.isAssociationType() && !elementType.isAnyType() ) {
        String entityName = ( ( AssociationType ) elementType ).getAssociatedEntityName( this );
        Set<String> roles = tmpEntityToCollectionRoleMap.get( entityName );
        if ( roles == null ) {
          roles = new HashSet<String>();
          tmpEntityToCollectionRoleMap.put( entityName, roles );
        }
        roles.add( persister.getRole() );
      }
    }
    collectionMetadata = Collections.unmodifiableMap( tmpCollectionMetadata );
    for ( Map.Entry<String, Set<String>> entry : tmpEntityToCollectionRoleMap.entrySet() ) {
      entry.setValue( Collections.unmodifiableSet( entry.getValue() ) );
    }
    collectionRolesByEntityParticipant = Collections.unmodifiableMap( tmpEntityToCollectionRoleMap );


    //Named Queries:
    namedQueryRepository = new NamedQueryRepository(
        metadata.getNamedQueryDefinitions(),
        metadata.getNamedNativeQueryDefinitions(),
        metadata.getResultSetMappingDefinitions(),
        new HashMap<String, ProcedureCallMemento>(  )
    );

    imports = new HashMap<String,String>();
    for ( Map.Entry<String,String> importEntry : metadata.getImports() ) {
      imports.put( importEntry.getKey(), importEntry.getValue() );
    }

    // after *all* persisters and named queries are registered
    Iterator iter = entityPersisters.values().iterator();
    while ( iter.hasNext() ) {
      final EntityPersister persister = ( ( EntityPersister ) iter.next() );
      persister.postInstantiate();
      registerEntityNameResolvers( persister );

    }
    iter = collectionPersisters.values().iterator();
    while ( iter.hasNext() ) {
      final CollectionPersister persister = ( ( CollectionPersister ) iter.next() );
      persister.postInstantiate();
    }

    //JNDI + Serialization:

    name = settings.getSessionFactoryName();
View Full Code Here

  public Map<String, EntityPersister> getEntityPersisters() {
    return entityPersisters;
  }

  public CollectionPersister getCollectionPersister(String role) throws MappingException {
    CollectionPersister result = collectionPersisters.get(role);
    if ( result == null ) {
      throw new MappingException( "Unknown collection role: " + role );
    }
    return result;
  }
View Full Code Here

      }
    }

    iter = collectionPersisters.values().iterator();
    while ( iter.hasNext() ) {
      CollectionPersister p = (CollectionPersister) iter.next();
      if ( p.hasCache() ) {
        p.getCacheAccessStrategy().getRegion().destroy();
      }
    }

    cacheAccess.close();
View Full Code Here

  @Override
  public void execute() throws HibernateException {
    final Serializable id = getKey();
    final SessionImplementor session = getSession();
    final CollectionPersister persister = getPersister();
    final PersistentCollection collection = getCollection();
    final boolean affectedByFilters = persister.isAffectedByEnabledFilters( session );

    preUpdate();

    if ( !collection.wasInitialized() ) {
      if ( !collection.hasQueuedOperations() ) {
        throw new AssertionFailure( "no queued adds" );
      }
      //do nothing - we only need to notify the cache...
    }
    else if ( !affectedByFilters && collection.empty() ) {
      if ( !emptySnapshot ) {
        persister.remove( id, session );
      }
    }
    else if ( collection.needsRecreate( persister ) ) {
      if ( affectedByFilters ) {
        throw new HibernateException(
            "cannot recreate collection while filter is enabled: " +
                MessageHelper.collectionInfoString( persister, collection, id, session )
        );
      }
      if ( !emptySnapshot ) {
        persister.remove( id, session );
      }
      persister.recreate( collection, id, session );
    }
    else {
      persister.deleteRows( collection, id, session );
      persister.updateRows( collection, id, session );
      persister.insertRows( collection, id, session );
    }

    getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
    evict();
    postUpdate();
View Full Code Here

      }

      final Set<String> roles = factory.getCollectionRolesByEntityParticipant( persister.getEntityName() );
      if ( roles != null ) {
        for ( String role : roles ) {
          final CollectionPersister collectionPersister = factory.getCollectionPersister( role );
          if ( collectionPersister.hasCache() ) {
            collectionCleanups.add( new CollectionCleanup( collectionPersister.getCacheAccessStrategy() ) );
          }
        }
      }
    }
View Full Code Here

        }

        final Set<String> roles = session.getFactory().getCollectionRolesByEntityParticipant( persister.getEntityName() );
        if ( roles != null ) {
          for ( String role : roles ) {
            final CollectionPersister collectionPersister = factory.getCollectionPersister( role );
            if ( collectionPersister.hasCache() ) {
              collectionCleanups.add(
                  new CollectionCleanup( collectionPersister.getCacheAccessStrategy() )
              );
            }
          }
        }
      }
View Full Code Here

TOP

Related Classes of org.hibernate.persister.collection.CollectionPersister

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.