Package org.hibernate.engine

Examples of org.hibernate.engine.SessionFactoryImplementor


          Serializable id,
          Object version,
          Object object,
          SessionImplementor session) throws StaleObjectStateException, JDBCException {

    SessionFactoryImplementor factory = session.getFactory();
    try {
      PreparedStatement st = session.getBatcher().prepareSelectStatement( sql );
      try {
        lockable.getIdentifierType().nullSafeSet( st, id, 1, session );
        if ( lockable.isVersioned() ) {
          lockable.getVersionType().nullSafeSet(
              st,
              version,
              lockable.getIdentifierType().getColumnSpan( factory ) + 1,
              session
          );
        }

        ResultSet rs = st.executeQuery();
        try {
          if ( !rs.next() ) {
            if ( factory.getStatistics().isStatisticsEnabled() ) {
              factory.getStatisticsImplementor()
                  .optimisticFailure( lockable.getEntityName() );
            }
            throw new StaleObjectStateException( lockable.getEntityName(), id );
          }
        }
View Full Code Here


  protected LockMode getLockMode() {
    return lockMode;
  }

  protected String generateLockString() {
    SessionFactoryImplementor factory = lockable.getFactory();
    SimpleSelect select = new SimpleSelect( factory.getDialect() )
        .setLockMode( lockMode )
        .setTableName( lockable.getRootTableName() )
        .addColumn( lockable.getRootTableIdentifierColumnNames()[0] )
        .addCondition( lockable.getRootTableIdentifierColumnNames(), "=?" );
    if ( lockable.isVersioned() ) {
      select.addCondition( lockable.getVersionColumnName(), "=?" );
    }
    if ( factory.getSettings().isCommentsEnabled() ) {
      select.setComment( lockMode + " lock " + lockable.getEntityName() );
    }
    return select.toStatementString();
  }
View Full Code Here

    if ( !useCache ) {
      return false;
    }
    else {
     
      final SessionFactoryImplementor factory = source.getFactory();

      final CacheKey ck = new CacheKey(
          id,
          persister.getKeyType(),
          persister.getRole(),
          source.getEntityMode(),
          source.getFactory()
        );
      Object ce = persister.getCacheAccessStrategy().get( ck, source.getTimestamp() );
     
      if ( factory.getStatistics().isStatisticsEnabled() ) {
        if ( ce == null ) {
          factory.getStatisticsImplementor().secondLevelCacheMiss(
              persister.getCacheAccessStrategy().getRegion().getName()
          );
        }
        else {
          factory.getStatisticsImplementor().secondLevelCacheHit(
              persister.getCacheAccessStrategy().getRegion().getName()
          );
        }

       
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

  protected final void mutateRowValueConstructorSyntaxesIfNecessary(Type lhsType, Type rhsType) {
    // TODO : this really needs to be delayed unitl 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

      if ( entityEntry.getStatus() == Status.DELETED ) {
        throw new AssertionFailure( "entity was deleted" );
      }

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

      Serializable requestedId = event.getRequestedId();

      Serializable savedId;
      if ( requestedId == null ) {
View Full Code Here

  public Object loadByUniqueKey(
      String entityName,
      String uniqueKeyPropertyName,
      Object key,
      SessionImplementor session) throws HibernateException {
    final SessionFactoryImplementor factory = session.getFactory();
    UniqueKeyLoadable persister = ( UniqueKeyLoadable ) factory.getEntityPersister( entityName );

    //TODO: implement caching?! proxies?!

    EntityUniqueKey euk = new EntityUniqueKey(
        entityName,
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

  public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
  throws HibernateException, SQLException {
    Object object = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() );
    final Type elementType = persister.getElementType();
    final SessionFactoryImplementor factory = persister.getFactory();
    String indexNode = getIndexAttributeName(persister);

    Element elem = element.addElement( persister.getElementNodeName() );
    elementType.setToXMLNode( elem, object, factory );
   
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.