Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spacings fixes #14

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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