BatchingEntityLoaderpublic class BatchingEntityLoader extends Object implements UniqueEntityLoader"Batch" loads entities, using multiple primary key values in the
SQL where clause. |
Fields Summary |
---|
private final org.hibernate.loader.Loader[] | loaders | private final int[] | batchSizes | private final org.hibernate.persister.entity.EntityPersister | persister | private final org.hibernate.type.Type | idType |
Methods Summary |
---|
public static UniqueEntityLoader | createBatchingEntityLoader(org.hibernate.persister.entity.OuterJoinLoadable persister, int maxBatchSize, org.hibernate.LockMode lockMode, org.hibernate.engine.SessionFactoryImplementor factory, java.util.Map enabledFilters)
if ( maxBatchSize>1 ) {
int[] batchSizesToCreate = ArrayHelper.getBatchSizes(maxBatchSize);
Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ];
for ( int i=0; i<batchSizesToCreate.length; i++ ) {
loadersToCreate[i] = new EntityLoader(persister, batchSizesToCreate[i], lockMode, factory, enabledFilters);
}
return new BatchingEntityLoader(persister, batchSizesToCreate, loadersToCreate);
}
else {
return new EntityLoader(persister, lockMode, factory, enabledFilters);
}
| private java.lang.Object | getObjectFromList(java.util.List results, java.io.Serializable id, org.hibernate.engine.SessionImplementor session)
// get the right object from the list ... would it be easier to just call getEntity() ??
Iterator iter = results.iterator();
while ( iter.hasNext() ) {
Object obj = iter.next();
final boolean equal = idType.isEqual(
id,
session.getContextEntityIdentifier(obj),
session.getEntityMode(),
session.getFactory()
);
if ( equal ) return obj;
}
return null;
| public java.lang.Object | load(java.io.Serializable id, java.lang.Object optionalObject, org.hibernate.engine.SessionImplementor session)
Serializable[] batch = session.getPersistenceContext()
.getBatchFetchQueue()
.getEntityBatch( persister, id, batchSizes[0], session.getEntityMode() );
for ( int i=0; i<batchSizes.length-1; i++) {
final int smallBatchSize = batchSizes[i];
if ( batch[smallBatchSize-1]!=null ) {
Serializable[] smallBatch = new Serializable[smallBatchSize];
System.arraycopy(batch, 0, smallBatch, 0, smallBatchSize);
final List results = loaders[i].loadEntityBatch(
session,
smallBatch,
idType,
optionalObject,
persister.getEntityName(),
id,
persister
);
return getObjectFromList(results, id, session); //EARLY EXIT
}
}
return ( (UniqueEntityLoader) loaders[batchSizes.length-1] ).load(id, optionalObject, session);
|
|