Mercurial > hg > monetdb-java
changeset 773:2bd1983f1c11
Reduce code by importing java.sql.Date; and remove prefix java.sql. where no longer needed.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Wed, 09 Aug 2023 21:19:21 +0200 (20 months ago) |
parents | 9493dacdd186 |
children | e029af7551b7 |
files | src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java src/main/java/org/monetdb/jdbc/MonetResultSet.java |
diffstat | 2 files changed, 32 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java +++ b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java @@ -18,6 +18,7 @@ import java.nio.CharBuffer; import java.sql.Array; import java.sql.Blob; import java.sql.Clob; +import java.sql.Date; import java.sql.NClob; import java.sql.ParameterMetaData; import java.sql.PreparedStatement; @@ -962,7 +963,7 @@ public class MonetPreparedStatement * @throws SQLException if a database access error occurs */ @Override - public void setDate(final int parameterIndex, final java.sql.Date x) + public void setDate(final int parameterIndex, final Date x) throws SQLException { setDate(parameterIndex, x, null); @@ -983,7 +984,7 @@ public class MonetPreparedStatement * @throws SQLException if a database access error occurs */ @Override - public void setDate(final int parameterIndex, final java.sql.Date x, final Calendar cal) + public void setDate(final int parameterIndex, final Date x, final Calendar cal) throws SQLException { if (x == null) { @@ -1442,7 +1443,7 @@ public class MonetPreparedStatement default: throw new SQLException("Conversion not allowed", "M1M05"); } - } else if (x instanceof java.sql.Date || + } else if (x instanceof Date || x instanceof Timestamp || x instanceof Time || x instanceof Calendar || @@ -1450,16 +1451,14 @@ public class MonetPreparedStatement { switch (targetSqlType) { case Types.DATE: - if (x instanceof java.sql.Date) { - setDate(parameterIndex, (java.sql.Date)x); + if (x instanceof Date) { + setDate(parameterIndex, (Date)x); } else if (x instanceof Timestamp) { - setDate(parameterIndex, new java.sql.Date(((Timestamp)x).getTime())); + setDate(parameterIndex, new Date(((Timestamp)x).getTime())); } else if (x instanceof java.util.Date) { - setDate(parameterIndex, new java.sql.Date( - ((java.util.Date)x).getTime())); + setDate(parameterIndex, new Date(((java.util.Date)x).getTime())); } else if (x instanceof Calendar) { - setDate(parameterIndex, new java.sql.Date( - ((Calendar)x).getTimeInMillis())); + setDate(parameterIndex, new Date(((Calendar)x).getTimeInMillis())); } else { throw new SQLException("Conversion not allowed", "M1M05"); } @@ -1471,11 +1470,9 @@ public class MonetPreparedStatement } else if (x instanceof Timestamp) { setTime(parameterIndex, new Time(((Timestamp)x).getTime())); } else if (x instanceof java.util.Date) { - setTime(parameterIndex, new java.sql.Time( - ((java.util.Date)x).getTime())); + setTime(parameterIndex, new Time(((java.util.Date)x).getTime())); } else if (x instanceof Calendar) { - setTime(parameterIndex, new java.sql.Time( - ((Calendar)x).getTimeInMillis())); + setTime(parameterIndex, new Time(((Calendar)x).getTimeInMillis())); } else { throw new SQLException("Conversion not allowed", "M1M05"); } @@ -1484,14 +1481,12 @@ public class MonetPreparedStatement case Types.TIMESTAMP_WITH_TIMEZONE: if (x instanceof Timestamp) { setTimestamp(parameterIndex, (Timestamp)x); - } else if (x instanceof java.sql.Date) { - setTimestamp(parameterIndex, new Timestamp(((java.sql.Date)x).getTime())); + } else if (x instanceof Date) { + setTimestamp(parameterIndex, new Timestamp(((Date)x).getTime())); } else if (x instanceof java.util.Date) { - setTimestamp(parameterIndex, new java.sql.Timestamp( - ((java.util.Date)x).getTime())); + setTimestamp(parameterIndex, new Timestamp(((java.util.Date)x).getTime())); } else if (x instanceof Calendar) { - setTimestamp(parameterIndex, new java.sql.Timestamp( - ((Calendar)x).getTimeInMillis())); + setTimestamp(parameterIndex, new Timestamp(((Calendar)x).getTimeInMillis())); } else { throw new SQLException("Conversion not allowed", "M1M05"); } @@ -1583,12 +1578,12 @@ public class MonetPreparedStatement } @Override - public void writeDate(java.sql.Date x) throws SQLException { + public void writeDate(Date x) throws SQLException { setDate(paramnr, x); } @Override - public void writeTime(java.sql.Time x) throws SQLException { + public void writeTime(Time x) throws SQLException { setTime(paramnr, x); } @@ -1963,7 +1958,7 @@ public class MonetPreparedStatement // check if the string represents a valid calendar date or time or timestamp to prevent // failing exec #(..., ...) calls which destroy the prepared statement, see bug 6351 if (paramJdbcType == Types.DATE) { - java.sql.Date datum = java.sql.Date.valueOf(x); + Date datum = Date.valueOf(x); } else if (paramJdbcType == Types.TIME || paramJdbcType == Types.TIME_WITH_TIMEZONE) { Time tijdstip = Time.valueOf(x);
--- a/src/main/java/org/monetdb/jdbc/MonetResultSet.java +++ b/src/main/java/org/monetdb/jdbc/MonetResultSet.java @@ -19,6 +19,7 @@ import java.sql.Blob; import java.sql.Clob; import java.sql.Connection; import java.sql.DatabaseMetaData; +import java.sql.Date; import java.sql.NClob; import java.sql.Ref; import java.sql.ResultSet; @@ -1323,7 +1324,7 @@ public class MonetResultSet throw newSQLInvalidColumnIndexException(columnIndex); } - switch(JdbcType) { + switch (JdbcType) { case Types.TINYINT: case Types.SMALLINT: try { @@ -1526,7 +1527,7 @@ public class MonetResultSet return Double.valueOf(getDouble(columnIndex)); } else if (type == byte[].class) { return getBytes(columnIndex); - } else if (type == java.sql.Date.class) { + } else if (type == Date.class) { return getDate(columnIndex, null); } else if (type == Time.class) { return getTime(columnIndex, null); @@ -1607,12 +1608,12 @@ public class MonetResultSet } @Override - public java.sql.Date readDate() throws SQLException { + public Date readDate() throws SQLException { return getDate(colnum, null); } @Override - public java.sql.Time readTime() throws SQLException { + public Time readTime() throws SQLException { return getTime(colnum, null); } @@ -2026,7 +2027,7 @@ public class MonetResultSet java.util.Date pdate = null; final java.text.ParsePosition ppos = new java.text.ParsePosition(0); - switch(JdbcType) { + switch (JdbcType) { case Types.DATE: if (dateFormat == null) { // first time usage, create and keep the dateFormat object for next usage @@ -2167,7 +2168,7 @@ public class MonetResultSet * @see #getDate(int col, Calendar cal) */ @Override - public java.sql.Date getDate(final int columnIndex) throws SQLException { + public Date getDate(final int columnIndex) throws SQLException { return getDate(columnIndex, null); } @@ -2184,7 +2185,7 @@ public class MonetResultSet * @throws SQLException if a database access error occurs */ @Override - public java.sql.Date getDate(final int columnIndex, Calendar cal) + public Date getDate(final int columnIndex, Calendar cal) throws SQLException { checkNotClosed(); @@ -2199,7 +2200,7 @@ public class MonetResultSet // try to convert string directly to a Date object // Note: the string must be in JDBC date escape format: yyyy-[m]m-[d]d try { - return java.sql.Date.valueOf(val); + return Date.valueOf(val); } catch (IllegalArgumentException iae) { // this happens if string doesn't match the format, such as for years < 1000 (including negative years) // in those cases just continue and use slower getJavaDate(cal, columnIndex, Types.DATE) method @@ -2208,7 +2209,7 @@ public class MonetResultSet } if (getJavaDate(cal, columnIndex, Types.DATE) == -1) return null; - return new java.sql.Date(cal.getTimeInMillis()); + return new Date(cal.getTimeInMillis()); } catch (IndexOutOfBoundsException e) { throw newSQLInvalidColumnIndexException(columnIndex); } @@ -2224,7 +2225,7 @@ public class MonetResultSet * @throws SQLException if a database access error occurs */ @Override - public java.sql.Date getDate(final String columnLabel) throws SQLException { + public Date getDate(final String columnLabel) throws SQLException { return getDate(findColumn(columnLabel), null); } @@ -2241,7 +2242,7 @@ public class MonetResultSet * @throws SQLException if a database access error occurs */ @Override - public java.sql.Date getDate(final String columnLabel, final Calendar cal) + public Date getDate(final String columnLabel, final Calendar cal) throws SQLException { return getDate(findColumn(columnLabel), cal); @@ -2989,12 +2990,12 @@ public class MonetResultSet } @Override - public void updateDate(int columnIndex, java.sql.Date x) throws SQLException { + public void updateDate(int columnIndex, Date x) throws SQLException { throw newSQLFeatureNotSupportedException("updateDate"); } @Override - public void updateDate(String columnLabel, java.sql.Date x) throws SQLException { + public void updateDate(String columnLabel, Date x) throws SQLException { throw newSQLFeatureNotSupportedException("updateDate"); }