Class CoreDataSource
- java.lang.Object
-
- com.avoka.core.cayenne.CoreDataSource
-
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,DataSource
public class CoreDataSource extends Object implements DataSource
Provides a DataSource wrapper for JDBC DataSource interface to enable configuring JDBC query timeouts. To set the query timeout in seconds the the JVM propertycom.avoka.core.cayenne.query.timeout
.- Since:
- 4.1.0
-
-
Constructor Summary
Constructors Constructor Description CoreDataSource(DataSource dataSource)
Create a monitored data source given the data source.CoreDataSource(DataSource dataSource, Integer queryTimeout)
Create a monitored data source given the data source.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Connection
getConnection()
Attempts to establish a connection with the data source that thisDataSource
object represents.Connection
getConnection(String username, String password)
Attempts to establish a connection with the data source that thisDataSource
object represents.int
getLoginTimeout()
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.PrintWriter
getLogWriter()
Retrieves the log writer for thisDataSource
object.Logger
getParentLogger()
boolean
isWrapperFor(Class<?> iface)
Checks if is wrapper for.void
setLoginTimeout(int seconds)
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.void
setLogWriter(PrintWriter out)
Sets the log writer for thisDataSource
object to the givenjava.io.PrintWriter
object.<T> T
unwrap(Class<T> iface)
Unwrap.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
-
-
-
Constructor Detail
-
CoreDataSource
public CoreDataSource(DataSource dataSource)
Create a monitored data source given the data source.- Parameters:
dataSource
- the data source
-
CoreDataSource
public CoreDataSource(DataSource dataSource, Integer queryTimeout)
Create a monitored data source given the data source.- Parameters:
dataSource
- the data sourcequeryTimeout
- the JDBC statement timeout (seconds)
-
-
Method Detail
-
getConnection
public Connection getConnection() throws SQLException
Attempts to establish a connection with the data source that this
DataSource
object represents.- Specified by:
getConnection
in interfaceDataSource
- Returns:
- a connection to the data source
- Throws:
SQLException
- if a database access error occurs
-
getConnection
public Connection getConnection(String username, String password) throws SQLException
Attempts to establish a connection with the data source that this
DataSource
object represents.- Specified by:
getConnection
in interfaceDataSource
- Parameters:
username
- the database user on whose behalf the connection is being madepassword
- the user's password- Returns:
- a connection to the data source
- Throws:
SQLException
- if a database access error occurs
-
getLogWriter
public PrintWriter getLogWriter() throws SQLException
Retrieves the log writer for this
DataSource
object.The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the
java.sql.Drivermanager
class. When aDataSource
object is created, the log writer is initially null; in other words, the default is for logging to be disabled.- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Returns:
- the log writer for this data source or null if logging is disabled
- Throws:
SQLException
- if a database access error occurs- See Also:
setLogWriter(java.io.PrintWriter)
-
getLoginTimeout
public int getLoginTimeout() throws SQLException
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise, it means that there is no timeout. When aDataSource
object is created, the login timeout is initially zero.- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Returns:
- the data source login time limit
- Throws:
SQLException
- if a database access error occurs.- See Also:
setLoginTimeout(int)
-
setLogWriter
public void setLogWriter(PrintWriter out) throws SQLException
Sets the log writer for this
DataSource
object to the givenjava.io.PrintWriter
object.The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source- specific log writer are not printed to the log writer associated with the
java.sql.Drivermanager
class. When aDataSource
object is created the log writer is initially null; in other words, the default is for logging to be disabled.- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Parameters:
out
- the new log writer; to disable logging, set to null- Throws:
SQLException
- if a database access error occurs- See Also:
getLogWriter()
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws SQLException
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When a
DataSource
object is created, the login timeout is initially zero.- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Parameters:
seconds
- the data source login time limit- Throws:
SQLException
- if a database access error occurs.- See Also:
getLoginTimeout()
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
Unwrap.- Specified by:
unwrap
in interfaceWrapper
- Type Parameters:
T
- the generic type- Parameters:
iface
- the iface- Returns:
- the t
- Throws:
SQLException
- the sQL exception- See Also:
Wrapper.unwrap(java.lang.Class)
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
Checks if is wrapper for.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
iface
- the iface- Returns:
- true, if is wrapper for
- Throws:
SQLException
- the sQL exception- See Also:
Wrapper.isWrapperFor(java.lang.Class)
-
getParentLogger
public Logger getParentLogger() throws SQLFeatureNotSupportedException
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Returns:
- the parent logger
- Throws:
SQLFeatureNotSupportedException
- if not supported- See Also:
CommonDataSource.getParentLogger()
-
-