Skip to content

Commit

Permalink
[CONJ-322] ResultSet.update* implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 23, 2017
1 parent 9ab2be8 commit ed270f9
Show file tree
Hide file tree
Showing 23 changed files with 4,302 additions and 508 deletions.
81 changes: 38 additions & 43 deletions src/main/java/org/mariadb/jdbc/BasePrepareStatement.java
Expand Up @@ -79,7 +79,7 @@ public abstract class BasePrepareStatement extends MariaDbStatement implements P
* a format that extends the ISO-8601 extended offset date-time format
* to add the time-zone.</p>
**/
private static final DateTimeFormatter SPEC_ISO_ZONED_DATE_TIME = new DateTimeFormatterBuilder()
public static final DateTimeFormatter SPEC_ISO_ZONED_DATE_TIME = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
.optionalStart()
Expand All @@ -99,10 +99,24 @@ public abstract class BasePrepareStatement extends MariaDbStatement implements P

protected boolean useFractionalSeconds;
protected boolean hasLongData = false;
private boolean noBackslashEscapes;


public BasePrepareStatement(MariaDbConnection connection, int resultSetScrollType) {
super(connection, resultSetScrollType);
/**
* Constructor.
* Base class that permit setting parameters for client and server PrepareStatement.
*
* @param connection current connection
* @param resultSetScrollType one of the following <code>ResultSet</code> constants:
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency one of the following <code>ResultSet</code> constants:
* <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
*/
public BasePrepareStatement(MariaDbConnection connection, int resultSetScrollType, int resultSetConcurrency) {
super(connection, resultSetScrollType, resultSetConcurrency);
this.noBackslashEscapes = protocol.noBackslashEscapes();
this.useFractionalSeconds = options.useFractionalSeconds;
}

Expand Down Expand Up @@ -152,7 +166,7 @@ public void setCharacterStream(final int parameterIndex, final Reader reader, fi
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new ReaderParameter(reader, length, connection.noBackslashEscapes));
setParameter(parameterIndex, new ReaderParameter(reader, length, noBackslashEscapes));
hasLongData = true;
}

Expand All @@ -178,7 +192,7 @@ public void setCharacterStream(final int parameterIndex, final Reader reader, fi
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new ReaderParameter(reader, length, connection.noBackslashEscapes));
setParameter(parameterIndex, new ReaderParameter(reader, length, noBackslashEscapes));
hasLongData = true;
}

Expand All @@ -205,7 +219,7 @@ public void setCharacterStream(final int parameterIndex, final Reader reader) th
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new ReaderParameter(reader, connection.noBackslashEscapes));
setParameter(parameterIndex, new ReaderParameter(reader, noBackslashEscapes));
hasLongData = true;
}

Expand Down Expand Up @@ -240,7 +254,7 @@ public void setBlob(final int parameterIndex, final Blob blob) throws SQLExcepti
setNull(parameterIndex, Types.BLOB);
return;
}
setParameter(parameterIndex, new StreamParameter(blob.getBinaryStream(), blob.length(), connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(blob.getBinaryStream(), blob.length(), noBackslashEscapes));
hasLongData = true;
}

Expand All @@ -267,7 +281,7 @@ public void setBlob(final int parameterIndex, final InputStream inputStream, fin
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new StreamParameter(inputStream, length, connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(inputStream, length, noBackslashEscapes));
hasLongData = true;
}

Expand Down Expand Up @@ -295,7 +309,7 @@ public void setBlob(final int parameterIndex, final InputStream inputStream) thr
return;
}

setParameter(parameterIndex, new StreamParameter(inputStream, connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(inputStream, noBackslashEscapes));
hasLongData = true;
}

Expand All @@ -317,7 +331,7 @@ public void setClob(final int parameterIndex, final Clob clob) throws SQLExcepti
return;
}

setParameter(parameterIndex, new ReaderParameter(clob.getCharacterStream(), clob.length(), connection.noBackslashEscapes));
setParameter(parameterIndex, new ReaderParameter(clob.getCharacterStream(), clob.length(), noBackslashEscapes));
hasLongData = true;
}

Expand Down Expand Up @@ -581,7 +595,7 @@ public void setNull(final int parameterIndex, final int sqlType, final String ty
setParameter(parameterIndex, new NullParameter());
}

protected abstract void setParameter(final int parameterIndex, final ParameterHolder holder) throws SQLException;
public abstract void setParameter(final int parameterIndex, final ParameterHolder holder) throws SQLException;

/**
* Sets the designated parameter to the given <code>java.net.URL</code> value. The driver converts this to an SQL
Expand All @@ -600,7 +614,7 @@ public void setURL(final int parameterIndex, final URL url) throws SQLException
setNull(parameterIndex, ColumnType.STRING);
return;
}
setParameter(parameterIndex, new StringParameter(url.toString(), connection.noBackslashEscapes));
setParameter(parameterIndex, new StringParameter(url.toString(), noBackslashEscapes));
}

/**
Expand Down Expand Up @@ -821,7 +835,7 @@ public void setObject(final int parameterIndex, final Object obj, final int targ
* @param targetSqlType the SQL type (as defined in java.sql.Types) to be sent to the database
* @throws SQLException if parameterIndex does not correspond to a parameter marker in the SQL statement;
* if a database access error occurs or this method is called on a closed
* <code>PreparedStatement</code>
* <code>PreparedStatement</code>s
* @throws SQLFeatureNotSupportedException if <code>targetSqlType</code> is a <code>ARRAY</code>, <code>BLOB</code>,
* <code>CLOB</code>, <code>DATALINK</code>, <code>JAVA_OBJECT</code>,
* <code>NCHAR</code>, <code>NCLOB</code>, <code>NVARCHAR</code>,
Expand Down Expand Up @@ -920,7 +934,7 @@ public void setObject(final int parameterIndex, final Object obj) throws SQLExce
} else {
//fallback to sending serialized object
try {
setParameter(parameterIndex, new SerializableParameter(obj, connection.noBackslashEscapes));
setParameter(parameterIndex, new SerializableParameter(obj, noBackslashEscapes));
hasLongData = true;
} catch (IOException e) {
throw ExceptionMapper.getSqlException(
Expand Down Expand Up @@ -1034,7 +1048,6 @@ protected void setInternalObject(final int parameterIndex, final Object obj, fin
throw ExceptionMapper.getSqlException("Could not convert [" + str + "] to " + targetSqlType, e);
}
} else if (obj instanceof Number) {
testNumbers(targetSqlType);
Number bd = (Number) obj;
switch (targetSqlType) {
case Types.TINYINT:
Expand Down Expand Up @@ -1100,7 +1113,6 @@ protected void setInternalObject(final int parameterIndex, final Object obj, fin
setTimestamp(parameterIndex, new Timestamp(timemillis));
}
} else if (obj instanceof Boolean) {
testNumbers(targetSqlType);
setBoolean(parameterIndex, (Boolean) obj);
} else if (obj instanceof Blob) {
setBlob(parameterIndex, (Blob) obj);
Expand Down Expand Up @@ -1168,7 +1180,7 @@ public void setAsciiStream(final int parameterIndex, final InputStream stream, f
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new StreamParameter(stream, length, connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(stream, length, noBackslashEscapes));
hasLongData = true;
}

Expand Down Expand Up @@ -1197,7 +1209,7 @@ public void setAsciiStream(final int parameterIndex, final InputStream stream) t
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new StreamParameter(stream, connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(stream, noBackslashEscapes));
hasLongData = true;
}

Expand All @@ -1222,7 +1234,7 @@ public void setAsciiStream(final int parameterIndex, final InputStream stream, f
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new StreamParameter(stream, length, connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(stream, length, noBackslashEscapes));
hasLongData = true;
}

Expand All @@ -1247,7 +1259,7 @@ public void setBinaryStream(final int parameterIndex, final InputStream stream,
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new StreamParameter(stream, length, connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(stream, length, noBackslashEscapes));
hasLongData = true;
}

Expand Down Expand Up @@ -1275,7 +1287,7 @@ public void setBinaryStream(final int parameterIndex, final InputStream stream)
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new StreamParameter(stream, connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(stream, noBackslashEscapes));
hasLongData = true;
}

Expand All @@ -1301,7 +1313,7 @@ public void setBinaryStream(final int parameterIndex, final InputStream stream,
setNull(parameterIndex, ColumnType.BLOB);
return;
}
setParameter(parameterIndex, new StreamParameter(stream, length, connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(stream, length, noBackslashEscapes));
hasLongData = true;
}

Expand Down Expand Up @@ -1365,7 +1377,7 @@ public void setString(final int parameterIndex, final String str) throws SQLExce
return;
}

setParameter(parameterIndex, new StringParameter(str, connection.noBackslashEscapes));
setParameter(parameterIndex, new StringParameter(str, noBackslashEscapes));
}

/**
Expand All @@ -1385,7 +1397,7 @@ public void setBytes(final int parameterIndex, final byte[] bytes) throws SQLExc
return;
}

setParameter(parameterIndex, new ByteArrayParameter(bytes, connection.noBackslashEscapes));
setParameter(parameterIndex, new ByteArrayParameter(bytes, noBackslashEscapes));
}


Expand Down Expand Up @@ -1417,27 +1429,10 @@ public void setUnicodeStream(final int parameterIndex, final InputStream x, fina
setNull(parameterIndex, Types.BLOB);
return;
}
setParameter(parameterIndex, new StreamParameter(x, length, connection.noBackslashEscapes));
setParameter(parameterIndex, new StreamParameter(x, length, noBackslashEscapes));
hasLongData = true;
}


private void testNumbers(int targetSqlType) throws SQLException {
switch (targetSqlType) {
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
case Types.BLOB:
throw ExceptionMapper.getSqlException("Cannot convert to " + targetSqlType);
default:
return;
}
}


public void setInt(final int column, final int value) throws SQLException {
setParameter(column, new IntParameter(value));
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/org/mariadb/jdbc/CallableFunctionStatement.java
Expand Up @@ -75,14 +75,18 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
/**
* Constructor for getter/setter of callableStatement.
*
* @param connection current connection
* @param sql query
* @param resultSetScrollType one of the following <code>ResultSet</code> constants: <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param connection current connection
* @param sql query
* @param resultSetType a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @throws SQLException if clientPrepareStatement creation throw an exception
*/
public CallableFunctionStatement(MariaDbConnection connection, String sql, int resultSetScrollType) throws SQLException {
super(connection, sql, resultSetScrollType);
public CallableFunctionStatement(MariaDbConnection connection, String sql, int resultSetType,
final int resultSetConcurrency) throws SQLException {
super(connection, sql, resultSetType, resultSetConcurrency);
}

/**
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/mariadb/jdbc/CallableProcedureStatement.java
Expand Up @@ -79,15 +79,17 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
/**
* Constructor for getter/setter of callableStatement.
*
* @param connection current connection
* @param sql query
* @param resultSetScrollType one of the following <code>ResultSet</code> constants: <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param connection current connection
* @param sql query
* @param resultSetScrollType one of the following <code>ResultSet</code> constants: <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @throws SQLException is prepareStatement connection throw any error
*/
public CallableProcedureStatement(MariaDbConnection connection, String sql, int resultSetScrollType)
public CallableProcedureStatement(MariaDbConnection connection, String sql, int resultSetScrollType, int resultSetConcurrency)
throws SQLException {
super(connection, sql, resultSetScrollType, true);
super(connection, sql, resultSetScrollType, resultSetConcurrency, true);
}

/**
Expand Down

0 comments on commit ed270f9

Please sign in to comment.