Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 6 files changed
  • 0 comments
  • 1 contributor
16  hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java
@@ -309,24 +309,20 @@ private ParameterMetadata buildParameterMetadata(ParameterTranslations parameter
309 309
 			);
310 310
 		}
311 311
 
312  
-		Iterator itr = recognizer.getNamedParameterDescriptionMap().entrySet().iterator();
313 312
 		Map<String, NamedParameterDescriptor> namedParamDescriptorMap = new HashMap<String, NamedParameterDescriptor>();
314  
-		while( itr.hasNext() ) {
315  
-			final Map.Entry entry = ( Map.Entry ) itr.next();
316  
-			final String name = ( String ) entry.getKey();
317  
-			final ParamLocationRecognizer.NamedParameterDescription description =
318  
-					( ParamLocationRecognizer.NamedParameterDescription ) entry.getValue();
  313
+		Map<String, ParamLocationRecognizer.NamedParameterDescription> map = recognizer.getNamedParameterDescriptionMap();
  314
+		for ( final String name : map.keySet() ) {
  315
+			final ParamLocationRecognizer.NamedParameterDescription description = map.get( name );
319 316
 			namedParamDescriptorMap.put(
320 317
 					name,
321 318
 					new NamedParameterDescriptor(
322 319
 							name,
323  
-					        parameterTranslations.getNamedParameterExpectedType( name ),
324  
-					        description.buildPositionsArray(),
325  
-					        description.isJpaStyle()
  320
+							parameterTranslations.getNamedParameterExpectedType( name ),
  321
+							description.buildPositionsArray(),
  322
+							description.isJpaStyle()
326 323
 					)
327 324
 			);
328 325
 		}
329  
-
330 326
 		return new ParameterMetadata( ordinalParamDescriptors, namedParamDescriptorMap );
331 327
 	}
332 328
 	public QueryTranslator[] getTranslators() {
22  hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParamLocationRecognizer.java
@@ -41,7 +41,7 @@
41 41
 
42 42
 	public static class NamedParameterDescription {
43 43
 		private final boolean jpaStyle;
44  
-		private final List positions = new ArrayList();
  44
+		private final List<Integer> positions = new ArrayList<Integer>();
45 45
 
46 46
 		public NamedParameterDescription(boolean jpaStyle) {
47 47
 			this.jpaStyle = jpaStyle;
@@ -60,8 +60,8 @@ private void add(int position) {
60 60
 		}
61 61
 	}
62 62
 
63  
-	private Map namedParameterDescriptions = new HashMap();
64  
-	private List ordinalParameterLocationList = new ArrayList();
  63
+	private Map<String, NamedParameterDescription> namedParameterDescriptions = new HashMap<String, NamedParameterDescription>();
  64
+	private List<Integer> ordinalParameterLocationList = new ArrayList<Integer>();
65 65
 
66 66
 	/**
67 67
 	 * Convenience method for creating a param location recognizer and
@@ -82,7 +82,7 @@ public static ParamLocationRecognizer parseLocations(String query) {
82 82
 	 *
83 83
 	 * @return The map of named parameter locations.
84 84
 	 */
85  
-	public Map getNamedParameterDescriptionMap() {
  85
+	public Map<String, NamedParameterDescription> getNamedParameterDescriptionMap() {
86 86
 		return namedParameterDescriptions;
87 87
 	}
88 88
 
@@ -94,38 +94,38 @@ public Map getNamedParameterDescriptionMap() {
94 94
 	 *
95 95
 	 * @return The list of ordinal parameter locations.
96 96
 	 */
97  
-	public List getOrdinalParameterLocationList() {
  97
+	public List<Integer> getOrdinalParameterLocationList() {
98 98
 		return ordinalParameterLocationList;
99 99
 	}
100 100
 
101 101
 
102 102
 	// Recognition code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103  
-
  103
+	@Override
104 104
 	public void ordinalParameter(int position) {
105 105
 		ordinalParameterLocationList.add( position );
106 106
 	}
107  
-
  107
+	@Override
108 108
 	public void namedParameter(String name, int position) {
109 109
 		getOrBuildNamedParameterDescription( name, false ).add( position );
110 110
 	}
111  
-
  111
+	@Override
112 112
 	public void jpaPositionalParameter(String name, int position) {
113 113
 		getOrBuildNamedParameterDescription( name, true ).add( position );
114 114
 	}
115 115
 
116 116
 	private NamedParameterDescription getOrBuildNamedParameterDescription(String name, boolean jpa) {
117  
-		NamedParameterDescription desc = ( NamedParameterDescription ) namedParameterDescriptions.get( name );
  117
+		NamedParameterDescription desc = namedParameterDescriptions.get( name );
118 118
 		if ( desc == null ) {
119 119
 			desc = new NamedParameterDescription( jpa );
120 120
 			namedParameterDescriptions.put( name, desc );
121 121
 		}
122 122
 		return desc;
123 123
 	}
124  
-
  124
+	@Override
125 125
 	public void other(char character) {
126 126
 		// don't care...
127 127
 	}
128  
-
  128
+	@Override
129 129
 	public void outParameter(int position) {
130 130
 		// don't care...
131 131
 	}
2  hibernate-core/src/main/java/org/hibernate/engine/query/spi/ParameterParser.java
@@ -88,7 +88,7 @@ else if ( '\\' == c ) {
88 88
 			else {
89 89
 				if ( c == ':' ) {
90 90
 					// named parameter
91  
-					int right = StringHelper.firstIndexOfChar( sqlString, ParserHelper.HQL_SEPARATORS, indx + 1 );
  91
+					int right = StringHelper.firstIndexOfChar( sqlString, ParserHelper.HQL_SEPARATORS_BITSET, indx + 1 );
92 92
 					int chopLocation = right < 0 ? sqlString.length() : right;
93 93
 					String param = sqlString.substring( indx + 1, chopLocation );
94 94
 					if ( StringHelper.isEmpty( param ) ) {
24  hibernate-core/src/main/java/org/hibernate/engine/query/spi/QueryPlanCache.java
@@ -139,23 +139,23 @@ private ParameterMetadata buildParameterMetadata(String query){
139 139
 		final int size = recognizer.getOrdinalParameterLocationList().size();
140 140
 		OrdinalParameterDescriptor[] ordinalDescriptors = new OrdinalParameterDescriptor[ size ];
141 141
 		for ( int i = 0; i < size; i++ ) {
142  
-			final Integer position = ( Integer ) recognizer.getOrdinalParameterLocationList().get( i );
  142
+			final Integer position = recognizer.getOrdinalParameterLocationList().get( i );
143 143
 			ordinalDescriptors[i] = new OrdinalParameterDescriptor( i, null, position );
144 144
 		}
145  
-
146  
-		Iterator itr = recognizer.getNamedParameterDescriptionMap().entrySet().iterator();
147  
-		Map<String,NamedParameterDescriptor> namedParamDescriptorMap = new HashMap<String,NamedParameterDescriptor>();
148  
-		while( itr.hasNext() ) {
149  
-			final Map.Entry entry = ( Map.Entry ) itr.next();
150  
-			final String name = ( String ) entry.getKey();
151  
-			final ParamLocationRecognizer.NamedParameterDescription description =
152  
-					( ParamLocationRecognizer.NamedParameterDescription ) entry.getValue();
  145
+		Map<String, NamedParameterDescriptor> namedParamDescriptorMap = new HashMap<String, NamedParameterDescriptor>();
  146
+		Map<String, ParamLocationRecognizer.NamedParameterDescription> map = recognizer.getNamedParameterDescriptionMap();
  147
+		for ( final String name : map.keySet() ) {
  148
+			final ParamLocationRecognizer.NamedParameterDescription description = map.get( name );
153 149
 			namedParamDescriptorMap.put(
154  
-					name ,
155  
-					new NamedParameterDescriptor( name, null, description.buildPositionsArray(), description.isJpaStyle() )
  150
+					name,
  151
+					new NamedParameterDescriptor(
  152
+							name,
  153
+							null,
  154
+							description.buildPositionsArray(),
  155
+							description.isJpaStyle()
  156
+					)
156 157
 			);
157 158
 		}
158  
-
159 159
 		return new ParameterMetadata( ordinalDescriptors, namedParamDescriptorMap );
160 160
 	}
161 161
 
16  hibernate-core/src/main/java/org/hibernate/hql/internal/classic/ParserHelper.java
@@ -23,6 +23,8 @@
23 23
  *
24 24
  */
25 25
 package org.hibernate.hql.internal.classic;
  26
+
  27
+import java.util.BitSet;
26 28
 import java.util.StringTokenizer;
27 29
 
28 30
 import org.hibernate.QueryException;
@@ -33,11 +35,19 @@
33 35
 	public static final String HQL_VARIABLE_PREFIX = ":";
34 36
 
35 37
 	public static final String HQL_SEPARATORS = " \n\r\f\t,()=<>&|+-=/*'^![]#~\\";
  38
+	public static final BitSet HQL_SEPARATORS_BITSET = new BitSet();
  39
+
  40
+	static {
  41
+		for ( int i = 0; i < HQL_SEPARATORS.length(); i++ ) {
  42
+			HQL_SEPARATORS_BITSET.set( HQL_SEPARATORS.charAt( i ) );
  43
+		}
  44
+	}
  45
+
36 46
 	//NOTICE: no " or . since they are part of (compound) identifiers
37 47
 	public static final String PATH_SEPARATORS = ".";
38 48
 
39 49
 	public static boolean isWhitespace(String str) {
40  
-		return StringHelper.WHITESPACE.indexOf( str ) > -1;
  50
+		return StringHelper.WHITESPACE.contains( str );
41 51
 	}
42 52
 
43 53
 	private ParserHelper() {
@@ -47,7 +57,9 @@ private ParserHelper() {
47 57
 	public static void parse(Parser p, String text, String seperators, QueryTranslatorImpl q) throws QueryException {
48 58
 		StringTokenizer tokens = new StringTokenizer( text, seperators, true );
49 59
 		p.start( q );
50  
-		while ( tokens.hasMoreElements() ) p.token( tokens.nextToken(), q );
  60
+		while ( tokens.hasMoreElements() ) {
  61
+			p.token( tokens.nextToken(), q );
  62
+		}
51 63
 		p.end( q );
52 64
 	}
53 65
 
27  hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java
@@ -27,6 +27,7 @@
27 27
 import java.io.Serializable;
28 28
 import java.util.ArrayList;
29 29
 import java.util.Arrays;
  30
+import java.util.BitSet;
30 31
 import java.util.Iterator;
31 32
 import java.util.StringTokenizer;
32 33
 import java.util.UUID;
@@ -472,21 +473,23 @@ public static String qualify(String prefix, String name) {
472 473
 		}
473 474
 		return qualified;
474 475
 	}
  476
+	public static int firstIndexOfChar(String sqlString, BitSet keys, int startindex) {
  477
+		for ( int i = startindex, size = sqlString.length(); i < size; i++ ) {
  478
+			if ( keys.get( sqlString.charAt( i ) ) ) {
  479
+				return i;
  480
+			}
  481
+		}
  482
+		return -1;
  483
+
  484
+	}
475 485
 
476 486
 	public static int firstIndexOfChar(String sqlString, String string, int startindex) {
477  
-		int matchAt = -1;
478  
-		for ( int i = 0; i < string.length(); i++ ) {
479  
-			int curMatch = sqlString.indexOf( string.charAt( i ), startindex );
480  
-			if ( curMatch >= 0 ) {
481  
-				if ( matchAt == -1 ) { // first time we find match!
482  
-					matchAt = curMatch;
483  
-				}
484  
-				else {
485  
-					matchAt = Math.min( matchAt, curMatch );
486  
-				}
487  
-			}
  487
+		BitSet keys = new BitSet();
  488
+		for ( int i = 0, size = string.length(); i < size; i++ ) {
  489
+			keys.set( string.charAt( i ) );
488 490
 		}
489  
-		return matchAt;
  491
+		return firstIndexOfChar( sqlString, keys, startindex );
  492
+
490 493
 	}
491 494
 
492 495
 	public static String truncate(String string, int length) {

No commit comments for this range

Something went wrong with that request. Please try again.