[Batchserver-cvs] batchserver/src/org/jmonks/batch/framework/config/db DBBasicJobControllerConfig.
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-15 20:06:13
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config/db In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19840 Added Files: DBBasicJobControllerConfig.java DBJobConfig.java DBJobConfigFactory.java DBJobControllerConfig.java DBJobLoggingConfig.java DBPoolJobControllerConfig.java Log Message: no message --- NEW FILE: DBJobConfigFactory.java --- /* * DBJobConfigFactory.java * * Created on March 2, 2006, 12:07 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.JobConfig; import org.jmonks.batch.framework.config.JobConfigFactory; import org.jmonks.batch.framework.util.JdbcConnectionHelper; /** * <p> * DBJobConfigFactory reads the job configuration from defined database to create the * configuration objects needed by the job. This factory looks for few properties * in the factory config properties map to identify the database it needs to connect to. This * factory looks for the job configuration in the <b>job-config</b> table in the database. * Controller configuration will be defined in a seperate tables, and DBJobControllerConfig * is responsible to read the job controller configuration from the database. * </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 any one of the properties * are missing, it throws ConfigurationException. Following example shows, how it can * be configured for Oracle database. * <br><br> * <pre> * <job-config-factory-config job-config-factory-class-name="org.jmonks.batch.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 border="1"> * <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> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class DBJobConfigFactory extends JobConfigFactory { /** * Property map holds the properites required by this factory. */ private Map configFactoryProps=null; /** * SQL Query to pull the job configuration. */ private static final String JOB_CONFIG_QUERY = "select 1 from job_config where job_name=?"; private static Logger logger=Logger.getLogger(DBJobConfigFactory.class); /** *<p> * <i> * Do not use this constructor to instantiate DBJobConfigFactory directly. Use * the factory method getJobConfigFactory in JobConfigFactory class to get the config factory * instance. This constructor has been provided to make sure this should be * instantiable and accessible to the JobConfigFactory class. * </i> * </p> */ public DBJobConfigFactory() { } /** * This method initializes the factory by accepting the required properties * as a map. If it doesnt find any required properties * and values are not valid to initialize the factory, * throws ConfigurationException with the appropriate error message. * * @param configFactoryProps Map consists of all the properties defined for this factory. * * @throws ConfigurationException If required properties are missing. */ protected void init(Map configFactoryProps) { logger.trace("Entering init"); this.configFactoryProps=new HashMap(configFactoryProps); /** * Do the basic validation like look for the required properites and make a connection * 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"); } /** * Returns the requested job configuration as JobConfig object. The requested job * name should be passed as a parameter. If it doesnt find the configuration of * the requested jobName in the table <b>job_config</b> in given database, it returns null. * * @param jobName Name of the job. * * @return Returns the job config object if found, null, otherwise. * * @throws IllegalArgumentException If jobName passed as parameter is null. * @throws IllegalStateException If factory is not initialized properly. */ public JobConfig getJobConfig(String jobName) { logger.trace("Entering getJobConfig " + jobName); JobConfig jobConfig=null; if(jobName==null) 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."); /** * Look up job configuration in table job_config and pass that information to DBJobConfig. */ try { PreparedStatement statement=connection.prepareStatement(DBJobConfigFactory.JOB_CONFIG_QUERY); statement.setString(1, jobName); ResultSet resultSet=statement.executeQuery(); if(resultSet.next()) { logger.debug("Job found in database configuration"); jobConfig=new DBJobConfig(jobName,connection); logger.trace("Would be able to read the job configuration from database"); } else { jobConfig=null; logger.error("Could not find an entry in table job_config with the job name " + jobName); } } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); } finally { try{ connection.close(); } catch(Exception exception){ exception.printStackTrace(); } } logger.trace("ExitinggetJobConfig"); return jobConfig; } } --- NEW FILE: DBJobConfig.java --- /* * DBJobConfig.java * * Created on March 2, 2006, 11:58 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.JobConfig; /** * <p> * DBJobConfig provides the implementation of JobConfig by reading the * job configuration from given connection. This reads the job configuration * from table <b>job_config</b>. Following is the schema of that table. * <br><br> * <pre> * <table border="1"> * <tr><td><b>Column Name</b></td><td><b>Data Type</b></td><td><b>Purpose</b></td></tr> * <tr><td>JOB_NAME</td><td>VARCHAR2(64)</td><td>Name of the Job.</td></tr> * <tr><td>JOB_STATUS</td><td>NUMBER</td><td>Status of the job. 1 - Active, 0 - Inactive</td></tr> * <tr><td>JOB_CONTROLLER_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Controller to be used for this job. For pool job controller "<code>org.jmonks.batch.framework.controller.pool.PoolJobController</code> and for basic job controller <code>org.jmonks.batch.framework.controller.basic.BasicJobController</code></td></tr> * <tr><td>JOB_CONTROLLER_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties for the controller. See the schema column comments for the format.</td></tr> * </table> * </pre> * </p> * * @author Suresh Pragada * @since 1.0 * @version 1.0 */ public class DBJobConfig extends JobConfig { /** * Query to load the job configuration from job_config table. */ private static final String JOB_CONFIG_QUERY = "select job_status from job_config where job_name=?"; private static Logger logger=Logger.getLogger(DBJobConfig.class); /** * Loads the job name and controller configuration into the job configuration object. * * @param jobName Name of the job to be loaded. * @param connection Connection to the Database. * * @throws ConfigurationException If job or controllers are not configured properly. */ DBJobConfig(String jobName,Connection connection) { logger.trace("Entering constructor " + jobName); this.jobName=jobName; logger.debug("Job Name = " + this.jobName); try { PreparedStatement statement=connection.prepareStatement(DBJobConfig.JOB_CONFIG_QUERY); statement.setString(1, jobName); ResultSet resultSet=statement.executeQuery(); if(resultSet.next()) { int status=resultSet.getInt(1); this.jobStatus=(status==1?true:false); logger.debug("Job Status = " + this.jobStatus); this.jobLoggingConfig=new DBJobLoggingConfig(jobName, connection); logger.debug("Job Logging configuration = " + this.jobLoggingConfig); this.jobControllerConfig=DBJobControllerConfig.getJobControllerConfig(jobName, connection); logger.debug("Job Controller configuration = " + this.jobControllerConfig); } else { /** * How can this is possible? Just now.. I could see this entry in job_config. */ logger.error("Could not find entry in job_config with job name " + jobName); throw new IllegalStateException("Surprisingly.. Could not find entry in job_config with job_name " + jobName); } } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); throw new ConfigurationException(ConfigurationException.JOB_CONFIG, exception.getMessage()); } logger.trace("Exiting constructor"); } } --- NEW FILE: DBPoolJobControllerConfig.java --- /* * DBPoolJobControllerConfig.java * * Created on March 2, 2006, 1:41 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.util.FrameworkUtil; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.PoolJobControllerConfig; /** * <p> * DBPoolJobControllerConfig loads the job controller configuration from the defined * database. This loads the pool controller configuration from the table <b>pool_job_controller_config</b>. * Following is the schema of that table defined in the database. * <br><br> * <pre> * <table border="1"> * <tr><td><b>Column Name</b></td><td><b>Data Type</b></td><td><b>Purpose</b></td></tr> * <tr><td>JOB_NAME</td><td>VARCHAR2(64)</td><td>Name of the Job.</td></tr> * <tr><td>POOL_JOB_PROCESSOR_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Name of the processor class writes the business logic of consumer the data from the pool by implementing the PoolJobProcessor interface.</td></tr> * <tr><td>POOL_JOB_PROCESSOR_THREAD_CNT</td><td>NUMBER</td><td>Number of processor instances (each instance will be run in its own thread) to be created while executing the job.</td></tr> * <tr><td>POOL_JOB_PROCESSOR_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties required by the job processor.</td></tr> * <tr><td>POOL_JOB_LOADER_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Name of the loader class writes the business logic of loading the jobs into the pool by implemention the PoolJobLoader interface. This will be run in its own thread.</td></tr> * <tr><td>POOL_JOB_LOADER_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties required by the job loader.</td></tr> * <tr><td>JOB_POOL_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Name of the class act as pool/channel/pipe between the loader and multiple processors. Multiple implementations will be available and can be chosen based on the need.</td></tr> * <tr><td>JOB_POOL_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties required by the job pool.</td></tr> * </table> * </pre> * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class DBPoolJobControllerConfig extends PoolJobControllerConfig { /** * SQL Query retrieves the job controller class name and controller properites from job_config. */ private static final String JOB_CONFIG_QUERY = "select job_controller_class_name,job_controller_props from job_config where job_name=?"; /** * SQL Query pulls the information pool_job_controller_config table. */ private static final String POOL_JOB_CONTROLLER_CONFIG_QUERY = "select pool_job_processor_class_name, " + "pool_job_processor_thread_cnt, pool_job_processor_props, pool_job_loader_class_name, " + "pool_job_loader_props, job_pool_class_name, job_pool_props from pool_job_controller_config " + "where job_name=?"; private static Logger logger=Logger.getLogger(DBPoolJobControllerConfig.class); /** * Loads the pool job controller configuration from table pool_job_controller_config * into DBPoolJobControllerConfig object. * * @param jobName Name of the job. * @param connection Connection to the defined database. * * @throws ConfigurationException If controller class name or job processor name doest not found. */ public DBPoolJobControllerConfig(String jobName,Connection connection) { logger.trace("Entering constructor " + jobName); try { PreparedStatement jobConfigStatement=connection.prepareStatement(DBPoolJobControllerConfig.JOB_CONFIG_QUERY); jobConfigStatement.setString(1, jobName); ResultSet jobConfigResultSet=jobConfigStatement.executeQuery(); if(jobConfigResultSet.next()) { this.jobControllerClassName=jobConfigResultSet.getString(1); String controllerConfigProps=jobConfigResultSet.getString(2); if(controllerConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(controllerConfigProps, this.jobControllerConfigProps); } else { /** * Surprising!!!!!!!!! */ logger.error("no controller configuration found"); } logger.trace("Started loading pool job controller configuration"); PreparedStatement controllerConfigStatement=connection.prepareStatement(DBPoolJobControllerConfig.POOL_JOB_CONTROLLER_CONFIG_QUERY); controllerConfigStatement.setString(1,jobName); ResultSet controllerConfigResultSet=controllerConfigStatement.executeQuery(); if(controllerConfigResultSet.next()) { this.poolJobProcessorClassName=controllerConfigResultSet.getString(1); this.poolJobProcessorThreadCount=controllerConfigResultSet.getInt(2); String processorConfigProps=controllerConfigResultSet.getString(3); if(processorConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(processorConfigProps,this.poolJobProcessorConfigProps); this.poolJobLoaderClassName=controllerConfigResultSet.getString(4); String loaderConfigProps=controllerConfigResultSet.getString(5); if(loaderConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(loaderConfigProps,this.poolJobLoaderConfigProps); this.poolClassName=controllerConfigResultSet.getString(6); String poolConfigProps=controllerConfigResultSet.getString(7); if(poolConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(poolConfigProps,this.poolConfigProps); } else { throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Controller configuration is not defined for the job " + jobName + "."); } logger.trace("Finished loading pool job controller configuration"); } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } logger.trace("Exiting constructor"); } } --- NEW FILE: DBJobControllerConfig.java --- /* * DBJobControllerConfig.java * * Created on March 2, 2006, 1:22 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.FrameworkConfig; import org.jmonks.batch.framework.config.JobControllerConfig; /** * <p> * DBJobControllerConfig responsible to build the controller specific * JobControllerConfig objects from the given database. It looks for the * configured controller in <b>job_config.job_controller_class_name</b> column * and instantiates the appropriate JobControllerConfig instance and set the * controller configuration properties. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class DBJobControllerConfig extends JobControllerConfig { /** * SQL Query retrieves the job controller class name and controller properites. */ private static final String JOB_CONFIG_QUERY = "select job_controller_class_name,job_controller_props from job_config where job_name=?"; /** * Identifier used to request the Framework controller configuration for the specific controller config for this factory. */ public static final String JOB_CONTROLLER_CONFIG_FACTORY_CLASS_ATTRIBUTE_NAME = "db-factory-config-class-name"; private static Logger logger=Logger.getLogger(DBJobControllerConfig.class); /** * <p> * Factory method creates and returns the controller specific controller config object * from the table job_config and controller specific tables. This looks for the * controller class name in job_config and tries to find specific controller config object for this controller * and defined for the DB factory in framework configuration file. * </p> * * @return Returns the controller specific controller config object. * * @throws ConfigurationException If controller config class name is not defined or controller specific config object cannot be found * in framework controller configuration. */ public static JobControllerConfig getJobControllerConfig(String jobName,Connection connection) { logger.trace("Entering getJobControllerConfig " + jobName); JobControllerConfig controllerConfig=null; try { PreparedStatement statement=connection.prepareStatement(DBJobControllerConfig.JOB_CONFIG_QUERY); statement.setString(1, jobName); ResultSet resultSet=statement.executeQuery(); if(resultSet.next()) { String controllerClassName=resultSet.getString(1); logger.debug("Controller class name = " + controllerClassName); try { String controllerConfigClassName=FrameworkConfig.getInstance().getJobControllerConfig().getConfigClassName(controllerClassName, DBJobControllerConfig.JOB_CONTROLLER_CONFIG_FACTORY_CLASS_ATTRIBUTE_NAME); logger.debug("Controller config class name = " + controllerConfigClassName); if(controllerConfigClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Could not found controller config class for the controller " + controllerClassName + " for the factory " + DBJobControllerConfig.JOB_CONTROLLER_CONFIG_FACTORY_CLASS_ATTRIBUTE_NAME + "."); else { Class configClass=Class.forName(controllerConfigClassName); Constructor constructor=configClass.getConstructor(new Class[]{String.class,Connection.class}); controllerConfig=(JobControllerConfig)constructor.newInstance(new Object[]{jobName,connection}); } } catch(InstantiationException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(NoSuchMethodException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(ClassNotFoundException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(IllegalAccessException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(InvocationTargetException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } } } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } logger.trace("Exiting getJobControllerConfig"); return controllerConfig; } } --- NEW FILE: DBBasicJobControllerConfig.java --- /* * DBBasicJobControllerConfig.java * * Created on March 2, 2006, 1:55 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.util.FrameworkUtil; import org.jmonks.batch.framework.config.BasicJobControllerConfig; import org.jmonks.batch.framework.config.ConfigurationException; /** * <p> * DBBasicJobControllerConfig loads the job controller configuration from the defined * database. This loads the basic controller configuration from the table <b>basic_job_controller_config</b>. * Following is the schema of that table defined in the database. * <br><br> * <pre> * <table border="1"> * <tr><td><b>Column Name</b></td><td><b>Data Type</b></td><td><b>Purpose</b></td></tr> * <tr><td>JOB_NAME</td><td>VARCHAR2(64)</td><td>Name of the Job.</td></tr> * <tr><td>BASIC_JOB_PROCESSOR_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Name of the processor class implements the business logic by extending the BasicJobProcessor class.</td></tr> * <tr><td>BASIC_JOB_PROCESSOR_THREAD_CNT</td><td>NUMBER</td><td>Number of processor instances(each instance will be executed in its own thread) to be created while executing the job.</td></tr> * <tr><td>BASIC_JOB_PROCESSOR_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties required by the processor. These can be accessed through JobContext reference.</td></tr> * </table> * </pre> * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class DBBasicJobControllerConfig extends BasicJobControllerConfig { /** * SQL Query retrieves the job controller class name and controller properites from job_config. */ private static final String JOB_CONFIG_QUERY = "select job_controller_class_name,job_controller_props from job_config where job_name=?"; /** * SQL Query pulls the information basic_job_controller_config table. */ private static final String BASIC_JOB_CONTROLLER_CONFIG_QUERY = "select basic_job_processor_class_name, basic_job_processor_thread_cnt, basic_job_processor_props from basic_job_controller_config where job_name=?"; private static Logger logger=Logger.getLogger(DBBasicJobControllerConfig.class); /** * Loads the basic job controller configuration from table basic_job_controller_config * into DBBasicJobControllerConfig object. * * @param jobName Name of the job. * @param connection Connection to the defined database. * * @throws ConfigurationException If controller class name or job processor name doest not found. */ public DBBasicJobControllerConfig(String jobName,Connection connection) { logger.trace("Entering constructor " + jobName); try { PreparedStatement jobConfigStatement=connection.prepareStatement(DBBasicJobControllerConfig.JOB_CONFIG_QUERY); jobConfigStatement.setString(1, jobName); ResultSet jobConfigResultSet=jobConfigStatement.executeQuery(); if(jobConfigResultSet.next()) { this.jobControllerClassName=jobConfigResultSet.getString(1); String controllerConfigProps=jobConfigResultSet.getString(2); logger.debug("controller configuration props = " + controllerConfigProps); if(controllerConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(controllerConfigProps, this.jobControllerConfigProps); } else { /** * Surprising!!!!!!!!! */ logger.error("Job configuration not found with the name " + jobName); } logger.trace("Started loading basic job processor configuration"); PreparedStatement controllerConfigStatement=connection.prepareStatement(DBBasicJobControllerConfig.BASIC_JOB_CONTROLLER_CONFIG_QUERY); controllerConfigStatement.setString(1,jobName); ResultSet controllerConfigResultSet=controllerConfigStatement.executeQuery(); if(controllerConfigResultSet.next()) { this.basicJobProcessorClassName=controllerConfigResultSet.getString(1); this.basicJobProcessorThreadCount=controllerConfigResultSet.getInt(2); String processorConfigProps=controllerConfigResultSet.getString(3); if(processorConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(processorConfigProps,this.basicJobProcessorConfigProps); } else { throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Controller configuration is not defined for the job " + jobName); } logger.trace("Finished loading basic job processor configuration"); } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } logger.trace("Exiting constructor"); } } --- NEW FILE: DBJobLoggingConfig.java --- /* * DBJobLoggingConfig.java * * Created on March 13, 2006, 8:17 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.JobLoggingConfig; /** * <p> * DBJobLoggingConfig reads the job logging configuration from the table <b>job_logging_config</b>. * Below is the schema of <b>job_logging_config</b> table. * <br><br> * <pre> * <table border="1"> * <tr><td><b>Column Name</b></td><td><b>Data Type</b></td><td><b>Purpose</b></td></tr> * <tr><td>JOB_NAME</td><td>VARCHAR2(64)</td><td>Name of the Job.</td></tr> * <tr><td>JOB_LOGGER_NAME</td><td>VARCHAR2(256)</td><td>Package name of the logger. Values will be like <code>com.mycompany.jobs.myjob</code></td></tr> * <tr><td>JOB_LOGGER_LEVEL</td><td>VARCHAR2(32)</td><td>Level of the logger. Values can be TRACE,DEBUG,INFO,WARN,ERROR,FATAL</td></tr> * </table> * </pre> * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class DBJobLoggingConfig extends JobLoggingConfig { private static final String JOB_LOGGING_CONFIG_QUERY="select job_logger_name,job_logger_level from job_logging_config where job_name=?"; private static Logger logger=Logger.getLogger(DBJobLoggingConfig.class); /** * Reads the configuration from the table <b>job_logging_config</b> and add * each record as JobLoggerConfig object. * * @param jobName Name of the job. * @param connection Database connection to the defined database. */ public DBJobLoggingConfig(String jobName,Connection connection) { logger.trace("Entering constructor"); try { PreparedStatement statement=connection.prepareStatement(DBJobLoggingConfig.JOB_LOGGING_CONFIG_QUERY); statement.setString(1, jobName); ResultSet resultSet=statement.executeQuery(); while(resultSet.next()) { String loggerName=resultSet.getString(1); String loggerLevel=resultSet.getString(2); this.addLogger(loggerName,loggerLevel); } } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONFIG, exception.getMessage()); } logger.trace("Exiting constructor"); } } |