use of com.mysql.cj.ServerPreparedQueryBindings in project aws-mysql-jdbc by awslabs.
the class ServerPreparedStatement method setOneBatchedParameterSet.
@Override
protected int setOneBatchedParameterSet(java.sql.PreparedStatement batchedStatement, int batchedParamIndex, Object paramSet) throws SQLException {
ServerPreparedQueryBindValue[] paramArg = ((ServerPreparedQueryBindings) paramSet).getBindValues();
for (int j = 0; j < paramArg.length; j++) {
if (paramArg[j].isNull()) {
batchedStatement.setNull(batchedParamIndex++, MysqlType.NULL.getJdbcType());
} else {
if (paramArg[j].isStream()) {
Object value = paramArg[j].value;
if (value instanceof byte[]) {
batchedStatement.setBytes(batchedParamIndex++, (byte[]) value);
} else if (value instanceof InputStream) {
batchedStatement.setBinaryStream(batchedParamIndex++, (InputStream) value, paramArg[j].getStreamLength());
} else if (value instanceof java.sql.Blob) {
try {
batchedStatement.setBinaryStream(batchedParamIndex++, ((java.sql.Blob) value).getBinaryStream(), paramArg[j].getStreamLength());
} catch (Throwable t) {
throw ExceptionFactory.createException(t.getMessage(), this.session.getExceptionInterceptor());
}
} else if (value instanceof Reader) {
batchedStatement.setCharacterStream(batchedParamIndex++, (Reader) value, paramArg[j].getStreamLength());
} else {
throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ServerPreparedStatement.18") + value.getClass().getName() + "'", this.session.getExceptionInterceptor());
}
} else {
switch(paramArg[j].bufferType) {
case MysqlType.FIELD_TYPE_TINY:
batchedStatement.setByte(batchedParamIndex++, ((Long) paramArg[j].value).byteValue());
break;
case MysqlType.FIELD_TYPE_SHORT:
batchedStatement.setShort(batchedParamIndex++, ((Long) paramArg[j].value).shortValue());
break;
case MysqlType.FIELD_TYPE_LONG:
batchedStatement.setInt(batchedParamIndex++, ((Long) paramArg[j].value).intValue());
break;
case MysqlType.FIELD_TYPE_LONGLONG:
batchedStatement.setLong(batchedParamIndex++, ((Long) paramArg[j].value).longValue());
break;
case MysqlType.FIELD_TYPE_FLOAT:
batchedStatement.setFloat(batchedParamIndex++, ((Float) paramArg[j].value).floatValue());
break;
case MysqlType.FIELD_TYPE_DOUBLE:
batchedStatement.setDouble(batchedParamIndex++, ((Double) paramArg[j].value).doubleValue());
break;
case MysqlType.FIELD_TYPE_TIME:
batchedStatement.setTime(batchedParamIndex++, (Time) paramArg[j].value);
break;
case MysqlType.FIELD_TYPE_DATE:
batchedStatement.setObject(batchedParamIndex++, paramArg[j].value, MysqlType.DATE);
break;
case MysqlType.FIELD_TYPE_DATETIME:
batchedStatement.setObject(batchedParamIndex++, paramArg[j].value);
break;
case MysqlType.FIELD_TYPE_TIMESTAMP:
batchedStatement.setTimestamp(batchedParamIndex++, (Timestamp) paramArg[j].value);
break;
case MysqlType.FIELD_TYPE_VAR_STRING:
case MysqlType.FIELD_TYPE_STRING:
case MysqlType.FIELD_TYPE_VARCHAR:
case MysqlType.FIELD_TYPE_DECIMAL:
case MysqlType.FIELD_TYPE_NEWDECIMAL:
Object value = paramArg[j].value;
if (value instanceof byte[]) {
batchedStatement.setBytes(batchedParamIndex, (byte[]) value);
} else {
batchedStatement.setString(batchedParamIndex, (String) value);
}
if (batchedStatement instanceof ServerPreparedStatement) {
ServerPreparedQueryBindValue asBound = ((ServerPreparedStatement) batchedStatement).getBinding(batchedParamIndex, false);
asBound.bufferType = paramArg[j].bufferType;
}
batchedParamIndex++;
break;
default:
throw new IllegalArgumentException(Messages.getString("ServerPreparedStatement.26", new Object[] { batchedParamIndex }));
}
}
}
}
return batchedParamIndex;
}
Aggregations