Re: Accessing in a static way



Anyone please? Thanks

"Rizwan" <hussains@xxxxxxxxxxxx> wrote in message
news:UCmYe.8905$0u2.1733607@xxxxxxxxxxxxxxxxxxxxxxxx
>I have 2 applications: one is stand-alone and one is using J2EE container.
>So for Connection logic I wrote code to support both DataSource (to be used
>by J2EE app) and DriverManager (to be used by stand-alone app). So
>
> public interface ConnectionManager {
> public void configure( Properties properties );
> public Connection getConnection();
> public void closeConnection( Connection connection );
> }
>
>
> Then I wrote a DataSource and a DriverManager implementation of
> ConnectionManager (The DataSource one uses JNDI lookup and connection
> pooling):
>
> public class DataSourceConnectionManager implements ConnectionManager {
> ...
> }
> public class DriverManagerConnectionManager implements ConnectionManager {
> ...
> }
>
>
> Then I wrote factory:
>
> public final class ConnectionManagerFactory {
> public static final String CONNECTIONTYPE = "CONNECTIONTYPE";
> public static final int DATASOURCE = 1;
> public static final int DRIVERMANAGER = 2;
>
> public static ConnectionManager getConnectionManager( Properties
> properties ) {
> ConnectionManager cm = null;
> int connectionType = new Integer( properties.getProperty(
> CONNECTIONTYPE ) ).intValue();
> if ( connectionType == DATASOURCE )
> cm = new DataSourceConnectionManager();
> else if ( connectionType == DRIVERMANAGER )
> cm = new DriverManagerConnectionManager();
>
> cm.configure( properties );
> return cm;
> }
> }
>
>
> To Get Connection:
>
> Properties props = new Properties();
> // populate the props accordingly (stand-alone or J2EE)
> ...
> ConnectionManager cm = ConnectionManagerFactory.getConnectionManager(
> props );
> Connection connection = cm.getConnection();
> ...
> cm.closeConnection( connection );
>
>
> The above code is working very good. I have no problems so far.
>
> Now I want to build a utiliy class for connection obtaining logic. I want
> it to have these static methods:
>
> public class ConnectionUtil {
> public static Connection getConnectionForStandalone(Properties props)
> {...}
> public static Connection getConnectionForJ2EE(Properties props) {...}
> public static void closeConnection(Connection conn) {...}
> }
>
> The stand-alone app programmers will use getConnectionForStandalone()
> while J2EE app programmers will use getConnectionForJ2EE() to obtain
> Connection.
>
> My concern is how to do it? Can anyobdy help me in this regard? Thanks.
>
>


.



Relevant Pages

  • Re: DriverManager vs. DataSource?
    ... > class to establish the connection. ... it is possible to use the DriverManager interface. ... JDBC driver jars go in a 'common' directory in the container. ... > the DataSource interface will typically be registered with a JNDI ...
    (comp.lang.java.databases)
  • Re: Connection for Data Source in SSAS 2005 Tutorial Lesson 6
    ... double click on the datasource and then click on ... I noticed that my server explorer showed a connection to ... When connecting to SQL Server 2005, this failure may be caused by the ... not be made to the data source with the DataSourceID of 'Adventure ...
    (microsoft.public.sqlserver.olap)
  • Re: ConnectionPoolDataSource + MM MySQL + Tomcat4
    ... to work with Tomcat 5.0.28 and MySQL or Oracle. ... <ResourceParams> ... in functions needing DB access, use the DataSource variable ... to create a Connection ...
    (comp.lang.java.programmer)
  • Java Database connection pooling for standalone server
    ... DBCP for connection pool for my web application. ... public class EngineDBConnection { ... static DataSource dataSource = null; ... Connection conn = null; ...
    (comp.lang.java.databases)
  • Re: mail merge code template with connection strings
    ... 'Get the details of the datasource ... .FirstRecord = wdDefaultFirstRecord ... I am currently connecting with an ODBC connection, ... Set rst = New ADODB.Recordset ...
    (microsoft.public.word.mailmerge.fields)