Skip to content

Commit

Permalink
Remove some unnecessary boxing in bindLong
Browse files Browse the repository at this point in the history
  • Loading branch information
npurushe committed Feb 28, 2016
1 parent 9efbb67 commit 2d3fdf3
Showing 1 changed file with 33 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,15 @@ private void bindNullOrString(int index, Object value) {
}
}

private void bindLong(int index, Long value) {
if (value == null) {
statement.bindNull(index);
if (bindings != null) {
bindings.add(null);
}
} else {
statement.bindLong(index, value);
if (bindings != null) {
bindings.add(value);
}
private void bindLong(int index, long value) {
statement.bindLong(index, value);
if (bindings != null) {
bindings.add(value);
}
}

private void bindDouble(int index, Double value) {
if (value == null) {
statement.bindNull(index);
} else {
statement.bindDouble(index, value);
}
private void bindDouble(int index, double value) {
statement.bindDouble(index, value);
if (bindings != null) {
bindings.add(value);
}
Expand Down Expand Up @@ -245,7 +234,6 @@ public void setAsciiStream(int parameterIndex, InputStream theInputStream, int l

@Override
public void setBigDecimal(int parameterIndex, BigDecimal theBigDecimal) throws SQLException {
throwIfClosed();
bindNullOrString(parameterIndex, theBigDecimal);
}

Expand All @@ -257,26 +245,22 @@ public void setBinaryStream(int parameterIndex, InputStream theInputStream, int

@Override
public void setBlob(int parameterIndex, Blob theBlob) throws SQLException {
throwIfClosed();
setBytes(parameterIndex, theBlob.getBytes(0, (int) theBlob.length()));
}

@Override
public void setBoolean(int parameterIndex, boolean theBoolean) throws SQLException {
throwIfClosed();
long value = theBoolean ? 1 : 0;
bindLong(parameterIndex, value);
}

@Override
public void setByte(int parameterIndex, byte theByte) throws SQLException {
throwIfClosed();
bindLong(parameterIndex, (long) theByte);
}

@Override
public void setBytes(int parameterIndex, byte[] theBytes) throws SQLException {
throwIfClosed();
bindBlob(parameterIndex, theBytes);
}

Expand All @@ -292,55 +276,50 @@ public void setClob(int parameterIndex, Clob theClob) throws SQLException {

@Override
public void setDate(int parameterIndex, Date theDate) throws SQLException {
throwIfClosed();
setDate(parameterIndex, theDate, null);
}

@Override
public void setDate(int parameterIndex, Date theDate, Calendar cal) throws SQLException {
throwIfClosed();
bindLong(parameterIndex, theDate == null ? null : theDate.getTime());
if (theDate == null) {
bindNullOrString(parameterIndex, null);
} else {
bindLong(parameterIndex, theDate.getTime());
}
}

@Override
public void setDouble(int parameterIndex, double theDouble) throws SQLException {
throwIfClosed();
bindDouble(parameterIndex, theDouble);
}

@Override
public void setFloat(int parameterIndex, float theFloat) throws SQLException {
throwIfClosed();
bindDouble(parameterIndex, (double) theFloat);
}

@Override
public void setInt(int parameterIndex, int theInt) throws SQLException {
throwIfClosed();
bindLong(parameterIndex, (long) theInt);
}

@Override
public void setLong(int parameterIndex, long theLong) throws SQLException {
throwIfClosed();
bindLong(parameterIndex, theLong);
}

@Override
public void setNull(int parameterIndex, int sqlType) throws SQLException {
throwIfClosed();
bindNullOrString(parameterIndex, null);
}

@Override
public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException {
throwIfClosed();
bindNullOrString(paramIndex, null);
}

@Override
public void setObject(int parameterIndex, Object theObject) throws SQLException {
throwIfClosed();
if (theObject == null) {
setNull(parameterIndex, Types.NULL);
} else {
Expand Down Expand Up @@ -450,38 +429,49 @@ public void setRef(int parameterIndex, Ref theRef) throws SQLException {

@Override
public void setShort(int parameterIndex, short theShort) throws SQLException {
throwIfClosed();
bindLong(parameterIndex, (long) theShort);
}

@Override
public void setString(int parameterIndex, String theString) throws SQLException {
throwIfClosed();
bindNullOrString(parameterIndex, theString);
}

@Override
public void setTime(int parameterIndex, Time theTime) throws SQLException {
throwIfClosed();
bindLong(parameterIndex, theTime == null ? null : theTime.getTime());
if (theTime == null) {
bindNullOrString(parameterIndex, null);
} else {
bindLong(parameterIndex, theTime.getTime());
}
}

@Override
public void setTime(int parameterIndex, Time theTime, Calendar cal) throws SQLException {
throwIfClosed();
bindLong(parameterIndex, theTime == null ? null : theTime.getTime());
if (theTime == null) {
bindNullOrString(parameterIndex, null);
} else {
bindLong(parameterIndex, theTime.getTime());
}
}

@Override
public void setTimestamp(int parameterIndex, Timestamp theTimestamp) throws SQLException {
throwIfClosed();
bindLong(parameterIndex, theTimestamp == null ? null : theTimestamp.getTime());
if (theTimestamp == null) {
bindNullOrString(parameterIndex, null);
} else {
bindLong(parameterIndex, theTimestamp.getTime());
}
}

@Override
public void setTimestamp(int parameterIndex, Timestamp theTimestamp, Calendar cal) throws SQLException {
throwIfClosed();
bindLong(parameterIndex, theTimestamp == null ? null : theTimestamp.getTime());
public void setTimestamp(int parameterIndex, Timestamp theTimestamp, Calendar cal)
throws SQLException {
if (theTimestamp == null) {
bindNullOrString(parameterIndex, null);
} else {
bindLong(parameterIndex, theTimestamp.getTime());
}
}

@Override
Expand All @@ -492,7 +482,6 @@ public void setUnicodeStream(int parameterIndex, InputStream theInputStream, int

@Override
public void setURL(int parameterIndex, URL theURL) throws SQLException {
throwIfClosed();
bindNullOrString(parameterIndex, theURL);
}

Expand All @@ -503,7 +492,6 @@ public void setRowId(int parameterIndex, RowId theRowId) throws SQLException {

@Override
public void setNString(int parameterIndex, String theString) throws SQLException {
throwIfClosed();
bindNullOrString(parameterIndex, theString);
}

Expand Down

0 comments on commit 2d3fdf3

Please sign in to comment.