1 package org.hibernate.loader; 2 3 import java.util.Map ; 4 5 import org.hibernate.persister.entity.Loadable; 6 import org.hibernate.util.CollectionHelper; 7 8 15 public class DefaultEntityAliases implements EntityAliases { 16 17 private final String [] suffixedKeyColumns; 18 private final String [] suffixedVersionColumn; 19 private final String [][] suffixedPropertyColumns; 20 private final String suffixedDiscriminatorColumn; 21 private final String suffix; 22 private final String rowIdAlias; 23 private final Map userProvidedAliases; 24 25 public DefaultEntityAliases(Loadable persister, String suffix) { 26 this(CollectionHelper.EMPTY_MAP, persister, suffix); 27 } 28 29 33 public DefaultEntityAliases(Map userProvidedAliases, Loadable persister, String suffix) { 34 this.suffix = suffix; 35 this.userProvidedAliases = userProvidedAliases; 36 37 String [] keyColumnsCandidates = getUserProvidedAliases( 38 persister.getIdentifierPropertyName(), 39 (String []) null 40 ); 41 if (keyColumnsCandidates==null) { 42 suffixedKeyColumns = getUserProvidedAliases( 43 "id", 44 getIdentifierAliases(persister, suffix) 45 ); 46 } 47 else { 48 suffixedKeyColumns = keyColumnsCandidates; 49 } 50 intern(suffixedKeyColumns); 51 52 suffixedPropertyColumns = getSuffixedPropertyAliases(persister); 53 suffixedDiscriminatorColumn = getUserProvidedAlias( 54 "class", 55 getDiscriminatorAlias(persister, suffix) 56 ); 57 if ( persister.isVersioned() ) { 58 suffixedVersionColumn = suffixedPropertyColumns[ persister.getVersionProperty() ]; 59 } 60 else { 61 suffixedVersionColumn = null; 62 } 63 rowIdAlias = Loadable.ROWID_ALIAS + suffix; } 65 66 protected String getDiscriminatorAlias(Loadable persister, String suffix) { 67 return persister.getDiscriminatorAlias(suffix); 68 } 69 70 protected String [] getIdentifierAliases(Loadable persister, String suffix) { 71 return persister.getIdentifierAliases(suffix); 72 } 73 74 protected String [] getPropertyAliases(Loadable persister, int j) { 75 return persister.getPropertyAliases(suffix, j); 76 } 77 78 private String [] getUserProvidedAliases(String propertyPath, String [] defaultAliases) { 79 String [] result = (String []) userProvidedAliases.get(propertyPath); 80 if (result==null) { 81 return defaultAliases; 82 } 83 else { 84 return result; 85 } 86 } 87 88 private String getUserProvidedAlias(String propertyPath, String defaultAlias) { 89 String [] columns = (String []) userProvidedAliases.get(propertyPath); 90 if (columns==null) { 91 return defaultAlias; 92 } 93 else { 94 return columns[0]; 95 } 96 } 97 98 public String [][] getSuffixedPropertyAliases(Loadable persister) { 99 int size = persister.getPropertyNames().length; 100 String [][] suffixedPropertyAliases = new String [size][]; 101 for ( int j = 0; j < size; j++ ) { 102 suffixedPropertyAliases[j] = getUserProvidedAliases( 103 persister.getPropertyNames()[j], 104 getPropertyAliases(persister, j) 105 ); 106 intern( suffixedPropertyAliases[j] ); 107 } 108 return suffixedPropertyAliases; 109 } 110 111 public String [] getSuffixedVersionAliases() { 112 return suffixedVersionColumn; 113 } 114 115 public String [][] getSuffixedPropertyAliases() { 116 return suffixedPropertyColumns; 117 } 118 119 public String getSuffixedDiscriminatorAlias() { 120 return suffixedDiscriminatorColumn; 121 } 122 123 public String [] getSuffixedKeyAliases() { 124 return suffixedKeyColumns; 125 } 126 127 public String getRowIdAlias() { 128 return rowIdAlias; 129 } 130 131 private static void intern(String [] strings) { 132 for (int i=0; i<strings.length; i++ ) { 133 strings[i] = strings[i].intern(); 134 } 135 } 136 137 } 138 | Popular Tags |