Awake SQL v1.2.1

org.awakefw.commons.api.server
Class AwakeDataSourceFactory

java.lang.Object
  extended by 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>


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).
 
Method Summary
 Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment)
          Creates and returns a new AwakeDataSource instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AwakeDataSourceFactory

public AwakeDataSourceFactory()
This class should *not* be instanced (this constructor is mandatory for EJB behavior).

Method Detail

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 object
name - 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 context
environment - 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 v1.2.1

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