Re: Accessing in a static way
- From: "Rizwan" <hussains@xxxxxxxxxxxx>
- Date: Fri, 23 Sep 2005 11:14:53 -0400
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.
>
>
.
- Follow-Ups:
- Re: Accessing in a static way
- From: Oliver Wong
- Re: Accessing in a static way
- References:
- Accessing in a static way
- From: Rizwan
- Accessing in a static way
- Prev by Date: Re: Opera 8.5 just out
- Next by Date: Re: Authenticating an UTF-8, I18N field in struts using regular expressions
- Previous by thread: Accessing in a static way
- Next by thread: Re: Accessing in a static way
- Index(es):
Relevant Pages
|