Mercurial > hg > monetdb-java
changeset 112:53ef497672bf embedded
Limit the StringBuilder size for the JDBC embedded connection.
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Wed, 25 Jan 2017 17:41:50 +0100 (2017-01-25) |
parents | d7added7aaf3 |
children | 0cfaeec9afcb |
files | src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java |
diffstat | 3 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -164,6 +164,13 @@ public abstract class MonetConnection ex public abstract int getDefFetchsize(); /** + * Gets the initial value for the StringBuilder size. + * + * @return The initial value for the StringBuilder size + */ + public abstract int initialStringBuilderSize(); + + /** * Gets the underlying connection socket timeout. * * @return The underlying connection socket timeout
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java @@ -191,11 +191,12 @@ public class MonetStatement extends Mone boolean error = false; BatchUpdateException e = new BatchUpdateException("Error(s) occurred while executing the batch, see next SQLExceptions for details", "22000", counts); - StringBuilder tmpBatch = new StringBuilder(connection.getBlockSize()); + int builderSize = connection.initialStringBuilderSize(); + StringBuilder tmpBatch = new StringBuilder(builderSize); String sep = connection.getLanguage().getQueryTemplateIndex(2); for (int i = 0; i < batch.size(); i++) { String tmp = batch.get(i); - if (sep.length() + tmp.length() > connection.getBlockSize()) { + if (sep.length() + tmp.length() > builderSize) { // The thing is too big. Way too big. Since it won't be optimal anyway, just add it to whatever we // have and continue. if (!first) { @@ -209,7 +210,7 @@ public class MonetStatement extends Mone first = true; continue; } - if (tmpBatch.length() + sep.length() + tmp.length() >= connection.getBlockSize()) { + if (tmpBatch.length() + sep.length() + tmp.length() >= builderSize) { // send and receive error |= internalBatch(tmpBatch.toString(), counts, offset, i + 1, e); offset = i;
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java +++ b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java @@ -191,6 +191,11 @@ public class MapiConnection extends Mone return DEF_FETCHSIZE; } + @Override + public int initialStringBuilderSize() { + return this.getBlockSize(); + } + /** * Closes the underlying connection implementation. On a MAPI connection, the underlying socket is closed. *