Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HHH-7869 simple improvement, using generic

  • Loading branch information...
commit ba2dc24c42926603379c2d57418467406743a55a 1 parent 8850c1f
@stliu stliu authored
View
16 hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java
@@ -309,24 +309,20 @@ private ParameterMetadata buildParameterMetadata(ParameterTranslations parameter
);
}
- 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() {
View
22 hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParamLocationRecognizer.java
@@ -41,7 +41,7 @@
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 @@ private void add(int position) {
}
}
- 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 static ParamLocationRecognizer parseLocations(String query) {
*
* @return The map of named parameter locations.
*/
- public Map getNamedParameterDescriptionMap() {
+ public Map<String, NamedParameterDescription> getNamedParameterDescriptionMap() {
return namedParameterDescriptions;
}
@@ -94,38 +94,38 @@ public Map getNamedParameterDescriptionMap() {
*
* @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...
}
View
2  hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java
@@ -88,7 +88,7 @@ else if ( '\\' == c ) {
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 ) ) {
View
24 hibernate-core/src/main/java/org/hibernate/engine/query/spi/QueryPlanCache.java
@@ -139,23 +139,23 @@ private ParameterMetadata buildParameterMetadata(String query){
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 );
}
Please sign in to comment.
Something went wrong with that request. Please try again.