[jboss-user] [JCA/JBoss] - SQL Trace output concern with mapped DS

wcydaip do-not-reply at jboss.com
Thu Sep 21 15:06:29 EDT 2006


I have two datasource mappings pointed at the same server-database combination.  The two are used by different applications as to differentiate between testing and release code.  Each datasource has their own respective login to the database, but, use the same group of classes to access the db.

I just released a new version of one of my apps and found that at times it appears to be confusing the datasource choice.  i.e., I tell it to use ds1, however, it looks to be using ds2.

I'm running JBossAS-4.0.2 on a W2K box against SQLServer2K.

Here's the connection object:

  | ...
  | 
  | /**
  |  * 
  |  * Handles connections to multiple databases.
  |  */
  | public class AppHelper
  | {
  |    private static AppHelper appHelperInstance = null;
  |    public static final String SC_DEFAULT_DS_CON = Constants.DEFAULT_DS_CON_VALUE;
  |       public static final String SC_CATS_DS_MAIN = Constants.CATS_DS_MAIN_VALUE;
  |       
  |    ...   
  | 
  |    //--------------------------------------------------------------------
  |    /**
  | 	* Static method used to retrieve an instance of the object (or to create
  | 	* a new instance, if none exists.)
  | 	* @return AppHelper app helper instance
  | 	*/
  |    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");
  |    }
  |    
  |   ...
  |       
  |    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;
  |    }                 
  |              
  |  ...
  |     
  | }
  | 
  | 
A call that switches ds:

  | con = AppHelper.getInstance().getConnection(
  | 						AppHelper.SC_DEFAULT_DS_CON);
  | // appears not to use the default ds con
  | ps = con.prepareStatement(
  | 						"UPDATE TempNewTest SET" +
  | 							"TC = ? " +
  | 						"WHERE SessionID = ? " +
  | 						"AND TC = ?");	
  | 
The Constants static lookup:

  | static {
  | try {
  | 	resourceBundle = ResourceBundle.getBundle("util");
  | 		
  | 	DEFAULT_DS_CON_VALUE = resourceBundle.getString(DEFAULT_DS_CON);
  | 	CATS_DS_MAIN_VALUE = resourceBundle.getString(CATS_DS_MAIN);
  | 
  | 		} catch(Exception e) {
  | 			System.err.println("Caught exception getting util.properties resource bundle.");
  | 		}
  | 	}	
  | 
The value:

  | default.ds.con=java:DefaultDS
  | cats.ds.con=java:CATS_DS_MAIN
  | 
In the trace the expected login for the call is not the one listed in the DefaultDS file.  Another strange thing is that it's only with Insert and Update calls.  All the Selects are done with the correct login.

If anyone could validate this or perhaps suggest something that I might be able to do to figure this out would be greatly appreciated.

Thanks.



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3973380#3973380

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3973380



More information about the jboss-user mailing list