jdbcconnection.java
来自「非常棒的java数据库」· Java 代码 · 共 1,501 行 · 第 1/4 页
JAVA
1,501 行
checkRunOver(i, len, sql);
while (Character.isSpaceChar(chars[i])) {
i++;
checkRunOver(i, len, sql);
}
if (sql.charAt(i) != '=') {
throw Message.getSyntaxError(sql, i, "=");
}
chars[i++] = ' ';
checkRunOver(i, len, sql);
while (Character.isSpaceChar(chars[i])) {
i++;
checkRunOver(i, len, sql);
}
}
while (!Character.isSpaceChar(chars[i])) {
i++;
checkRunOver(i, len, sql);
}
int remove = 0;
if (found(sql, start, "fn")) {
remove = 2;
} else if (found(sql, start, "escape")) {
break;
} else if (found(sql, start, "call")) {
break;
} else if (found(sql, start, "oj")) {
remove = 2;
} else if (found(sql, start, "ts")) {
remove = 2;
} else if (found(sql, start, "t")) {
remove = 1;
} else if (found(sql, start, "d")) {
remove = 1;
} else if (found(sql, start, "params")) {
remove = "params".length();
}
for (i = start; remove > 0; i++, remove--) {
chars[i] = ' ';
}
break;
case '}':
if (--level < 0) {
throw Message.getSyntaxError(sql, i);
}
chars[i] = ' ';
break;
default:
}
}
if (level != 0) {
throw Message.getSyntaxError(sql, sql.length() - 1);
}
if (chars != null) {
sql = new String(chars);
}
return sql;
}
private void checkRunOver(int i, int len, String sql) throws SQLException {
if (i >= len) {
throw Message.getSyntaxError(sql, i);
}
}
private boolean found(String sql, int start, String other) {
return sql.regionMatches(true, start, other, 0, other.length());
}
private void checkTypeAndConcurrency(int resultSetType, int resultSetConcurrency) throws SQLException {
// TODO compatibility / correctness: OpenOffice uses TYPE_SCROLL_SENSITIVE
// if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) {
// throw Message.getInvalidValueException(
// "" + resultSetType, "resultSetType");
// }
// if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
// throw Message.getInvalidValueException(
// "" + resultSetConcurrency, "resultSetConcurrency");
// }
}
private void checkHoldability(int resultSetHoldability) throws SQLException {
// TODO compatibility / correctness: DBPool uses
// ResultSet.HOLD_CURSORS_OVER_COMMIT
//#ifdef JDK14
if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT
&& resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
throw Message.getInvalidValueException("" + resultSetHoldability, "resultSetHoldability");
}
//#endif
}
void checkClosed() throws SQLException {
if (session == null) {
throw Message.getSQLException(ErrorCode.OBJECT_CLOSED);
}
if (session.isClosed()) {
throw Message.getSQLException(ErrorCode.DATABASE_CALLED_AT_SHUTDOWN);
}
}
String getURL() throws SQLException {
checkClosed();
return url;
}
String getUser() throws SQLException {
checkClosed();
return user;
}
protected void finalize() {
if (!SysProperties.runFinalize) {
return;
}
if (isInternal) {
return;
}
if (session != null) {
trace.error("Connection not closed", openStackTrace);
try {
close();
} catch (SQLException e) {
trace.debug("finalize", e);
}
}
}
private void rollbackInternal() throws SQLException {
rollback = prepareCommand("ROLLBACK", rollback);
rollback.executeUpdate();
}
/**
* INTERNAL
*/
public int getPowerOffCount() {
return (session == null || session.isClosed()) ? 0 : session.getPowerOffCount();
}
/**
* INTERNAL
*/
public void setPowerOffCount(int count) throws SQLException {
if (session != null) {
session.setPowerOffCount(count);
}
}
/**
* INTERNAL
*/
public void setExecutingStatement(Statement stat) {
executingStatement = stat;
}
ResultInterface getGeneratedKeys(JdbcStatement statement, int id) throws SQLException {
getGeneratedKeys = prepareCommand("CALL IDENTITY()", getGeneratedKeys);
return getGeneratedKeys.executeQuery(0, false);
}
/**
* Create a new empty Clob object.
*
* @return the object
*/
public Clob createClob() throws SQLException {
try {
int id = getNextId(TraceObject.CLOB);
debugCodeAssign("Clob", TraceObject.CLOB, id, "createClob()");
checkClosed();
ValueLob v = ValueLob.createSmallLob(Value.CLOB, new byte[0]);
return new JdbcClob(session, this, v, id);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Create a new empty Blob object.
*
* @return the object
*/
public Blob createBlob() throws SQLException {
try {
int id = getNextId(TraceObject.BLOB);
debugCodeAssign("Blob", TraceObject.BLOB, id, "createClob()");
checkClosed();
ValueLob v = ValueLob.createSmallLob(Value.BLOB, new byte[0]);
return new JdbcBlob(session, this, v, id);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Create a new empty NClob object.
*
* @return the object
*/
//#ifdef JDK16
/*
public NClob createNClob() throws SQLException {
try {
int id = getNextId(TraceObject.CLOB);
debugCodeAssign("NClob", TraceObject.CLOB, id, "createNClob()");
checkClosed();
ValueLob v = ValueLob.createSmallLob(Value.CLOB, new byte[0]);
return new JdbcClob(session, this, v, id);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
*/
//#endif
/**
* [Not supported] Create a new empty SQLXML object.
*/
//#ifdef JDK16
/*
public SQLXML createSQLXML() throws SQLException {
throw Message.getUnsupportedException();
}
*/
//#endif
/**
* [Not supported] Create a new empty Array object.
*/
//#ifdef JDK16
/*
public Array createArrayOf(String typeName, Object[] elements)
throws SQLException {
throw Message.getUnsupportedException();
}
*/
//#endif
/**
* [Not supported] Create a new empty Struct object.
*/
//#ifdef JDK16
/*
public Struct createStruct(String typeName, Object[] attributes)
throws SQLException {
throw Message.getUnsupportedException();
}
*/
//#endif
/**
* Returns true if this connection is still valid.
*
* @return true if the connection is valid.
*/
public synchronized boolean isValid(int timeout) {
try {
debugCodeCall("isValid", timeout);
checkClosed();
getInternalAutoCommit();
return true;
} catch (Throwable e) {
// this method doesn't throw an exception, but it logs it
logAndConvert(e);
return false;
}
}
/**
* [Not supported] Set a client property.
*/
//#ifdef JDK16
/*
public void setClientInfo(String name, String value)
throws SQLClientInfoException {
throw new SQLClientInfoException();
}
*/
//#endif
/**
* [Not supported] Set the client properties.
*/
//#ifdef JDK16
/*
public void setClientInfo(Properties properties) throws SQLClientInfoException {
throw new SQLClientInfoException();
}
*/
//#endif
/**
* [Not supported] Get the client properties.
*/
//#ifdef JDK16
/*
public Properties getClientInfo() throws SQLClientInfoException {
throw new SQLClientInfoException();
}
*/
//#endif
/**
* [Not supported] Set a client property.
*/
public String getClientInfo(String name) throws SQLException {
throw Message.getUnsupportedException();
}
/**
* [Not supported] Return an object of this class if possible.
*
* @param iface the class
*/
//#ifdef JDK16
/*
public <T> T unwrap(Class<T> iface) throws SQLException {
throw Message.getUnsupportedException();
}
*/
//#endif
/**
* [Not supported] Checks if unwrap can return an object of this class.
*
* @param iface the class
*/
//#ifdef JDK16
/*
public boolean isWrapperFor(Class< ? > iface) throws SQLException {
throw Message.getUnsupportedException();
}
*/
//#endif
Value createClob(Reader x, long length) throws SQLException {
if (x == null) {
return ValueNull.INSTANCE;
}
if (length <= 0) {
length = -1;
}
Value v = ValueLob.createClob(x, length, session.getDataHandler());
return v;
}
Value createBlob(InputStream x, long length) throws SQLException {
if (x == null) {
return ValueNull.INSTANCE;
}
if (length <= 0) {
length = -1;
}
Value v = ValueLob.createBlob(x, length, session.getDataHandler());
return v;
}
private void checkMap(Map map) throws SQLException {
if (map != null && map.size() > 0) {
throw Message.getUnsupportedException();
}
}
/**
* INTERNAL
*/
public String toString() {
return getTraceObjectName() + ": url=" + url + " user=" + user;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?