Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.SessionFactoryImplementor


          .ENTITY.equals( jpaType.getPersistenceType() )
          ? BindableType.ENTITY_TYPE
          : BindableType.SINGULAR_ATTRIBUTE;

      String guessedRoleName = determineRole( attribute );
      SessionFactoryImplementor sfi = criteriaBuilder.getEntityManagerFactory().getSessionFactory();
      mapPersister = sfi.getCollectionPersister( guessedRoleName );
      if ( mapPersister == null ) {
        throw new IllegalStateException( "Could not locate collection persister [" + guessedRoleName + "]" );
      }
      mapKeyType = mapPersister.getIndexType();
      if ( mapKeyType == null ) {
View Full Code Here


      }

      getSession().getPersistenceContext().registerInsertedKey( getPersister(), getId() );
    }

    final SessionFactoryImplementor factory = getSession().getFactory();

    if ( isCachePutEnabled( persister, session ) ) {
      final CacheEntry ce = persister.buildCacheEntry(
          instance,
          getState(),
          version,
          session
      );
      cacheEntry = persister.getCacheEntryStructure().structure( ce );
      final CacheKey ck = session.generateCacheKey( id, persister.getIdentifierType(), persister.getRootEntityName() );

      final boolean put = cacheInsert( persister, ck );

      if ( put && factory.getStatistics().isStatisticsEnabled() ) {
        factory.getStatisticsImplementor().secondLevelCachePut( getPersister().getCacheAccessStrategy().getRegion().getName() );
      }
    }

    handleNaturalIdPostSaveNotifications( id );

    postInsert();

    if ( factory.getStatistics().isStatisticsEnabled() && !veto ) {
      factory.getStatisticsImplementor().insertEntity( getPersister().getEntityName() );
    }

    markExecuted();
  }
View Full Code Here

  protected final void mutateRowValueConstructorSyntaxesIfNecessary(Type lhsType, Type rhsType) {
    // TODO : this really needs to be delayed until after we definitively know all node types
    // where this is currently a problem is parameters for which where we cannot unequivocally
    // resolve an expected type
    SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
    if ( lhsType != null && rhsType != null ) {
      int lhsColumnSpan = getColumnSpan( lhsType, sessionFactory );
      if ( lhsColumnSpan != getColumnSpan( rhsType, sessionFactory ) ) {
        throw new TypeMismatchException(
            "left and right hand sides of a binary logic operator were incompatibile [" +
                lhsType.getName() + " : " + rhsType.getName() + "]"
        );
      }
      if ( lhsColumnSpan > 1 ) {
        // for dialects which are known to not support ANSI-SQL row-value-constructor syntax,
        // we should mutate the tree.
        if ( !sessionFactory.getDialect().supportsRowValueConstructorSyntax() ) {
          mutateRowValueConstructorSyntax( lhsColumnSpan );
        }
      }
    }
  }
View Full Code Here

    final SessionImplementor session = getSession();
    final Object instance = getInstance();

    final boolean veto = preUpdate();

    final SessionFactoryImplementor factory = getSession().getFactory();
    Object previousVersion = this.previousVersion;
    if ( persister.isVersionPropertyGenerated() ) {
      // we need to grab the version value from the entity, otherwise
      // we have issues with generated-version entities that may have
      // multiple actions queued during the same flush
      previousVersion = persister.getVersion( instance );
    }
   
    final CacheKey ck;
    if ( persister.hasCache() ) {
      ck = session.generateCacheKey(
          id,
          persister.getIdentifierType(),
          persister.getRootEntityName()
      );
      lock = persister.getCacheAccessStrategy().lockItem( ck, previousVersion );
    }
    else {
      ck = null;
    }

    if ( !veto ) {
      persister.update(
          id,
          state,
          dirtyFields,
          hasDirtyCollection,
          previousState,
          previousVersion,
          instance,
          rowId,
          session
      );
    }

    final EntityEntry entry = getSession().getPersistenceContext().getEntry( instance );
    if ( entry == null ) {
      throw new AssertionFailure( "possible nonthreadsafe access to session" );
    }
   
    if ( entry.getStatus()==Status.MANAGED || persister.isVersionPropertyGenerated() ) {
      // get the updated snapshot of the entity state by cloning current state;
      // it is safe to copy in place, since by this time no-one else (should have)
      // has a reference  to the array
      TypeHelper.deepCopy(
          state,
          persister.getPropertyTypes(),
          persister.getPropertyCheckability(),
          state,
          session
      );
      if ( persister.hasUpdateGeneratedProperties() ) {
        // this entity defines proeprty generation, so process those generated
        // values...
        persister.processUpdateGeneratedProperties( id, instance, state, session );
        if ( persister.isVersionPropertyGenerated() ) {
          nextVersion = Versioning.getVersion( state, persister );
        }
      }
      // have the entity entry doAfterTransactionCompletion post-update processing, passing it the
      // update state and the new version (if one).
      entry.postUpdate( instance, state, nextVersion );
    }

    if ( persister.hasCache() ) {
      if ( persister.isCacheInvalidationRequired() || entry.getStatus()!= Status.MANAGED ) {
        persister.getCacheAccessStrategy().remove( ck );
      }
      else {
        //TODO: inefficient if that cache is just going to ignore the updated state!
        final CacheEntry ce = persister.buildCacheEntry( instance,state, nextVersion, getSession() );
        cacheEntry = persister.getCacheEntryStructure().structure( ce );

        final boolean put = cacheUpdate( persister, previousVersion, ck );
        if ( put && factory.getStatistics().isStatisticsEnabled() ) {
          factory.getStatisticsImplementor().secondLevelCachePut( getPersister().getCacheAccessStrategy().getRegion().getName() );
        }
      }
    }

    session.getPersistenceContext().getNaturalIdHelper().manageSharedNaturalIdCrossReference(
        persister,
        id,
        state,
        previousNaturalIdValues,
        CachedNaturalIdValueSource.UPDATE
    );

    postUpdate();

    if ( factory.getStatistics().isStatisticsEnabled() && !veto ) {
      factory.getStatisticsImplementor().updateEntity( getPersister().getEntityName() );
    }
  }
View Full Code Here

   *
   * @param session The session to which this request is tied.
   * @param affectedQueryables The affected entity persisters.
   */
  public BulkOperationCleanupAction(SessionImplementor session, Queryable... affectedQueryables) {
    final SessionFactoryImplementor factory = session.getFactory();
    final LinkedHashSet<String> spacesList = new LinkedHashSet<String>();
    for ( Queryable persister : affectedQueryables ) {
      spacesList.addAll( Arrays.asList( (String[]) persister.getQuerySpaces() ) );

      if ( persister.hasCache() ) {
        entityCleanups.add( new EntityCleanup( persister.getCacheAccessStrategy() ) );
      }
      if ( persister.hasNaturalIdentifier() && persister.hasNaturalIdCache() ) {
        naturalIdCleanups.add( new NaturalIdCleanup( persister.getNaturalIdCacheAccessStrategy() ) );
      }

      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

  @SuppressWarnings({ "unchecked" })
  public BulkOperationCleanupAction(SessionImplementor session, Set tableSpaces) {
    final LinkedHashSet<String> spacesList = new LinkedHashSet<String>();
    spacesList.addAll( tableSpaces );

    final SessionFactoryImplementor factory = session.getFactory();
    for ( String entityName : factory.getAllClassMetadata().keySet() ) {
      final EntityPersister persister = factory.getEntityPersister( entityName );
      final String[] entitySpaces = (String[]) persister.getQuerySpaces();
      if ( affectedEntity( tableSpaces, entitySpaces ) ) {
        spacesList.addAll( Arrays.asList( entitySpaces ) );

        if ( persister.hasCache() ) {
          entityCleanups.add( new EntityCleanup( persister.getCacheAccessStrategy() ) );
        }
        if ( persister.hasNaturalIdentifier() && persister.hasNaturalIdCache() ) {
          naturalIdCleanups.add( new NaturalIdCleanup( persister.getNaturalIdCacheAccessStrategy() ) );
        }

        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

    // resolve an expected type
    Type operandType = extractDataType( getOperand() );
    if ( operandType == null ) {
      return;
    }
    SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
    int operandColumnSpan = operandType.getColumnSpan( sessionFactory );
    if ( operandColumnSpan > 1 ) {
      mutateRowValueConstructorSyntax( operandColumnSpan );
    }
  }
View Full Code Here

    final boolean tracing = LOG.isTraceEnabled();
    if ( tracing ) {
      LOG.trace( "Serializing persistent-context" );
    }
    final StatefulPersistenceContext rtn = new StatefulPersistenceContext( session );
    SessionFactoryImplementor sfi = session.getFactory();

    // during deserialization, we need to reconnect all proxies and
    // collections to this session, as well as the EntityEntry and
    // CollectionEntry instances; these associations are transient
    // because serialization is used for different things.
View Full Code Here

      }
    }

    persister.setPropertyValues( entity, hydratedState );

    final SessionFactoryImplementor factory = session.getFactory();
    if ( persister.hasCache() && session.getCacheMode().isPutEnabled() ) {

      if ( debugEnabled ) {
        LOG.debugf(
            "Adding entity to second-level cache: %s",
            MessageHelper.infoString( persister, id, session.getFactory() )
        );
      }

      final Object version = Versioning.getVersion( hydratedState, persister );
      final CacheEntry entry = persister.buildCacheEntry( entity, hydratedState, version, session );
      final CacheKey cacheKey = session.generateCacheKey( id, persister.getIdentifierType(), persister.getRootEntityName() );

      // explicit handling of caching for rows just inserted and then somehow forced to be read
      // from the database *within the same transaction*.  usually this is done by
      //     1) Session#refresh, or
      //     2) Session#clear + some form of load
      //
      // we need to be careful not to clobber the lock here in the cache so that it can be rolled back if need be
      if ( session.getPersistenceContext().wasInsertedDuringTransaction( persister, id ) ) {
        persister.getCacheAccessStrategy().update(
            cacheKey,
            persister.getCacheEntryStructure().structure( entry ),
            version,
            version
        );
      }
      else {
        try {
          session.getEventListenerManager().cachePutStart();
          final boolean put = persister.getCacheAccessStrategy().putFromLoad(
              cacheKey,
              persister.getCacheEntryStructure().structure( entry ),
              session.getTimestamp(),
              version,
              useMinimalPuts( session, entityEntry )
          );

          if ( put && factory.getStatistics().isStatisticsEnabled() ) {
            factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
          }
        }
        finally {
          session.getEventListenerManager().cachePutEnd();
        }
      }
    }

    if ( persister.hasNaturalIdentifier() ) {
      persistenceContext.getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad(
          persister,
          id,
          persistenceContext.getNaturalIdHelper().extractNaturalIdValues( hydratedState, persister )
      );
    }

    boolean isReallyReadOnly = readOnly;
    if ( !persister.isMutable() ) {
      isReallyReadOnly = true;
    }
    else {
      final Object proxy = persistenceContext.getProxy( entityEntry.getEntityKey() );
      if ( proxy != null ) {
        // there is already a proxy for this impl
        // only set the status to read-only if the proxy is read-only
        isReallyReadOnly = ( (HibernateProxy) proxy ).getHibernateLazyInitializer().isReadOnly();
      }
    }
    if ( isReallyReadOnly ) {
      //no need to take a snapshot - this is a
      //performance optimization, but not really
      //important, except for entities with huge
      //mutable property values
      persistenceContext.setEntryStatus( entityEntry, Status.READ_ONLY );
    }
    else {
      //take a snapshot
      TypeHelper.deepCopy(
          hydratedState,
          persister.getPropertyTypes(),
          persister.getPropertyUpdateability(),
          //after setting values to object
          hydratedState,
          session
      );
      persistenceContext.setEntryStatus( entityEntry, Status.MANAGED );
    }

    persister.afterInitialize(
        entity,
        entityEntry.isLoadedWithLazyPropertiesUnfetched(),
        session
    );

    if ( debugEnabled ) {
      LOG.debugf(
          "Done materializing entity %s",
          MessageHelper.infoString( persister, id, session.getFactory() )
      );
    }

    if ( factory.getStatistics().isStatisticsEnabled() ) {
      factory.getStatisticsImplementor().loadEntity( persister.getEntityName() );
    }
  }
View Full Code Here

    if ( !useCache ) {
      return false;
    }

    final SessionFactoryImplementor factory = source.getFactory();
    final CacheKey ck = source.generateCacheKey( id, persister.getKeyType(), persister.getRole() );
    final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() );

    if ( factory.getStatistics().isStatisticsEnabled() ) {
      if ( ce == null ) {
        factory.getStatisticsImplementor()
            .secondLevelCacheMiss( persister.getCacheAccessStrategy().getRegion().getName() );
      }
      else {
        factory.getStatisticsImplementor()
            .secondLevelCacheHit( persister.getCacheAccessStrategy().getRegion().getName() );
      }
    }

    if ( ce == null ) {
View Full Code Here

TOP

Related Classes of org.hibernate.engine.spi.SessionFactoryImplementor

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.