Save This Page
Home » hibernate-distribution-3.3.1.GA-dist » org.hibernate » loader » entity » [javadoc | source]
    1   /*
    2    * Hibernate, Relational Persistence for Idiomatic Java
    3    *
    4    * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
    5    * indicated by the @author tags or express copyright attribution
    6    * statements applied by the authors.  All third-party contributions are
    7    * distributed under license by Red Hat Middleware LLC.
    8    *
    9    * This copyrighted material is made available to anyone wishing to use, modify,
   10    * copy, or redistribute it subject to the terms and conditions of the GNU
   11    * Lesser General Public License, as published by the Free Software Foundation.
   12    *
   13    * This program is distributed in the hope that it will be useful,
   14    * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15    * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
   16    * for more details.
   17    *
   18    * You should have received a copy of the GNU Lesser General Public License
   19    * along with this distribution; if not, write to:
   20    * Free Software Foundation, Inc.
   21    * 51 Franklin Street, Fifth Floor
   22    * Boston, MA  02110-1301  USA
   23    *
   24    */
   25   package org.hibernate.loader.entity;
   26   
   27   import java.util.Map;
   28   
   29   import org.hibernate.HibernateException;
   30   import org.hibernate.LockMode;
   31   import org.hibernate.MappingException;
   32   import org.hibernate.engine.SessionFactoryImplementor;
   33   import org.hibernate.engine.SessionImplementor;
   34   import org.hibernate.loader.JoinWalker;
   35   import org.hibernate.persister.entity.OuterJoinLoadable;
   36   import org.hibernate.type.Type;
   37   
   38   /**
   39    * Loads an entity instance using outerjoin fetching to fetch associated entities.
   40    * <br>
   41    * The <tt>EntityPersister</tt> must implement <tt>Loadable</tt>. For other entities,
   42    * create a customized subclass of <tt>Loader</tt>.
   43    *
   44    * @author Gavin King
   45    */
   46   public class EntityLoader extends AbstractEntityLoader {
   47   	
   48   	private final boolean batchLoader;
   49   	
   50   	public EntityLoader(
   51   			OuterJoinLoadable persister, 
   52   			LockMode lockMode,
   53   			SessionFactoryImplementor factory, 
   54   			Map enabledFilters) 
   55   	throws MappingException {
   56   		this(persister, 1, lockMode, factory, enabledFilters);
   57   	}
   58   	
   59   	public EntityLoader(
   60   			OuterJoinLoadable persister, 
   61   			int batchSize, 
   62   			LockMode lockMode,
   63   			SessionFactoryImplementor factory, 
   64   			Map enabledFilters) 
   65   	throws MappingException {
   66   		this( 
   67   				persister, 
   68   				persister.getIdentifierColumnNames(), 
   69   				persister.getIdentifierType(), 
   70   				batchSize,
   71   				lockMode,
   72   				factory, 
   73   				enabledFilters 
   74   			);
   75   	}
   76   
   77   	public EntityLoader(
   78   			OuterJoinLoadable persister, 
   79   			String[] uniqueKey, 
   80   			Type uniqueKeyType, 
   81   			int batchSize, 
   82   			LockMode lockMode,
   83   			SessionFactoryImplementor factory, 
   84   			Map enabledFilters) 
   85   	throws MappingException {
   86   		super(persister, uniqueKeyType, factory, enabledFilters);
   87   
   88   		JoinWalker walker = new EntityJoinWalker(
   89   				persister, 
   90   				uniqueKey, 
   91   				batchSize, 
   92   				lockMode, 
   93   				factory, 
   94   				enabledFilters
   95   			);
   96   		initFromWalker( walker );
   97   
   98   		postInstantiate();
   99   
  100   		batchLoader = batchSize > 1;
  101   		
  102   		log.debug( "Static select for entity " + entityName + ": " + getSQLString() );
  103   
  104   	}
  105   
  106   	public Object loadByUniqueKey(SessionImplementor session, Object key) 
  107   	throws HibernateException {
  108   		return load(session, key, null, null);
  109   	}
  110   
  111   	protected boolean isSingleRowLoader() {
  112   		return !batchLoader;
  113   	}
  114   	
  115   }

Save This Page
Home » hibernate-distribution-3.3.1.GA-dist » org.hibernate » loader » entity » [javadoc | source]