userconnection.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 978 行 · 第 1/2 页
JAVA
978 行
*/ public void setCatalog(String catalog) throws SQLException { getMConn().setCatalog(catalog); } /** * Gets the connection's metadata. */ public DatabaseMetaData getMetaData() throws SQLException { try { return getDriverConnection().getMetaData(); } catch (SQLException e) { fatalEvent(); throw e; } } /** * Returns the connection's type map. */ public Map getTypeMap() throws SQLException { try { return getDriverConnection().getTypeMap(); } catch (SQLException e) { fatalEvent(); throw e; } } /** * Sets the connection's type map. */ public void setTypeMap(Map<String,Class<?>> map) throws SQLException { getMConn().setTypeMap(map); } /** * Calls the nativeSQL method for the connection. */ public String nativeSQL(String sql) throws SQLException { try { return getDriverConnection().nativeSQL(sql); } catch (SQLException e) { fatalEvent(); throw e; } } public int getTransactionIsolation() throws SQLException { try { return getDriverConnection().getTransactionIsolation(); } catch (SQLException e) { fatalEvent(); throw e; } } public void setTransactionIsolation(int isolation) throws SQLException { getMConn().setTransactionIsolation(isolation); } public SQLWarning getWarnings() throws SQLException { try { Connection conn = getDriverConnection(); if (conn != null) return conn.getWarnings(); else return null; } catch (SQLException e) { fatalEvent(); throw e; } } public void clearWarnings() throws SQLException { try { Connection conn = getDriverConnection(); if (conn != null) conn.clearWarnings(); } catch (SQLException e) { fatalEvent(); throw e; } } public void setReadOnly(boolean readOnly) throws SQLException { getMConn().setReadOnly(readOnly); } public boolean isReadOnly() throws SQLException { try { return getDriverConnection().isReadOnly(); } catch (SQLException e) { fatalEvent(); throw e; } } public boolean getAutoCommit() throws SQLException { try { return getDriverConnection().getAutoCommit(); } catch (SQLException e) { fatalEvent(); throw e; } } public void setAutoCommit(boolean autoCommit) throws SQLException { getMConn().setAutoCommit(autoCommit); } public void commit() throws SQLException { try { Connection conn = getDriverConnection(); if (conn != null) conn.commit(); } catch (SQLException e) { fatalEvent(); throw e; } } public void rollback() throws SQLException { try { Connection conn = getDriverConnection(); if (conn != null) conn.rollback(); } catch (SQLException e) { fatalEvent(); throw e; } } /** * Returns true if the connection is closed. */ public boolean isClosed() throws SQLException { try { return _mConn == null || getDriverConnection() == null || getDriverConnection().isClosed(); } catch (SQLException e) { log.log(Level.FINER, e.toString(), e); return true; } } /** * Reset the connection and return the underlying JDBC connection to * the pool. */ public void close() throws SQLException { ManagedConnectionImpl mConn; synchronized (this) { mConn = _mConn; _mConn = null; if (mConn == null) return; } try { // Clean up the connection and put it back in the pool resetConnection(mConn); } catch (Throwable e) { mConn.fatalEvent(); log.log(Level.WARNING, e.toString(), e); /* if (e instanceof SQLException) throw (SQLException) e; else if (e instanceof RuntimeException) throw (RuntimeException) e; else throw new SQLExceptionWrapper(e); */ } finally { mConn.closeEvent(this); } } /** * Adds the statement to a list, so they can be automatically closed * when the connection returns to the pool. */ private void addStatement(Statement stmt) { if (_statement == null) _statement = stmt; else if (_statements != null) _statements.add(stmt); else { _statements = new ArrayList<Statement>(); _statements.add(stmt); } } public void setHoldability(int hold) throws SQLException { getDriverConnection().setHoldability(hold); } public int getHoldability() throws SQLException { return getDriverConnection().getHoldability(); } public Savepoint setSavepoint() throws SQLException { return getDriverConnection().setSavepoint(); } public Savepoint setSavepoint(String name) throws SQLException { return getDriverConnection().setSavepoint(name); } public void releaseSavepoint(Savepoint savepoint) throws SQLException { getDriverConnection().releaseSavepoint(savepoint); } public void rollback(Savepoint savepoint) throws SQLException { getDriverConnection().rollback(savepoint); } /** * Resets the underlying connection to its initial state and closes * any open statements. */ private void resetConnection(ManagedConnectionImpl mConn) { closeStatements(mConn); } /** * Closes a single statement. */ void closeStatement(Statement stmt) { if (_statement == stmt) _statement = null; else if (_statements != null) _statements.remove(stmt); } /** * Closes the connection's statements. */ private void closeStatements(ManagedConnectionImpl mConn) { ArrayList<Statement> statements = _statements; _statements = null; Statement stmt = _statement; _statement = null; try { if (stmt != null) stmt.close(); } catch (Throwable e) { log.log(Level.FINE, e.toString(), e); // Can't set fatalEvent because Sybase throws an exception // if statements are closed twice // fatalEvent(); } for (int i = 0; statements != null && i < statements.size(); i++) { try { stmt = statements.get(i); if (stmt != null) stmt.close(); } catch (Throwable e) { log.log(Level.FINE, e.toString(), e); // Can't set fatalEvent because Sybase throws an exception // if statements are closed twice // fatalEvent(); } } } /** * Returns the underlying connection. */ public Connection getDriverConnection() throws SQLException { ManagedConnectionImpl mConn = getMConn(); if (mConn == null) throw new IllegalStateException(L.l("Cannot use closed connection. Check max-active-time and review application code. ")); Connection conn = mConn.getDriverConnection(); return conn; } /** * Returns the underlying connection. */ public ManagedConnectionImpl getMConn() { ManagedConnectionImpl mConn = _mConn; if (mConn == null) throw new IllegalStateException("connection is closed"); return mConn; } /** * Marks the connection as error. */ public void discardConnection() { fatalEvent(); } /** * Returns the underlying connection. */ private void fatalEvent() { ManagedConnectionImpl mConn = _mConn; if (mConn != null) mConn.fatalEvent(); } /** * Returns the underlying connection. */ private void fatalEvent(SQLException exn) { ManagedConnectionImpl mConn = _mConn; if (mConn != null) mConn.fatalEvent(exn); } /** * Returns the underlying connection. */ void killPool() { ManagedConnectionImpl mConn = _mConn; if (mConn != null) mConn.killPool(); } protected void finalize() throws Exception { close(); } public String toString() { return "UserConnection[" + _mConn + "]"; } public Clob createClob() throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public Blob createBlob() throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public NClob createNClob() throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public SQLXML createSQLXML() throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public boolean isValid(int timeout) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public void setClientInfo(String name, String value) throws SQLClientInfoException { throw new UnsupportedOperationException("Not supported yet."); } public void setClientInfo(Properties properties) throws SQLClientInfoException { throw new UnsupportedOperationException("Not supported yet."); } public String getClientInfo(String name) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public Properties getClientInfo() throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public Array createArrayOf(String typeName, Object[] elements) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public Struct createStruct(String typeName, Object[] attributes) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public <T> T unwrap(Class<T> iface) throws SQLException { return (T) getConnection(); } public boolean isWrapperFor(Class<?> iface) throws SQLException { return iface.isAssignableFrom(getConnection().getClass()); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?