diff --git a/src/share/classes/com/sun/rowset/CachedRowSetImpl.java b/src/share/classes/com/sun/rowset/CachedRowSetImpl.java index dde5b7b271c85fbbb6c9ea88022b76fc7c9a788e..cc3ebbfc21b4d5b104a21d986ec84bad1df5c01f 100644 --- a/src/share/classes/com/sun/rowset/CachedRowSetImpl.java +++ b/src/share/classes/com/sun/rowset/CachedRowSetImpl.java @@ -765,7 +765,6 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern if( conn != null){ // JDBC 4.0 mandates as does the Java EE spec that all DataBaseMetaData methods // must be implemented, therefore, the previous fix for 5055528 is being backed out - dbmslocatorsUpdateCopy = conn.getMetaData().locatorsUpdateCopy(); } } @@ -10131,5 +10130,14 @@ a } + //------------------------- JDBC 4.1 ----------------------------------- + public T getObject(int columnIndex, Class type) throws SQLException { + throw new SQLFeatureNotSupportedException("Not supported yet."); + } + + public T getObject(String columnLabel, Class type) throws SQLException { + throw new SQLFeatureNotSupportedException("Not supported yet."); + } + static final long serialVersionUID =1884577171200622428L; } diff --git a/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java b/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java index 5ad82a8bd3ea30a2bfdd98eec28fdcea48474d17..34178d4984d244621b38c6263c9198a42a5d7949 100644 --- a/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java +++ b/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java @@ -7034,4 +7034,14 @@ a } static final long serialVersionUID = -3591946023893483003L; + + //------------------------- JDBC 4.1 ----------------------------------- + + public T getObject(int columnIndex, Class type) throws SQLException { + throw new SQLFeatureNotSupportedException("Not supported yet."); + } + + public T getObject(String columnLabel, Class type) throws SQLException { + throw new SQLFeatureNotSupportedException("Not supported yet."); + } } diff --git a/src/share/classes/java/sql/CallableStatement.java b/src/share/classes/java/sql/CallableStatement.java index c328858de3694b96d350bdcf90d9762b48365560..2f2a77594e113a74e0e54cd06c947fe19cffbaa1 100644 --- a/src/share/classes/java/sql/CallableStatement.java +++ b/src/share/classes/java/sql/CallableStatement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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 @@ -2436,4 +2436,64 @@ public interface CallableStatement extends PreparedStatement { */ void setNClob(String parameterName, Reader reader) throws SQLException; + + //------------------------- JDBC 4.1 ----------------------------------- + + + /** + *

Returns an object representing the value of OUT parameter + * {@code parameterIndex} and will convert from the + * SQL type of the parameter to the requested Java data type, if the + * conversion is supported. If the conversion is not + * supported or null is specified for the type, a + * SQLException is thrown. + *

+ * At a minimum, an implementation must support the conversions defined in + * Appendix B, Table B-3 and conversion of appropriate user defined SQL + * types to a Java type which implements {@code SQLData}, or {@code Struct}. + * Additional conversions may be supported and are vendor defined. + * + * @param parameterIndex the first parameter is 1, the second is 2, and so on + * @param type Class representing the Java data type to convert the + * designated parameter to. + * @return an instance of {@code type} holding the OUT parameter value + * @throws SQLException if conversion is not supported, type is null or + * another error occurs. The getCause() method of the + * exception may provide a more detailed exception, for example, if + * a conversion error occurs + * @throws SQLFeatureNotSupportedException if the JDBC driver does not support + * this method + * @since 1.7 + */ + public T getObject(int parameterIndex, Class type) throws SQLException; + + + /** + *

Returns an object representing the value of OUT parameter + * {@code parameterName} and will convert from the + * SQL type of the parameter to the requested Java data type, if the + * conversion is supported. If the conversion is not + * supported or null is specified for the type, a + * SQLException is thrown. + *

+ * At a minimum, an implementation must support the conversions defined in + * Appendix B, Table B-3 and conversion of appropriate user defined SQL + * types to a Java type which implements {@code SQLData}, or {@code Struct}. + * Additional conversions may be supported and are vendor defined. + * + * @param parameterName the name of the parameter + * @param type Class representing the Java data type to convert + * the designated parameter to. + * @return an instance of {@code type} holding the OUT parameter + * value + * @throws SQLException if conversion is not supported, type is null or + * another error occurs. The getCause() method of the + * exception may provide a more detailed exception, for example, if + * a conversion error occurs + * @throws SQLFeatureNotSupportedException if the JDBC driver does not support + * this method + * @since 1.7 + */ + public T getObject(String parameterName, Class type) throws SQLException; + } diff --git a/src/share/classes/java/sql/Connection.java b/src/share/classes/java/sql/Connection.java index b850e25a38da9561a9ca724e33570a978d4fa190..9b6706562ba7e2b2a81974370f87c5702baded95 100644 --- a/src/share/classes/java/sql/Connection.java +++ b/src/share/classes/java/sql/Connection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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 @@ -26,6 +26,7 @@ package java.sql; import java.util.Properties; +import java.util.concurrent.Executor; /** *

A connection (session) with a specific @@ -38,7 +39,7 @@ import java.util.Properties; * information is obtained with the getMetaData method. * *

Note: When configuring a Connection, JDBC applications - * should use the appropritate Connection method such as + * should use the appropriate Connection method such as * setAutoCommit or setTransactionIsolation. * Applications should not invoke SQL commands directly to change the connection's * configuration when there is a JDBC method available. By default a Connection object is in @@ -80,7 +81,7 @@ import java.util.Properties; * @see ResultSet * @see DatabaseMetaData */ -public interface Connection extends Wrapper { +public interface Connection extends Wrapper, AutoCloseable { /** * Creates a Statement object for sending @@ -347,6 +348,13 @@ public interface Connection extends Wrapper { *

* If the driver does not support catalogs, it will * silently ignore this request. + *

+ * Calling {@code setCatalog} has no effect on previously created or prepared + * {@code Statement} objects. It is implementation defined whether a DBMS + * prepare operation takes place immediately when the {@code Connection} + * method {@code prepareStatement} or {@code prepareCall} is invoked. + * For maximum portability, {@code setCatalog} should be called before a + * {@code Statement} is created or prepared. * * @param catalog the name of a catalog (subspace in this * Connection object's database) in which to work @@ -598,7 +606,17 @@ public interface Connection extends Wrapper { * Connection object. * Unless the application has added an entry, the type map returned * will be empty. - * + *

+ * You must invoke setTypeMap after making changes to the + * Map object returned from + * getTypeMap as a JDBC driver may create an internal + * copy of the Map object passed to setTypeMap: + *

+ *

+     *      Map<String,Class<?>> myMap = con.getTypeMap();
+     *      myMap.put("mySchemaName.ATHLETES", Athletes.class);
+     *      con.setTypeMap(myMap);
+     * 
* @return the java.util.Map object associated * with this Connection object * @exception SQLException if a database access error occurs @@ -614,7 +632,16 @@ public interface Connection extends Wrapper { * Installs the given TypeMap object as the type map for * this Connection object. The type map will be used for the * custom mapping of SQL structured types and distinct types. - * + *

+ * You must set the the values for the TypeMap prior to + * callng setMap as a JDBC driver may create an internal copy + * of the TypeMap: + *

+ *

+     *      Map myMap<String,Class<?>> = new HashMap<String,Class<?>>();
+     *      myMap.put("mySchemaName.ATHLETES", Athletes.class);
+     *      con.setTypeMap(myMap);
+     * 
* @param map the java.util.Map object to install * as the replacement for this Connection * object's default type map @@ -1274,4 +1301,186 @@ SQLException; */ Struct createStruct(String typeName, Object[] attributes) throws SQLException; + + //--------------------------JDBC 4.1 ----------------------------- + + /** + * Sets the given schema name to access. + *

+ * If the driver does not support schemas, it will + * silently ignore this request. + *

+ * Calling {@code setSchema} has no effect on previously created or prepared + * {@code Statement} objects. It is implementation defined whether a DBMS + * prepare operation takes place immediately when the {@code Connection} + * method {@code prepareStatement} or {@code prepareCall} is invoked. + * For maximum portability, {@code setSchema} should be called before a + * {@code Statement} is created or prepared. + * + * @param schema the name of a schema in which to work + * @exception SQLException if a database access error occurs + * or this method is called on a closed connection + * @see #getSchema + * @since 1.7 + */ + void setSchema(String schema) throws SQLException; + + /** + * Retrieves this Connection object's current schema name. + * + * @return the current schema name or null if there is none + * @exception SQLException if a database access error occurs + * or this method is called on a closed connection + * @see #setSchema + * @since 1.7 + */ + String getSchema() throws SQLException; + + /** + * Terminates an open connection. Calling abort results in: + *

    + *
  • The connection marked as closed + *
  • Closes any physical connection to the database + *
  • Releases resources used by the connection + *
  • Insures that any thread that is currently accessing the connection + * will either progress to completion or throw an SQLException. + *
+ *

+ * Calling abort marks the connection closed and releases any + * resources. Calling abort on a closed connection is a + * no-op. + *

+ * It is possible that the aborting and releasing of the resources that are + * held by the connection can take an extended period of time. When the + * abort method returns, the connection will have been marked as + * closed and the Executor that was passed as a parameter to abort + * may still be executing tasks to release resources. + *

+ * This method checks to see that there is an SQLPermission + * object before allowing the method to proceed. If a + * SecurityManager exists and its + * checkPermission method denies calling abort, + * this method throws a + * java.lang.SecurityException. + * @param executor The Executor implementation which will + * be used by abort. + * @throws java.sql.SQLException if a database access error occurs or + * the {@code executor} is {@code null}, + * @throws java.lang.SecurityException if a security manager exists and its + * checkPermission method denies calling abort + * @see SecurityManager#checkPermission + * @see Executor + * @since 1.7 + */ + void abort(Executor executor) throws SQLException; + + /** + * + * Sets the maximum period a Connection or + * objects created from the Connection + * will wait for the database to reply to any one request. If any + * request remains unanswered, the waiting method will + * return with a SQLException, and the Connection + * or objects created from the Connection will be marked as + * closed. Any subsequent use of + * the objects, with the exception of the close, + * isClosed or Connection.isValid + * methods, will result in a SQLException. + *

+ * Note: This method is intended to address a rare but serious + * condition where network partitions can cause threads issuing JDBC calls + * to hang uninterruptedly in socket reads, until the OS TCP-TIMEOUT + * (typically 10 minutes). This method is related to the + * {@link #abort abort() } method which provides an administrator + * thread a means to free any such threads in cases where the + * JDBC connection is accessible to the administrator thread. + * The setNetworkTimeout method will cover cases where + * there is no administrator thread, or it has no access to the + * connection. This method is severe in it's effects, and should be + * given a high enough value so it is never triggered before any more + * normal timeouts, such as transaction timeouts. + *

+ * JDBC driver implementations may also choose to support the + * {@code setNetworkTimeout} method to impose a limit on database + * response time, in environments where no network is present. + *

+ * Drivers may internally implement some or all of their API calls with + * multiple internal driver-database transmissions, and it is left to the + * driver implementation to determine whether the limit will be + * applied always to the response to the API call, or to any + * single request made during the API call. + *

+ * + * This method can be invoked more than once, such as to set a limit for an + * area of JDBC code, and to reset to the default on exit from this area. + * Invocation of this method has no impact on already outstanding + * requests. + *

+ * The {@code Statement.setQueryTimeout()} timeout value is independent of the + * timeout value specified in {@code setNetworkTimeout}. If the query timeout + * expires before the network timeout then the + * statement execution will be canceled. If the network is still + * active the result will be that both the statement and connection + * are still usable. However if the network timeout expires before + * the query timeout or if the statement timeout fails due to network + * problems, the connection will be marked as closed, any resources held by + * the connection will be released and both the connection and + * statement will be unusable. + *

+ * When the driver determines that the {@code setNetworkTimeout} timeout + * value has expired, the JDBC driver marks the connection + * closed and releases any resources held by the connection. + *

+ * + * This method checks to see that there is an SQLPermission + * object before allowing the method to proceed. If a + * SecurityManager exists and its + * checkPermission method denies calling + * setNetworkTimeout, this method throws a + * java.lang.SecurityException. + * + * @param executor The Executor implementation which will + * be used by setNetworkTimeout. + * @param milliseconds The time in milliseconds to wait for the database + * operation + * to complete. If the JDBC driver does not support milliseconds, the + * JDBC driver will round the value up to the nearest second. If the + * timeout period expires before the operation + * completes, a SQLException will be thrown. + * A value of 0 indicates that there is not timeout for database operations. + * @throws java.sql.SQLException if a database access error occurs, this + * method is called on a closed connection, + * the {@code executor} is {@code null}, + * or the value specified for seconds is less than 0. + * @throws java.lang.SecurityException if a security manager exists and its + * checkPermission method denies calling + * setNetworkTimeout. + * @exception SQLFeatureNotSupportedException if the JDBC driver does not support + * this method + * @see SecurityManager#checkPermission + * @see Statement#setQueryTimeout + * @see #getNetworkTimeout + * @see #abort + * @see Executor + * @since 1.7 + */ + void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException; + + + /** + * Retrieves the number of milliseconds the driver will + * wait for a database request to complete. + * If the limit is exceeded, a + * SQLException is thrown. + * + * @return the current timeout limit in milliseconds; zero means there is + * no limit + * @throws SQLException if a database access error occurs or + * this method is called on a closed Connection + * @exception SQLFeatureNotSupportedException if the JDBC driver does not support + * this method + * @see #setNetworkTimeout + * @since 1.7 + */ + int getNetworkTimeout() throws SQLException; } diff --git a/src/share/classes/java/sql/DatabaseMetaData.java b/src/share/classes/java/sql/DatabaseMetaData.java index 0792302620331bbc6c8f036bf496c500d60a6cfe..3fda3f9f5e6431a26f60c7dfbefbbc338a360d70 100644 --- a/src/share/classes/java/sql/DatabaseMetaData.java +++ b/src/share/classes/java/sql/DatabaseMetaData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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 @@ -1342,10 +1342,10 @@ public interface DatabaseMetaData extends Wrapper { * defined. *

  • IS_NULLABLE String => ISO rules are used to determine the nullability for a column. *
      - *
    • YES --- if the parameter can include NULLs - *
    • NO --- if the parameter cannot include NULLs + *
    • YES --- if the column can include NULLs + *
    • NO --- if the column cannot include NULLs *
    • empty string --- if the nullability for the - * parameter is unknown + * column is unknown *
    *
  • SPECIFIC_NAME String => the name which uniquely identifies this procedure within its schema. * @@ -1610,17 +1610,17 @@ public interface DatabaseMetaData extends Wrapper { * (starting at 1) *
  • IS_NULLABLE String => ISO rules are used to determine the nullability for a column. *
      - *
    • YES --- if the parameter can include NULLs - *
    • NO --- if the parameter cannot include NULLs + *
    • YES --- if the column can include NULLs + *
    • NO --- if the column cannot include NULLs *
    • empty string --- if the nullability for the - * parameter is unknown + * column is unknown *
    - *
  • SCOPE_CATLOG String => catalog of table that is the scope + *
  • SCOPE_CATALOG String => catalog of table that is the scope * of a reference attribute (null if DATA_TYPE isn't REF) *
  • SCOPE_SCHEMA String => schema of table that is the scope * of a reference attribute (null if the DATA_TYPE isn't REF) *
  • SCOPE_TABLE String => table name that this the scope - * of a reference attribure (null if the DATA_TYPE isn't REF) + * of a reference attribute (null if the DATA_TYPE isn't REF) *
  • SOURCE_DATA_TYPE short => source type of a distinct type or user-generated * Ref type, SQL type from java.sql.Types (null if DATA_TYPE * isn't DISTINCT or user-generated REF) @@ -1629,11 +1629,16 @@ public interface DatabaseMetaData extends Wrapper { *
  • YES --- if the column is auto incremented *
  • NO --- if the column is not auto incremented *
  • empty string --- if it cannot be determined whether the column is auto incremented - * parameter is unknown + * + *
  • IS_GENERATEDCOLUMN String => Indicates whether this is a generated column + *
      + *
    • YES --- if this a generated column + *
    • NO --- if this not a generated column + *
    • empty string --- if it cannot be determined whether this is a generated column *
    * * - *

    The COLUMN_SIZE column the specified column size for the given column. + *

    The COLUMN_SIZE column specifies the column size for the given column. * For numeric data, this is the maximum precision. For character data, this is the length in characters. * For datetime datatypes, this is the length in characters of the String representation (assuming the * maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype, @@ -3186,7 +3191,7 @@ public interface DatabaseMetaData extends Wrapper { * Retrieves whether this database supports statement pooling. * * @return true if so; false otherwise - * @throws SQLExcpetion if a database access error occurs + * @throws SQLException if a database access error occurs * @since 1.4 */ boolean supportsStatementPooling() throws SQLException; @@ -3568,4 +3573,83 @@ public interface DatabaseMetaData extends Wrapper { */ int functionReturnsTable = 2; + //--------------------------JDBC 4.1 ----------------------------- + + /** + * Retrieves a description of the pseudo or hidden columns available + * in a given table within the specified catalog and schema. + * Psuedo or hidden columns may not always be stored within + * a table and are not visible in a ResultSet unless they are + * specified in the query's outermost SELECT list. Psuedo or hidden + * columns may not necessarily be able to be modified. If there are + * no pseudo or hidden columns, an empty ResultSet is returned. + * + *

    Only column descriptions matching the catalog, schema, table + * and column name criteria are returned. They are ordered by + * TABLE_CAT,TABLE_SCHEM, TABLE_NAME + * and COLUMN_NAME. + * + *

    Each column description has the following columns: + *

      + *
    1. TABLE_CAT String => table catalog (may be null) + *
    2. TABLE_SCHEM String => table schema (may be null) + *
    3. TABLE_NAME String => table name + *
    4. COLUMN_NAME String => column name + *
    5. DATA_TYPE int => SQL type from java.sql.Types + *
    6. COLUMN_SIZE int => column size. + *
    7. DECIMAL_DIGITS int => the number of fractional digits. Null is returned for data types where + * DECIMAL_DIGITS is not applicable. + *
    8. NUM_PREC_RADIX int => Radix (typically either 10 or 2) + *
    9. COLUMN_USAGE String => The allowed usage for the column. The + * value returned will correspond to the enum name returned by {@link PseudoColumnUsage#name PseudoColumnUsage.name()} + *
    10. REMARKS String => comment describing column (may be null) + *
    11. CHAR_OCTET_LENGTH int => for char types the + * maximum number of bytes in the column + *
    12. IS_NULLABLE String => ISO rules are used to determine the nullability for a column. + *
        + *
      • YES --- if the column can include NULLs + *
      • NO --- if the column cannot include NULLs + *
      • empty string --- if the nullability for the column is unknown + *
      + *
    + * + *

    The COLUMN_SIZE column specifies the column size for the given column. + * For numeric data, this is the maximum precision. For character data, this is the length in characters. + * For datetime datatypes, this is the length in characters of the String representation (assuming the + * maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype, + * this is the length in bytes. Null is returned for data types where the + * column size is not applicable. + * + * @param catalog a catalog name; must match the catalog name as it + * is stored in the database; "" retrieves those without a catalog; + * null means that the catalog name should not be used to narrow + * the search + * @param schemaPattern a schema name pattern; must match the schema name + * as it is stored in the database; "" retrieves those without a schema; + * null means that the schema name should not be used to narrow + * the search + * @param tableNamePattern a table name pattern; must match the + * table name as it is stored in the database + * @param columnNamePattern a column name pattern; must match the column + * name as it is stored in the database + * @return ResultSet - each row is a column description + * @exception SQLException if a database access error occurs + * @see PseudoColumnUsage + * @since 1.7 + */ + ResultSet getPseudoColumns(String catalog, String schemaPattern, + String tableNamePattern, String columnNamePattern) + throws SQLException; + + /** + * Retrieves whether a generated key will always be returned if the column + * name(s) or indexe(s) specified for the auto generated key column(s) + * are valid and the statement succeeds. The key that is returned may or + * may not be based on the column(s) for the auto generated key. + * Consult your JDBC driver documentation for additional details. + * @return true if so; false otherwise + * @exception SQLException if a database access error occurs + * @since 1.7 + */ + boolean generatedKeyAlwaysReturned() throws SQLException; } diff --git a/src/share/classes/java/sql/Date.java b/src/share/classes/java/sql/Date.java index 7c2356e75c2bd61dfd87dbbf8da0619b53f5f266..1d82ab36a1b2eaa43796401eec71f78779190998 100644 --- a/src/share/classes/java/sql/Date.java +++ b/src/share/classes/java/sql/Date.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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 @@ -96,11 +96,12 @@ public class Date extends java.util.Date { * a Date value. * * @param s a String object representing a date in - * in the format "yyyy-mm-dd" + * in the format "yyyy-[m]m-[d]d". The leading zero for mm + * and dd may also be omitted. * @return a java.sql.Date object representing the * given date * @throws IllegalArgumentException if the date given is not in the - * JDBC date escape format (yyyy-mm-dd) + * JDBC date escape format (yyyy-[m]m-[d]d) */ public static Date valueOf(String s) { final int YEAR_LENGTH = 4; @@ -123,8 +124,9 @@ public class Date extends java.util.Date { String yyyy = s.substring(0, firstDash); String mm = s.substring(firstDash + 1, secondDash); String dd = s.substring(secondDash + 1); - if (yyyy.length() == YEAR_LENGTH && mm.length() == MONTH_LENGTH && - dd.length() == DAY_LENGTH) { + if (yyyy.length() == YEAR_LENGTH && + (mm.length() >= 1 && mm.length() <= MONTH_LENGTH) && + (dd.length() >= 1 && dd.length() <= DAY_LENGTH)) { int year = Integer.parseInt(yyyy); int month = Integer.parseInt(mm); int day = Integer.parseInt(dd); diff --git a/src/share/classes/java/sql/Driver.java b/src/share/classes/java/sql/Driver.java index 8325452534cb9f14c5114036a1d3206b4e81ace6..4abc6b3c81f213718408b9a81c9fb1bd13963491 100644 --- a/src/share/classes/java/sql/Driver.java +++ b/src/share/classes/java/sql/Driver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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 @@ -25,6 +25,8 @@ package java.sql; +import java.util.logging.Logger; + /** * The interface that every driver class must implement. *

    The Java SQL framework allows for multiple database drivers. @@ -150,4 +152,19 @@ public interface Driver { * otherwise */ boolean jdbcCompliant(); + + //------------------------- JDBC 4.1 ----------------------------------- + + /** + * Return the parent Logger of all the Loggers used by this driver. This + * should be the Logger farthest from the root Logger that is + * still an ancestor of all of the Loggers used by this driver. Configuring + * this Logger will affect all of the log messages generated by the driver. + * In the worst case, this may be the root Logger. + * + * @return the parent Logger for this driver + * @throws SQLFeatureNotSupportedException if the driver does not use java.util.logging. + * @since 1.7 + */ + public Logger getParentLogger() throws SQLFeatureNotSupportedException; } diff --git a/src/share/classes/java/sql/PreparedStatement.java b/src/share/classes/java/sql/PreparedStatement.java index eb55d199fcc6aa8377340b9307a97b2ae44e240e..1d32c3dd0b9a84d5b90464763055f5d7b95c1741 100644 --- a/src/share/classes/java/sql/PreparedStatement.java +++ b/src/share/classes/java/sql/PreparedStatement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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 @@ -69,6 +69,10 @@ public interface PreparedStatement extends Statement { * @exception SQLException if a database access error occurs; * this method is called on a closed PreparedStatement or the SQL * statement does not return a ResultSet object + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} */ ResultSet executeQuery() throws SQLException; @@ -82,8 +86,11 @@ public interface PreparedStatement extends Statement { * or (2) 0 for SQL statements that return nothing * @exception SQLException if a database access error occurs; * this method is called on a closed PreparedStatement - * or the SQL - * statement returns a ResultSet object + * or the SQL statement returns a ResultSet object + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} */ int executeUpdate() throws SQLException; @@ -463,6 +470,10 @@ public interface PreparedStatement extends Statement { * @exception SQLException if a database access error occurs; * this method is called on a closed PreparedStatement * or an argument is supplied to this method + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} * @see Statement#execute * @see Statement#getResultSet * @see Statement#getUpdateCount @@ -1208,4 +1219,5 @@ public interface PreparedStatement extends Statement { void setNClob(int parameterIndex, Reader reader) throws SQLException; + } diff --git a/src/share/classes/java/sql/PseudoColumnUsage.java b/src/share/classes/java/sql/PseudoColumnUsage.java new file mode 100644 index 0000000000000000000000000000000000000000..bc9c1add47c436744289843bdeb508e5e2a3ff29 --- /dev/null +++ b/src/share/classes/java/sql/PseudoColumnUsage.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.sql; + + +/** + * Enumeration for pseudo/hidden column usage. + * + * @since 1.7 + * @see DatabaseMetaData#getPseudoColumns + */ +public enum PseudoColumnUsage { + + /** + * The pseudo/hidden column may only be used in a SELECT list. + */ + SELECT_LIST_ONLY, + + /** + * The pseudo/hidden column may only be used in a WHERE clause. + */ + WHERE_CLAUSE_ONLY, + + /** + * There are no restrictions on the usage of the pseudo/hidden columns. + */ + NO_USAGE_RESTRICTIONS, + + /** + * The usage of the pseudo/hidden column cannot be determined. + */ + USAGE_UNKNOWN + +} diff --git a/src/share/classes/java/sql/ResultSet.java b/src/share/classes/java/sql/ResultSet.java index 579270c783faa940b519f856820f910caf402795..a8aac4ffeea626dde677dd31682cec609210aa96 100644 --- a/src/share/classes/java/sql/ResultSet.java +++ b/src/share/classes/java/sql/ResultSet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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 @@ -145,7 +145,7 @@ import java.io.InputStream; * @see ResultSetMetaData */ -public interface ResultSet extends Wrapper { +public interface ResultSet extends Wrapper, AutoCloseable { /** * Moves the cursor froward one row from its current position. @@ -1187,6 +1187,9 @@ public interface ResultSet extends Wrapper { * cursor on the last row; calling the method absolute(-2) * moves the cursor to the next-to-last row, and so on. * + *

    If the row number specified is zero, the cursor is moved to + * before the first row. + * *

    An attempt to position the cursor beyond the first/last row in * the result set leaves the cursor before the first row or after * the last row. @@ -1196,9 +1199,10 @@ public interface ResultSet extends Wrapper { * is the same as calling last(). * * @param row the number of the row to which the cursor should move. - * A positive number indicates the row number counting from the - * beginning of the result set; a negative number indicates the - * row number counting from the end of the result set + * A value of zero indicates that the cursor will be positioned + * before the first row; a positive number indicates the row number + * counting from the beginning of the result set; a negative number + * indicates the row number counting from the end of the result set * @return true if the cursor is moved to a position in this * ResultSet object; * false if the cursor is before the first row or after the @@ -2529,7 +2533,7 @@ public interface ResultSet extends Wrapper { * @exception SQLException if the columnLabel is not valid; * if a database access error occurs * or this method is called on a closed result set - * @exception SQLFeatureNotSupportedException if the JDBC driver does not support + * @exception SQLFeatureNotSupportedException if the JDBC driver does not support * this method * @since 1.2 */ @@ -4072,4 +4076,64 @@ public interface ResultSet extends Wrapper { */ void updateNClob(String columnLabel, Reader reader) throws SQLException; + //------------------------- JDBC 4.1 ----------------------------------- + + + /** + *

    Retrieves the value of the designated column in the current row + * of this ResultSet object and will convert from the + * SQL type of the column to the requested Java data type, if the + * conversion is supported. If the conversion is not + * supported or null is specified for the type, a + * SQLException is thrown. + *

    + * At a minimum, an implementation must support the conversions defined in + * Appendix B, Table B-3 and conversion of appropriate user defined SQL + * types to a Java type which implements {@code SQLData}, or {@code Struct}. + * Additional conversions may be supported and are vendor defined. + * + * @param columnIndex the first column is 1, the second is 2, ... + * @param type Class representing the Java data type to convert the designated + * column to. + * @return an instance of {@code type} holding the column value + * @throws SQLException if conversion is not supported, type is null or + * another error occurs. The getCause() method of the + * exception may provide a more detailed exception, for example, if + * a conversion error occurs + * @throws SQLFeatureNotSupportedException if the JDBC driver does not support + * this method + * @since 1.7 + */ + public T getObject(int columnIndex, Class type) throws SQLException; + + + /** + *

    Retrieves the value of the designated column in the current row + * of this ResultSet object and will convert from the + * SQL type of the column to the requested Java data type, if the + * conversion is supported. If the conversion is not + * supported or null is specified for the type, a + * SQLException is thrown. + *

    + * At a minimum, an implementation must support the conversions defined in + * Appendix B, Table B-3 and conversion of appropriate user defined SQL + * types to a Java type which implements {@code SQLData}, or {@code Struct}. + * Additional conversions may be supported and are vendor defined. + * + * @param columnLabel the label for the column specified with the SQL AS clause. + * If the SQL AS clause was not specified, then the label is the name + * of the column + * @param type Class representing the Java data type to convert the designated + * column to. + * @return an instance of {@code type} holding the column value + * @throws SQLException if conversion is not supported, type is null or + * another error occurs. The getCause() method of the + * exception may provide a more detailed exception, for example, if + * a conversion error occurs + * @throws SQLFeatureNotSupportedException if the JDBC driver does not support + * this method + * @since 1.7 + */ + public T getObject(String columnLabel, Class type) throws SQLException; + } diff --git a/src/share/classes/java/sql/SQLPermission.java b/src/share/classes/java/sql/SQLPermission.java index e5b3ff69e004ef0e0ad71d3141c5dcfb0a460221..e7e799c1caca038fb4defc9d04046693f00f705d 100644 --- a/src/share/classes/java/sql/SQLPermission.java +++ b/src/share/classes/java/sql/SQLPermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2010, 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 @@ -30,9 +30,14 @@ import java.security.*; /** * The permission for which the SecurityManager will check - * when code that is running in an applet calls the - * DriverManager.setLogWriter method or the - * DriverManager.setLogStream (deprecated) method. + * when code that is running in an applet, or an application with a + * SecurityManager enabled, calls the + * DriverManager.setLogWriter method, + * DriverManager.setLogStream (deprecated) method, + * {@code SyncFactory.setJNDIContext} method, + * {@code SyncFactory.setLogger} method, + * {@code Connection.setNetworktimeout} method, + * or the Connection.abort method. * If there is no SQLPermission object, these methods * throw a java.lang.SecurityException as a runtime exception. *

    @@ -48,7 +53,6 @@ import java.security.*; * but *loadLibrary or a*b is not valid. *

    * The following table lists all the possible SQLPermission target names. - * Currently, the only name allowed is setLog. * The table gives a description of what the permission allows * and a discussion of the risks of granting code the permission. *

    @@ -67,9 +71,33 @@ import java.security.*; * The contents of the log may contain usernames and passwords, * SQL statements, and SQL data. * + * + * callAbort + * Allows the invocation of the {@code Connection} method + * {@code abort} + * Permits an application to terminate a physical connection to a + * database. + * + * + * setSyncFactory + * Allows the invocation of the {@code SyncFactory} methods + * {@code setJNDIContext} and {@code setLogger} + * Permits an application to specify the JNDI context from which the + * {@code SyncProvider} implementations can be retrieved from and the logging + * object to be used by the{@codeSyncProvider} implementation. + * * + * + * setNetworkTimeout + * Allows the invocation of the {@code Connection} method + * {@code setNetworkTimeout} + * Permits an application to specify the maximum period a + * Connection or + * objects created from the Connection + * will wait for the database to reply to any one request. + * * - * + *

    * The person running an applet decides what permissions to allow * and will run the Policy Tool to create an * SQLPermission in a policy file. A programmer does diff --git a/src/share/classes/java/sql/Statement.java b/src/share/classes/java/sql/Statement.java index a99f2d348bea92acb79d9adb98146da07828608e..88684a79a57ca385a80ac23081df02ce2bed8695 100644 --- a/src/share/classes/java/sql/Statement.java +++ b/src/share/classes/java/sql/Statement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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 @@ -40,20 +40,27 @@ package java.sql; * @see Connection#createStatement * @see ResultSet */ -public interface Statement extends Wrapper { +public interface Statement extends Wrapper, AutoCloseable { /** * Executes the given SQL statement, which returns a single * ResultSet object. - * + *

    + * Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql an SQL statement to be sent to the database, typically a * static SQL SELECT statement * @return a ResultSet object that contains the data produced * by the given query; never null * @exception SQLException if a database access error occurs, - * this method is called on a closed Statement or the given + * this method is called on a closed Statement, the given * SQL statement produces anything other than a single - * ResultSet object + * ResultSet object, the method is called on a + * PreparedStatement or CallableStatement + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} */ ResultSet executeQuery(String sql) throws SQLException; @@ -61,7 +68,9 @@ public interface Statement extends Wrapper { * Executes the given SQL statement, which may be an INSERT, * UPDATE, or DELETE statement or an * SQL statement that returns nothing, such as an SQL DDL statement. - * + *

    + * Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or * DELETE; or an SQL statement that returns nothing, * such as a DDL statement. @@ -70,8 +79,13 @@ public interface Statement extends Wrapper { * or (2) 0 for SQL statements that return nothing * * @exception SQLException if a database access error occurs, - * this method is called on a closed Statement or the given - * SQL statement produces a ResultSet object + * this method is called on a closed Statement, the given + * SQL statement produces a ResultSet object, the method is called on a + * PreparedStatement or CallableStatement + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} */ int executeUpdate(String sql) throws SQLException; @@ -198,11 +212,21 @@ public interface Statement extends Wrapper { /** * Sets the number of seconds the driver will wait for a * Statement object to execute to the given number of seconds. - * If the limit is exceeded, an SQLException is thrown. A JDBC - * driver must apply this limit to the execute, - * executeQuery and executeUpdate methods. JDBC driver - * implementations may also apply this limit to ResultSet methods + *By default there is no limit on the amount of time allowed for a running + * statement to complete. If the limit is exceeded, an + * SQLTimeoutException is thrown. + * A JDBC driver must apply this limit to the execute, + * executeQuery and executeUpdate methods. + *

    + * Note: JDBC driver implementations may also apply this + * limit to {@code ResultSet} methods * (consult your driver vendor documentation for details). + *

    + * Note: In the case of {@code Statement} batching, it is + * implementation defined as to whether the time-out is applied to + * individual SQL commands added via the {@code addBatch} method or to + * the entire batch of SQL commands invoked by the {@code executeBatch} + * method (consult your driver vendor documentation for details). * * @param seconds the new query timeout limit in seconds; zero means * there is no limit @@ -300,13 +324,21 @@ public interface Statement extends Wrapper { * getResultSet or getUpdateCount * to retrieve the result, and getMoreResults to * move to any subsequent result(s). - * + *

    + *Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql any SQL statement * @return true if the first result is a ResultSet * object; false if it is an update count or there are * no results - * @exception SQLException if a database access error occurs or - * this method is called on a closed Statement + * @exception SQLException if a database access error occurs, + * this method is called on a closed Statement, + * the method is called on a + * PreparedStatement or CallableStatement + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} * @see #getResultSet * @see #getUpdateCount * @see #getMoreResults @@ -465,12 +497,14 @@ public interface Statement extends Wrapper { * Statement object. The commands in this list can be * executed as a batch by calling the method executeBatch. *

    - * + *Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql typically this is a SQL INSERT or * UPDATE statement * @exception SQLException if a database access error occurs, - * this method is called on a closed Statement or the - * driver does not support batch updates + * this method is called on a closed Statement, the + * driver does not support batch updates, the method is called on a + * PreparedStatement or CallableStatement * @see #executeBatch * @see DatabaseMetaData#supportsBatchUpdates * @since 1.2 @@ -536,7 +570,10 @@ public interface Statement extends Wrapper { * driver does not support batch statements. Throws {@link BatchUpdateException} * (a subclass of SQLException) if one of the commands sent to the * database fails to execute properly or attempts to return a result set. - * + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} * * @see #addBatch * @see DatabaseMetaData#supportsBatchUpdates @@ -678,7 +715,9 @@ public interface Statement extends Wrapper { * flag if the SQL statement * is not an INSERT statement, or an SQL statement able to return * auto-generated keys (the list of such statements is vendor-specific). - * + *

    + * Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or * DELETE; or an SQL statement that returns nothing, * such as a DDL statement. @@ -693,10 +732,15 @@ public interface Statement extends Wrapper { * * @exception SQLException if a database access error occurs, * this method is called on a closed Statement, the given - * SQL statement returns a ResultSet object, or - * the given constant is not one of those allowed + * SQL statement returns a ResultSet object, + * the given constant is not one of those allowed, the method is called on a + * PreparedStatement or CallableStatement * @exception SQLFeatureNotSupportedException if the JDBC driver does not support * this method with a constant of Statement.RETURN_GENERATED_KEYS + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} * @since 1.4 */ int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException; @@ -709,7 +753,9 @@ public interface Statement extends Wrapper { * available. The driver will ignore the array if the SQL statement * is not an INSERT statement, or an SQL statement able to return * auto-generated keys (the list of such statements is vendor-specific). - * + *

    + * Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or * DELETE; or an SQL statement that returns nothing, * such as a DDL statement. @@ -721,10 +767,15 @@ public interface Statement extends Wrapper { * * @exception SQLException if a database access error occurs, * this method is called on a closed Statement, the SQL - * statement returns a ResultSet object, or the - * second argument supplied to this method is not an int array - * whose elements are valid column indexes + * statement returns a ResultSet object,the second argument + * supplied to this method is not an + * int array whose elements are valid column indexes, the method is called on a + * PreparedStatement or CallableStatement * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} * @since 1.4 */ int executeUpdate(String sql, int columnIndexes[]) throws SQLException; @@ -737,7 +788,9 @@ public interface Statement extends Wrapper { * available. The driver will ignore the array if the SQL statement * is not an INSERT statement, or an SQL statement able to return * auto-generated keys (the list of such statements is vendor-specific). - * + *

    + * Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or * DELETE; or an SQL statement that returns nothing, * such as a DDL statement. @@ -748,11 +801,15 @@ public interface Statement extends Wrapper { * that return nothing * @exception SQLException if a database access error occurs, * this method is called on a closed Statement, the SQL - * statement returns a ResultSet object, or the + * statement returns a ResultSet object, the * second argument supplied to this method is not a String array - * whose elements are valid column names - * + * whose elements are valid column names, the method is called on a + * PreparedStatement or CallableStatement * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} * @since 1.4 */ int executeUpdate(String sql, String columnNames[]) throws SQLException; @@ -776,7 +833,9 @@ public interface Statement extends Wrapper { * getResultSet or getUpdateCount * to retrieve the result, and getMoreResults to * move to any subsequent result(s). - * + *

    + *Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql any SQL statement * @param autoGeneratedKeys a constant indicating whether auto-generated * keys should be made available for retrieval using the method @@ -787,12 +846,18 @@ public interface Statement extends Wrapper { * object; false if it is an update count or there are * no results * @exception SQLException if a database access error occurs, - * this method is called on a closed Statement or the second + * this method is called on a closed Statement, the second * parameter supplied to this method is not * Statement.RETURN_GENERATED_KEYS or - * Statement.NO_GENERATED_KEYS. + * Statement.NO_GENERATED_KEYS, + * the method is called on a + * PreparedStatement or CallableStatement * @exception SQLFeatureNotSupportedException if the JDBC driver does not support * this method with a constant of Statement.RETURN_GENERATED_KEYS + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} * @see #getResultSet * @see #getUpdateCount * @see #getMoreResults @@ -823,7 +888,9 @@ public interface Statement extends Wrapper { * getResultSet or getUpdateCount * to retrieve the result, and getMoreResults to * move to any subsequent result(s). - * + *

    + * Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql any SQL statement * @param columnIndexes an array of the indexes of the columns in the * inserted row that should be made available for retrieval by a @@ -832,10 +899,15 @@ public interface Statement extends Wrapper { * object; false if it is an update count or there * are no results * @exception SQLException if a database access error occurs, - * this method is called on a closed Statement or the + * this method is called on a closed Statement, the * elements in the int array passed to this method - * are not valid column indexes + * are not valid column indexes, the method is called on a + * PreparedStatement or CallableStatement * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} * @see #getResultSet * @see #getUpdateCount * @see #getMoreResults @@ -865,7 +937,9 @@ public interface Statement extends Wrapper { * getResultSet or getUpdateCount * to retrieve the result, and getMoreResults to * move to any subsequent result(s). - * + *

    + * Note:This method cannot be called on a + * PreparedStatement or CallableStatement. * @param sql any SQL statement * @param columnNames an array of the names of the columns in the inserted * row that should be made available for retrieval by a call to the @@ -874,10 +948,15 @@ public interface Statement extends Wrapper { * object; false if it is an update count or there * are no more results * @exception SQLException if a database access error occurs, - * this method is called on a closed Statement or the + * this method is called on a closed Statement,the * elements of the String array passed to this - * method are not valid column names + * method are not valid column names, the method is called on a + * PreparedStatement or CallableStatement * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method + * @throws SQLTimeoutException when the driver has determined that the + * timeout value that was specified by the {@code setQueryTimeout} + * method has been exceeded and has at least attempted to cancel + * the currently running {@code Statement} * @see #getResultSet * @see #getUpdateCount * @see #getMoreResults @@ -951,4 +1030,34 @@ public interface Statement extends Wrapper { boolean isPoolable() throws SQLException; + //--------------------------JDBC 4.1 ----------------------------- + + /** + * Specifies that this {@code Statement} will be closed when all its + * dependent result sets are closed. If execution of the {@code Statement} + * does not produce any result sets, this method has no effect. + *

    + * Note: Multiple calls to {@code closeOnCompletion} do + * not toggle the effect on this {@code Statement}. However, a call to + * {@code closeOnCompletion} does effect both the subsequent execution of + * statements, and statements that currently have open, dependent, + * result sets. + * + * @throws SQLException if this method is called on a closed + * {@code Statement} + * @since 1.7 + */ + public void closeOnCompletion() throws SQLException; + + /** + * Returns a value indicating whether this {@code Statement} will be + * closed when all dependent objects such as resultsets are closed. + * @return {@code true} if the {@code Statement} will be closed when all + * of its dependent objects are closed; {@code false} otherwise + * @throws SQLException if this method is called on a closed + * {@code Statement} + * @since 1.7 + */ + public boolean isCloseOnCompletion() throws SQLException; + } diff --git a/src/share/classes/java/sql/Timestamp.java b/src/share/classes/java/sql/Timestamp.java index 4852d8d33afc9154dcd499259515156036ab4cc8..411c04eb19e2749136c937323644fddcffc092af 100644 --- a/src/share/classes/java/sql/Timestamp.java +++ b/src/share/classes/java/sql/Timestamp.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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 @@ -155,19 +155,26 @@ public class Timestamp extends java.util.Date { * Converts a String object in JDBC timestamp escape format to a * Timestamp value. * - * @param s timestamp in format yyyy-mm-dd hh:mm:ss[.f...]. The - * fractional seconds may be omitted. + * @param s timestamp in format yyyy-[m]m-[d]d hh:mm:ss[.f...]. The + * fractional seconds may be omitted. The leading zero for mm + * and dd may also be omitted. + * * @return corresponding Timestamp value * @exception java.lang.IllegalArgumentException if the given argument - * does not have the format yyyy-mm-dd hh:mm:ss[.f...] + * does not have the format yyyy-[m]m-[d]d hh:mm:ss[.f...] */ public static Timestamp valueOf(String s) { + final int YEAR_LENGTH = 4; + final int MONTH_LENGTH = 2; + final int DAY_LENGTH = 2; + final int MAX_MONTH = 12; + final int MAX_DAY = 31; String date_s; String time_s; String nanos_s; - int year; - int month; - int day; + int year = 0; + int month = 0; + int day = 0; int hour; int minute; int second; @@ -182,17 +189,9 @@ public class Timestamp extends java.util.Date { String zeros = "000000000"; String delimiterDate = "-"; String delimiterTime = ":"; - StringTokenizer stringTokeninzerDate; - StringTokenizer stringTokeninzerTime; if (s == null) throw new java.lang.IllegalArgumentException("null string"); - int counterD = 0; - int intDate[] = {4,2,2}; - - int counterT = 0; - int intTime[] = {2,2,12}; - // Split the string into date and time components s = s.trim(); dividingSpace = s.indexOf(' '); @@ -203,30 +202,6 @@ public class Timestamp extends java.util.Date { throw new java.lang.IllegalArgumentException(formatError); } - stringTokeninzerTime = new StringTokenizer(time_s, delimiterTime); - stringTokeninzerDate = new StringTokenizer(date_s, delimiterDate); - - while(stringTokeninzerDate.hasMoreTokens()) { - String tokenDate = stringTokeninzerDate.nextToken(); - if(tokenDate.length() != intDate[counterD] ) { - throw new java.lang.IllegalArgumentException(formatError); - } - counterD++; - } - - /* - //Commenting this portion out for checking of time - - while(stringTokeninzerTime.hasMoreTokens()) { - String tokenTime = stringTokeninzerTime.nextToken(); - - if (counterT < 2 && tokenTime.length() != intTime[counterT] ) { - throw new java.lang.IllegalArgumentException(formatError); - } - counterT++; - } - */ - // Parse the date firstDash = date_s.indexOf('-'); secondDash = date_s.indexOf('-', firstDash+1); @@ -239,14 +214,24 @@ public class Timestamp extends java.util.Date { period = time_s.indexOf('.', secondColon+1); // Convert the date - if ((firstDash > 0) && (secondDash > 0) && - (secondDash < date_s.length()-1)) { - year = Integer.parseInt(date_s.substring(0, firstDash)) - 1900; - month = - Integer.parseInt(date_s.substring - (firstDash+1, secondDash)) - 1; - day = Integer.parseInt(date_s.substring(secondDash+1)); - } else { + boolean parsedDate = false; + if ((firstDash > 0) && (secondDash > 0) && (secondDash < date_s.length() - 1)) { + String yyyy = date_s.substring(0, firstDash); + String mm = date_s.substring(firstDash + 1, secondDash); + String dd = date_s.substring(secondDash + 1); + if (yyyy.length() == YEAR_LENGTH && + (mm.length() >= 1 && mm.length() <= MONTH_LENGTH) && + (dd.length() >= 1 && dd.length() <= DAY_LENGTH)) { + year = Integer.parseInt(yyyy); + month = Integer.parseInt(mm); + day = Integer.parseInt(dd); + + if ((month >= 1 && month <= MAX_MONTH) && (day >= 1 && day <= MAX_DAY)) { + parsedDate = true; + } + } + } + if (! parsedDate) { throw new java.lang.IllegalArgumentException(formatError); } @@ -272,10 +257,10 @@ public class Timestamp extends java.util.Date { second = Integer.parseInt(time_s.substring(secondColon+1)); } } else { - throw new java.lang.IllegalArgumentException(); + throw new java.lang.IllegalArgumentException(formatError); } - return new Timestamp(year, month, day, hour, minute, second, a_nanos); + return new Timestamp(year - 1900, month - 1, day, hour, minute, second, a_nanos); } /** @@ -502,14 +487,10 @@ public class Timestamp extends java.util.Date { /** * Compares this Timestamp object to the given - * Date, which must be a Timestamp - * object. If the argument is not a Timestamp object, - * this method throws a ClassCastException object. - * (Timestamp objects are - * comparable only to other Timestamp objects.) + * Date object. * - * @param o the Date to be compared, which must be a - * Timestamp object + * @param o the Date to be compared to + * this Timestamp object * @return the value 0 if this Timestamp object * and the given object are equal; a value less than 0 * if this Timestamp object is before the given argument; diff --git a/src/share/classes/javax/sql/CommonDataSource.java b/src/share/classes/javax/sql/CommonDataSource.java index 8d06bd63745aa16d03100664904dc3b1f20e0e77..25b40686d87bb785700e1527ca24d7c9a34d6e08 100644 --- a/src/share/classes/javax/sql/CommonDataSource.java +++ b/src/share/classes/javax/sql/CommonDataSource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2010, 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 @@ -27,6 +27,8 @@ package javax.sql; import java.sql.SQLException; import java.io.PrintWriter; +import java.sql.SQLFeatureNotSupportedException; +import java.util.logging.Logger; /** * Interface that defines the methods which are common between DataSource, @@ -35,79 +37,93 @@ import java.io.PrintWriter; */ public interface CommonDataSource { - /** - *

    Retrieves the log writer for this DataSource - * object. - * - *

    The log writer is a character output stream to which all logging - * and tracing messages for this data source will be - * printed. This includes messages printed by the methods of this - * object, messages printed by methods of other objects manufactured - * by this object, and so on. Messages printed to a data source - * specific log writer are not printed to the log writer associated - * with the java.sql.DriverManager class. When a - * DataSource object is - * created, the log writer is initially null; in other words, the - * default is for logging to be disabled. - * - * @return the log writer for this data source or null if - * logging is disabled - * @exception java.sql.SQLException if a database access error occurs - * @see #setLogWriter - * @since 1.4 - */ - java.io.PrintWriter getLogWriter() throws SQLException; + /** + *

    Retrieves the log writer for this DataSource + * object. + * + *

    The log writer is a character output stream to which all logging + * and tracing messages for this data source will be + * printed. This includes messages printed by the methods of this + * object, messages printed by methods of other objects manufactured + * by this object, and so on. Messages printed to a data source + * specific log writer are not printed to the log writer associated + * with the java.sql.DriverManager class. When a + * DataSource object is + * created, the log writer is initially null; in other words, the + * default is for logging to be disabled. + * + * @return the log writer for this data source or null if + * logging is disabled + * @exception java.sql.SQLException if a database access error occurs + * @see #setLogWriter + * @since 1.4 + */ + java.io.PrintWriter getLogWriter() throws SQLException; - /** - *

    Sets the log writer for this DataSource - * object to the given java.io.PrintWriter object. - * - *

    The log writer is a character output stream to which all logging - * and tracing messages for this data source will be - * printed. This includes messages printed by the methods of this - * object, messages printed by methods of other objects manufactured - * by this object, and so on. Messages printed to a data source- - * specific log writer are not printed to the log writer associated - * with the java.sql.DriverManager class. When a - * DataSource object is created the log writer is - * initially null; in other words, the default is for logging to be - * disabled. - * - * @param out the new log writer; to disable logging, set to null - * @exception SQLException if a database access error occurs - * @see #getLogWriter - * @since 1.4 - */ - void setLogWriter(java.io.PrintWriter out) throws SQLException; + /** + *

    Sets the log writer for this DataSource + * object to the given java.io.PrintWriter object. + * + *

    The log writer is a character output stream to which all logging + * and tracing messages for this data source will be + * printed. This includes messages printed by the methods of this + * object, messages printed by methods of other objects manufactured + * by this object, and so on. Messages printed to a data source- + * specific log writer are not printed to the log writer associated + * with the java.sql.DriverManager class. When a + * DataSource object is created the log writer is + * initially null; in other words, the default is for logging to be + * disabled. + * + * @param out the new log writer; to disable logging, set to null + * @exception SQLException if a database access error occurs + * @see #getLogWriter + * @since 1.4 + */ + void setLogWriter(java.io.PrintWriter out) throws SQLException; - /** - *

    Sets the maximum time in seconds that this data source will wait - * while attempting to connect to a database. A value of zero - * specifies that the timeout is the default system timeout - * if there is one; otherwise, it specifies that there is no timeout. - * When a DataSource object is created, the login timeout is - * initially zero. - * - * @param seconds the data source login time limit - * @exception SQLException if a database access error occurs. - * @see #getLoginTimeout - * @since 1.4 - */ - void setLoginTimeout(int seconds) throws SQLException; + /** + *

    Sets the maximum time in seconds that this data source will wait + * while attempting to connect to a database. A value of zero + * specifies that the timeout is the default system timeout + * if there is one; otherwise, it specifies that there is no timeout. + * When a DataSource object is created, the login timeout is + * initially zero. + * + * @param seconds the data source login time limit + * @exception SQLException if a database access error occurs. + * @see #getLoginTimeout + * @since 1.4 + */ + void setLoginTimeout(int seconds) throws SQLException; - /** - * Gets the maximum time in seconds that this data source can wait - * while attempting to connect to a database. A value of zero - * means that the timeout is the default system timeout - * if there is one; otherwise, it means that there is no timeout. - * When a DataSource object is created, the login timeout is - * initially zero. - * - * @return the data source login time limit - * @exception SQLException if a database access error occurs. - * @see #setLoginTimeout - * @since 1.4 - */ - int getLoginTimeout() throws SQLException; + /** + * Gets the maximum time in seconds that this data source can wait + * while attempting to connect to a database. A value of zero + * means that the timeout is the default system timeout + * if there is one; otherwise, it means that there is no timeout. + * When a DataSource object is created, the login timeout is + * initially zero. + * + * @return the data source login time limit + * @exception SQLException if a database access error occurs. + * @see #setLoginTimeout + * @since 1.4 + */ + int getLoginTimeout() throws SQLException; + //------------------------- JDBC 4.1 ----------------------------------- + + /** + * Return the parent Logger of all the Loggers used by this data source. This + * should be the Logger farthest from the root Logger that is + * still an ancestor of all of the Loggers used by this data source. Configuring + * this Logger will affect all of the log messages generated by the data source. + * In the worst case, this may be the root Logger. + * + * @return the parent Logger for this data source + * @throws SQLFeatureNotSupportedException if the data source does not use java.util.logging. + * @since 1.7 + */ + public Logger getParentLogger() throws SQLFeatureNotSupportedException; }