📄 jdbcconnection.java
字号:
debugCodeCall("isClosed");
return session == null || session.isClosed();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Translates a SQL statement into the database grammar.
*
* @return the translated statement
* @throws SQLException
* if the connection is closed
*/
public String nativeSQL(String sql) throws SQLException {
try {
debugCodeCall("nativeSQL", sql);
checkClosed();
return translateSQL(sql);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* According to the JDBC specs, this
* setting is only a hint to the database to enable optimizations - it does
* not cause writes to be prohibited.
*
* @throws SQLException
* if the connection is closed
*/
public void setReadOnly(boolean readOnly) throws SQLException {
try {
if (debug()) {
debugCode("setReadOnly(" + readOnly + ");");
}
checkClosed();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns true if the database is read-only.
*
* @return if the database is read-only
* @throws SQLException
* if the connection is closed
*/
public boolean isReadOnly() throws SQLException {
try {
debugCodeCall("isReadOnly");
checkClosed();
getReadOnly = prepareCommand("CALL READONLY()", getReadOnly);
ResultInterface result = getReadOnly.executeQuery(0, false);
result.next();
boolean readOnly = result.currentRow()[0].getBoolean().booleanValue();
return readOnly;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Set the default catalog name.
* This call is ignored.
*
* @throws SQLException if the connection is closed
*/
public void setCatalog(String catalog) throws SQLException {
try {
debugCodeCall("setCatalog", catalog);
checkClosed();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Gets the current catalog name.
*
* @throws SQLException
* if the connection is closed
*/
public String getCatalog() throws SQLException {
try {
debugCodeCall("getCatalog");
checkClosed();
if (catalog == null) {
CommandInterface cat = prepareCommand("CALL DATABASE()", Integer.MAX_VALUE);
ResultInterface result = cat.executeQuery(0, false);
result.next();
catalog = result.currentRow()[0].getString();
cat.close();
}
return catalog;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Gets the first warning reported by calls on this object.
*
* @return null
*/
public SQLWarning getWarnings() throws SQLException {
try {
debugCodeCall("getWarnings");
checkClosed();
return null;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Clears all warnings.
*/
public void clearWarnings() throws SQLException {
try {
debugCodeCall("clearWarnings");
checkClosed();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Creates a prepared statement with the specified result set type and
* concurrency.
*
* @return the prepared statement
* @throws SQLException
* if the connection is closed or the result set type or
* concurrency are not supported
*/
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
try {
int id = getNextId(TraceObject.PREPARED_STATEMENT);
if (debug()) {
debugCodeAssign("PreparedStatement", TraceObject.PREPARED_STATEMENT, id, "prepareStatement(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ")");
}
checkClosed();
checkTypeAndConcurrency(resultSetType, resultSetConcurrency);
sql = translateSQL(sql);
return new JdbcPreparedStatement(session, this, sql, resultSetType, id, false);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Changes the current transaction isolation level. Calling this method will
* commit an open transaction, even if the new level is the same as the old
* one, except if the level is not supported.
*
* @param level the new transaction isolation level,
* Connection.TRANSACTION_READ_UNCOMMITTED,
* Connection.TRANSACTION_READ_COMMITTED, or
* Connection.TRANSACTION_SERIALIZABLE
* @throws SQLException if the connection is closed or the isolation level
* is not supported
*/
public void setTransactionIsolation(int level) throws SQLException {
try {
debugCodeCall("setTransactionIsolation", level);
checkClosed();
int lockMode;
switch(level) {
case Connection.TRANSACTION_READ_UNCOMMITTED:
lockMode = Constants.LOCK_MODE_OFF;
break;
case Connection.TRANSACTION_READ_COMMITTED:
lockMode = Constants.LOCK_MODE_READ_COMMITTED;
break;
case Connection.TRANSACTION_REPEATABLE_READ:
case Connection.TRANSACTION_SERIALIZABLE:
lockMode = Constants.LOCK_MODE_TABLE;
break;
default:
throw Message.getInvalidValueException("" + level, "level");
}
commit();
setLockMode = prepareCommand("SET LOCK_MODE ?", setLockMode);
((ParameterInterface) setLockMode.getParameters().get(0)).setValue(ValueInt.get(lockMode));
setLockMode.executeUpdate();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* INTERNAL
*/
public void setQueryTimeout(int seconds) throws SQLException {
try {
commit();
setQueryTimeout = prepareCommand("SET QUERY_TIMEOUT ?", setQueryTimeout);
((ParameterInterface) setQueryTimeout.getParameters().get(0)).setValue(ValueInt.get(seconds * 1000));
setQueryTimeout.executeUpdate();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* INTERNAL
*/
public int getQueryTimeout() throws SQLException {
try {
getQueryTimeout = prepareCommand("SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?", getQueryTimeout);
((ParameterInterface) getQueryTimeout.getParameters().get(0)).setValue(ValueString.get("QUERY_TIMEOUT"));
ResultInterface result = getQueryTimeout.executeQuery(0, false);
result.next();
int queryTimeout = result.currentRow()[0].getInt();
result.close();
if (queryTimeout == 0) {
return 0;
} else {
// round to the next second, otherwise 999 millis would return 0 seconds
return (queryTimeout + 999) / 1000;
}
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns the current transaction isolation level.
*
* @return the isolation level.
* @throws SQLException if the connection is closed
*/
public int getTransactionIsolation() throws SQLException {
try {
debugCodeCall("getTransactionIsolation");
checkClosed();
getLockMode = prepareCommand("CALL LOCK_MODE()", getLockMode);
ResultInterface result = getLockMode.executeQuery(0, false);
result.next();
int lockMode = result.currentRow()[0].getInt();
result.close();
int transactionIsolationLevel;
switch(lockMode) {
case Constants.LOCK_MODE_OFF:
transactionIsolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
break;
case Constants.LOCK_MODE_READ_COMMITTED:
transactionIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;
break;
case Constants.LOCK_MODE_TABLE:
case Constants.LOCK_MODE_TABLE_GC:
transactionIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
break;
default:
throw Message.getInternalError("lockMode:" + lockMode);
}
return transactionIsolationLevel;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Changes the current result set holdability.
*
* @param holdability
* ResultSet.HOLD_CURSORS_OVER_COMMIT or
* ResultSet.CLOSE_CURSORS_AT_COMMIT;
* @throws SQLException
* if the connection is closed or the holdability is not
* supported
*/
public void setHoldability(int holdability) throws SQLException {
try {
debugCodeCall("setHoldability", holdability);
checkClosed();
checkHoldability(holdability);
this.holdability = holdability;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns the current result set holdability.
*
* @return the holdability
* @throws SQLException if the connection is closed
*/
public int getHoldability() throws SQLException {
try {
debugCodeCall("getHoldability");
checkClosed();
return holdability;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Gets the type map.
*
* @return null
* @throws SQLException
* if the connection is closed
*/
public Map getTypeMap() throws SQLException {
try {
debugCodeCall("getTypeMap");
checkClosed();
return null;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* [Partially supported] Sets the type map. This is only supported if the
* map is empty or null.
*/
public void setTypeMap(Map map) throws SQLException {
try {
debugCode("setTypeMap(" + quoteMap(map) + ");");
checkMap(map);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Creates a new callable statement.
*
* @return the callable statement
* @throws SQLException
* if the connection is closed or the statement is not valid
*/
public CallableStatement prepareCall(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.CALLABLE_STATEMENT);
if (debug()) {
debugCodeAssign("CallableStatement", TraceObject.CALLABLE_STATEMENT, id, "prepareCall(" + quote(sql) + ")");
}
checkClosed();
sql = translateSQL(sql);
return new JdbcCallableStatement(session, this, sql, ResultSet.TYPE_FORWARD_ONLY, id);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Creates a callable statement with the specified result set type and
* concurrency.
*
* @return the callable statement
* @throws SQLException
* if the connection is closed or the result set type or
* concurrency are not supported
*/
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
try {
int id = getNextId(TraceObject.CALLABLE_STATEMENT);
if (debug()) {
debugCodeAssign("CallableStatement", TraceObject.CALLABLE_STATEMENT, id, "prepareCall(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ")");
}
checkClosed();
checkTypeAndConcurrency(resultSetType, resultSetConcurrency);
sql = translateSQL(sql);
return new JdbcCallableStatement(session, this, sql, resultSetType, id);
} catch (Throwable e) {
throw logAndConvert(e);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -