From 681528b7cc86b34fb02b2f8c2e21fa6b2939ee85 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Mon, 17 Dec 2012 14:09:14 +0800 Subject: [PATCH] HHH-7869 simple improvement, using generic --- .../engine/query/spi/HQLQueryPlan.java | 16 +++++-------- .../query/spi/ParamLocationRecognizer.java | 22 ++++++++--------- .../engine/query/spi/ParameterParser.java | 2 +- .../engine/query/spi/QueryPlanCache.java | 24 +++++++++---------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java index b2bcc272d8..6d229c65c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java @@ -309,24 +309,20 @@ public class HQLQueryPlan implements Serializable { ); } - Iterator itr = recognizer.getNamedParameterDescriptionMap().entrySet().iterator(); Map namedParamDescriptorMap = new HashMap(); - 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 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() { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParamLocationRecognizer.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParamLocationRecognizer.java index f86deb2d68..8daab1a104 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParamLocationRecognizer.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParamLocationRecognizer.java @@ -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 positions = new ArrayList(); 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 namedParameterDescriptions = new HashMap(); + private List ordinalParameterLocationList = new ArrayList(); /** * 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 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 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... } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java index 1c6b94babe..b41402d561 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java @@ -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 ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/QueryPlanCache.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/QueryPlanCache.java index 0cf7f84d1c..d7574e2a85 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/QueryPlanCache.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/QueryPlanCache.java @@ -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 namedParamDescriptorMap = new HashMap(); - 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 namedParamDescriptorMap = new HashMap(); + Map 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 ); }