|
Awake File v1.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; 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.setLogFile(logfile); } // Extracting the Connection from the connection pool: Connection connection = awakeDataSource.getConnection();
AwakeDataSourceFactory
,
DefaultAwakeCommonsConfigurator
Constructor Summary | |
---|---|
AwakeDataSource()
This constructor is mandatory for EJB behavior. |
Method Summary | ||
---|---|---|
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 |
getMaxConns()
Returns the maximum number of connections in dynamic pool. |
|
int |
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. |
|
String |
getUrl()
Returns the Connection URL. |
|
String |
getUsername()
Returns the database username. |
|
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 |
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 |
setMaxConns(int maxConns)
Sets the maximum number of connections in dynamic pool. |
|
void |
setMaxConnTime(int 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 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 getMaxConns()
public int getMaxConnTime()
public int getMinConns()
public Logger getParentLogger() throws SQLFeatureNotSupportedException
SQLFeatureNotSupportedException
- if the data source does not use java.util.logging
.public String getPassword()
public String getUrl()
public String getUsername()
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 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 setMaxConns(int maxConns)
maxConns
- the maximum number of connections in dynamic pool. Must be >=
minConns.public void setMaxConnTime(int 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 File v1.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |