Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)

com.lapetus_ltd.api.db.utils
Class TLptsDriverLoader

java.lang.Object
  extended by com.lapetus_ltd.api.db.utils.TLptsDriverLoader

public class TLptsDriverLoader
extends java.lang.Object

Class Description : This module is responsible for loading all the drivers from Database Connections.

It looks for a file called "driver.loader.xml" which is in the application directory. By default this file in packaged inside the JAR file of dbJAPI. It can be extracted into the application directory and then set to contain the correct information.
Below is an example of some settings in the file. Comments are included, but are not XML format.

 <XLptsDriverLoaderType xmlns="http://www.lapetus-ltd.com/2009/xml/types"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="XLptsDriverLoaderType"
                        version="1.0" id="357c84a9-8ebf-74f5-27f3-57860bf7cf01">
  <title>Lapetus Driver Loader Configuration</title>                         // the title of the whole config
   <driverListItem id="ed4714a7-cee0-1e7a-6ed3-3e310b8c59bf">                // a single item - a driver in other words
     <title>PostgreSQL Datasource Driver</title>                             // The title for the driver.
     <driverClass>                                                           // this specifies where the external JAR is and the driver class
       <contextLookupName></contextLookupName>                               // the context support is planned for the next version of dbJAPI
       <JarFilePath>drivers/postgresql-8.4-701.jdbc4.jar</JarFilePath>       // the JAR file that contains the driver to load
       <fullClassName>org.postgresql.ds.PGSimpleDataSource</fullClassName>   // the class for the driver (either javax.sql.DataSource or java.sql.Driver types)
       <pathType>FILE</pathType>                                             // to be read from file (URL is another option)
     </driverClass>
     <rowSetClass>                                                           // this is to be released in the next version of dbJAPI
       <contextLookupName></contextLookupName>                               // this is to be released in the next version of dbJAPI
       <JarFilePath></JarFilePath>                                           // this is to be released in the next version of dbJAPI
       <fullClassName></fullClassName>                                       // this is to be released in the next version of dbJAPI
       <pathType>FILE</pathType>                                             // this is to be released in the next version of dbJAPI
     </rowSetClass>
     <type>DATASOURCE</type>                                                 // either DATASOURCE or DRIVER
     <jdbcType>4</jdbcType>                                                  // 1-4 based on the JAVA default type
 <p/>
     // the format of the connection string. The $$ relates to the functions declared below. The values at runtime are placed in here.
     // the information in this connection string could be partial, which is then supplemented by the functions below being called on the driver interface.
     <connectionStringFormat>jdbc:postgresql//$$Server Name$$:$$Server Port$$</connectionStringFormat>
 <p/>
     <defaultCharSet>UTF-8</defaultCharSet>                           // Default Charset for this driver. This is rattled down to Connection, Statement and Rowset.
     <operatingSystemListItem>WINDOWS</operatingSystemListItem>       // the list of operating systems that support this driver
     <operatingSystemListItem>LINUX</operatingSystemListItem>
     <operatingSystemListItem>SOLARIS</operatingSystemListItem>
     <operatingSystemListItem>MACINTOSH</operatingSystemListItem>
     <interfaceListItem>                                              // this is a function to be called at runtime on the driver inteface
       <title>ServerName</title>                                      // a friendly title
       <functionName>setServerName</functionName>                     // the actual function in the driver interface - case sensitive
       <parameterListItem>                                            // the list of parameters for this function
         <name>Server Name</name>                                     // friendly name
         <type>STRING</type>                                          // type of variable (STRING,INTEGER,CHARS,CHAR,BYTES,BYTE,DOUBLE,BOOLEAN)
         <value>172.31.2.20</value>                                   // the default value that is passed to the function if not changed with {@link com.lapetus_ltd.api.db.xml.types.TLptsDriverType#setValueForInterfaceFunctionParameter(String, String, String)} or dbJAPI GUI
       </parameterListItem>
     </interfaceListItem>
     <interfaceListItem>                                              // another function
       <title>DatabaseName</title>
       <functionName>setDatabaseName</functionName>
       <parameterListItem>                                            // another parameter
         <name>Database Name</name>
         <type>STRING</type>
         <value>postgres</value>
       </parameterListItem>
     </interfaceListItem>
     <interfaceListItem>                                              // another function
       <title>PortNumber</title>
       <functionName>setPortNumber</functionName>
       <parameterListItem>                                            // another parameter
         <name>Server Port</name>
         <type>INTEGER</type>
         <value>5432</value>
       </parameterListItem>
     </interfaceListItem>
     <guestUser>postgres</guestUser>                                  // the guest username, which is not ENCRYPTED. The credentials of the connection are encrypted {@link com.lapetus_ltd.api.db.xml.types.TLptsDBConnectionType}.
     <guestPassword>test</guestPassword>                              // the guest password, which is not ENCRYPTED. The connection credentials are encrypted {@link com.lapetus_ltd.api.db.xml.types.TLptsDBConnectionType}.
   </driverListItem>
   <defaultCharSet>windows-1253</defaultCharSet>
 </XLptsDriverLoaderType>
 
 

$LastChangedRevision: 1224 $
$LastChangedDate:: 2010-12-06 06:02:28#$


Method Summary
static java.lang.Object executeDriverInterface(XLptsDriverType driverType)
          Executes the interface of the driver and returns either the DRIVER or DATASOURCE object.
static javax.sql.DataSource getDataSourceForClassName(java.lang.String className)
          This gets the javax.sql.DataSource type with the given name.
static javax.sql.DataSource getDataSourceWithJNDIContextName(java.lang.String name)
          Gets the datasource driver under the supplied context name.
static java.lang.String getDefaultCharSet()
          Gets the default charset configured.
static java.sql.Driver getDriverForClassName(java.lang.String className)
          This gets the java.sql.Driver type with the given name.
static XLptsDriverType getDriverTypeByClassName(java.lang.String fullClassName)
          This returns the internal driver type for a given class name.
static java.util.List<XLptsDriverType> getDriverTypeList()
          Gets the driver type list.
static java.sql.Driver getDriverWithJNDIContextName(java.lang.String name)
          Gets the driver under the supplied context name.
static javax.sql.RowSet getRowSetByClassName(java.lang.String fullClassName, java.sql.Connection connection)
          Gets the rowset class object with its full class name.
static void zI()
          Obfuscated, as it is not required by the application.
static void zI(java.lang.String path)
          Obfuscated, as it is not required by the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

executeDriverInterface

public static java.lang.Object executeDriverInterface(XLptsDriverType driverType)
Executes the interface of the driver and returns either the DRIVER or DATASOURCE object.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes, if there is an error.

Notes : The configuration within the config file and the data in the supplied driverType
are executed as functions with paramters against the driver.
The driver or Data source java object is then returned.
Notes: 1. This is normally perfomed in the GUI automatically.
2. One would normally use the function TLptsDriverType.setValueForInterfaceFunctionParameter(String, String, String) to set values before calling this function.

Returns:
The java.sql.Driver or javax.sql.Datasource obbject, or null on error.

getDataSourceForClassName

public static javax.sql.DataSource getDataSourceForClassName(java.lang.String className)
This gets the javax.sql.DataSource type with the given name.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes, if not found.

Notes : The datasource needs to be declared in driver.loader.xml, so that it can be found.

Example :

 Driver myDriver = TLptsDriverLoader.getDataSourceForClassName("org.postgresql.ds.PGSimpleDataSource");
 

Parameters:
className - the fully qualified class name.
Returns:
The java.sql.Driver class object.

getDataSourceWithJNDIContextName

public static javax.sql.DataSource getDataSourceWithJNDIContextName(java.lang.String name)
Gets the datasource driver under the supplied context name.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes, if not found.

Notes :
Although this function works, the full context support for dbJAPI is to be implemented in the next release.

Example :

 Driver myContextDriver = TLptsDriverLoader.getDataSourceWithJNDIContextName("contextNameOfDriver");
 

Parameters:
name - The context name which holds the driver.
Returns:
The driver loaded in the context name supplied.

getDefaultCharSet

public static java.lang.String getDefaultCharSet()
Gets the default charset configured.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes, if not configured.

Notes : This is configured in driver.loader.xml.

Returns:
The string representing the charset or null.

getDriverForClassName

public static java.sql.Driver getDriverForClassName(java.lang.String className)
This gets the java.sql.Driver type with the given name.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes, if not found.

Notes : The driver needs to be declared in driver.loader.xml, so that it can be found.

Example :

 Driver myDriver = TLptsDriverLoader.getDriverForClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
 

Parameters:
className - the fully qualified class name.
Returns:
The java.sql.Driver class object.

getDriverTypeByClassName

public static XLptsDriverType getDriverTypeByClassName(java.lang.String fullClassName)
This returns the internal driver type for a given class name.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes, if not found.

Notes :

Example :

 XLptsDriverType driverType = getDriverTypeByClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
 if (dt.getType().equals(XLptsDriverEnumType.DATASOURCE))
   TLptsDriverLoader.getDataSourceForClassName(dt.getDriverClass().getFullClassName()));
 else
   TLptsDriverLoader.getDriverForClassName(dt.getDriverClass().getFullClassName()));
 

Parameters:
fullClassName - The full class name of the driver.
Returns:
The internal XLptsDriverType.

getDriverTypeList

public static java.util.List<XLptsDriverType> getDriverTypeList()
Gets the driver type list.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Never, empty list in the worst case.

Notes : Used internally for the GUI list of drivers.

Example :

 for (XLptsDriverType dt : TLptsDriverLoader.getDriverTypeList())
 {
   if (dt.getType().equals(XLptsDriverEnumType.DATASOURCE))
     TLptsDriverLoader.getDataSourceForClassName(dt.getDriverClass().getFullClassName()));
   else
     TLptsDriverLoader.getDriverForClassName(dt.getDriverClass().getFullClassName()));
 }
 

Returns:
The list of XLptsDriverType, which represent the drivers.

getDriverWithJNDIContextName

public static java.sql.Driver getDriverWithJNDIContextName(java.lang.String name)
Gets the driver under the supplied context name.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes, if not found.

Notes :
Although this function works, the full context support for dbJAPI is to be implemented in the next release.

Example :

 Driver myContextDriver = TLptsDriverLoader.getDriverWithJNDIContextName("contextNameOfDriver");
 

Parameters:
name - The context name which holds the driver.
Returns:
The driver loaded in the context name supplied.

getRowSetByClassName

public static javax.sql.RowSet getRowSetByClassName(java.lang.String fullClassName,
                                                    java.sql.Connection connection)
Gets the rowset class object with its full class name.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes, if not found.

Notes :
Although this function works, the full dynamic rowset support of dbJAPI is not yet supported.
The rowset needs to be declare in "driver.loader.xml".

Example :

   RowSet declaredRowSet = TLptsDriverLoader.getRowSetByClassName("com.sun.rowset.JdbcRowSetImpl", myConnection);
 

Parameters:
fullClassName - The fill class name of the rowSet.
connection - The java Connection (from TLptsConnection) that is to be passed to the rowset constructor for dynamic creation.
Returns:
The dynamic RowSet or null.

zI

public static void zI()
Obfuscated, as it is not required by the application.


zI

public static void zI(java.lang.String path)
Obfuscated, as it is not required by the application.



Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)