1 package org.hibernate.loader; 3 4 import java.util.Map ; 5 6 import org.hibernate.persister.collection.CollectionPersister; 7 import org.hibernate.util.CollectionHelper; 8 import org.hibernate.util.StringHelper; 9 10 15 public class GeneratedCollectionAliases implements CollectionAliases { 16 private final String suffix; 17 private final String [] keyAliases; 18 private final String [] indexAliases; 19 private final String [] elementAliases; 20 private final String identifierAlias; 21 private Map userProvidedAliases; 22 23 public GeneratedCollectionAliases(Map userProvidedAliases, CollectionPersister persister, String suffix) { 24 this.suffix = suffix; 25 this.userProvidedAliases = userProvidedAliases; 26 27 this.keyAliases = getUserProvidedAliases( 28 "key", 29 persister.getKeyColumnAliases( suffix ) 30 ); 31 32 this.indexAliases = getUserProvidedAliases( 33 "index", 34 persister.getIndexColumnAliases( suffix ) 35 ); 36 37 this.elementAliases = getUserProvidedAliases( "element", 38 persister.getElementColumnAliases( suffix ) 39 ); 40 41 this.identifierAlias = getUserProvidedAlias( "id", 42 persister.getIdentifierColumnAlias( suffix ) 43 ); 44 } 45 46 public GeneratedCollectionAliases(CollectionPersister persister, String string) { 47 this(CollectionHelper.EMPTY_MAP, persister, string); 48 } 49 50 56 public String [] getSuffixedKeyAliases() { 57 return keyAliases; 58 } 59 60 65 public String [] getSuffixedIndexAliases() { 66 return indexAliases; 67 } 68 69 74 public String [] getSuffixedElementAliases() { 75 return elementAliases; 76 } 77 78 83 public String getSuffixedIdentifierAlias() { 84 return identifierAlias; 85 } 86 87 92 public String getSuffix() { 93 return suffix; 94 } 95 96 public String toString() { 97 return super.toString() + " [suffix=" + suffix + 98 ", suffixedKeyAliases=[" + join( keyAliases ) + 99 "], suffixedIndexAliases=[" + join( indexAliases ) + 100 "], suffixedElementAliases=[" + join( elementAliases ) + 101 "], suffixedIdentifierAlias=[" + identifierAlias + "]]"; 102 } 103 104 private String join(String [] aliases) { 105 if ( aliases == null) return null; 106 107 return StringHelper.join( ", ", aliases ); 108 } 109 110 private String [] getUserProvidedAliases(String propertyPath, String [] defaultAliases) { 111 String [] result = (String []) userProvidedAliases.get(propertyPath); 112 if (result==null) { 113 return defaultAliases; 114 } 115 else { 116 return result; 117 } 118 } 119 120 private String getUserProvidedAlias(String propertyPath, String defaultAlias) { 121 String [] columns = (String []) userProvidedAliases.get(propertyPath); 122 if (columns==null) { 123 return defaultAlias; 124 } 125 else { 126 return columns[0]; 127 } 128 } 129 130 } 131 | Popular Tags |