Hi,

I made a ConnectionFactory system that uses a FactoryMethod design 
pattern to provide JDBC connection objects
depending on the underlying "connection provider".

Here's the archive:
http://www.pow2.com/download/dbforms-connectionFactory.zip
(564.718 bytes, too big for sourceforge patch tracker...)

Hope it could be useful ;^)
I'm testing it with a project of mine; it seems to work well with 
non-jndi connections...
I never  used / tested the retrieving of connections from a jndi 
server...  so it's possible I broke it.

 
DbForms modified files:

org/dbforms/ConfigServlet.java:
-----------------------------------------------------------
1) method public void init() throws ServletException:
    added:   initConnectionFactory(), line ~119

            initLocaleKey();

            // try to set up the ConnectionFactory [Luca Fossato 
<[EMAIL PROTECTED]> 2002.06.26]
            initConnectionFactory();

        } catch(IOException ioe) {



2) added the method  protected void initConnectionFactory() throws 
Exception, line ~562


org/dbforms/util/DbConnection.java:
-----------------------------------------------------------
rewrited...





The readme.txt file:

---------------------------------------------------------------------------------------------------------------------
Hi,

I apologize for my english... ;^)

this DbForms contrib. adds a ConnectionFactory object to DbForms.
A ConnectionFactory provides JDBC connections using an underlying 
ConnectionProvider object.
It contains the specific connection pooler code.


With a ConnectionFactory it should be easier to:

a) "switch" between connection pooling libraries without modify the 
DbForms code;
b) add the support for other connection pooling libraries;



Up to now there are 3 providers:


ProtomatterConnectionProvider
-------------------------------------------------

uses the Protomatter Connection Pool library

see

http://protomatter.sourceforge.net/

for further informations




JakartaConnectionProvider
-------------------------------------------------

uses the Jakarta commons-dbcp ConnectionPool

see http://jakarta.apache.org/commons/index.html for further informations



SimpleConnectionProvider
-------------------------------------------------

doesn't use connection pooling at all ;^)



To create your own connection provider, follow these steps:


a) create a new class that extends "com.pow2.dao.ConnectionProvider" class;
b) create a default constructor like this one:

  /**
   *  Default constructor.
   *
   * @throws Exception because of the <code>throws Exception</code> clause
   *                   of the  <code>init</code> method.
   */
  public MyConnectionProvider() throws Exception
  {
    super();    // up to now, do nothing...
  }


c) override the following ConnectionProvider abstract methods:

   protected abstract void init() throws Exception;
   protected abstract Connection getConnection() throws SQLException;

   init()
   contains the initialization / configuration code for a specific 
ConnectionPOol library;
  
   getConnection()
   must return a JDBC connection...



ConnectionFactory CONFIGURATION
-------------------------------

see "db-connection.txt" to see the config. examples for the 
"dbconnection" xml element contained into the
dbforms-config.xml file.


Package name
--------------------------------
To DbForms mantainers:

The ConnectionFactory classes use the "com.pow2.dao" package name because
this code is used into the pow2tollkit library 
([http://sourceforge.net/projects/pow2toolkit], older versions)

Feel free to modify the package name according to your needs !!

---------------------------------------------------------------------------------------------------------------------



Luca Fossato
<[EMAIL PROTECTED]>




-------------------------------------------------------
This sf.net email is sponsored by: Jabber Inc.
Don't miss the IM event of the season | Special offer for OSDN members! 
JabberConf 2002, Aug. 20-22, Keystone, CO http://www.jabberconf.com/osdn
_______________________________________________
DbForms Mailing List

http://www.wap-force.net/dbforms

Reply via email to