[jboss-user] [JCA/JBoss] - Re: SQL Trace output concern with mapped DS
wcydaip
do-not-reply at jboss.com
Thu Sep 21 16:37:33 EDT 2006
Weston,
Thanks for the reply.
The AppHelper works like a ServiceLocator. One place to call and get whichever ds is needed. I added the Singleton thought it made sense. :)
I began caching the ds references early on and realized that was a bad choice, so, the reset is basically an old call that I never changed.
Here's the AppHelper with the excluded methods:
| public static synchronized AppHelper getInstance() {
| logger.debug("entering getInstance()");
| appHelperInstance = (null == appHelperInstance) ?
| new AppHelper() : appHelperInstance;
| logger.debug("leaving getInstance()");
| return appHelperInstance;
| }
|
| private AppHelper(){
| logger.debug("creating the AppHelper Singleton");
| logger.debug("leaving AppHelper Singleton");
| }
|
| private DataSource initializeDataSource(String dataSourceJNDI) throws NamingException{
| logger.debug("entering initializeDataSource()");
| DataSource dataSource = null;
| try{
| InitialContext ic = new InitialContext();
| dataSource = (DataSource) ic.lookup(dataSourceJNDI);
| }catch (NamingException ne){
| throw new NamingException("NamingException while looking" +
| " up DataSource Connection "
| + ": \n" + ne.getMessage());
| }
| logger.debug("leaving initializeDataSource()");
| return dataSource;
| }
|
| synchronized public Connection getConnection(String ds)throws NamingException, SQLException
| {
| logger.debug("entering getConnection()");
| logger.info("get connection for "+ds);
|
| DataSource dataSource = initializeDataSource(ds);
|
| Connection conn = null;
|
| try {
| conn = dataSource.getConnection();
| logger.info("connection:"+conn.toString());
| } catch (NullPointerException e) {
| logger.error("caught np exception getting connection from cached resource!");
| logger.info("attempting to restart the datasource...");
| /*
| * If the dataSource has been shutdown or perhaps
| * the database server has been restarted, then, these
| * exception handlers will restart the datasource...
| * NOTE: All works fine if a user is in the middle of using the app,
| * however, since the Security relies on JBoss CMP then
| * are unable to authenticate
| */
| conn = resetDataSource(ds);
| logger.info("connection established!");
| } catch (SQLException e) {
| logger.error("caught sql exception getting connection from cached resource!");
| logger.info("sql ex->"+e.getMessage());
| logger.info("attempting to restart the datasource...");
| /*
| * If the dataSource has been shutdown or perhaps
| * the database server has been restarted, then, these
| * exception handlers will restart the datasource...
| * NOTE: All works fine if a user is in the middle of using the app,
| * however, since the Security relies on JBoss CMP then
| * are unable to authenticate
| */
| conn = resetDataSource(ds);
| logger.info("connection established!");
| }
|
| //conn.setAutoCommit(true);
| logger.debug("leaving getConnection()");
| return conn;
| }
|
| private Connection resetDataSource(String dataSourceJNDI)throws NamingException, SQLException{
| // try and restart it
| DataSource ds = initializeDataSource(dataSourceJNDI);
| return ds.getConnection();
| }
|
The data source's are:
| <datasources>
| <local-tx-datasource>
| <jndi-name>DefaultDS</jndi-name>
|
| <connection-url>jdbc:microsoft:sqlserver://####:1433;DatabaseName=Main;SelectMethod=cursor</connection-url>
| <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
| <user-name>reg</user-name>
| <password>****</password>
| <check-valid-connection-sql>SELECT * FROM Site(NOLOCK) WHERE SiteID = 179</check-valid-connection-sql>
| <!-- pooling parameters -->
| <min-pool-size>5</min-pool-size>
| <max-pool-size>10</max-pool-size>
| <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
| <metadata>
| <type-mapping>MS SQLSERVER2000</type-mapping>
| </metadata>
| <idle-timeout-minutes>0</idle-timeout-minutes>
| </local-tx-datasource>
| </datasources>
|
And the other:
| <datasources>
| <local-tx-datasource>
| <jndi-name>CATS_DS_MAIN</jndi-name>
|
| <connection-url>jdbc:microsoft:sqlserver://####:1433;DatabaseName=Main;SelectMethod=cursor</connection-url>
| <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
| <!-- Use the security domain defined in conf/login-config.xml -->
| <security-domain>PortalCatsEncryptDBPassword</security-domain>
| <!-- ensures a valid connection -->
| <check-valid-connection-sql>SELECT * FROM Site(NOLOCK) WHERE SiteID = 179</check-valid-connection-sql>
| <!--pooling parameters-->
| <min-pool-size>5</min-pool-size>
| <max-pool-size>10</max-pool-size>
| <idle-timeout-minutes>0</idle-timeout-minutes>
| <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
| <metadata>
| <type-mapping>MS SQLSERVER2000</type-mapping>
| </metadata>
| </local-tx-datasource>
| </data-sources>
|
and the login-config entry:
| <application-policy name = "PortalCatsEncryptDBPassword">
| <authentication>
| <login-module code = "org.jboss.resource.security.SecureIdentityLoginModule"
| flag = "required">
| <module-option name = "username">portal</module-option>
| <module-option name = "password">-1c4fcf3f77be50b7</module-option>
| <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=CATS_DS_MAIN</module-option>
| </login-module>
| </authentication>
| </application-policy>
|
The trace is done using the SQL Profiler. The expected login was reg, however, the trace shows the Insert and Updates performed by portal.
Thanks again.
Graham
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3973410#3973410
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3973410
More information about the jboss-user
mailing list