📄 connection.java
字号:
Object[] args = { new Boolean(readOnly) };
Debug.methodCall(this, "setReadOnly", args);
Debug.returnValue(this, "setReadOnly", new Boolean(readOnly));
}
checkClosed();
this.readOnly = readOnly;
}
/**
* Tests to see if the connection is in Read Only Mode. Note that we
* cannot really put the database in read only mode, but we pretend we can
* by returning the value of the readOnly flag
*
* @return true if the connection is read only
*
* @exception java.sql.SQLException if a database access error occurs
*/
public boolean isReadOnly() throws java.sql.SQLException {
if (Driver.TRACE) {
Object[] args = new Object[0];
Debug.methodCall(this, "isReadOnly", args);
Debug.returnValue(this, "isReadOnly", new Boolean(this.readOnly));
}
return this.readOnly;
}
/**
* @see Connection#setSavepoint()
*/
public java.sql.Savepoint setSavepoint() throws SQLException {
throw new NotImplemented();
}
/**
* @see Connection#setSavepoint(String)
*/
public java.sql.Savepoint setSavepoint(String arg0)
throws SQLException {
throw new NotImplemented();
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public TimeZone getServerTimezone() {
return this.serverTimezone;
}
/**
* DOCUMENT ME!
*
* @param level DOCUMENT ME!
*
* @throws java.sql.SQLException DOCUMENT ME!
* @throws SQLException DOCUMENT ME!
*/
public void setTransactionIsolation(int level) throws java.sql.SQLException {
if (Driver.TRACE) {
Object[] args = { new Integer(level) };
Debug.methodCall(this, "setTransactionIsolation", args);
}
checkClosed();
if (this.hasIsolationLevels) {
StringBuffer sql = new StringBuffer(
"SET SESSION TRANSACTION ISOLATION LEVEL ");
switch (level) {
case java.sql.Connection.TRANSACTION_NONE:
throw new SQLException("Transaction isolation level "
+ "NONE not supported by MySQL");
case java.sql.Connection.TRANSACTION_READ_COMMITTED:
sql.append("READ COMMITTED");
break;
case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED:
sql.append("READ UNCOMMITTED");
break;
case java.sql.Connection.TRANSACTION_REPEATABLE_READ:
sql.append("REPEATABLE READ");
break;
case java.sql.Connection.TRANSACTION_SERIALIZABLE:
sql.append("SERIALIZABLE");
break;
default:
throw new SQLException("Unsupported transaction "
+ "isolation level '" + level + "'", "S1C00");
}
execSQL(sql.toString(), -1, this.database);
isolationLevel = level;
} else {
throw new java.sql.SQLException("Transaction Isolation Levels are "
+ "not supported on MySQL versions older than 3.23.36.", "S1C00");
}
}
/**
* Get this Connection's current transaction isolation mode.
*
* @return the current TRANSACTION_ mode value
*
* @exception java.sql.SQLException if a database access error occurs
* @throws SQLException DOCUMENT ME!
*/
public int getTransactionIsolation() throws java.sql.SQLException {
if (Driver.TRACE) {
Object[] args = new Object[0];
Debug.methodCall(this, "getTransactionIsolation", args);
Debug.returnValue(this, "getTransactionIsolation",
new Integer(isolationLevel));
}
if (this.hasIsolationLevels) {
java.sql.Statement stmt = null;
java.sql.ResultSet rs = null;
try {
stmt = this.createStatement();
if (stmt.getMaxRows() != 0) {
stmt.setMaxRows(0);
}
String query = null;
if (this.io.versionMeetsMinimum(4, 0, 3)) {
query = "SHOW VARIABLES LIKE 'tx_isolation'";
} else {
query = "SHOW VARIABLES LIKE 'transaction_isolation'";
}
rs = stmt.executeQuery(query);
if (rs.next()) {
String s = rs.getString(2);
if (s != null) {
Integer intTI = (Integer) mapTransIsolationName2Value
.get(s);
if (intTI != null) {
return intTI.intValue();
}
}
throw new SQLException(
"Could not map transaction isolation '" + s
+ " to a valid JDBC level.",
SQLError.SQL_STATE_GENERAL_ERROR);
} else {
throw new SQLException("Could not retrieve transaction isolation level from server",
SQLError.SQL_STATE_GENERAL_ERROR);
}
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception ex) {
// ignore
}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
} catch (Exception ex) {
// ignore
}
stmt = null;
}
}
}
return isolationLevel;
}
/**
* JDBC 2.0 Install a type-map object as the default type-map for this
* connection
*
* @param map the type mapping
*
* @throws SQLException if a database error occurs.
*/
public void setTypeMap(java.util.Map map) throws SQLException {
this.typeMap = map;
}
/**
* JDBC 2.0 Get the type-map object associated with this connection. By
* default, the map returned is empty.
*
* @return the type map
*
* @throws SQLException if a database error occurs
*/
public synchronized java.util.Map getTypeMap() throws SQLException {
if (this.typeMap == null) {
this.typeMap = new HashMap();
}
return this.typeMap;
}
/**
* The first warning reported by calls on this Connection is returned.
* <B>Note:</B> Sebsequent warnings will be changed to this
* java.sql.SQLWarning
*
* @return the first java.sql.SQLWarning or null
*
* @exception java.sql.SQLException if a database access error occurs
*/
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException {
if (Driver.TRACE) {
Object[] args = new Object[0];
Debug.methodCall(this, "getWarnings", args);
Debug.returnValue(this, "getWarnings", null);
}
return null;
}
/**
* Allow use of LOAD LOCAL INFILE?
*
* @return true if allowLoadLocalInfile was set to true.
*/
public boolean allowLoadLocalInfile() {
return this.allowLoadLocalInfile;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public boolean capitalizeDBMDTypes() {
return this.capitalizeDBMDTypes;
}
/**
* After this call, getWarnings returns null until a new warning is
* reported for this connection.
*
* @exception java.sql.SQLException if a database access error occurs
*/
public void clearWarnings() throws java.sql.SQLException {
if (Driver.TRACE) {
Object[] args = new Object[0];
Debug.methodCall(this, "clearWarnings", args);
}
// firstWarning = null;
}
/**
* In some cases, it is desirable to immediately release a Connection's
* database and JDBC resources instead of waiting for them to be
* automatically released (cant think why off the top of my head)
* <B>Note:</B> A Connection is automatically closed when it is garbage
* collected. Certain fatal errors also result in a closed connection.
*
* @exception java.sql.SQLException if a database access error occurs
*/
public void close() throws java.sql.SQLException {
if (this.explicitCloseLocation == null) {
this.explicitCloseLocation = new Throwable();
}
realClose(true, true);
}
/**
* The method commit() makes all changes made since the previous
* commit/rollback permanent and releases any database locks currently
* held by the Connection. This method should only be used when
* auto-commit has been disabled.
*
* <p>
* <b>Note:</b> MySQL does not support transactions, so this method is a
* no-op.
* </p>
*
* @exception java.sql.SQLException if a database access error occurs
* @throws SQLException DOCUMENT ME!
*
* @see setAutoCommit
*/
public void commit() throws java.sql.SQLException {
if (Driver.TRACE) {
Object[] args = new Object[0];
Debug.methodCall(this, "commit", args);
}
checkClosed();
try {
// no-op if _relaxAutoCommit == true
if (this.autoCommit && !this.relaxAutoCommit) {
throw new SQLException("Can't call commit when autocommit=true",
SQLError.SQL_STATE_GENERAL_ERROR);
} else if (this.transactionsSupported) {
execSQL("commit", -1, this.database);
}
} finally {
if (this.reconnectAtTxEnd) {
pingAndReconnect(true);
}
}
return;
}
//--------------------------JDBC 2.0-----------------------------
/**
* JDBC 2.0 Same as createStatement() above, but allows the default result
* set type and result set concurrency type to be overridden.
*
* @param resultSetType a result set type, see ResultSet.TYPE_XXX
* @param resultSetConcurrency a concurrency type, see ResultSet.CONCUR_XXX
*
* @return a new Statement object
*
* @exception SQLException if a database-access error occurs.
*/
public java.sql.Statement createStatement(int resultSetType,
int resultSetConcurrency) throws SQLException {
checkClosed();
Statement stmt = new com.mysql.jdbc.Statement(this, this.database);
stmt.setResultSetType(resultSetType);
stmt.setResultSetConcurrency(resultSetConcurrency);
return stmt;
}
/**
* SQL statements without parameters are normally executed using Statement
* objects. If the same SQL statement is executed many times, it is more
* efficient to use a PreparedStatement
*
* @return a new Statement object
*
* @throws SQLException passed through from the constructor
*/
public java.sql.Statement createStatement() throws SQLException {
return createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY);
}
/**
* @see Connection#createStatement(int, int, int)
*/
public java.sql.Statement createStatement(int resultSetType,
int resultSetConcurrency, int resultSetHoldability)
throws SQLException {
if (this.pedantic) {
if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
throw new SQLException("HOLD_CUSRORS_OVER_COMMIT is only supported holdability level",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
}
return createStatement(resultSetType, resultSetConcurrency);
}
/**
* DOCUMENT ME!
*
* @throws Throwable DOCUMENT ME!
*/
public void finalize() throws Throwable {
cleanup(null);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -