Skip to content

Commit

Permalink
(#29) Added registerOutParameter and setter implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Feb 5, 2019
1 parent d9811f5 commit 1891b6e
Show file tree
Hide file tree
Showing 4 changed files with 499 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.sql.Ref;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLType;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
Expand All @@ -39,18 +40,18 @@

public class JdbcCallableStatement extends JdbcPreparedStatement implements CallableStatement {

public JdbcCallableStatement(final HttpClient httpClient, final String callableStatement, final String serverUrl, JdbcConnection connection) {
public JdbcCallableStatement(final HttpClient httpClient, final String callableStatement, final String serverUrl, final JdbcConnection connection) {
super(httpClient, callableStatement, serverUrl, connection);
}

@Override
public void registerOutParameter(final int parameterIndex, final int sqlType) throws SQLException {

setOutParameter(parameterIndex);
}

@Override
public void registerOutParameter(final int parameterIndex, final int sqlType, final int scale) throws SQLException {

registerOutParameter(parameterIndex, sqlType);
}

@Override
Expand Down Expand Up @@ -175,22 +176,22 @@ public Timestamp getTimestamp(final int parameterIndex, final Calendar cal) thro

@Override
public void registerOutParameter(final int parameterIndex, final int sqlType, final String typeName) throws SQLException {

registerOutParameter(parameterIndex, sqlType);
}

@Override
public void registerOutParameter(final String parameterName, final int sqlType) throws SQLException {

setOutParameter(parameterName);
}

@Override
public void registerOutParameter(final String parameterName, final int sqlType, final int scale) throws SQLException {

registerOutParameter(parameterName, sqlType);
}

@Override
public void registerOutParameter(final String parameterName, final int sqlType, final String typeName) throws SQLException {

registerOutParameter(parameterName, sqlType);
}

@Override
Expand All @@ -200,77 +201,77 @@ public URL getURL(final int parameterIndex) throws SQLException {

@Override
public void setURL(final String parameterName, final URL val) throws SQLException {

setParameter(parameterName, val);
}

@Override
public void setNull(final String parameterName, final int sqlType) throws SQLException {

setParameter(parameterName, "null");
}

@Override
public void setBoolean(final String parameterName, final boolean x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setByte(final String parameterName, final byte x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setShort(final String parameterName, final short x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setInt(final String parameterName, final int x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setLong(final String parameterName, final long x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setFloat(final String parameterName, final float x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setDouble(final String parameterName, final double x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setBigDecimal(final String parameterName, final BigDecimal x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setString(final String parameterName, final String x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setBytes(final String parameterName, final byte[] x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setDate(final String parameterName, final Date x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setTime(final String parameterName, final Time x) throws SQLException {

setParameter(parameterName, x);
}

@Override
public void setTimestamp(final String parameterName, final Timestamp x) throws SQLException {

setParameter(parameterName, x);
}

@Override
Expand Down Expand Up @@ -607,4 +608,42 @@ public <T> T getObject(final int parameterIndex, final Class<T> type) throws SQL
public <T> T getObject(final String parameterName, final Class<T> type) throws SQLException {
return null;
}

@Override
public void registerOutParameter(final int parameterIndex, final SQLType sqlType){
setOutParameter(parameterIndex);
}

@Override
public void registerOutParameter(final int parameterIndex, final SQLType sqlType, final int scale){
registerOutParameter(parameterIndex, sqlType);
}

@Override
public void registerOutParameter(final int parameterIndex, final SQLType sqlType, final String typeName){
registerOutParameter(parameterIndex, sqlType);
}

@Override
public void registerOutParameter(final String parameterName, final SQLType sqlType){
setOutParameter(parameterName);
}

@Override
public void registerOutParameter(final String parameterName, final SQLType sqlType, final int scale){
registerOutParameter(parameterName, sqlType);
}

@Override
public void registerOutParameter(final String parameterName, final SQLType sqlType, final String typeName){
registerOutParameter(parameterName, sqlType);
}

private void setOutParameter(final int parameterIndex) {
setParameter(parameterIndex, "?");
}

private void setOutParameter(final String parameterName) {
setParameter(parameterName, "?");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

/**
Expand All @@ -48,7 +48,7 @@
public class JdbcPreparedStatement extends JdbcStatement implements PreparedStatement {

private final String preparedStatement;
private List<Object> parameters = new ArrayList<>();
private Map<String, Object> parameters = new TreeMap<>();

public JdbcPreparedStatement(final HttpClient httpClient, final String preparedStatement, final String serverUrl, JdbcConnection connection) {
super(httpClient, serverUrl, connection);
Expand Down Expand Up @@ -330,18 +330,18 @@ public void setNClob(final int parameterIndex, final Reader reader) throws SQLEx
}

void setParameter(final int parameterIndex, final Object value){
if (parameters.size() > parameterIndex - 1) {
parameters.set(parameterIndex - 1,value);
}else {
parameters.add(parameterIndex - 1, value);
}
setParameter(String.valueOf(parameterIndex - 1), value);
}

void setParameter(final String parameterName, final Object value){
parameters.put(parameterName, value);
}

private String composeStatement() {
return preparedStatement + " - (" + parameters.stream().map(param -> param != null ? param.toString() : "null").collect(Collectors.joining(",")) + ")";
return preparedStatement + " - (" + parameters.values().stream().map(param -> param != null ? param.toString() : "null").collect(Collectors.joining(",")) + ")";
}

List<Object> getParameters() {
Map<String, Object> getParameters() {
return parameters;
}
}
Expand Down
Loading

0 comments on commit 1891b6e

Please sign in to comment.