java - How to extend c3p0 ComboPooledDataSource -


ok have resource in tomcat 5.5 in server.xml database connection this:

<resource name="jdbc/myapp" auth="container" type="com.mchange.v2.c3p0.combopooleddatasource" driverclass="com.microsoft.sqlserver.jdbc.sqlserverdriver"  maxpoolsize="100"  minpoolsize="5"    acquireincrement="5"      user="username"  password="password" factory="org.apache.naming.factory.beanfactory"   jdbcurl="jdbc:sqlserver://localhost:1433;databasename=mydatabase;autoreconnect=true" /> 

has tried extend above combopooleddatasource? problem database password in clear text. idea first encrypt password , place encrypted key in server.xml. have decrypting utility can decrypt key before trying connect database.

i found example solution problem org.apache.tomcat.dbcp.dbcp.basicdatasourcefactory, i'm not using connection pool. i'm using c3p0. tried before c3p0?

yes, can't extend com.mchange.v2.c3p0.combopooleddatasource because public. here workaround have achieved this.

i have extended org.springframework.jdbc.datasource.transactionawaredatasourceproxy , passed com.mchange.v2.c3p0.combopooleddatasource datasource constructor argument.

here hibernate.cfg.xml configuration of above datasource:

<bean id="datasource" class="mydatasource">          <constructor-arg ref="c3p0datasource" />     </bean>      <bean id="c3p0datasource" class="com.mchange.v2.c3p0.combopooleddatasource"         destroy-method="close">         <property name="driverclass" value="${jdbc.driver.classname}" />         <property name="jdbcurl" value="${jdbc.url}" />         <property name="user" value="${jdbc.username}" />         <property name="password" value="${jdbc.password}" />         <property name="acquireincrement" value="${datasource.acquireincrement}" />         <property name="acquireretryattempts" value="${datasource.acquireretryattempts}" />         <property name="acquireretrydelay" value="${datasource.acquireretrydelay}" />         <property name="autocommitonclose" value="${datasource.autocommitonclose}" />         <property name="breakafteracquirefailure" value="${datasource.breakafteracquirefailure}" />         <property name="checkouttimeout" value="${datasource.checkouttimeout}" />         <property name="debugunreturnedconnectionstacktraces"             value="${datasource.debugunreturnedconnectionstacktraces}" />         <property name="forceignoreunresolvedtransactions"             value="${datasource.forceignoreunresolvedtransactions}" />         <property name="idleconnectiontestperiod" value="${datasource.idleconnectiontestperiod}" />         <property name="initialpoolsize" value="${datasource.initialpoolsize}" />         <property name="maxadministrativetasktime" value="${datasource.maxadministrativetasktime}" />         <property name="maxconnectionage" value="${datasource.maxconnectionage}" />         <property name="maxidletime" value="${datasource.maxidletime}" />         <property name="maxidletimeexcessconnections" value="${datasource.maxidletimeexcessconnections}" />         <property name="maxpoolsize" value="${datasource.maxpoolsize}" />         <property name="maxstatements" value="${datasource.maxstatements}" />         <property name="maxstatementsperconnection" value="${datasource.maxstatementsperconnection}" />         <property name="minpoolsize" value="${datasource.minpoolsize}" />         <property name="numhelperthreads" value="${datasource.numhelperthreads}" />         <property name="propertycycle" value="${datasource.propertycycle}" />         <property name="testconnectiononcheckin" value="${datasource.testconnectiononcheckin}" />         <property name="testconnectiononcheckout" value="${datasource.testconnectiononcheckout}" />         <property name="unreturnedconnectiontimeout" value="${datasource.unreturnedconnectiontimeout}" />     </bean>  mine jdbc.properties file:   jdbc.driver.classname=com.microsoft.sqlserver.jdbc.sqlserverdriver jdbc.url=xxxxx jdbc.username=xxx jdbc.password=xxxxxxxxx #encrytped password here jdbc.hibernate.dialect=org.hibernate.dialect.sqlserverdialect hibernate.show_sql=false hibernate.hbm2ddl.auto=update  datasource.acquireincrement=3 datasource.acquireretryattempts=30 datasource.acquireretrydelay=60000 datasource.autocommitonclose=false datasource.breakafteracquirefailure=false datasource.checkouttimeout=0 datasource.debugunreturnedconnectionstacktraces=false datasource.forceignoreunresolvedtransactions=false datasource.idleconnectiontestperiod=0 datasource.initialpoolsize=10 datasource.maxadministrativetasktime=0 datasource.maxconnectionage=0 datasource.maxidletime=0 datasource.maxidletimeexcessconnections=0 datasource.maxpoolsize=10 datasource.maxstatements=0 datasource.maxstatementsperconnection=0 datasource.minpoolsize=10 datasource.numhelperthreads=3 datasource.propertycycle=0 datasource.testconnectiononcheckin=false datasource.testconnectiononcheckout=false datasource.unreturnedconnectiontimeout=0   mine extended class decrypt password before passing datasource transaction proxy wrapper.  import javax.sql.datasource;  import org.jasypt.util.text.basictextencryptor; import org.springframework.beans.factory.annotation.autowired; import org.springframework.jdbc.datasource.transactionawaredatasourceproxy;  import com.csc.emms.common.emmsconstraints; import com.mchange.v2.c3p0.combopooleddatasource;  public class mydatasource extends transactionawaredatasourceproxy {     private static char[] appname =     {             'b', 'i', 'n', 'g', 'o', 'd', 'i', 'n', 'g', 'o'     };      @autowired     // inject class constructor     mydatasource(combopooleddatasource datasource)     {         super.settargetdatasource(decryptpassword(datasource));     }      private datasource decryptpassword(combopooleddatasource datasource)     {         datasource.setpassword(decode(datasource.getpassword()));         return datasource;     }      private string decode(string encodedpassword)     {         basictextencryptor decoder = new basictextencryptor();         decoder.setpasswordchararray(appname);         return decoder.decrypt(encodedpassword);     }      private string encode(string password)     {         basictextencryptor encoder = new basictextencryptor();         encoder.setpasswordchararray(appname);         return encoder.encrypt(password);     } } hope resolved issue. 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -