SimpleProjection should reuse commonly generated Strings
This commit is contained in:
parent
f9ab0eb6ae
commit
10df95bbcd
|
@ -34,10 +34,34 @@ import org.hibernate.type.Type;
|
|||
*/
|
||||
public abstract class SimpleProjection implements EnhancedProjection {
|
||||
|
||||
private static final int NUM_REUSABLE_ALIASES = 40;
|
||||
private static final String[] reusableAliases = initializeReusableAliases();
|
||||
|
||||
public Projection as(String alias) {
|
||||
return Projections.alias(this, alias);
|
||||
}
|
||||
|
||||
private static String[] initializeReusableAliases() {
|
||||
String[] aliases = new String[NUM_REUSABLE_ALIASES];
|
||||
for ( int i = 0; i < NUM_REUSABLE_ALIASES; i++ ) {
|
||||
aliases[i] = aliasForLocation( i );
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
|
||||
private static String aliasForLocation(final int loc) {
|
||||
return "y" + loc + "_";
|
||||
}
|
||||
|
||||
private static String getAliasForLocation(final int loc) {
|
||||
if ( loc >= NUM_REUSABLE_ALIASES ) {
|
||||
return aliasForLocation( loc );
|
||||
}
|
||||
else {
|
||||
return reusableAliases[loc];
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getColumnAliases(String alias, int loc) {
|
||||
return null;
|
||||
}
|
||||
|
@ -52,7 +76,7 @@ public abstract class SimpleProjection implements EnhancedProjection {
|
|||
}
|
||||
|
||||
public String[] getColumnAliases(int loc) {
|
||||
return new String[] { "y" + loc + "_" };
|
||||
return new String[] { getAliasForLocation( loc ) };
|
||||
}
|
||||
|
||||
public int getColumnCount(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
|
@ -68,7 +92,7 @@ public abstract class SimpleProjection implements EnhancedProjection {
|
|||
int numColumns = getColumnCount( criteria, criteriaQuery );
|
||||
String[] aliases = new String[ numColumns ];
|
||||
for (int i = 0; i < numColumns; i++) {
|
||||
aliases[i] = "y" + loc + "_";
|
||||
aliases[i] = getAliasForLocation( loc );
|
||||
loc++;
|
||||
}
|
||||
return aliases;
|
||||
|
|
Loading…
Reference in New Issue