Skip to content
Snippets Groups Projects
Commit f83bc549 authored by User expired's avatar User expired
Browse files

fixed problem in placeHolder caching

parent fda86fb3
No related branches found
No related tags found
No related merge requests found
......@@ -74,7 +74,7 @@ public class Database {
final int preachingLength = 10;
PRECACHED_PLACEHOLDERS = new String[preachingLength];
for (int i = 0; i < preachingLength; ++i) {
PRECACHED_PLACEHOLDERS[i] = preparePlaceHolders(i);
PRECACHED_PLACEHOLDERS[i] = calculatePlaceHolders(i);
}
}
......@@ -743,31 +743,6 @@ public class Database {
// Private static methods
/**
* Prepares a number of place holders for a prepared statement.
*
* @param length The number of placeholders that is needed
* @return a string with the placeholders plugged in to a statement.
*/
private static String preparePlaceHolders(final int length) {
if (length <= 0) {
return "";
}
if (length < PRECACHED_PLACEHOLDERS.length) {
return PRECACHED_PLACEHOLDERS[length];
}
final StringBuilder builder = new StringBuilder((2 * length) - 1);
builder.append("?");
final int max = length - 1;
for (int i = 0; i < max; ++i) {
builder.append(",?");
}
return builder.toString();
}
/**
* Adds a node to the network.
*
......@@ -800,6 +775,25 @@ public class Database {
}
}
/**
* Calculates a number of place holders for a prepared statement.
* In difference to @see {@link #preparePlaceHolders(int)} this does not use any caching approach at all.
*
* @param length The number of placeholders that is needed
* @return a string with the placeholders plugged in to a statement.
*/
private static String calculatePlaceHolders(final int length) {
final StringBuilder builder = new StringBuilder((2 * length) - 1);
builder.append("?");
final int max = length - 1;
for (int i = 0; i < max; ++i) {
builder.append(",?");
}
return builder.toString();
}
/**
* Transforms the day into something machine-readable.
*
......@@ -827,6 +821,25 @@ public class Database {
}
}
/**
* Prepares a number of place holders for a prepared statement.
* In difference to @see {@link #calculatePlaceHolders(int)} this uses a caching approach for small lengths
*
* @param length The number of placeholders that is needed
* @return a string with the placeholders plugged in to a statement.
*/
private static String preparePlaceHolders(final int length) {
if (length <= 0) {
return "";
}
if (length < PRECACHED_PLACEHOLDERS.length) {
return PRECACHED_PLACEHOLDERS[length];
}
return calculatePlaceHolders(length);
}
private static String subQuery(final Node[] loaded, final int idx, final int srid) {
if (idx == 0) {
return "st_buffer(st_pointfromtext('POINT(" + loaded[idx].getCoordinates().getX() + " "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment