From 874b6e6b377dd8d497364aaa463cafbd4999284f Mon Sep 17 00:00:00 2001 From: lancea Date: Wed, 6 Feb 2013 14:15:05 -0500 Subject: [PATCH] 8006505: additional changes for JSR 310 support Reviewed-by: naoto, ulfzibis --- src/share/classes/java/sql/JDBCType.java | 12 ++++++- src/share/classes/java/sql/SQLInput.java | 36 ++++++++++++++++++- src/share/classes/java/sql/SQLOutput.java | 42 +++++++++++++++++++++-- src/share/classes/java/sql/Types.java | 18 ++++++++++ 4 files changed, 104 insertions(+), 4 deletions(-) diff --git a/src/share/classes/java/sql/JDBCType.java b/src/share/classes/java/sql/JDBCType.java index f14530596..74ee8e016 100644 --- a/src/share/classes/java/sql/JDBCType.java +++ b/src/share/classes/java/sql/JDBCType.java @@ -190,7 +190,17 @@ public enum JDBCType implements SQLType { /** * Identifies the generic SQL type {@code REF_CURSOR}. */ - REF_CURSOR(Types.REF_CURSOR); + REF_CURSOR(Types.REF_CURSOR), + + /** + * Identifies the generic SQL type {@code TIME_WITH_TIMEZONE}. + */ + TIME_WITH_TIMEZONE(Types.TIME_WITH_TIMEZONE), + + /** + * Identifies the generic SQL type {@code TIMESTAMP_WITH_TIMEZONE}. + */ + TIMESTAMP_WITH_TIMEZONE(Types.TIMESTAMP_WITH_TIMEZONE); /** * The Integer value for the JDBCType. It maps to a value in diff --git a/src/share/classes/java/sql/SQLInput.java b/src/share/classes/java/sql/SQLInput.java index c607e83cb..8d2540dc4 100644 --- a/src/share/classes/java/sql/SQLInput.java +++ b/src/share/classes/java/sql/SQLInput.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -421,4 +421,38 @@ public interface SQLInput { */ RowId readRowId() throws SQLException; + //--------------------------JDBC 4.2 ----------------------------- + + /** + * Reads the next attribute in the stream and returns it as an + * {@code Object} in the Java programming language. The + * actual type of the object returned is determined by the specified + * Java data type, and any customizations present in this + * stream's type map. + * + *

A type map is registered with the stream by the JDBC driver before the + * stream is passed to the application. + * + *

When the attribute at the head of the stream is an SQL {@code NULL} + * the method returns {@code null}. If the attribute is an SQL + * structured or distinct + * type, it determines the SQL type of the attribute at the head of the stream. + * If the stream's type map has an entry for that SQL type, the driver + * constructs an object of the appropriate class and calls the method + * {@code SQLData.readSQL} on that object, which reads additional data from the + * stream, using the protocol described for that method. + *

+ * The default implementation will throw {@code SQLFeatureNotSupportedException} + * + * @param type Class representing the Java data type to convert the attribute to. + * @return the attribute at the head of the stream as an {@code Object} in the + * Java programming language;{@code null} if the attribute is SQL {@code NULL} + * @exception SQLException if a database access error occurs + * @exception SQLFeatureNotSupportedException if the JDBC driver does not support + * this method + * @since 1.8 + */ + default T readObject(Class type) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } } diff --git a/src/share/classes/java/sql/SQLOutput.java b/src/share/classes/java/sql/SQLOutput.java index 8aa1d1453..0edfc998a 100644 --- a/src/share/classes/java/sql/SQLOutput.java +++ b/src/share/classes/java/sql/SQLOutput.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -272,7 +272,7 @@ package java.sql; * Otherwise, it calls the SQLData.writeSQL * method of the given object, which * writes the object's attributes to the stream. - * The implementation of the method SQLData.writeSQ + * The implementation of the method SQLData.writeSQL * calls the appropriate SQLOutput writer method(s) * for writing each of the object's attributes in order. * The attributes must be read from an SQLInput @@ -433,5 +433,43 @@ package java.sql; */ void writeSQLXML(SQLXML x) throws SQLException; + //--------------------------JDBC 4.2 ----------------------------- + + /** + * Writes to the stream the data contained in the given object. The + * object will be converted to the specified targetSqlType + * before being sent to the stream. + *

+ * When the {@code object} is {@code null}, this + * method writes an SQL {@code NULL} to the stream. + *

+ * If the object has a custom mapping (is of a class implementing the + * interface {@code SQLData}), + * the JDBC driver should call the method {@code SQLData.writeSQL} to + * write it to the SQL data stream. + * If, on the other hand, the object is of a class implementing + * {@code Ref}, {@code Blob}, {@code Clob}, {@code NClob}, + * {@code Struct}, {@code java.net.URL}, + * or {@code Array}, the driver should pass it to the database as a + * value of the corresponding SQL type. + *

+ * The default implementation will throw {@code SQLFeatureNotSupportedException} + * + * @param x the object containing the input parameter value + * @param targetSqlType the SQL type to be sent to the database. + * @exception SQLException if a database access error occurs or + * if the Java Object specified by x is an InputStream + * or Reader object and the value of the scale parameter is less + * than zero + * @exception SQLFeatureNotSupportedException if + * the JDBC driver does not support this data type + * @see JDBCType + * @see SQLType + * @since 1.8 + */ + default void writeObject(Object x, SQLType targetSqlType) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } } + diff --git a/src/share/classes/java/sql/Types.java b/src/share/classes/java/sql/Types.java index d6fc80a32..f12ff0dc1 100644 --- a/src/share/classes/java/sql/Types.java +++ b/src/share/classes/java/sql/Types.java @@ -319,6 +319,24 @@ public class Types { */ public static final int REF_CURSOR = 2012; + /** + * The constant in the Java programming language, sometimes referred to + * as a type code, that identifies the generic SQL type + * {@code TIME WITH TIMEZONE}. + * + * @since 1.8 + */ + public static final int TIME_WITH_TIMEZONE = 2013; + + /** + * The constant in the Java programming language, sometimes referred to + * as a type code, that identifies the generic SQL type + * {@code TIMESTAMP WITH TIMEZONE}. + * + * @since 1.8 + */ + public static final int TIMESTAMP_WITH_TIMEZONE = 2014; + // Prevent instantiation private Types() {} } -- GitLab