Improved BatchEncoder: writeNextString() v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 08 Jan 2014 19:24:26 +0100
branchv_0
changeset 1474a704c1669f4
parent 146 4f4f515df807
child 148 1b2f40cd432b
Improved BatchEncoder: writeNextString()
java/sql-dk/src/info/globalcode/sql/dk/batch/BatchEncoder.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/batch/BatchEncoder.java	Wed Jan 08 19:18:52 2014 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/batch/BatchEncoder.java	Wed Jan 08 19:24:26 2014 +0100
     1.3 @@ -45,9 +45,7 @@
     1.4  				sqlCommand = ((SQLCommandNamed) sqlCommand).getSQLCommandNumbered();
     1.5  			}
     1.6  
     1.7 -			byte[] sqlBytes = toBytes(sqlCommand.getQuery());
     1.8 -			buffer.writeInt(sqlBytes.length);
     1.9 -			buffer.write(sqlBytes);
    1.10 +			writeNextString(sqlCommand.getQuery(), buffer);
    1.11  
    1.12  			List<? extends Parameter> parameters = sqlCommand.getParameters();
    1.13  
    1.14 @@ -55,9 +53,7 @@
    1.15  
    1.16  			for (Parameter p : parameters) {
    1.17  				buffer.writeInt(p.getType().getCode());
    1.18 -				byte[] value = toBytes((String) p.getValue()); // parameters are encoded before any preprocessing
    1.19 -				buffer.writeInt(value.length);
    1.20 -				buffer.write(value);
    1.21 +				writeNextString((String) p.getValue(), buffer); // parameters are encoded before any preprocessing
    1.22  			}
    1.23  
    1.24  			buffer.flush();
    1.25 @@ -71,6 +67,12 @@
    1.26  		}
    1.27  	}
    1.28  
    1.29 +	private void writeNextString(String s, DataOutputStream out) throws IOException {
    1.30 +		byte[] bytes = toBytes(s);
    1.31 +		out.writeInt(bytes.length);
    1.32 +		out.write(bytes);
    1.33 +	}
    1.34 +
    1.35  	private static byte[] toBytes(String s) {
    1.36  		if (s == null) {
    1.37  			return new byte[]{};