public class Connection extends Object implements Connection
注:默认情况下,Connection 对象处于自动提交模式下,这意味着它在执行每个语句后都会自动提交更改。 如果禁用自动提交模式,为了提交更改,必须显式调用 commit 方法;否则无法保存数据库更改。
| 限定符和类型 | 字段和说明 |
|---|---|
protected boolean |
autoCommit
是否自动提交
|
static AtomicInteger |
checkConnectionIsValidTimes |
protected boolean |
closeCurrResult
结果集数据全部读取完后,是否自动关闭
|
protected static HashMap<Integer,IsoLevel> |
iosLevelMap
事务隔离级别映射Map(JDK-XUGU)
|
protected static Object |
ipPoolLock
ip地址列表操作锁对象
|
protected static HashMap<String,Vector<ArrayList<String>>> |
ipsPool
集群正常连接节点的ip地址列表(一个应用中可以连接多个集群会产生多个集群的IP地址都背put进ipsPool中)
ArrayList: IP地址、连接数、连接失败次数、端口号、isNewConn。
|
protected static boolean |
isNewConnection
是否以新加入节点建立连接方式建立连接
|
protected static boolean |
isSSLLoad |
protected String |
lob_ret
新添加的大对象返回方式
|
protected Map |
openStatements
当前Connection打开的所有 Statement 对象
|
protected boolean |
redirect
benchmarksql模式下,建立连接时,重定向到分域的节点上(false表示需要重定向)
|
protected static int |
roundIdx |
protected int |
RsHoldablity |
protected SlowSQLBean |
slowSQLBean
慢SQL对象
|
protected SQLException |
sqlE |
protected static LinkedList<String[]> |
unConList
集群异常连接的节点ip地址列表(用于定时探测活性的死亡节点列表)
String[]:IP地址和端口号
|
protected boolean |
useSSL |
protected static ScheduledThreadPoolExecutor |
validTaskExecutor
定时探活作业对象
|
| 构造器和说明 |
|---|
Connection() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
abort(Executor executor) |
void |
addDataType(String type,
Class<? extends DBobject> klass) |
protected boolean |
checkRecordSlowSQL()
是否开启慢SQL记载
|
protected void |
checkSQLNull(String sql)
判断执行语句为NULL时,应该抛异常
|
void |
clearBuffer() |
void |
clearWarnings()
清除为此 Connection 对象报告的所有警告。
|
Connection |
cloneCurConnection() |
void |
close()
立即释放此 Connection 对象的数据库和 JDBC 资源,而不是等待它们被自动释放。
|
void |
closeAllOpenStatements()
关闭所有打开的 Statement 对象
|
void |
commit()
使自从上一次提交/回滚以来进行的所有更改成为持久更改,并释放此 Connection 对象当前保存的所有数据库锁定。
|
protected ArrayList<String> |
CreateAndInitArrayList(String ipStr,
int port,
boolean isNewConn)
用于构造ipsVector中的List元素:IP地址、连接数、连接失败次数、端口号、isNewConn(是否是新加入节点)
|
Array |
createArrayOf(String typeName,
Object[] elements)
------------------------ end ------------------------------
|
Blob |
createBlob()
创建XUGU Blob对象
|
Clob |
createClob()
创建XUGU Clob对象
|
NClob |
createNClob() |
SQLXML |
createSQLXML() |
Statement |
createStatement()
创建一个 Statement 对象来将 SQL 语句发送到数据库。
|
Statement |
createStatement(int resultSetType,
int resultSetConcurrency)
创建一个 Statement 对象,该对象将生成具有给定类型和并发性的 ResultSet 对象。
|
Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
创建一个 Statement 对象,该对象将生成具有给定类型、并发性和可保存性的 ResultSet 对象。
|
Struct |
createStruct(String typeName,
Object[] attributes) |
boolean |
getAutoCommit()
检索此 Connection 对象的当前自动提交模式
|
protected int |
getBatchOrMoreResultMode()
当执行命令为插入多条记录时,结果接收到I时,是按照多结果集接受,还是按照批量接收。
|
String |
getCatalog()
检索此 Connection 对象的当前目录名称。
|
String |
getCharSet()
返回连接上字符集合
|
Properties |
getClientInfo() |
String |
getClientInfo(String name) |
ClientInfo |
getClientInformation() |
int |
getCloseTime() |
int |
getConnState() |
String |
getDataBase() |
protected int |
getDatabseMajorVersion()
获取服务器的主版本好。
|
protected int |
getDatabseMinorVersion()
获取服务器的主版本好。
|
int |
getHoldability()
检索使用此 Connection 对象创建的 ResultSet 对象的当前可保存性。
|
ConnectionIO |
getIO() |
boolean |
getIsStreamEnd()
管理器用来判断流式导入是否结束,返回true表示导入结束
|
DatabaseMetaData |
getMetaData()
获取 DatabaseMetaData 对象,该对象包含关于 Connection 对象连接到的数据库的元数据。
|
int |
getNetworkTimeout()
------------------- JDBC4.1 ----------------------------------
|
DBobject |
getObject(String type,
@Nullable String value,
byte[] byteValue) |
protected int |
getRealTimeout(int expectedTimeout) |
protected static int |
getRoundIdx(boolean next)
互斥获取IpVector中的当前下标
|
String |
getSchema() |
String |
getServerIp() |
int |
getServerPort() |
Vector<String> |
getStreamErrorVector()
管理器用来取流式导入的错误信息的Vector
|
int |
getTransactionIsolation()
检索此 Connection 对象的当前事务隔离级别。
|
Map<String,Class<?>> |
getTypeMap()
将给定的 TypeMap 对象安装为此 Connection 对象的类型映射表。
|
String |
getUser() |
protected static ScheduledThreadPoolExecutor |
getValidTaskExecutor()
同步获取定时探测作业对象
|
SQLWarning |
getWarnings()
检索此 Connection 对象上的调用报告的第一个警告。
|
protected boolean |
is301Protocol()
当前连接是否使用301协议
|
boolean |
isClosed()
检索此 Connection 对象是否已经被关闭。
|
protected static boolean |
isNewConnection()
同步获取建立连接的方式(true:新加入节点方式;false:轮转方式)
当有新节点加入时,IP分配调用getConnectInfoListByConTimes()
否则IP分配调用getConnectInfoListRound()
|
boolean |
isReadOnly()
检索此 Connection 对象是否处于只读模式。
|
boolean |
isUseBatch()
返回批处理功能是否开启
|
boolean |
isValid(int timeout)
检查连接对象是否有效
|
protected static boolean |
isValidateFlag()
同步获取定时探活作业是否已启动,true表示已启动
|
boolean |
isWrapperFor(Class<?> arg0) |
Statement |
lobStatement() |
String |
nativeSQL(String sql)
将给定的 SQL 语句转换成系统本机 SQL 语法。
|
List<ArrayList<String>> |
parserXml(String fileName,
int port)
add by sdc for connection ips xml file parsing
|
CallableStatement |
prepareCall(String sql)
创建一个 CallableStatement 对象来调用数据库存储过程。
|
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency)
创建一个 CallableStatement 对象,该对象将生成具有给定类型和并发性的 ResultSet 对象。
|
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
创建一个 CallableStatement 对象,该对象将生成具有给定类型和并发性的 ResultSet 对象。
|
PreparedStatement |
prepareStatement(String sql)
创建一个 PreparedStatement 对象来将参数化的 SQL 语句发送到数据库。
|
PreparedStatement |
prepareStatement(String sql,
int autoGenKeyIndex)
创建一个默认 PreparedStatement 对象,该对象能检索自动生成的键。
|
PreparedStatement |
prepareStatement(String sql,
int[] autoGenKeyIndexes)
创建一个能够返回由给定数组指定的自动生成键的默认 PreparedStatement 对象。
|
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency)
创建一个 PreparedStatement 对象,该对象将生成具有给定类型和并发性的 ResultSet 对象。
|
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
创建一个 PreparedStatement 对象,该对象将生成具有给定类型、并发性和可保存性的 ResultSet 对象。
|
PreparedStatement |
prepareStatement(String sql,
String[] autoGenKeyColNames)
创建一个能够返回由给定数组指定的自动生成键的默认 PreparedStatement 对象。
|
void |
releaseSavepoint(Savepoint savepoint)
从当前事务中移除给定 Savepoint 对象。
|
void |
rollback()
取消在当前事务中进行的所有更改,并释放此 Connection 对象当前保存的所有数据库锁定。
|
void |
rollback(Savepoint savepoint)
取消设置给定 Savepoint 对象之后进行的所有更改。
|
void |
sendHalt()
发送中断信号,停止接受服务器返回数据
|
void |
setAutoCommit(boolean autoCommitFlag)
将此连接的自动提交模式设置为给定状态。
|
void |
setCatalog(String catalog)
设置给定目录名称,以便选择要在其中进行工作的此 Connection 对象数据库的子空间。
|
void |
setClientInfo(Properties properties) |
void |
setClientInfo(String name,
String value) |
void |
setClose(boolean b) |
void |
setHoldability(int arg0)
将使用此 Connection 对象创建的 ResultSet 对象的可保存性 (holdability) 更改为给定可保存性。
|
void |
setIsora(boolean isora) |
void |
setNetworkTimeout(Executor executor,
int milliseconds) |
protected static void |
setNewConnection(boolean isNewConnection) |
void |
setReadOnly(boolean readOnlyFlag)
将此连接设置为只读模式,作为驱动程序启用数据库优化的提示。
|
protected static void |
setRoundIdx(int indexVal) |
Savepoint |
setSavepoint()
在当前事务中创建一个未命名的保存点 (savepoint),并返回表示它的新 Savepoint 对象。
|
Savepoint |
setSavepoint(String name)
在当前事务中创建一个具有给定名称的保存点,并返回表示它的新 Savepoint 对象。
|
void |
setSchema(String schema) |
void |
setTransactionIsolation(int isoLevel)
试图将此 Connection 对象的事务隔离级别更改为给定的级别。
|
void |
setTypeMap(Map<String,Class<?>> arg0) |
protected static void |
setValidateFlag(boolean validateFlag) |
protected static void |
setValidTaskExecutor(ScheduledThreadPoolExecutor validTask) |
<T> T |
unwrap(Class<T> arg0) |
protected boolean |
useLobDescribMode()
返回数据库返回LOB字段值时,是否采用描述符方式返回
|
public static AtomicInteger checkConnectionIsValidTimes
protected boolean useSSL
protected static boolean isSSLLoad
protected int RsHoldablity
protected SQLException sqlE
protected boolean autoCommit
protected String lob_ret
protected boolean closeCurrResult
protected static HashMap<String,Vector<ArrayList<String>>> ipsPool
protected static LinkedList<String[]> unConList
protected static boolean isNewConnection
protected static ScheduledThreadPoolExecutor validTaskExecutor
protected static Object ipPoolLock
protected static int roundIdx
protected boolean redirect
protected Map openStatements
protected SlowSQLBean slowSQLBean
public int getCloseTime()
public String getServerIp()
public int getServerPort()
public String getDataBase()
public void closeAllOpenStatements()
throws SQLException
SQLExceptionpublic Statement createStatement() throws SQLException
没有参数的 SQL 语句通常使用 Statement 对象执行
createStatement 在接口中 ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql) throws SQLException
带有 IN 参数或不带有 IN 参数的 SQL 语句都可以被预编译并存储在 PreparedStatement 对象中。 然后可以有效地使用此对象来多次执行该语句。
prepareStatement 在接口中 ConnectionSQLExceptionpublic CallableStatement prepareCall(String sql) throws SQLException
prepareCall 在接口中 ConnectionSQLExceptionpublic String nativeSQL(String sql) throws SQLException
---暂时不实现
暂时实现为和服务器编码(UTF-8)一致,将发送语句先转成连接串编码,然后在构造utf-8码的字串发给服务器
nativeSQL 在接口中 ConnectionSQLExceptionpublic void setAutoCommit(boolean autoCommitFlag)
throws SQLException
setAutoCommit 在接口中 ConnectionSQLExceptionpublic boolean getAutoCommit()
throws SQLException
getAutoCommit 在接口中 ConnectionSQLExceptionpublic void commit()
throws SQLException
commit 在接口中 ConnectionSQLExceptionpublic void rollback()
throws SQLException
rollback 在接口中 ConnectionSQLExceptionpublic void close()
throws SQLException
在已经关闭的 Connection 对象上调用 close 方法是无操作 (no-op)。
close 在接口中 AutoCloseableclose 在接口中 ConnectionSQLExceptionpublic boolean isClosed()
如果已经在连接上调用 close 方法或者发生某些严重的错误,则关闭 connection。 此方法只保证在已经调用 Connection.close 方法之后被调用时返回 true。
isClosed 在接口中 Connectionpublic DatabaseMetaData getMetaData() throws SQLException
getMetaData 在接口中 ConnectionSQLExceptionpublic void setReadOnly(boolean readOnlyFlag)
throws SQLException
注:此方法无法在事务处理期间调用。
setReadOnly 在接口中 ConnectionSQLExceptionpublic boolean isReadOnly()
throws SQLException
isReadOnly 在接口中 ConnectionSQLExceptionpublic void setCatalog(String catalog) throws SQLException
setCatalog 在接口中 ConnectionSQLExceptionpublic String getCatalog() throws SQLException
getCatalog 在接口中 ConnectionSQLExceptionpublic String getUser() throws SQLException
SQLExceptionpublic void setTransactionIsolation(int isoLevel)
throws SQLException
setTransactionIsolation 在接口中 ConnectionSQLExceptionpublic int getTransactionIsolation()
throws SQLException
getTransactionIsolation 在接口中 ConnectionSQLExceptionpublic SQLWarning getWarnings() throws SQLException
---暂时不考虑实现
getWarnings 在接口中 ConnectionSQLExceptionpublic void clearWarnings()
throws SQLException
---暂时不考虑实现
clearWarnings 在接口中 ConnectionSQLExceptionpublic Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
createStatement 在接口中 ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
prepareStatement 在接口中 ConnectionSQLExceptionpublic CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
prepareCall 在接口中 ConnectionSQLExceptionpublic Map<String,Class<?>> getTypeMap() throws SQLException
getTypeMap 在接口中 ConnectionSQLExceptionpublic void setHoldability(int arg0)
throws SQLException
---暂时考虑不实现
setHoldability 在接口中 ConnectionSQLExceptionpublic int getHoldability()
throws SQLException
---暂时考虑不实现
getHoldability 在接口中 ConnectionSQLExceptionpublic Savepoint setSavepoint() throws SQLException
setSavepoint 在接口中 ConnectionSQLExceptionpublic Savepoint setSavepoint(String name) throws SQLException
setSavepoint 在接口中 ConnectionSQLExceptionpublic void rollback(Savepoint savepoint) throws SQLException
此方法应该只在已禁用自动提交时使用。
rollback 在接口中 ConnectionSQLExceptionpublic void releaseSavepoint(Savepoint savepoint) throws SQLException
releaseSavepoint 在接口中 ConnectionSQLExceptionpublic Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
createStatement 在接口中 ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
prepareStatement 在接口中 ConnectionSQLExceptionpublic CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
prepareCall 在接口中 ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, int autoGenKeyIndex) throws SQLException
prepareStatement 在接口中 ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, int[] autoGenKeyIndexes) throws SQLException
带有 IN 参数或不带有 IN 参数的 SQL 语句都可以被预编辑并存储在 PreparedStatement 对象中。 然后可以有效地使用此对象来多次执行该语句。
---暂时考虑不实现
prepareStatement 在接口中 ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, String[] autoGenKeyColNames) throws SQLException
prepareStatement 在接口中 ConnectionSQLExceptionpublic int getNetworkTimeout()
throws SQLException
getNetworkTimeout 在接口中 ConnectionSQLExceptionpublic void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException
setNetworkTimeout 在接口中 ConnectionSQLExceptionpublic String getSchema() throws SQLException
getSchema 在接口中 ConnectionSQLExceptionpublic void abort(Executor executor)
abort 在接口中 Connectionpublic Array createArrayOf(String typeName, Object[] elements) throws SQLException
createArrayOf 在接口中 ConnectionSQLExceptionpublic Blob createBlob() throws SQLException
createBlob 在接口中 ConnectionSQLExceptionpublic Clob createClob() throws SQLException
createClob 在接口中 ConnectionSQLExceptionpublic NClob createNClob() throws SQLException
createNClob 在接口中 ConnectionSQLExceptionpublic SQLXML createSQLXML() throws SQLException
createSQLXML 在接口中 ConnectionSQLExceptionpublic Struct createStruct(String typeName, Object[] attributes) throws SQLException
createStruct 在接口中 ConnectionSQLExceptionpublic void setSchema(String schema) throws SQLException
setSchema 在接口中 ConnectionSQLExceptionpublic Properties getClientInfo() throws SQLException
getClientInfo 在接口中 ConnectionSQLExceptionpublic ClientInfo getClientInformation() throws SQLException
SQLExceptionpublic String getClientInfo(String name) throws SQLException
getClientInfo 在接口中 ConnectionSQLExceptionpublic boolean isValid(int timeout)
throws SQLException
isValid 在接口中 Connectiontimeout - 等待用来验证连接是否完成的数据库操作的时间,以秒为单位SQLExceptionpublic void setClientInfo(Properties properties) throws SQLClientInfoException
setClientInfo 在接口中 ConnectionSQLClientInfoExceptionpublic void setClientInfo(String name, String value) throws SQLClientInfoException
setClientInfo 在接口中 ConnectionSQLClientInfoExceptionpublic void setClose(boolean b)
public int getConnState()
public void clearBuffer()
public String getCharSet()
public void sendHalt()
throws SQLException
SQLExceptionpublic List<ArrayList<String>> parserXml(String fileName, int port) throws SQLException
fileName - SQLExceptionpublic Connection cloneCurConnection() throws SQLException
SQLExceptionpublic Statement lobStatement() throws SQLException
SQLExceptionpublic boolean getIsStreamEnd()
public void setIsora(boolean isora)
public ConnectionIO getIO()
protected int getDatabseMajorVersion()
throws SQLException
SQLExceptionprotected int getDatabseMinorVersion()
throws SQLException
SQLExceptionpublic boolean isWrapperFor(Class<?> arg0) throws SQLException
isWrapperFor 在接口中 WrapperSQLExceptionpublic <T> T unwrap(Class<T> arg0) throws SQLException
unwrap 在接口中 WrapperSQLExceptionpublic void setTypeMap(Map<String,Class<?>> arg0) throws SQLException
setTypeMap 在接口中 ConnectionSQLExceptionprotected static int getRoundIdx(boolean next)
protected static void setRoundIdx(int indexVal)
protected static ScheduledThreadPoolExecutor getValidTaskExecutor()
protected static void setValidTaskExecutor(ScheduledThreadPoolExecutor validTask)
protected static boolean isValidateFlag()
protected static void setValidateFlag(boolean validateFlag)
protected ArrayList<String> CreateAndInitArrayList(String ipStr, int port, boolean isNewConn)
protected static boolean isNewConnection()
protected static void setNewConnection(boolean isNewConnection)
protected boolean is301Protocol()
protected boolean checkRecordSlowSQL()
protected void checkSQLNull(String sql) throws SQLException
sql - SQLExceptionprotected int getBatchOrMoreResultMode()
protected boolean useLobDescribMode()
public boolean isUseBatch()
public DBobject getObject(String type, @Nullable String value, byte[] byteValue) throws SQLException
SQLExceptionpublic void addDataType(String type, Class<? extends DBobject> klass) throws SQLException
SQLExceptionprotected int getRealTimeout(int expectedTimeout)
Copyright © 2025. All rights reserved.