Class ConnectionHolder40
- java.lang.Object
-
- com.sun.gjc.spi.base.ConnectionHolder
-
- com.sun.gjc.spi.jdbc40.ConnectionHolder40
-
- All Implemented Interfaces:
AutoCloseable,Connection,Wrapper
- Direct Known Subclasses:
ConnectionWrapper40,ProfiledConnectionWrapper40
public class ConnectionHolder40 extends ConnectionHolder
Holds the java.sql.Connection object, which is to be passed to the application program.- Version:
- 1.0, 25-Aug-2006
- Author:
- Jagadish Ramu
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.sun.gjc.spi.base.ConnectionHolder
ConnectionHolder.ConnectionType
-
-
Field Summary
Fields Modifier and Type Field Description protected PropertiesdefaultClientInfoprotected static StringManagerlocalStrings-
Fields inherited from class com.sun.gjc.spi.base.ConnectionHolder
active, con, isClosed, mc, sm, statementTimeout, statementTimeoutEnabled, valid, wrappedAlready
-
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
-
Constructor Summary
Constructors Constructor Description ConnectionHolder40(Connection con, ManagedConnectionImpl mc, jakarta.resource.spi.ConnectionRequestInfo cxRequestInfo)Connection wrapper given to application program
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort(Executor executor)Abort operation to mark the connection internally as a bad connection for removal and to close the connection.voidclose()Closes the logical connection.
Cleans up client specific detailsArraycreateArrayOf(String typeName, Object[] elements)Factory method for creating Array objects.BlobcreateBlob()Constructs an object that implements theBlobinterface.ClobcreateClob()Constructs an object that implements theClobinterface.NClobcreateNClob()Constructs an object that implements theNClobinterface.SQLXMLcreateSQLXML()Constructs an object that implements theSQLXMLinterface.StructcreateStruct(String typeName, Object[] attributes)Factory method for creating Struct objects.PropertiesgetClientInfo()Returns a list containing the name and current value of each client info property supported by the driver.StringgetClientInfo(String name)Returns the value of the client info property specified by name.intgetNetworkTimeout()StringgetSchema()protected voidinit()cache the default client info which can will set back during close()
as this connection may be re-used by connection pool of application serverbooleanisValid(int timeout)Returns true if the connection has not been closed and is still valid.booleanisWrapperFor(Class<?> iface)Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.voidsetClientInfo(String name, String value)Sets the value of the client info property specified by name to the value specified by value.voidsetClientInfo(Properties properties)Sets the value of the connection's client info properties.voidsetNetworkTimeout(Executor executorObj, int milliseconds)voidsetSchema(String schema)<T> Tunwrap(Class<T> iface)Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.-
Methods inherited from class com.sun.gjc.spi.base.ConnectionHolder
associateConnection, checkValidity, clearWarnings, commit, createStatement, createStatement, createStatement, dissociateConnection, getAutoCommit, getCatalog, getConnection, getConnectionType, getHoldability, getManagedConnection, getMetaData, getMethodExecutor, getTransactionIsolation, getTypeMap, getWarnings, invalidate, isClosed, isReadOnly, isWrapped, jdbcPreInvoke, nativeSQL, performLazyAssociation, performLazyEnlistment, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setActive, setAutoCommit, setCatalog, setClosed, setConnectionType, setHoldability, setLazyAssociatableConnectionManager, setLazyEnlistableConnectionManager, setReadOnly, setSavepoint, setSavepoint, setTransactionIsolation, setTypeMap, wrapped
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
-
-
-
Field Detail
-
localStrings
protected static final StringManager localStrings
-
defaultClientInfo
protected Properties defaultClientInfo
-
-
Constructor Detail
-
ConnectionHolder40
public ConnectionHolder40(Connection con, ManagedConnectionImpl mc, jakarta.resource.spi.ConnectionRequestInfo cxRequestInfo)
Connection wrapper given to application program- Parameters:
con- Connection that is wrappedmc- ManagedConnectioncxRequestInfo- Connection Request Information
-
-
Method Detail
-
init
protected void init()
cache the default client info which can will set back during close()
as this connection may be re-used by connection pool of application server
-
createClob
public Clob createClob() throws SQLException
Constructs an object that implements theClobinterface. The object returned initially contains no data. ThesetAsciiStream,setCharacterStreamandsetStringmethods of theClobinterface may be used to add data to theClob.- Returns:
- An object that implements the
Clobinterface - Throws:
SQLException- if an object that implements theClobinterface can not be constructed, this method is called on a closed connection or a database access error occurs.SQLFeatureNotSupportedException- if the JDBC driver does not support this data type- Since:
- 1.6
-
createBlob
public Blob createBlob() throws SQLException
Constructs an object that implements theBlobinterface. The object returned initially contains no data. ThesetBinaryStreamandsetBytesmethods of theBlobinterface may be used to add data to theBlob.- Returns:
- An object that implements the
Blobinterface - Throws:
SQLException- if an object that implements theBlobinterface can not be constructed, this method is called on a closed connection or a database access error occurs.SQLFeatureNotSupportedException- if the JDBC driver does not support this data type- Since:
- 1.6
-
createNClob
public NClob createNClob() throws SQLException
Constructs an object that implements theNClobinterface. The object returned initially contains no data. ThesetAsciiStream,setCharacterStreamandsetStringmethods of theNClobinterface may be used to add data to theNClob.- Returns:
- An object that implements the
NClobinterface - Throws:
SQLException- if an object that implements theNClobinterface can not be constructed, this method is called on a closed connection or a database access error occurs.SQLFeatureNotSupportedException- if the JDBC driver does not support this data type- Since:
- 1.6
-
createSQLXML
public SQLXML createSQLXML() throws SQLException
Constructs an object that implements theSQLXMLinterface. The object returned initially contains no data. ThecreateXmlStreamWriterobject andsetStringmethod of theSQLXMLinterface may be used to add data to theSQLXMLobject.- Returns:
- An object that implements the
SQLXMLinterface - Throws:
SQLException- if an object that implements theSQLXMLinterface can not be constructed, this method is called on a closed connection or a database access error occurs.SQLFeatureNotSupportedException- if the JDBC driver does not support this data type- Since:
- 1.6
-
isValid
public boolean isValid(int timeout) throws SQLExceptionReturns true if the connection has not been closed and is still valid. The driver shall submit a query on the connection or use some other mechanism that positively verifies the connection is still valid when this method is called.The query submitted by the driver to validate the connection shall be executed in the context of the current transaction.
- Parameters:
timeout- The time in seconds to wait for the database operation used to validate the connection to complete. If the timeout period expires before the operation completes, this method returns false. A value of 0 indicates a timeout is not applied to the database operation.- Returns:
- true if the connection is valid, false otherwise
- Throws:
SQLException- if the value supplied fortimeoutis less then 0- Since:
- 1.6
- See Also:
DatabaseMetaData.getClientInfoProperties()
-
setClientInfo
public void setClientInfo(String name, String value) throws SQLClientInfoException
Sets the value of the client info property specified by name to the value specified by value.Applications may use the
The driver stores the value specified in a suitable location in the database. For example in a special register, session parameter, or system table column. For efficiency the driver may defer setting the value in the database until the next time a statement is executed or prepared. Other than storing the client information in the appropriate place in the database, these methods shall not alter the behavior of the connection in anyway. The values supplied to these methods are used for accounting, diagnostics and debugging purposes only.DatabaseMetaData.getClientInfoPropertiesmethod to determine the client info properties supported by the driver and the maximum length that may be specified for each property.The driver shall generate a warning if the client info name specified is not recognized by the driver.
If the value specified to this method is greater than the maximum length for the property the driver may either truncate the value and generate a warning or generate aSQLClientInfoException. If the driver generates aSQLClientInfoException, the value specified was not set on the connection.The following are standard client info properties. Drivers are not required to support these properties however if the driver supports a client info property that can be described by one of the standard properties, the standard property name should be used.
- ApplicationName - The name of the application currently utilizing the connection
- ClientUser - The name of the user that the application using the connection is performing work for. This may not be the same as the user name that was used in establishing the connection.
- ClientHostname - The hostname of the computer the application using the connection is running on.
- Parameters:
name- The name of the client info property to setvalue- The value to set the client info property to. If the value is null, the current value of the specified property is cleared.- Throws:
SQLClientInfoException- if the database server returns an error while setting the client info value on the database server or this method is called on a closed connection- Since:
- 1.6
-
setClientInfo
public void setClientInfo(Properties properties) throws SQLClientInfoException
Sets the value of the connection's client info properties. ThePropertiesobject contains the names and values of the client info properties to be set. The set of client info properties contained in the properties list replaces the current set of client info properties on the connection. If a property that is currently set on the connection is not present in the properties list, that property is cleared. Specifying an empty properties list will clear all of the properties on the connection. SeesetClientInfo (String, String)for more information.If an error occurs in setting any of the client info properties, a
SQLClientInfoExceptionis thrown. TheSQLClientInfoExceptioncontains information indicating which client info properties were not set. The state of the client information is unknown because some databases do not allow multiple client info properties to be set atomically. For those databases, one or more properties may have been set before the error occurred.- Parameters:
properties- the list of client info properties to set- Throws:
SQLClientInfoException- if the database server returns an error while setting the clientInfo values on the database server or this method is called on a closed connection- Since:
- 1.6
- See Also:
setClientInfo(String, String)
-
getClientInfo
public String getClientInfo(String name) throws SQLException
Returns the value of the client info property specified by name. This method may return null if the specified client info property has not been set and does not have a default value. This method will also return null if the specified client info property name is not supported by the driver.Applications may use the
DatabaseMetaData.getClientInfoPropertiesmethod to determine the client info properties supported by the driver.- Parameters:
name- The name of the client info property to retrieve- Returns:
- The value of the client info property specified
- Throws:
SQLException- if the database server returns an error when fetching the client info value from the database or this method is called on a closed connection- Since:
- 1.6
- See Also:
DatabaseMetaData.getClientInfoProperties()
-
getClientInfo
public Properties getClientInfo() throws SQLException
Returns a list containing the name and current value of each client info property supported by the driver. The value of a client info property may be null if the property has not been set and does not have a default value.- Returns:
- A
Propertiesobject that contains the name and current value of each of the client info properties supported by the driver. - Throws:
SQLException- if the database server returns an error when fetching the client info values from the database or this method is called on a closed connection- Since:
- 1.6
-
createArrayOf
public Array createArrayOf(String typeName, Object[] elements) throws SQLException
Factory method for creating Array objects.- Parameters:
typeName- the SQL name of the type the elements of the array map to. The typeName is a database-specific name which may be the name of a built-in type, a user-defined type or a standard SQL type supported by this database. This is the value returned byArray.getBaseTypeNameelements- the elements that populate the returned object- Returns:
- an Array object whose elements map to the specified SQL type
- Throws:
SQLException- if a database error occurs, the typeName is null or this method is called on a closed connectionSQLFeatureNotSupportedException- if the JDBC driver does not support this data type- Since:
- 1.6
-
createStruct
public Struct createStruct(String typeName, Object[] attributes) throws SQLException
Factory method for creating Struct objects.- Parameters:
typeName- the SQL type name of the SQL structured type that thisStructobject maps to. The typeName is the name of a user-defined type that has been defined for this database. It is the value returned byStruct.getSQLTypeName.attributes- the attributes that populate the returned object- Returns:
- a Struct object that maps to the given SQL type and is populated with the given attributes
- Throws:
SQLException- if a database error occurs, the typeName is null or this method is called on a closed connectionSQLFeatureNotSupportedException- if the JDBC driver does not support this data type- Since:
- 1.6
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. If the receiver implements the interface then the result is the receiver or a proxy for the receiver. If the receiver is a wrapper and the wrapped object implements the interface then the result is the wrapped object or a proxy for the wrapped object. Otherwise return the the result of callingunwraprecursively on the wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface, then anSQLExceptionis thrown.- Parameters:
iface- A Class defining an interface that the result must implement.- Returns:
- an object that implements the interface. May be a proxy for the actual implementing object.
- Throws:
SQLException- If no object found that implements the interface- Since:
- 1.6
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. Returns false otherwise. If this implements the interface then return true, else if this is a wrapper then return the result of recursively callingisWrapperForon the wrapped object. If this does not implement the interface and is not a wrapper, return false. This method should be implemented as a low-cost operation compared tounwrapso that callers can use this method to avoid expensiveunwrapcalls that may fail. If this method returns true then callingunwrapwith the same argument should succeed.- Parameters:
iface- a Class defining an interface.- Returns:
- true if this implements the interface or directly or indirectly wraps an object that does.
- Throws:
SQLException- if an error occurs while determining whether this is a wrapper for an object with the given interface.- Since:
- 1.6
-
close
public void close() throws SQLExceptionCloses the logical connection.
Cleans up client specific details- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Overrides:
closein classConnectionHolder- Throws:
SQLException- In case of a database error.
-
setSchema
public void setSchema(String schema) throws SQLException
- Throws:
SQLException
-
getSchema
public String getSchema() throws SQLException
- Throws:
SQLException
-
setNetworkTimeout
public void setNetworkTimeout(Executor executorObj, int milliseconds) throws SQLException
- Throws:
SQLException
-
getNetworkTimeout
public int getNetworkTimeout() throws SQLException- Throws:
SQLException
-
abort
public void abort(Executor executor) throws SQLException
Abort operation to mark the connection internally as a bad connection for removal and to close the connection. This ensures that at the end of the transaction, the connection is destroyed. A running thread holding a connection will run to completion before the connection is destroyed- Parameters:
executor-- Throws:
SQLException
-
-