1 package org.hibernate.loader; 3 4 import org.hibernate.engine.SessionFactoryImplementor; 5 import org.hibernate.persister.entity.Loadable; 6 import org.hibernate.persister.collection.CollectionPersister; 7 8 15 public abstract class BasicLoader extends Loader { 16 17 protected static final String [] NO_SUFFIX = {""}; 18 19 private EntityAliases[] descriptors; 20 private CollectionAliases[] collectionDescriptors; 21 22 public BasicLoader(SessionFactoryImplementor factory) { 23 super(factory); 24 } 25 26 protected final EntityAliases[] getEntityAliases() { 27 return descriptors; 28 } 29 30 protected final CollectionAliases[] getCollectionAliases() { 31 return collectionDescriptors; 32 } 33 34 protected abstract String [] getSuffixes(); 35 protected abstract String [] getCollectionSuffixes(); 36 37 protected void postInstantiate() { 38 Loadable[] persisters = getEntityPersisters(); 39 String [] suffixes = getSuffixes(); 40 descriptors = new EntityAliases[persisters.length]; 41 for ( int i=0; i<descriptors.length; i++ ) { 42 descriptors[i] = new DefaultEntityAliases( persisters[i], suffixes[i] ); 43 } 44 45 CollectionPersister[] collectionPersisters = getCollectionPersisters(); 46 if ( collectionPersisters != null ) { 47 String [] collectionSuffixes = getCollectionSuffixes(); 48 collectionDescriptors = new CollectionAliases[collectionPersisters.length]; 49 for ( int i = 0; i < collectionPersisters.length; i++ ) { 50 collectionDescriptors[i] = new GeneratedCollectionAliases( collectionPersisters[i], collectionSuffixes[i] ); 51 } 52 } 53 else { 54 collectionDescriptors = null; 55 } 56 } 57 58 63 public static String [] generateSuffixes(int length) { 64 return generateSuffixes( 0, length ); 65 } 66 67 public static String [] generateSuffixes(int seed, int length) { 68 if ( length == 0 ) return NO_SUFFIX; 69 70 String [] suffixes = new String [length]; 71 for ( int i = 0; i < length; i++ ) { 72 suffixes[i] = Integer.toString( i + seed ) + "_"; 73 } 74 return suffixes; 75 } 76 77 } 78 | Popular Tags |