Mercurial > hg > monetdb-java
changeset 714:ad7b08ef7745
Moving static method getClassForType() from MonetResulSet to MonetDriver class which is a much more logical place.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 05 Jan 2023 00:01:06 +0100 (2023-01-04) |
parents | c3c424a90a42 |
children | a7c7fc58d622 |
files | src/main/java/org/monetdb/jdbc/MonetDriver.java.in src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java src/main/java/org/monetdb/jdbc/MonetResultSet.java src/main/java/org/monetdb/jdbc/MonetResultSetMetaData.java |
diffstat | 4 files changed, 62 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetDriver.java.in +++ b/src/main/java/org/monetdb/jdbc/MonetDriver.java.in @@ -390,6 +390,62 @@ public class MonetDriver implements Driv return Types.OTHER; } + /** + * Returns the Class object for a given java.sql.Types value. + * + * @param type a value from java.sql.Types + * @return a Class object from which an instance would be returned + */ + static final Class<?> getClassForType(final int type) { + /** + * This switch returns the types as objects according to table B-3 from + * Oracle's JDBC specification 4.1 + */ + switch(type) { + case Types.CHAR: + case Types.VARCHAR: + case Types.LONGVARCHAR: + return String.class; + case Types.NUMERIC: + case Types.DECIMAL: + return java.math.BigDecimal.class; + case Types.BOOLEAN: + return Boolean.class; + case Types.TINYINT: + case Types.SMALLINT: + return Short.class; + case Types.INTEGER: + return Integer.class; + case Types.BIGINT: + return Long.class; + case Types.REAL: + return Float.class; + case Types.FLOAT: + case Types.DOUBLE: + return Double.class; + case Types.BINARY: // MonetDB currently does not support these + case Types.VARBINARY: // see treat_blob_as_binary property + case Types.LONGVARBINARY: + return byte[].class; + case Types.DATE: + return java.sql.Date.class; + case Types.TIME: + case Types.TIME_WITH_TIMEZONE: + return java.sql.Time.class; + case Types.TIMESTAMP: + case Types.TIMESTAMP_WITH_TIMEZONE: + return java.sql.Timestamp.class; + case Types.CLOB: + return java.sql.Clob.class; + case Types.BLOB: + return java.sql.Blob.class; + + // all the rest are currently not implemented and used + default: + return String.class; + } + } + private static String TypeMapppingSQL; // cache to optimise getSQLTypeMap() /** * Returns a String usable in an SQL statement to map the server types
--- a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java +++ b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java @@ -736,7 +736,7 @@ public class MonetPreparedStatement if (map != null && map.containsKey(MonetDBType)) { c = (Class)map.get(MonetDBType); } else { - c = MonetResultSet.getClassForType(getColumnType(column)); + c = MonetDriver.getClassForType(getColumnType(column)); } if (c != null) return c.getCanonicalName(); @@ -1072,7 +1072,7 @@ public class MonetPreparedStatement if (map != null && map.containsKey(MonetDBType)) { c = (Class)map.get(MonetDBType); } else { - c = MonetResultSet.getClassForType(getParameterType(param)); + c = MonetDriver.getClassForType(getParameterType(param)); } if (c != null) return c.getCanonicalName();
--- a/src/main/java/org/monetdb/jdbc/MonetResultSet.java +++ b/src/main/java/org/monetdb/jdbc/MonetResultSet.java @@ -1257,62 +1257,6 @@ public class MonetResultSet } /** - * Returns the Class object for a given java.sql.Types value. - * - * @param type a value from java.sql.Types - * @return a Class object from which an instance would be returned - */ - static final Class<?> getClassForType(final int type) { - /** - * This switch returns the types as objects according to table B-3 from - * Oracle's JDBC specification 4.1 - */ - switch(type) { - case Types.CHAR: - case Types.VARCHAR: - case Types.LONGVARCHAR: - return String.class; - case Types.NUMERIC: - case Types.DECIMAL: - return BigDecimal.class; - case Types.BOOLEAN: - return Boolean.class; - case Types.TINYINT: - case Types.SMALLINT: - return Short.class; - case Types.INTEGER: - return Integer.class; - case Types.BIGINT: - return Long.class; - case Types.REAL: - return Float.class; - case Types.FLOAT: - case Types.DOUBLE: - return Double.class; - case Types.BINARY: // MonetDB currently does not support these - case Types.VARBINARY: // see treat_blob_as_binary property - case Types.LONGVARBINARY: - return byte[].class; - case Types.DATE: - return java.sql.Date.class; - case Types.TIME: - case Types.TIME_WITH_TIMEZONE: - return Time.class; - case Types.TIMESTAMP: - case Types.TIMESTAMP_WITH_TIMEZONE: - return Timestamp.class; - case Types.CLOB: - return Clob.class; - case Types.BLOB: - return Blob.class; - - // all the rest are currently not implemented and used - default: - return String.class; - } - } - - /** * Gets the value of the designated column in the current row of this * ResultSet object as an Object in the Java programming language. * @@ -1534,7 +1478,7 @@ public class MonetResultSet } if (type == null) { // fallback to the standard SQL type Class mappings - type = getClassForType(JdbcSQLTypes[columnIndex - 1]); + type = MonetDriver.getClassForType(JdbcSQLTypes[columnIndex - 1]); } if (type == null || type == String.class) {
--- a/src/main/java/org/monetdb/jdbc/MonetResultSetMetaData.java +++ b/src/main/java/org/monetdb/jdbc/MonetResultSetMetaData.java @@ -8,10 +8,9 @@ package org.monetdb.jdbc; +import java.sql.ResultSetMetaData; import java.sql.SQLException; -import java.sql.ResultSetMetaData; import java.sql.Types; -import java.util.Map; /** *<pre> @@ -698,14 +697,14 @@ public final class MonetResultSetMetaDat final String MonetDBType = types[column - 1]; Class<?> type = null; if (conn != null) { - final Map<String,Class<?>> map = conn.getTypeMap(); + final java.util.Map<String,Class<?>> map = conn.getTypeMap(); if (map != null && map.containsKey(MonetDBType)) { type = (Class)map.get(MonetDBType); } } if (type == null) { // fallback to the standard SQL type Class mappings - type = MonetResultSet.getClassForType(JdbcSQLTypes[column - 1]); + type = MonetDriver.getClassForType(JdbcSQLTypes[column - 1]); } if (type != null) { return type.getCanonicalName();