Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
landawn committed Aug 18, 2022
1 parent 9915911 commit a8aece2
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 15 deletions.
70 changes: 62 additions & 8 deletions src/main/java/com/landawn/abacus/jdbc/NamedQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ public NamedQuery setBoolean(String parameterName, boolean x) throws SQLExceptio
* @throws SQLException the SQL exception
*/
public NamedQuery setBoolean(String parameterName, Boolean x) throws SQLException {
setBoolean(parameterName, N.defaultIfNull(x));
if (x == null) {
setNull(parameterName, java.sql.Types.BOOLEAN);
} else {
setBoolean(parameterName, x.booleanValue());
}

return this;
}
Expand Down Expand Up @@ -351,7 +355,11 @@ public NamedQuery setByte(String parameterName, byte x) throws SQLException {
* @throws SQLException the SQL exception
*/
public NamedQuery setByte(String parameterName, Byte x) throws SQLException {
setByte(parameterName, N.defaultIfNull(x));
if (x == null) {
setNull(parameterName, java.sql.Types.TINYINT);
} else {
setByte(parameterName, x.byteValue());
}

return this;
}
Expand Down Expand Up @@ -419,7 +427,11 @@ public NamedQuery setShort(String parameterName, short x) throws SQLException {
* @throws SQLException the SQL exception
*/
public NamedQuery setShort(String parameterName, Short x) throws SQLException {
setShort(parameterName, N.defaultIfNull(x));
if (x == null) {
setNull(parameterName, java.sql.Types.SMALLINT);
} else {
setShort(parameterName, x.shortValue());
}

return this;
}
Expand Down Expand Up @@ -487,17 +499,47 @@ public NamedQuery setInt(String parameterName, int x) throws SQLException {
* @throws SQLException the SQL exception
*/
public NamedQuery setInt(String parameterName, Integer x) throws SQLException {
setInt(parameterName, N.defaultIfNull(x));
if (x == null) {
setNull(parameterName, java.sql.Types.INTEGER);
} else {
setInt(parameterName, x.intValue());
}

return this;
}

/**
*
* @param parameterName
* @param x
* @return
* @throws SQLException
* @deprecated generally {@code char} should be saved as {@code String} in db.
* @see #setString(String, char)
*/
@Deprecated
public NamedQuery setInt(String parameterName, char x) throws SQLException {
return setInt(parameterName, (int) x);
}

/**
*
* @param parameterName
* @param x
* @return
* @throws SQLException
* @deprecated generally {@code char} should be saved as {@code String} in db.
* @see #setString(String, Character)
*/
@Deprecated
public NamedQuery setInt(String parameterName, Character x) throws SQLException {
return setInt(parameterName, x == null ? 0 : (int) x.charValue());
if (x == null) {
setNull(parameterName, java.sql.Types.INTEGER);
} else {
setInt(parameterName, x.charValue());
}

return this;
}

/**
Expand Down Expand Up @@ -563,7 +605,11 @@ public NamedQuery setLong(String parameterName, long x) throws SQLException {
* @throws SQLException the SQL exception
*/
public NamedQuery setLong(String parameterName, Long x) throws SQLException {
setLong(parameterName, N.defaultIfNull(x));
if (x == null) {
setNull(parameterName, java.sql.Types.BIGINT);
} else {
setLong(parameterName, x.longValue());
}

return this;
}
Expand Down Expand Up @@ -631,7 +677,11 @@ public NamedQuery setFloat(String parameterName, float x) throws SQLException {
* @throws SQLException the SQL exception
*/
public NamedQuery setFloat(String parameterName, Float x) throws SQLException {
setFloat(parameterName, N.defaultIfNull(x));
if (x == null) {
setNull(parameterName, java.sql.Types.FLOAT);
} else {
setFloat(parameterName, x.floatValue());
}

return this;
}
Expand Down Expand Up @@ -699,7 +749,11 @@ public NamedQuery setDouble(String parameterName, double x) throws SQLException
* @throws SQLException the SQL exception
*/
public NamedQuery setDouble(String parameterName, Double x) throws SQLException {
setDouble(parameterName, N.defaultIfNull(x));
if (x == null) {
setNull(parameterName, java.sql.Types.DOUBLE);
} else {
setDouble(parameterName, x.doubleValue());
}

return this;
}
Expand Down
42 changes: 35 additions & 7 deletions src/main/java/com/landawn/abacus/jdbc/PreparedCallableQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ public PreparedCallableQuery setBoolean(String parameterName, boolean x) throws
* @throws SQLException the SQL exception
*/
public PreparedCallableQuery setBoolean(String parameterName, Boolean x) throws SQLException {
cstmt.setBoolean(parameterName, N.defaultIfNull(x));
if (x == null) {
cstmt.setNull(parameterName, java.sql.Types.BOOLEAN);
} else {
cstmt.setBoolean(parameterName, x.booleanValue());
}

return this;
}
Expand Down Expand Up @@ -166,7 +170,11 @@ public PreparedCallableQuery setByte(String parameterName, byte x) throws SQLExc
* @throws SQLException the SQL exception
*/
public PreparedCallableQuery setByte(String parameterName, Byte x) throws SQLException {
cstmt.setByte(parameterName, N.defaultIfNull(x));
if (x == null) {
cstmt.setNull(parameterName, java.sql.Types.TINYINT);
} else {
cstmt.setByte(parameterName, x.byteValue());
}

return this;
}
Expand Down Expand Up @@ -194,7 +202,11 @@ public PreparedCallableQuery setShort(String parameterName, short x) throws SQLE
* @throws SQLException the SQL exception
*/
public PreparedCallableQuery setShort(String parameterName, Short x) throws SQLException {
cstmt.setShort(parameterName, N.defaultIfNull(x));
if (x == null) {
cstmt.setNull(parameterName, java.sql.Types.SMALLINT);
} else {
cstmt.setShort(parameterName, x.shortValue());
}

return this;
}
Expand Down Expand Up @@ -222,7 +234,11 @@ public PreparedCallableQuery setInt(String parameterName, int x) throws SQLExcep
* @throws SQLException the SQL exception
*/
public PreparedCallableQuery setInt(String parameterName, Integer x) throws SQLException {
cstmt.setInt(parameterName, N.defaultIfNull(x));
if (x == null) {
cstmt.setNull(parameterName, java.sql.Types.INTEGER);
} else {
cstmt.setInt(parameterName, x.intValue());
}

return this;
}
Expand Down Expand Up @@ -250,7 +266,11 @@ public PreparedCallableQuery setLong(String parameterName, long x) throws SQLExc
* @throws SQLException the SQL exception
*/
public PreparedCallableQuery setLong(String parameterName, Long x) throws SQLException {
cstmt.setLong(parameterName, N.defaultIfNull(x));
if (x == null) {
cstmt.setNull(parameterName, java.sql.Types.BIGINT);
} else {
cstmt.setLong(parameterName, x.longValue());
}

return this;
}
Expand Down Expand Up @@ -278,7 +298,11 @@ public PreparedCallableQuery setFloat(String parameterName, float x) throws SQLE
* @throws SQLException the SQL exception
*/
public PreparedCallableQuery setFloat(String parameterName, Float x) throws SQLException {
cstmt.setFloat(parameterName, N.defaultIfNull(x));
if (x == null) {
cstmt.setNull(parameterName, java.sql.Types.FLOAT);
} else {
cstmt.setFloat(parameterName, x.floatValue());
}

return this;
}
Expand Down Expand Up @@ -306,7 +330,11 @@ public PreparedCallableQuery setDouble(String parameterName, double x) throws SQ
* @throws SQLException the SQL exception
*/
public PreparedCallableQuery setDouble(String parameterName, Double x) throws SQLException {
cstmt.setDouble(parameterName, N.defaultIfNull(x));
if (x == null) {
cstmt.setNull(parameterName, java.sql.Types.DOUBLE);
} else {
cstmt.setDouble(parameterName, x.doubleValue());
}

return this;
}
Expand Down

0 comments on commit a8aece2

Please sign in to comment.