Package org.hibernate.engine

Examples of org.hibernate.engine.SessionImplementor


  Object processCollection(Object collection, CollectionType collectionType)
  throws HibernateException {

    if ( collection!=null && (collection instanceof PersistentCollection) ) {

      final SessionImplementor session = getSession();
      PersistentCollection coll = (PersistentCollection) collection;
      if ( coll.setCurrentSession(session) ) {
        reattachCollection( coll, collectionType );
      }
      return null;
View Full Code Here


  }

  final Object processArrayOrNewCollection(Object collection, CollectionType collectionType)
  throws HibernateException {

    final SessionImplementor session = getSession();

    if (collection==null) {
      //do nothing
      return null;
    }
    else {
      CollectionPersister persister = session.getFactory().getCollectionPersister( collectionType.getRole() );

      final PersistenceContext persistenceContext = session.getPersistenceContext();
      //TODO: move into collection type, so we can use polymorphism!
      if ( collectionType.hasHolder( session.getEntityMode() ) ) {
       
        if (collection==CollectionType.UNFETCHED_COLLECTION) return null;

        PersistentCollection ah = persistenceContext.getCollectionHolder(collection);
        if (ah==null) {
View Full Code Here

   * @param event The create event to be handled.
   * @throws HibernateException
   */
  public void onPersist(PersistEvent event, Map createCache) throws HibernateException {
     
    final SessionImplementor source = event.getSession();
    final Object object = event.getObject();
   
    final Object entity;
    if (object instanceof HibernateProxy) {
      LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
      if ( li.isUninitialized() ) {
        if ( li.getSession()==source ) {
          return; //NOTE EARLY EXIT!
        }
        else {
          throw new PersistentObjectException("uninitialized proxy passed to persist()");
        }
      }
      entity = li.getImplementation();
    }
    else {
      entity = object;
    }
   
    int entityState = getEntityState(
        entity,
        event.getEntityName(),
        source.getPersistenceContext().getEntry(entity),
        source
      );
   
    switch (entityState) {
      case DETACHED:
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() ) {
      if ( log.isTraceEnabled() ) {
        log.trace(
            "initializing collection " +
            MessageHelper.collectionInfoString( ce.getLoadedPersister(), ce.getLoadedKey(), source.getFactory() )
          );
      }

      log.trace("checking second-level cache");
      final boolean foundInCache = initializeCollectionFromCache(
          ce.getLoadedKey(),
          ce.getLoadedPersister(),
          collection,
          source
        );

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

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

  Object processCollection(Object collection, CollectionType type)
    throws HibernateException {

    if (collection!=null) {

      SessionImplementor session = getSession();

      final PersistentCollection persistentCollection;
      if ( type.isArrayType() ) {
         persistentCollection = session.getPersistenceContext().getCollectionHolder(collection);
        // if no array holder we found an unwrappered array (this can't occur,
        // because we now always call wrap() before getting to here)
        // return (ah==null) ? true : searchForDirtyCollections(ah, type);
      }
      else {
View Full Code Here

    super( session, key, owner );
  }

  Object processCollection(Object collection, CollectionType type) throws HibernateException {

    SessionImplementor session = getSession();
    CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );

    if ( collection == null ) {
      //do nothing
    }
    else if ( collection instanceof PersistentCollection ) {
View Full Code Here

    if ( event.getLockMode() == LockMode.WRITE ) {
      throw new HibernateException( "Invalid lock mode for lock()" );
    }

    SessionImplementor source = event.getSession();
   
    Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
    //TODO: if object was an uninitialized proxy, this is inefficient,
    //      resulting in two SQL selects
   
    EntityEntry entry = source.getPersistenceContext().getEntry(entity);
    if (entry==null) {
      final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
      final Serializable id = persister.getIdentifier( entity, source.getEntityMode() );
      if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) {
        throw new TransientObjectException(
            "cannot lock an unsaved transient instance: " +
            persister.getEntityName()
        );
View Full Code Here

   * Handle the given update event.
   *
   * @param event The update event to be handled.
   */
  public void onSaveOrUpdate(SaveOrUpdateEvent event) {
    final SessionImplementor source = event.getSession();
    final Object object = event.getObject();
    final Serializable requestedId = event.getRequestedId();

    if ( requestedId != null ) {
      //assign the requested id to the proxy, *before*
      //reassociating the proxy
      if ( object instanceof HibernateProxy ) {
        ( ( HibernateProxy ) object ).getHibernateLazyInitializer().setIdentifier( requestedId );
      }
    }

    if ( reassociateIfUninitializedProxy( object, source ) ) {
      log.trace( "reassociated uninitialized proxy" );
      // an uninitialized proxy, noop, don't even need to
      // return an id, since it is never a save()
    }
    else {
      //initialize properties of the event:
      final Object entity = source.getPersistenceContext().unproxyAndReassociate( object );
      event.setEntity( entity );
      event.setEntry( source.getPersistenceContext().getEntry( entity ) );
      //return the id in the event object
      event.setResultId( performSaveOrUpdate( event ) );
    }

  }
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()
        );
    }

    if ( persister.getIdentifierType().isComponentType() && EntityMode.DOM4J == event.getSession().getEntityMode() ) {
      // skip this check for composite-ids relating to dom4j entity-mode;
      // alternatively, we could add a check to make sure the incoming id value is
      // an instance of Element...
    }
    else {
      Class idClass = persister.getIdentifierType().getReturnedClass();
      if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
        throw new TypeMismatchException(
            "Provided id of the wrong type for class " + persister.getEntityName() + ". Expected: " + idClass + ", got " + event.getEntityId().getClass()
        );
      }
    }

    EntityKey keyToLoad = new EntityKey( event.getEntityId(), persister, source.getEntityMode()  );

    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.getLockMode(),
        source
    );

    if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) {
      source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() );
    }

    return entity;
  }
View Full Code Here

TOP

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