Connection Pooling

Shai If
2010-07-15
2013-05-08
  • Shai If

    Shai If - 2010-07-15

    Hi,
    I am trying to implement connection pooling with jGuard. Can anyone give any pointers as to how this can be done? I believe that this would greatly boost the performance of jGuard as a whole.

    Shai

     
  • Vinicius Pitta Lima de Araujo

    Hi Shai,
    Can you be more clear about that? I can't figure out why you need implement that. If you use the jdbc managers and login module you can configure your connection trough JNDI and use a datasource with native conection pooling. If you use hibernate managers and login module you can use the datasource in the same way or use hibernate conection pool. Why you need to implement a new one?

    's
    Vinícius Pitta Lima de Araújo
    http://www.viniciusaraujo.net

     
  • Shai If

    Shai If - 2010-07-15

    Hi Vinicius,
    Yes, you are right. I am trying to configure jGuard  to do connection pooling via JNDI. I looked into the net.sf.jguard.ext.database.ConnectionFactory code. It seems like if connection pooling via JNDI is working, then the following code in net.sf.jguard.ext.database.ConnectionFactory should be executed:

    Hashtable env = new Hashtable(opts);
                  InitialContext initCtx = new InitialContext(env);
                  Object object = (DataSource) initCtx.lookup(jndiRef);
                   if (object instanceof DataSource) {
    datasource= (DataSource) object;
    }else{
    throw new IllegalArgumentException(" JNDI lookup "+jndiRef+" must return an object of type javax.sql.DataSource ");
    }
                  connMap.put(key,datasource);
                  JNDI= true;

    To make jGuard use connection pooling via JNDi, i inserted the following code into Tomcat's server. xml:

    <Context docBase="jGuard" path="/jGuard" reloadable="true" source="org.eclipse.jst.j2ee.server:jGuard">
    <Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="100" maxIdle="30" maxWait="10000" name="JNDI" password="icode" removeAbandoned="true" removeAbandonedTimeout="30" type="javax.sql.DataSource" url="jdbc:mysql://icode:3306/jGuardGanesh" username="icode"/>
    </Context>

    However, the piece of code that i highighted above is not executed. The jndiRef variable is always null. Can you pls let me know what mistake i am making. Also,  am i right in assuming that the code highlighted above should be executed if connection pooliing via JNDi is working

    Shai

     
  • Vinicius Pitta Lima de Araujo

    Did you include the JNDI parameter in your manager configuration files?

    Seems like that:
    <option>
    <name>JNDI</name>
    <value>java:comp/env/jdbc/JNDI</value>
    </option>

    I suggest you to change the datasource name. Isn't very good. :)

    's
    Vinícius Pitta Lima de Araújo
    http://www.viniciusaraujo.net

     
  • Shai If

    Shai If - 2010-07-19

    Thanks a lot Vinicius! Now i have connection pooling going !!! :)

    Shailendra

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks