📄 jdbcconnection.java
字号:
* * @exception SQLException if a database access error occurs */ public synchronized void close() throws SQLException { // Changed to synchronized above because // we would not want a sessionProxy.close() // operation to occur concurrently with a // statementXXX.executeXXX operation. if (isInternal || isClosed) { return; } isClosed = true; if (sessionProxy != null) { sessionProxy.close(); } sessionProxy = null; rootWarning = null; connProperties = null; } /** * Tests to see if a Connection is closed. * * @return true if the connection is closed; false if it's still * open */ public synchronized boolean isClosed() { return isClosed; } /** * <!-- start generic documentation --> * Gets the metadata regarding this connection's database. * A Connection's database is able to provide information describing * its tables, its supported SQL grammar, its stored procedures, * the capabilities of this connection, and so on. This information * is made available through a <code>DatabaseMetaData</code> object. <p> * * <!-- end generic documentation --> * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * JDBC <code>DatabaseMetaData</code> methods returning * <code>ResultSet</code> were not implemented fully before 1.7.2. * Some of these methods always returned empty result sets. * Other methods did not accurately * reflect all of the MetaData for the category. * Also, some method ignored the filters provided as * parameters, returning an unfiltered result each time. <p> * * Also, the majority of methods returning <code>ResultSet</code> * threw an <code>SQLException</code> when accessed by a non-admin * user. * <hr> * * Starting with HSQLDB 1.7.2, essentially full database metadata * is supported. <p> * * For discussion in greater detail, please follow the link to the * overview for jdbcDatabaseMetaData, below. * * </div> <!-- end release-specific documentation --> * * @return a DatabaseMetaData object for this Connection * @throws SQLException if a database access error occurs * @see jdbcDatabaseMetaData */ public synchronized DatabaseMetaData getMetaData() throws SQLException { checkClosed(); return new jdbcDatabaseMetaData(this); } /** * <!-- start generic documentation --> * Puts this connection in read-only mode as a hint to enable * database optimizations. <p> * * <B>Note:</B> This method should not be called while in the * middle of a transaction. <p> * * <!-- end generic documentation --> * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Up to and including 1.7.2, HSQLDB will commit the current * transaction automatically when this method is called. <p> * * Additionally, HSQLDB provides a way to put a whole database in * read-only mode. This is done by manually adding the line * 'readonly=true' to the database's .properties file while the * database is offline. Upon restart, all connections will be * readonly, since the entire database will be readonly. To take * a database out of readonly mode, simply take the database * offline and remove the line 'readonly=true' from the * database's .properties file. Upon restart, the database will * be in regular (read-write) mode. <p> * * When a database is put in readonly mode, its files are opened * in readonly mode, making it possible to create CD-based * readonly databases. To create a CD-based readonly database * that has CACHED tables and whose .data file is suspected of * being highly fragmented, it is recommended that the database * first be SHUTDOWN COMPACTed before copying the database * files to CD. This will reduce the space required and may * improve access times against the .data file which holds the * CACHED table data. <p> * * Starting with 1.7.2, an alternate approach to opimizing the * .data file before creating a CD-based readonly database is to issue * the CHECKPOINT DEFRAG command followed by SHUTDOWN to take the * database offline in preparation to burn the database files to CD. <p> * * </div> <!-- end release-specific documentation --> * * @param readonly The new readOnly value * @exception SQLException if a database access error occurs */ public synchronized void setReadOnly(boolean readonly) throws SQLException { checkClosed(); try { sessionProxy.setReadOnly(readonly); } catch (HsqlException e) { throw Util.sqlException(e); } } /** * Tests to see if the connection is in read-only mode. * * @return true if connection is read-only and false otherwise * @exception SQLException if a database access error occurs */ public synchronized boolean isReadOnly() throws SQLException { try { return sessionProxy.isReadOnly(); } catch (HsqlException e) { throw Util.sqlException(e); } } /** * <!-- start generic documentation --> * Sets a catalog name in order to * select a subspace of this Connection's database in which to * work. <p> * * <!-- end generic documentation --> * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSQLDB does not yet support catalogs and simply ignores this * request. <p> * </div> * <!-- end release-specific documentation --> * * @param catalog the name of a catalog (subspace in this * Connection object's database) in which to work (Ignored) * @throws SQLException if a database access error occurs <p> */ public synchronized void setCatalog(String catalog) throws SQLException { checkClosed(); } /** * <!-- start generic documentation --> * Returns the Connection's current catalog name. <p> * * <!-- end generic documentation --> * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSQLDB does not yet support catalogs and always returns null. * <p> * * </div> <!-- end release-specific documentation --> * * @return the current catalog name or null <p> * * For HSQLDB, this is always null. * @exception SQLException Description of the Exception */ public synchronized String getCatalog() throws SQLException { checkClosed(); return null; } /** * <!-- start generic documentation --> * Attempts to change the transaction isolation level for this * <code>Connection</code> object to the one given. The constants * defined in the interface <code>Connection</code> are the * possible transaction isolation levels. <p> * * <B>Note:</B> If this method is called during a transaction, * the result is implementation-defined. <p> * * <!-- end generic documentation --> * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * </div> <!-- end release-specific documentation --> * * @param level one of the following <code>Connection</code> * constants: <code>Connection.TRANSACTION_READ_UNCOMMITTED</code> * , <code>Connection.TRANSACTION_READ_COMMITTED</code>, * <code>Connection.TRANSACTION_REPEATABLE_READ</code>, or * <code>Connection.TRANSACTION_SERIALIZABLE</code>. (Note * that <code>Connection.TRANSACTION_NONE</code> cannot be * used because it specifies that transactions are not * supported.) * @exception SQLException if a database access error occurs or * the given parameter is not one of the <code>Connection</code> * constants <p> * @see jdbcDatabaseMetaData#supportsTransactionIsolationLevel * @see #getTransactionIsolation */ public synchronized void setTransactionIsolation(int level) throws SQLException { checkClosed(); switch (level) { case TRANSACTION_READ_UNCOMMITTED : case TRANSACTION_READ_COMMITTED : case TRANSACTION_REPEATABLE_READ : case TRANSACTION_SERIALIZABLE : break; default : throw Util.invalidArgument(); } try { sessionProxy.setIsolation(level); } catch (HsqlException e) { throw Util.sqlException(e); } } /** * <!-- start generic documentation --> * Retrieves this <code>Connection</code> * object's current transaction isolation level. <p> * * <!-- end generic documentation --> * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSQLDB always returns * <code>Connection.TRANSACTION_READ_UNCOMMITED</code>. <p> * * </div> <!-- end release-specific documentation --> * * @return the current transaction isolation level, which will be * one of the following constants: * <code>Connection.TRANSACTION_READ_UNCOMMITTED</code> * , <code>Connection.TRANSACTION_READ_COMMITTED</code>, * <code>Connection.TRANSACTION_REPEATABLE_READ</code>, * <code>Connection.TRANSACTION_SERIALIZABLE</code>, or * <code>Connection.TRANSACTION_NONE</code> <p> * * Up to and including 1.7.1, TRANSACTION_READ_UNCOMMITTED is * always returned * @exception SQLException if a database access error occurs <p> * @see jdbcDatabaseMetaData#supportsTransactionIsolationLevel * @see #setTransactionIsolation setTransactionIsolation */ public synchronized int getTransactionIsolation() throws SQLException { checkClosed(); try { return sessionProxy.getIsolation(); } catch (HsqlException e) { throw Util.sqlException(e); } } /** * <!-- start generic documentation --> * Retrieves the first warning reported by calls on this * <code>Connection</code> object. If there is more than one * warning, subsequent warnings will be chained to the first * one and can be retrieved by calling the method * <code>SQLWarning.getNextWarning</code> on the warning * that was retrieved previously. <p> * * This method may not be called on a closed connection; doing so * will cause an <code>SQLException</code> to be thrown. <p> * * <B>Note:</B> Subsequent warnings will be chained to this * SQLWarning. <p> * * <!-- end generic documentation --> * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Starting with 1.7.2, HSQLDB produces warnings whenever a createStatement(), * prepareStatement() or prepareCall() invocation requests an unsupported * but defined combination of result set type, concurrency and holdability, * such that another set is substituted. * * </div> <!-- end release-specific documentation --> * @return the first <code>SQLWarning</code> object or <code>null</code> * if there are none<p> * @exception SQLException if a database access error occurs or * this method is called on a closed connection <p> * @see SQLWarning */ public synchronized SQLWarning getWarnings() throws SQLException { checkClosed(); synchronized (rootWarning_mutex) { if (!isNetConn) { HsqlException[] warnings = ((Session) sessionProxy).getAndClearWarnings();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -