Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.SessionImplementor


    return intercepted;
  }

  protected boolean handleInterception(FlushEntityEvent event) {
    SessionImplementor session = event.getSession();
    EntityEntry entry = event.getEntityEntry();
    EntityPersister persister = entry.getPersister();
    Object entity = event.getEntity();

    //give the Interceptor a chance to modify property values
View Full Code Here


   */
  protected void dirtyCheck(final FlushEntityEvent event) throws HibernateException {

    final Object entity = event.getEntity();
    final Object[] values = event.getPropertyValues();
    final SessionImplementor session = event.getSession();
    final EntityEntry entry = event.getEntityEntry();
    final EntityPersister persister = entry.getPersister();
    final Serializable id = entry.getId();
    final Object[] loadedState = entry.getLoadedState();

    int[] dirtyProperties = session.getInterceptor().findDirty(
        entity,
        id,
        values,
        loadedState,
        persister.getPropertyNames(),
        persister.getPropertyTypes()
    );

    if ( dirtyProperties == null ) {
      // see if the custom dirtiness strategy can tell us...
      class DirtyCheckContextImpl implements CustomEntityDirtinessStrategy.DirtyCheckContext {
        int[] found = null;
        @Override
        public void doDirtyChecking(CustomEntityDirtinessStrategy.AttributeChecker attributeChecker) {
          found = new DirtyCheckAttributeInfoImpl( event ).visitAttributes( attributeChecker );
          if ( found != null && found.length == 0 ) {
            found = null;
          }
        }
      }
      DirtyCheckContextImpl context = new DirtyCheckContextImpl();
      session.getFactory().getCustomEntityDirtinessStrategy().findDirty(
          entity,
          persister,
          (Session) session,
          context
      );
View Full Code Here

   * @param event The load event to be handled.
   * @throws HibernateException
   */
  public void onLoad(LoadEvent event, LoadEventListener.LoadType loadType) throws HibernateException {

    final SessionImplementor source = event.getSession();

    EntityPersister persister;
    if ( event.getInstanceToLoad() != null ) {
      persister = source.getEntityPersister( null, event.getInstanceToLoad() ); //the load() which takes an entity does not pass an entityName
      event.setEntityClassName( event.getInstanceToLoad().getClass().getName() );
    }
    else {
      persister = source.getFactory().getEntityPersister( event.getEntityClassName() );
    }

    if ( persister == null ) {
      throw new HibernateException(
          "Unable to locate persister: " +
          event.getEntityClassName()
        );
    }

    final Class idClass = persister.getIdentifierType().getReturnedClass();
    if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
      // we may have the kooky jpa requirement of allowing find-by-id where
      // "id" is the "simple pk value" of a dependent objects parent.  This
      // is part of its generally goofy "derived identity" "feature"
      if ( persister.getEntityMetamodel().getIdentifierProperty().isEmbedded() ) {
        final EmbeddedComponentType dependentIdType =
            (EmbeddedComponentType) persister.getEntityMetamodel().getIdentifierProperty().getType();
        if ( dependentIdType.getSubtypes().length == 1 ) {
          final Type singleSubType = dependentIdType.getSubtypes()[0];
          if ( singleSubType.isEntityType() ) {
            final EntityType dependentParentType = (EntityType) singleSubType;
            final Type dependentParentIdType = dependentParentType.getIdentifierOrUniqueKeyType( source.getFactory() );
            if ( dependentParentIdType.getReturnedClass().isInstance( event.getEntityId() ) ) {
              // yep that's what we have...
              loadByDerivedIdentitySimplePkValue(
                  event,
                  loadType,
                  persister,
                  dependentIdType,
                  source.getFactory().getEntityPersister( dependentParentType.getAssociatedEntityName() )
              );
              return;
            }
          }
        }
      }
      throw new TypeMismatchException(
          "Provided id of the wrong type for class " + persister.getEntityName() + ". Expected: " + idClass + ", got " + event.getEntityId().getClass()
      );
    }

    final  EntityKey keyToLoad = source.generateEntityKey( event.getEntityId(), persister );

    try {
      if ( loadType.isNakedEntityReturned() ) {
        //do not return a proxy!
        //(this option indicates we are initializing a proxy)
View Full Code Here

  protected Object loadFromDatasource(
      final LoadEvent event,
      final EntityPersister persister,
      final EntityKey keyToLoad,
      final LoadEventListener.LoadType options) {
    final SessionImplementor source = event.getSession();
    Object entity = persister.load(
        event.getEntityId(),
        event.getInstanceToLoad(),
        event.getLockOptions(),
        source
    );
   
    if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) {
      source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() );
    }

    return entity;
  }
View Full Code Here

  protected Object loadFromSessionCache(
      final LoadEvent event,
      final EntityKey keyToLoad,
      final LoadEventListener.LoadType options) throws HibernateException {

    SessionImplementor session = event.getSession();
    Object old = session.getEntityUsingInterceptor( keyToLoad );

    if ( old != null ) {
      // this object was already loaded
      EntityEntry oldEntry = session.getPersistenceContext().getEntry( old );
      if ( options.isCheckDeleted() ) {
        Status status = oldEntry.getStatus();
        if ( status == Status.DELETED || status == Status.GONE ) {
          return REMOVED_ENTITY_MARKER;
        }
View Full Code Here

  protected Object loadFromSecondLevelCache(
      final LoadEvent event,
      final EntityPersister persister,
      final LoadEventListener.LoadType options) {

    final SessionImplementor source = event.getSession();
    final boolean useCache = persister.hasCache()
        && source.getCacheMode().isGetEnabled()
        && event.getLockMode().lessThan(LockMode.READ);

    if ( ! useCache ) {
      // we can't use cache here
      return null;
    }

    final SessionFactoryImplementor factory = source.getFactory();
    final CacheKey ck = source.generateCacheKey(
        event.getEntityId(),
        persister.getIdentifierType(),
        persister.getRootEntityName()
    );

    Object ce = persister.getCacheAccessStrategy().get( ck, source.getTimestamp() );

    if ( factory.getStatistics().isStatisticsEnabled() ) {
      if ( ce == null ) {
        factory.getStatisticsImplementor().secondLevelCacheMiss(
            persister.getCacheAccessStrategy().getRegion().getName()
View Full Code Here

   */
  public void onInitializeCollection(InitializeCollectionEvent event)
  throws HibernateException {

    PersistentCollection collection = event.getCollection();
    SessionImplementor source = event.getSession();

    CollectionEntry ce = source.getPersistenceContext().getCollectionEntry(collection);
    if (ce==null) throw new HibernateException("collection was evicted");
    if ( !collection.wasInitialized() ) {
      final boolean traceEnabled = LOG.isTraceEnabled();
      if ( traceEnabled ) {
        LOG.tracev( "Initializing collection {0}",
            MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), source ) );
        LOG.trace( "Checking second-level cache" );
      }

      final boolean foundInCache = initializeCollectionFromCache(
          ce.getLoadedKey(),
          ce.getLoadedPersister(),
          collection,
          source
        );

      if ( foundInCache ) {
        if ( traceEnabled ) {
          LOG.trace( "Collection initialized from cache" );
        }
      }
      else {
        if ( traceEnabled ) {
          LOG.trace( "Collection not cached" );
        }
        ce.getLoadedPersister().initialize( ce.getLoadedKey(), source );
        if ( traceEnabled ) {
          LOG.trace( "Collection initialized" );
        }

        if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
          source.getFactory().getStatisticsImplementor().fetchCollection(
              ce.getLoadedPersister().getRole()
            );
        }
      }
    }
View Full Code Here

    }
  }

  protected void resultClassChecking(Class resultClass, org.hibernate.Query hqlQuery) {
    // make sure the query is a select -> HHH-7192
    final SessionImplementor session = unwrap( SessionImplementor.class );
    final HQLQueryPlan queryPlan = session.getFactory().getQueryPlanCache().getHQLQueryPlan(
        hqlQuery.getQueryString(),
        false,
        session.getLoadQueryInfluencers().getEnabledFilters()
    );
    if ( queryPlan.getTranslators()[0].isManipulationStatement() ) {
      throw new IllegalArgumentException( "Update/delete queries cannot be typed" );
    }
View Full Code Here

  @Override
  public boolean isJoinedToTransaction() {
    checkOpen();

    final SessionImplementor session = (SessionImplementor) internalGetSession();
    final TransactionCoordinator transactionCoordinator = session.getTransactionCoordinator();
    final TransactionImplementor transaction = transactionCoordinator.getTransaction();

    return isOpen() && transaction.getJoinStatus() == JoinStatus.JOINED;
  }
View Full Code Here

          LOG.callingJoinTransactionOnNonJtaEntityManager();
      }
      return;
    }

    final SessionImplementor session = (SessionImplementor) internalGetSession();
    final TransactionCoordinator transactionCoordinator = session.getTransactionCoordinator();
    final TransactionImplementor transaction = transactionCoordinator.getTransaction();

    transaction.markForJoin();
    transactionCoordinator.pulse();
View Full Code Here

TOP

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

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.