Package org.hibernate.engine

Examples of org.hibernate.engine.SessionFactoryImplementor


      source.getCacheMode().isGetEnabled() &&
      event.getLockMode().lessThan(LockMode.READ);
   
    if (useCache) {
     
      final SessionFactoryImplementor factory = source.getFactory();
     
      final CacheKey ck = new CacheKey(
          event.getEntityId(),
          persister.getIdentifierType(),
          persister.getRootEntityName(),
          source.getEntityMode(),
          source.getFactory()
        );
      Object ce = persister.getCache()
        .get( ck, source.getTimestamp() );
     
      if ( factory.getStatistics().isStatisticsEnabled() ) {
        if (ce==null) {
          factory.getStatisticsImplementor().secondLevelCacheMiss(
            persister.getCache().getRegionName()
          );
        }
        else {
          factory.getStatisticsImplementor().secondLevelCacheHit(
            persister.getCache().getRegionName()
          );
        }
      }
View Full Code Here


      final EntityPersister persister,
      final LoadEvent event) throws HibernateException {
   
    final Object optionalObject = event.getInstanceToLoad();
    final EventSource session = event.getSession();
    final SessionFactoryImplementor factory = session.getFactory();
   
    if ( log.isTraceEnabled() ) {
      log.trace(
          "assembling entity from second-level cache: " +
          MessageHelper.infoString( persister, id, factory )
        );
    }

    EntityPersister subclassPersister = factory.getEntityPersister( entry.getSubclass() );
    Object result = optionalObject == null ?
        session.instantiate( subclassPersister, id ) : optionalObject;
       
    // make it circular-reference safe
    TwoPhaseLoad.addUninitializedCachedEntity(
View Full Code Here

  public final String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    String entityName = criteriaQuery.getEntityName( criteria, propertyName );
    String actualPropertyName = criteriaQuery.getPropertyName( propertyName );
    String sqlAlias = criteriaQuery.getSQLAlias( criteria, propertyName );

    SessionFactoryImplementor factory = criteriaQuery.getFactory();
    QueryableCollection collectionPersister = getQueryableCollection( entityName, actualPropertyName, factory );

    String[] collectionKeys = collectionPersister.getKeyColumnNames();
    String[] ownerKeys = ( ( Loadable ) factory.getEntityPersister( entityName ) ).getIdentifierColumnNames();

    String innerSelect = "(select 1 from " + collectionPersister.getTableName()
            + " where "
            + new ConditionFragment().setTableAlias( sqlAlias ).setCondition( ownerKeys, collectionKeys ).toFragmentString()
            + ")";
View Full Code Here

        implicitParameterTypes.put( parameterName, javaType );
        return parameterName;
      }

      public String getCastType(Class javaType) {
        SessionFactoryImplementor factory =
            ( SessionFactoryImplementor ) entityManager.getFactory().getSessionFactory();
        Type hibernateType = factory.getTypeResolver().heuristicType( javaType.getName() );
        if ( hibernateType == null ) {
          throw new IllegalArgumentException(
              "Could not convert java type [" + javaType.getName() + "] to Hibernate type"
          );
        }
        int[] sqlTypeCodes = hibernateType.sqlTypes( factory );
        if ( sqlTypeCodes.length != 1 ) {
          throw new IllegalArgumentException(
              "Invalid Hibernate Type [" + hibernateType.getName() +
                  "] for cast : more than one column spanned"
          );
        }
        return factory.getDialect().getCastTypeName( sqlTypeCodes[0] );
      }
    };

    final RenderedCriteriaQuery renderedCriteriaQuery = criteriaQueryImpl.render( renderingContext );
View Full Code Here

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

    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, session.getEntityMode() );
    }
   
    final CacheKey ck;
    if ( persister.hasCache() ) {
      ck = new CacheKey(
          id,
          persister.getIdentifierType(),
          persister.getRootEntityName(),
          session.getEntityMode(),
          session.getFactory()
      );
      lock = persister.getCacheAccessStrategy().lockItem( ck, previousVersion );
    }
    else {
      ck = null;
    }

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

    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
      TypeFactory.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 perform 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!
        CacheEntry ce = new CacheEntry(
            state,
            persister,
            persister.hasUninitializedLazyProperties( instance, session.getEntityMode() ),
            nextVersion,
            getSession(),
            instance
        );
        cacheEntry = persister.getCacheEntryStructure().structure( ce );
        boolean put = persister.getCacheAccessStrategy().update( ck, cacheEntry, nextVersion, previousVersion );
        if ( put && factory.getStatistics().isStatisticsEnabled() ) {
          factory.getStatisticsImplementor().secondLevelCachePut( getPersister().getCacheAccessStrategy().getRegion().getName() );
        }
      }
    }

    postUpdate();

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

   **/
  public BulkOperationCleanupAction(SessionImplementor session, Set querySpaces) {
    this.session = session;

    Set tmpSpaces = new HashSet(querySpaces);
    SessionFactoryImplementor factory = session.getFactory();
    Iterator iterator = factory.getAllClassMetadata().entrySet().iterator();
    while ( iterator.hasNext() ) {
      Map.Entry entry = (Map.Entry) iterator.next();
      String entityName = (String) entry.getKey();
      EntityPersister persister = factory.getEntityPersister( entityName );
      Serializable[] entitySpaces = persister.getQuerySpaces();

      if (affectedEntity( querySpaces, entitySpaces )) {
        if ( persister.hasCache() ) {
          affectedEntityNames.add( persister.getEntityName() );
View Full Code Here

    this.attribute = attribute;
    this.persister = resolvePersister( criteriaBuilder, attribute );
  }

  private static CollectionPersister resolvePersister(CriteriaBuilderImpl criteriaBuilder, PluralAttribute attribute) {
    SessionFactoryImplementor sfi = (SessionFactoryImplementor)
        criteriaBuilder.getEntityManagerFactory().getSessionFactory();
    return sfi.getCollectionPersister( resolveRole( attribute ) );
  }
View Full Code Here

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

      String guessedRoleName = determineRole( attribute );
      SessionFactoryImplementor sfi = (SessionFactoryImplementor)
          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

  }

  protected abstract String toLeftSqlString(Criteria criteria, CriteriaQuery outerQuery);

  public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    final SessionFactoryImplementor factory = criteriaQuery.getFactory();
    final OuterJoinLoadable persister =
        ( OuterJoinLoadable ) factory.getEntityPersister( criteriaImpl.getEntityOrClassName() );

    createAndSetInnerQuery( criteriaQuery, factory );
    criteriaImpl.setSession( deriveRootSession( criteria ) );

    CriteriaJoinWalker walker = new CriteriaJoinWalker(
View Full Code Here

  public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
  throws HibernateException {
    //the following two lines were added to ensure that this.params is not null, which
    //can happen with two-deep nested subqueries
    SessionFactoryImplementor factory = criteriaQuery.getFactory();
    createAndSetInnerQuery(criteriaQuery, factory);

    Type[] ppTypes = params.getPositionalParameterTypes();
    Object[] ppValues = params.getPositionalParameterValues();
    TypedValue[] tv = new TypedValue[ppTypes.length];
View Full Code Here

TOP

Related Classes of org.hibernate.engine.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.