Skip to content

Commit

Permalink
Merge pull request #14 from rene-ye/hashKeyChanges2
Browse files Browse the repository at this point in the history
Fix for review comments
  • Loading branch information
cheenamalhotra authored Jul 9, 2018
2 parents 27da9e2 + d349ff5 commit b442832
Showing 1 changed file with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,20 @@ void removeReference() {
}

/** Get prepared statement cache entry if exists, if not parse and create a new one */
static ParsedSQLCacheItem getCachedParsedSQL(CityHash128Key key) {
static ParsedSQLCacheItem getCachedParsedSQL(CityHash128Key key) {
return parsedSQLCache.get(key);
}

/** Parse and create a information about parsed SQL text */
static ParsedSQLCacheItem parseAndCacheSQL(CityHash128Key key, String sql) throws SQLServerException {
static ParsedSQLCacheItem parseAndCacheSQL(CityHash128Key key, String sql) throws SQLServerException {
JDBCSyntaxTranslator translator = new JDBCSyntaxTranslator();

String parsedSql = translator.translate(sql);
String procName = translator.getProcedureName(); // may return null
boolean returnValueSyntax = translator.hasReturnValueSyntax();
int[] parameterPositions = locateParams(parsedSql);

ParsedSQLCacheItem cacheItem = new ParsedSQLCacheItem (parsedSql, parameterPositions, procName, returnValueSyntax);
ParsedSQLCacheItem cacheItem = new ParsedSQLCacheItem(parsedSql, parameterPositions, procName, returnValueSyntax);
parsedSQLCache.putIfAbsent(key, cacheItem);
return cacheItem;
}
Expand All @@ -304,21 +304,16 @@ static ParsedSQLCacheItem parseAndCacheSQL(CityHash128Key key, String sql) thro
* SQL text to parse for positions of parameters to intialize.
*/
private static int[] locateParams(String sql) {
List<Integer> parameterPositions = new ArrayList<Integer>(0);
LinkedList<Integer> parameterPositions = new LinkedList<>();

// Locate the parameter placeholders in the SQL string.
int offset = -1;
while ((offset = ParameterUtils.scanSQLForChar('?', sql, ++offset)) < sql.length()) {
parameterPositions.add(offset);
}

// Convert to int[]
int[] result = new int[parameterPositions.size()];
int i = 0;
for (Integer parameterPosition : parameterPositions) {
result[i++] = parameterPosition;
}
return result;
// return as int[]
return parameterPositions.stream().mapToInt(Integer::valueOf).toArray();
}

SqlFedAuthToken getAuthenticationResult() {
Expand Down Expand Up @@ -5384,13 +5379,7 @@ String replaceParameterMarkers(String sqlSrc,

int paramIndex = 0;
while (true) {
int srcEnd;
if (paramIndex >= paramPositions.length) {
srcEnd = sqlSrc.length();
}
else {
srcEnd = paramPositions[paramIndex];
}
int srcEnd = (paramIndex >= paramPositions.length) ? sqlSrc.length() : paramPositions[paramIndex];
sqlSrc.getChars(srcBegin, srcEnd, sqlDst, dstBegin);
dstBegin += srcEnd - srcBegin;

Expand Down

0 comments on commit b442832

Please sign in to comment.