1 package org.hibernate.engine; 3 4 import org.hibernate.persister.entity.Joinable; 5 import org.hibernate.persister.entity.OuterJoinLoadable; 6 import org.hibernate.persister.entity.PropertyMapping; 7 import org.hibernate.type.AssociationType; 8 import org.hibernate.util.ArrayHelper; 9 import org.hibernate.util.StringHelper; 10 11 14 public final class JoinHelper { 15 16 private JoinHelper() {} 17 18 22 public static String [] getAliasedLHSColumnNames( 23 AssociationType type, 24 String alias, 25 int property, 26 OuterJoinLoadable lhsPersister, 27 Mapping mapping 28 ) { 29 return getAliasedLHSColumnNames(type, alias, property, 0, lhsPersister, mapping); 30 } 31 32 36 public static String [] getLHSColumnNames( 37 AssociationType type, 38 int property, 39 OuterJoinLoadable lhsPersister, 40 Mapping mapping 41 ) { 42 return getLHSColumnNames(type, property, 0, lhsPersister, mapping); 43 } 44 45 49 public static String [] getAliasedLHSColumnNames( 50 AssociationType type, 51 String alias, 52 int property, 53 int begin, 54 OuterJoinLoadable lhsPersister, 55 Mapping mapping 56 ) { 57 if ( type.useLHSPrimaryKey() ) { 58 return StringHelper.qualify( alias, lhsPersister.getIdentifierColumnNames() ); 59 } 60 else { 61 String propertyName = type.getLHSPropertyName(); 62 if (propertyName==null) { 63 return ArrayHelper.slice( 64 lhsPersister.toColumns(alias, property), 65 begin, 66 type.getColumnSpan(mapping) 67 ); 68 } 69 else { 70 return ( (PropertyMapping) lhsPersister ).toColumns(alias, propertyName); } 72 } 73 } 74 75 79 public static String [] getLHSColumnNames( 80 AssociationType type, 81 int property, 82 int begin, 83 OuterJoinLoadable lhsPersister, 84 Mapping mapping 85 ) { 86 if ( type.useLHSPrimaryKey() ) { 87 return lhsPersister.getIdentifierColumnNames(); 89 } 90 else { 91 String propertyName = type.getLHSPropertyName(); 92 if (propertyName==null) { 93 return ArrayHelper.slice( 96 lhsPersister.getSubclassPropertyColumnNames(property), 97 begin, 98 type.getColumnSpan(mapping) 99 ); 100 } 101 else { 102 return lhsPersister.getPropertyColumnNames(propertyName); 105 } 106 } 107 } 108 109 public static String getLHSTableName( 110 AssociationType type, 111 int property, 112 OuterJoinLoadable lhsPersister 113 ) { 114 if ( type.useLHSPrimaryKey() ) { 115 return lhsPersister.getTableName(); 116 } 117 else { 118 String propertyName = type.getLHSPropertyName(); 119 if (propertyName==null) { 120 return lhsPersister.getSubclassPropertyTableName(property); 124 } 125 else { 126 String propertyRefTable = lhsPersister.getPropertyTableName(propertyName); 128 if (propertyRefTable==null) { 129 propertyRefTable = lhsPersister.getSubclassPropertyTableName(property); 137 } 138 return propertyRefTable; 139 } 140 } 141 } 142 143 147 public static String [] getRHSColumnNames(AssociationType type, SessionFactoryImplementor factory) { 148 String uniqueKeyPropertyName = type.getRHSUniqueKeyPropertyName(); 149 Joinable joinable = type.getAssociatedJoinable(factory); 150 if (uniqueKeyPropertyName==null) { 151 return joinable.getKeyColumnNames(); 152 } 153 else { 154 return ( (OuterJoinLoadable) joinable ).getPropertyColumnNames(uniqueKeyPropertyName); 155 } 156 } 157 } 158 | Popular Tags |