org.awakefw.commons.api.server
Class AwakeDataSourceFactory
java.lang.Object
org.awakefw.commons.api.server.AwakeDataSourceFactory
- All Implemented Interfaces:
- ObjectFactory
public class AwakeDataSourceFactory
- extends Object
- implements ObjectFactory
JNDI object factory that creates an instance of the
AwakeDataSource
class for the Awake default connection
pooling system.
This class must *not* be called directly by a user program.
This class will be called/created automatically by any Java EE compatible
modern application/web server.
( GlassFish, JBoss, JOnAS, Orion, Tomcat, WebLogic, WebSphere, etc.).
The RefAddr
values of the specified
Reference
must match the names and data
types of the AwakeDataSource
bean properties.
Please configure your application server to load this factory and configure
the values of the RefAddr
parameters in a <Resource>
- driverClassName: Fully qualified Java class name of your JDBC
driver to be used.
- url: Connection URL to be passed to your JDBC driver.
- username: Database username to be passed to your JDBC driver.
- password: Database password to be passed to your JDBC driver.
- minConns: Minimum number of connections to start with. Must be
> 0.
- maxConns: Maximum number of connections in dynamic pool. Must be
>= minConns.
- maxConnTime: Time in days between connection resets. Defaults to
1. (Reset does a basic cleanup.)
- maxCheckoutSeconds: Maximum time in seconds a
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.
- logAppend: Boolean that says if log is in append mode. Defaults to false.
- logFile: Absolute path name for log file. e.g. '/tmp/mylog.log'.
Defaults to 'user.home/.awake/log/DbConnectionBroker.log'
Configuration example in server.xml:
<Context path="/awake-test">
<!-- JDBC Driver values used by DefaultAwakeCommonsConfigurator.getConnection() -->
<!-- Modify the driver info according to your JDBC Driver -->
<Resource name="jdbc/awake-oracle"
auth="Container"
type="javax.sql.DataSource"
factory="org.awakefw.commons.api.server.AwakeDataSourceFactory"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:awake-example@//localhost:1521/XE"
username="user1"
password="password1"
minConns="2"
maxConns="10" />
</Context>
Corresponding Java code in a concrete
AwakeCommonsConfigurator
implementation in order to retrieve a
Connection from the pool:
// The connection pool will be loaded only once and the kept in memory:
private DataSource dataSource = null;
@Override
public Connection getConnection() throws SQLException {
String defaultResourceName = "jdbc/awake-oracle";
// Load only once the pool
if (this.dataSource == null) {
try {
Context initCtx0 = (Context) new InitialContext()
.lookup("java:comp/env");
dataSource = (DataSource) initCtx0.lookup(defaultResourceName);
} catch (NamingException e) {
throw new SQLException(
"Invalid configuration. Lookup failed on resource: ",
e);
}
}
return dataSource.getConnection();
}
- Since:
- 1.0
Constructor Summary |
AwakeDataSourceFactory()
This class should *not* be instanced (this constructor is mandatory for
EJB behavior). |
AwakeDataSourceFactory
public AwakeDataSourceFactory()
- This class should *not* be instanced (this constructor is mandatory for
EJB behavior).
getObjectInstance
public Object getObjectInstance(Object obj,
Name name,
Context nameCtx,
Hashtable environment)
throws Exception
- Creates and returns a new
AwakeDataSource
instance. If no
instance can be created, return null
instead.
- Specified by:
getObjectInstance
in interface ObjectFactory
- Parameters:
obj
- The object, which may be null, that contains location or
reference information to be used to create an objectname
- The name of this object relating to nameCtx
nameCtx
- The context relative to which the name
parameter
is specified, or null
if name
relates to the default initial contextenvironment
- The environment, which may be null, that is used in to create
this object
- Throws:
Exception
- if an exception occurs creating the instance
Awake SQL - Virtual JDBC Driver over HTTP for Android, Swing and JavaFX
Android & Desktop Edition allow easy access to majors remote SQL databases with regular JDBC calls:
DB2 - H2 - HSQLDB (HyperSQL) - Informix - Ingres - MySQL - Oracle - PostgreSQL - SQL Server - Sybase - Teradata
Copyright © 2012 Kawan Softwares SAS