HHH-7869 simple improvement, using generic
This commit is contained in:
parent
8850c1fa91
commit
ba2dc24c42
|
@ -309,24 +309,20 @@ public class HQLQueryPlan implements Serializable {
|
|||
);
|
||||
}
|
||||
|
||||
Iterator itr = recognizer.getNamedParameterDescriptionMap().entrySet().iterator();
|
||||
Map<String, NamedParameterDescriptor> namedParamDescriptorMap = new HashMap<String, NamedParameterDescriptor>();
|
||||
while( itr.hasNext() ) {
|
||||
final Map.Entry entry = ( Map.Entry ) itr.next();
|
||||
final String name = ( String ) entry.getKey();
|
||||
final ParamLocationRecognizer.NamedParameterDescription description =
|
||||
( ParamLocationRecognizer.NamedParameterDescription ) entry.getValue();
|
||||
Map<String, ParamLocationRecognizer.NamedParameterDescription> map = recognizer.getNamedParameterDescriptionMap();
|
||||
for ( final String name : map.keySet() ) {
|
||||
final ParamLocationRecognizer.NamedParameterDescription description = map.get( name );
|
||||
namedParamDescriptorMap.put(
|
||||
name,
|
||||
new NamedParameterDescriptor(
|
||||
name,
|
||||
parameterTranslations.getNamedParameterExpectedType( name ),
|
||||
description.buildPositionsArray(),
|
||||
description.isJpaStyle()
|
||||
parameterTranslations.getNamedParameterExpectedType( name ),
|
||||
description.buildPositionsArray(),
|
||||
description.isJpaStyle()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return new ParameterMetadata( ordinalParamDescriptors, namedParamDescriptorMap );
|
||||
}
|
||||
public QueryTranslator[] getTranslators() {
|
||||
|
|
|
@ -41,7 +41,7 @@ public class ParamLocationRecognizer implements ParameterParser.Recognizer {
|
|||
|
||||
public static class NamedParameterDescription {
|
||||
private final boolean jpaStyle;
|
||||
private final List positions = new ArrayList();
|
||||
private final List<Integer> positions = new ArrayList<Integer>();
|
||||
|
||||
public NamedParameterDescription(boolean jpaStyle) {
|
||||
this.jpaStyle = jpaStyle;
|
||||
|
@ -60,8 +60,8 @@ public class ParamLocationRecognizer implements ParameterParser.Recognizer {
|
|||
}
|
||||
}
|
||||
|
||||
private Map namedParameterDescriptions = new HashMap();
|
||||
private List ordinalParameterLocationList = new ArrayList();
|
||||
private Map<String, NamedParameterDescription> namedParameterDescriptions = new HashMap<String, NamedParameterDescription>();
|
||||
private List<Integer> ordinalParameterLocationList = new ArrayList<Integer>();
|
||||
|
||||
/**
|
||||
* Convenience method for creating a param location recognizer and
|
||||
|
@ -82,7 +82,7 @@ public class ParamLocationRecognizer implements ParameterParser.Recognizer {
|
|||
*
|
||||
* @return The map of named parameter locations.
|
||||
*/
|
||||
public Map getNamedParameterDescriptionMap() {
|
||||
public Map<String, NamedParameterDescription> getNamedParameterDescriptionMap() {
|
||||
return namedParameterDescriptions;
|
||||
}
|
||||
|
||||
|
@ -94,38 +94,38 @@ public class ParamLocationRecognizer implements ParameterParser.Recognizer {
|
|||
*
|
||||
* @return The list of ordinal parameter locations.
|
||||
*/
|
||||
public List getOrdinalParameterLocationList() {
|
||||
public List<Integer> getOrdinalParameterLocationList() {
|
||||
return ordinalParameterLocationList;
|
||||
}
|
||||
|
||||
|
||||
// Recognition code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@Override
|
||||
public void ordinalParameter(int position) {
|
||||
ordinalParameterLocationList.add( position );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void namedParameter(String name, int position) {
|
||||
getOrBuildNamedParameterDescription( name, false ).add( position );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jpaPositionalParameter(String name, int position) {
|
||||
getOrBuildNamedParameterDescription( name, true ).add( position );
|
||||
}
|
||||
|
||||
private NamedParameterDescription getOrBuildNamedParameterDescription(String name, boolean jpa) {
|
||||
NamedParameterDescription desc = ( NamedParameterDescription ) namedParameterDescriptions.get( name );
|
||||
NamedParameterDescription desc = namedParameterDescriptions.get( name );
|
||||
if ( desc == null ) {
|
||||
desc = new NamedParameterDescription( jpa );
|
||||
namedParameterDescriptions.put( name, desc );
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void other(char character) {
|
||||
// don't care...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void outParameter(int position) {
|
||||
// don't care...
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class ParameterParser {
|
|||
else {
|
||||
if ( c == ':' ) {
|
||||
// named parameter
|
||||
int right = StringHelper.firstIndexOfChar( sqlString, ParserHelper.HQL_SEPARATORS, indx + 1 );
|
||||
int right = StringHelper.firstIndexOfChar( sqlString, ParserHelper.HQL_SEPARATORS_BITSET, indx + 1 );
|
||||
int chopLocation = right < 0 ? sqlString.length() : right;
|
||||
String param = sqlString.substring( indx + 1, chopLocation );
|
||||
if ( StringHelper.isEmpty( param ) ) {
|
||||
|
|
|
@ -139,23 +139,23 @@ public class QueryPlanCache implements Serializable {
|
|||
final int size = recognizer.getOrdinalParameterLocationList().size();
|
||||
OrdinalParameterDescriptor[] ordinalDescriptors = new OrdinalParameterDescriptor[ size ];
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
final Integer position = ( Integer ) recognizer.getOrdinalParameterLocationList().get( i );
|
||||
final Integer position = recognizer.getOrdinalParameterLocationList().get( i );
|
||||
ordinalDescriptors[i] = new OrdinalParameterDescriptor( i, null, position );
|
||||
}
|
||||
|
||||
Iterator itr = recognizer.getNamedParameterDescriptionMap().entrySet().iterator();
|
||||
Map<String,NamedParameterDescriptor> namedParamDescriptorMap = new HashMap<String,NamedParameterDescriptor>();
|
||||
while( itr.hasNext() ) {
|
||||
final Map.Entry entry = ( Map.Entry ) itr.next();
|
||||
final String name = ( String ) entry.getKey();
|
||||
final ParamLocationRecognizer.NamedParameterDescription description =
|
||||
( ParamLocationRecognizer.NamedParameterDescription ) entry.getValue();
|
||||
Map<String, NamedParameterDescriptor> namedParamDescriptorMap = new HashMap<String, NamedParameterDescriptor>();
|
||||
Map<String, ParamLocationRecognizer.NamedParameterDescription> map = recognizer.getNamedParameterDescriptionMap();
|
||||
for ( final String name : map.keySet() ) {
|
||||
final ParamLocationRecognizer.NamedParameterDescription description = map.get( name );
|
||||
namedParamDescriptorMap.put(
|
||||
name ,
|
||||
new NamedParameterDescriptor( name, null, description.buildPositionsArray(), description.isJpaStyle() )
|
||||
name,
|
||||
new NamedParameterDescriptor(
|
||||
name,
|
||||
null,
|
||||
description.buildPositionsArray(),
|
||||
description.isJpaStyle()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return new ParameterMetadata( ordinalDescriptors, namedParamDescriptorMap );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue