[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/config/db DBJobConfigFactory.ja
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-10 17:58:09
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/config/db In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv10342/jmonks/batchserver/framework/config/db Modified Files: DBJobConfigFactory.java Log Message: no message Index: DBJobConfigFactory.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/config/db/DBJobConfigFactory.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** DBJobConfigFactory.java 22 Mar 2006 14:20:45 -0000 1.9 --- DBJobConfigFactory.java 10 Sep 2006 17:58:07 -0000 1.10 *************** *** 12,16 **** import java.sql.Connection; - import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; --- 12,15 ---- *************** *** 22,25 **** --- 21,25 ---- import org.jmonks.batchserver.framework.config.JobConfig; import org.jmonks.batchserver.framework.config.JobConfigFactory; + import org.jmonks.batchserver.framework.util.JdbcConnectionHelper; /** *************** *** 33,48 **** * </p> * <p> ! * Following are the four properties, this factory looks in job config properties ! * to connect to the database. If anyone of the property is missing, it throws ! * ConfigurationException. ! * <table> ! * <tr><td><b>property key</b></td><td><b>property value</b></td></tr> ! * <tr><td>config-db-jdbc-driver-class-name</td><td>oracle.jdbc.driver.OracleDriver</td></tr> ! * <tr><td>config-db-url</td><td>jdbc:oracle:thin:@hostname:1521:instname</td></tr> ! * <tr><td>config-db-username</td><td>scott</td></tr> ! * <tr><td>config-db-password</td><td>tiger</td></tr> ! * </table> ! * These properties can be configured using <property> element in the <job-config-factory-config> element ! * in the framework configuration file. * </p> * --- 33,57 ---- * </p> * <p> ! * This factory looks for the properties "jdbc-driver-class-name","jdbc-url", ! * "username" and "password" in job config factory config in framework configuration to ! * establish the connection to read the job configuration. If anyone of the properties ! * are missing, it throws ConfigurationException. Following example shows, how it can ! * be configured. ! * <br><br> ! * <pre> ! * <job-config-factory-config job-config-factory-class-name="org.jmonks.batchserver.framework.config.db.DBJobConfigFactory"> ! * <property key="jdbc-driver-class-name">oracle.jdbc.driver.OracleDriver</property> ! * <property key="jdbc-url">jdbc:oracle:thin:@hostname:1521:instancename</property> ! * <property key="username">scott</property> ! * <property key="password">tiger</property> ! * </job-config-factory-config> ! * </pre> ! * <br>The user specified in the configuration should have read privileges to the following database table objects. ! * <table> ! * <tr><td>JOB_CONFIG</td></tr> ! * <tr><td>JOB_LOGGING_CONFIG</td></tr> ! * <tr><td>BASIC_JOB_CONTROLLER_CONFIG</td></tr> ! * <tr><td>POOL_JOB_CONTROLLER_CONFIG</td></tr> ! * </table> * </p> * *************** *** 58,77 **** private Map configFactoryProps=null; /** - * Constant defines the property name of jdbc driver class name. - */ - private static final String PROPERTY_JOB_CONFIG_JDBC_DRIVER_CLASS_NAME = "config-db-jdbc-driver-class-name"; - /** - * Constant defines the property name of database URL. - */ - private static final String PROPERTY_JOB_CONFIG_DATABASE_URL = "config-db-url"; - /** - * Constant defines the property name of daabase user name. - */ - private static final String PROPERTY_JOB_CONFIG_DATABASE_USER_NAME = "config-db-username"; - /** - * Constant defines the property name of database password. - */ - private static final String PROPERTY_JOB_CONFIG_DATABASE_PASSWORD = "config-db-password"; - /** * SQL Query to pull the job configuration. */ --- 67,70 ---- *************** *** 112,131 **** * and close it to make sure property values are valid. */ ! Connection connection=this.getConnection(); if(connection==null) throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, "Unable to establish the database " + "connection with the properties " + this.configFactoryProps +"."); else ! { ! try ! { ! connection.close(); ! } ! catch(SQLException sqle) ! { ! sqle.printStackTrace(); ! logger.error(sqle.getMessage(),sqle); ! } ! } logger.trace("Exiting init"); } --- 105,114 ---- * and close it to make sure property values are valid. */ ! Connection connection=JdbcConnectionHelper.getConnection(this.configFactoryProps); if(connection==null) throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, "Unable to establish the database " + "connection with the properties " + this.configFactoryProps +"."); else ! JdbcConnectionHelper.closeConnection(connection); logger.trace("Exiting init"); } *************** *** 150,154 **** throw new IllegalArgumentException("Job name cannot be null."); ! Connection connection=this.getConnection(); if(connection==null) throw new IllegalStateException("DBJobConfigFacotry not initialized properly. Unable to get the connection."); --- 133,137 ---- throw new IllegalArgumentException("Job name cannot be null."); ! Connection connection=JdbcConnectionHelper.getConnection(this.configFactoryProps); if(connection==null) throw new IllegalStateException("DBJobConfigFacotry not initialized properly. Unable to get the connection."); *************** *** 185,231 **** return jobConfig; } - - /** - * Get the required properties from the configFactoryProperties map and - * establishes the connection. Returns null, if it cannot establish the - * connection. - * - * @return Returns the database connction, null, if it cannot establish the connection. - */ - private Connection getConnection() - { - logger.trace("Exiting getConnection"); - logger.info("Connection configuration : " + this.configFactoryProps); - - Connection connection=null; - - String driverClassName=(String)this.configFactoryProps.get(DBJobConfigFactory.PROPERTY_JOB_CONFIG_JDBC_DRIVER_CLASS_NAME); - String databaseURL=(String)this.configFactoryProps.get(DBJobConfigFactory.PROPERTY_JOB_CONFIG_DATABASE_URL); - String userName=(String)this.configFactoryProps.get(DBJobConfigFactory.PROPERTY_JOB_CONFIG_DATABASE_USER_NAME); - String password=(String)this.configFactoryProps.get(DBJobConfigFactory.PROPERTY_JOB_CONFIG_DATABASE_PASSWORD); - - if(driverClassName==null || "".equals(driverClassName) || databaseURL==null || "".equals(databaseURL) || - userName==null || "".equals(userName) || password==null || "".equals(password)) - connection=null; - else - { - try - { - Class.forName(driverClassName); - connection=DriverManager.getConnection(databaseURL,userName, password); - } - /** - * No need to worry about the specific exception. Either case need to return null. - * So catching the generic one. - */ - catch(Exception exception) - { - exception.printStackTrace(); - logger.error(exception.getMessage(), exception); - connection=null; - } - } - logger.trace("Exiting getConnection"); - return connection; - } } --- 168,170 ---- |