|
Awake SQL v1.2.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.awakefw.commons.api.server.AwakeDataSource
public class AwakeDataSource
Implementation of
that allows the
wrapping of Awake default connection pooling system. DataSource
Notes:
1) This class will be automatically loaded by
in a Java EE environment. AwakeDataSourceFactory
2) This class may also be called directly using the constructor and setting
the values in order to extract a Connection from the pool.
Note that the class is not immutable because it must be a Java Bean
for some Java EE servers as Caucho Resin.
Example:
// Declare the DataSource as member to load only once the pool: private AwakeDataSource awakeDataSource = null; ... ... // Driver parameters to use: String driverClassName = "org.postgresql.Driver"; String url = "jdbc:postgresql://localhost:5432/awake-example"; String username = "user1"; String password = "password1"; int minConns = 2; int maxConns = 15; int maxConnTime = 1; int maxCheckoutSeconds = 180; boolean logAppend = false; File logfile = new File("/home/admin/log/mylog.log"); // Creating the DataSource bean and populating the values: if (awakeDataSource == null) { awakeDataSource = new AwakeDataSource(); awakeDataSource.setDriverClassName(driverClassName); awakeDataSource.setUrl(url); awakeDataSource.setUsername(username); awakeDataSource.setPassword(password); awakeDataSource.setMinConns(minConns); awakeDataSource.setMaxConns(maxConns); awakeDataSource.setMaxConnTime(maxConnTime); awakeDataSource.setMaxCheckoutSeconds(maxCheckoutSeconds); awakeDataSource.setLogAppend(logAppend); awakeDataSource.setLogFile(logFile); } // Extracting the Connection from the connection pool: Connection connection = awakeDataSource.getConnection();Note that after the first call to
awakeDataSource.getConnection()
, it is then possible
to query the state of the connection pool with:
AwakeDataSourceFactory
,
DefaultAwakeCommonsConfigurator
Constructor Summary | |
---|---|
AwakeDataSource()
This constructor is mandatory for EJB behavior. |
Method Summary | ||
---|---|---|
long |
getAge(Connection connnection)
Returns the age of a Connection -- the time since it was handed out to an application. |
|
Connection |
getConnection()
Returns a Connection to the database. |
|
Connection |
getConnection(String username,
String password)
Returns a Connection to the database. |
|
String |
getDriverClassName()
Returns the fully qualified Java class name of your JDBC driver. |
|
File |
getLogFile()
Returns the absolute path name for log file. |
|
int |
getLoginTimeout()
Returns the login timeout (in seconds) for connecting to the database. |
|
PrintWriter |
getLogWriter()
Returns the log writer being used by this data source. |
|
int |
getMaxCheckoutSeconds()
Returns the maximum time in seconds a Connection can be checked out before being
recycled. |
|
int |
getMaxConns()
Returns the maximum number of connections in dynamic pool. |
|
double |
getMaxConnTime()
Returns the time in days between connection resets. |
|
int |
getMinConns()
Returns the minimum number of connections to start with. |
|
Logger |
getParentLogger()
Method not implemented in Awake SQL v1.0. |
|
String |
getPassword()
Returns the database password. |
|
int |
getSize()
Returns the number of Connections in the dynamic pool. |
|
String |
getUrl()
Returns the Connection URL. |
|
int |
getUseCount()
Returns the number of Connections in use. |
|
String |
getUsername()
Returns the database username. |
|
int |
idOfConnection(Connection connnection)
Returns the local JDBC ID for a Connection. |
|
boolean |
isLogAppend()
Returns if log is in append. |
|
boolean |
isWrapperFor(Class<?> iface)
Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. |
|
void |
setDriverClassName(String driverClassName)
Sets the JDBC driver class name. |
|
void |
setLogAppend(boolean logAppend)
Sets if the log is in append. |
|
void |
setLogFile(File logFile)
Sets the absolute path name for log file. e.g. |
|
void |
setLoginTimeout(int loginTimeout)
Sets the login timeout (in seconds) for connecting to the database. |
|
void |
setLogWriter(PrintWriter logWriter)
Sets the log writer being used by this data source. |
|
void |
setMaxCheckoutSeconds(int maxCheckoutSeconds)
Sets the maximum time in seconds a Connection can be checked out before being
recycled. |
|
void |
setMaxConns(int maxConns)
Sets the maximum number of connections in dynamic pool. |
|
void |
setMaxConnTime(double maxConnTime)
Sets the time in days between connection resets. |
|
void |
setMinConns(int minConns)
Sets the minimum number of connections to start with. |
|
void |
setPassword(String password)
Sets the database password to be passed to your JDBC driver. |
|
void |
setUrl(String url)
Sets the Connection URL to be passed to your JDBC driver |
|
void |
setUsername(String username)
Sets the database username to be passed to your JDBC driver. |
|
|
unwrap(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 java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AwakeDataSource()
Method Detail |
---|
public long getAge(Connection connnection)
connnection
- the JDBC Connectionpublic Connection getConnection() throws SQLException
getConnection
in interface DataSource
SQLException
- if a database access error occurspublic Connection getConnection(String username, String password) throws SQLException
getConnection
in interface DataSource
username
- Database user on whose behalf the Connection is being madepassword
- The database user's password
SQLException
- if a database access error occurspublic String getDriverClassName()
public File getLogFile()
public int getLoginTimeout() throws SQLException
getLoginTimeout
in interface CommonDataSource
SQLException
- if a database access error occurspublic PrintWriter getLogWriter() throws SQLException
getLogWriter
in interface CommonDataSource
SQLException
- if a database access error occurspublic int getMaxCheckoutSeconds()
Connection
can be checked out before being
recycled. This value is thus the maximum duration of a SQL request.
Connection
can be checked out before being
recycled.public int getMaxConns()
public double getMaxConnTime()
public int getMinConns()
public Logger getParentLogger() throws SQLFeatureNotSupportedException
SQLFeatureNotSupportedException
- if the data source does not use java.util.logging
.public String getPassword()
public int getSize()
public String getUrl()
public int getUseCount()
public String getUsername()
public int idOfConnection(Connection connnection)
connnection
- the JDBC Connectionpublic boolean isLogAppend()
public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
on 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 to
unwrap
so that callers can use this method to avoid
expensive unwrap
calls that may fail. If this method returns
true then calling unwrap
with the same argument should
succeed.
isWrapperFor
in interface Wrapper
iface
- a Class defining an interface.
SQLException
- if an error occurs while determining whether this is a
wrapper for an object with the given interface.public void setDriverClassName(String driverClassName)
driverClassName
- JDBC driver class name.public void setLogAppend(boolean logAppend)
logAppend
- true to log in append, else falsepublic void setLogFile(File logFile)
logFile
- absolute path name for log file.public void setLoginTimeout(int loginTimeout) throws SQLException
setLoginTimeout
in interface CommonDataSource
loginTimeout
- The new login timeout, or zero for no timeout
SQLException
- if a database access error occurspublic void setLogWriter(PrintWriter logWriter) throws SQLException
setLogWriter
in interface CommonDataSource
logWriter
- The new log writer
SQLException
- if a database access error occurspublic void setMaxCheckoutSeconds(int maxCheckoutSeconds)
Connection
can be checked out before being
recycled. This value is thus the maximum duration of a SQL request.
Default value is 180 seconds. Zero value turns option off.
maxCheckoutSeconds
- the maximum time in seconds a Connection
can be checked out before being
recycled.public void setMaxConns(int maxConns)
maxConns
- the maximum number of connections in dynamic pool. Must be >=
minConns.public void setMaxConnTime(double maxConnTime)
maxConnTime
- time in days between connection resets.public void setMinConns(int minConns)
minConns
- minimum number of connections to start with. Must be > 0.public void setPassword(String password)
password
- the Database password to be passed to your JDBC driver.public void setUrl(String url)
url
- the Connection URL to be passed to your JDBC driverpublic void setUsername(String username)
username
- the Database username to be passed to your JDBC driver.public <T> T unwrap(Class<T> iface) throws SQLException
unwrap
recursively on the wrapped object or a proxy
for that result. If the receiver is not a wrapper and does not implement
the interface, then an SQLException
is thrown.
unwrap
in interface Wrapper
iface
- A Class defining an interface that the result must implement.
SQLException
- If no object found that implements the interface
|
Awake SQL v1.2.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |