[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/repository/db4o Db4oRepository.
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-15 06:21:15
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/repository/db4o In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16940/framework/repository/db4o Modified Files: Db4oRepository.java Log Message: no message Index: Db4oRepository.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/repository/db4o/Db4oRepository.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Db4oRepository.java 13 Sep 2006 23:29:45 -0000 1.11 --- Db4oRepository.java 15 Sep 2006 06:21:12 -0000 1.12 *************** *** 6,14 **** import com.db4o.query.Predicate; import java.io.File; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.ConfigurationException; - import org.jmonks.batchserver.framework.controller.JobController; import org.jmonks.batchserver.framework.Repository; import org.jmonks.batchserver.framework.JobStatistics; --- 6,14 ---- import com.db4o.query.Predicate; import java.io.File; + import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.ConfigurationException; import org.jmonks.batchserver.framework.Repository; import org.jmonks.batchserver.framework.JobStatistics; *************** *** 40,65 **** private static Logger logger=Logger.getLogger(Db4oRepository.class); /** ! * Property identifies the repository location. ! */ ! public static final String PROPERTY_REPOSIOTRY_LOCATION = "repository-location"; ! /** ! * Name of the db40 datbase file used as the repository. */ ! public static final String REPOSITORY_FILENAME = "batchserver_repository.db"; /** * Map holds the configuration properties of repository. */ protected Map repositoryConfigProperties=null; - /** - * Db4o container object. - */ - protected ObjectContainer container=null; /** *<p> * <i> ! * Do not use this constructor to instantiate Db4oRepository directly. Use ! * the factory method getRepository in Repository class to get the repository ! * instance. This constructor has been provided to make sure this should be * instantiable and accessible to the Repository class. * </i> --- 40,57 ---- private static Logger logger=Logger.getLogger(Db4oRepository.class); /** ! * Property identifies the db4o file name which <code>db4o-filename</code>. */ ! public static final String PROPERTY_DB4O_FILENAME = "db4o-filename"; /** * Map holds the configuration properties of repository. */ protected Map repositoryConfigProperties=null; /** *<p> * <i> ! * Do not use this constructor to instantiate Db4oRepository directly. ! * Access the repository only through the JobContext reference. ! * This constructor has been provided to make sure this should be * instantiable and accessible to the Repository class. * </i> *************** *** 80,105 **** * @throws ConfigurationException If repository-location property is not defined and * the value specified is invalid. */ protected void init(Map configProps) { logger.trace("Entering init"); this.repositoryConfigProperties=new HashMap(configProps); ! String repositoryLocation=(String)this.repositoryConfigProperties.get(Db4oRepository.PROPERTY_REPOSIOTRY_LOCATION); ! if(repositoryLocation==null || "".equals(repositoryLocation)) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, ! "repository-location is required for DefaultReposiotry implementation."); else { ! File repositoryDirectory=new File(repositoryLocation); ! if(!repositoryDirectory.exists()) { ! boolean created=repositoryDirectory.mkdirs(); ! if(!created) ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Attempt to create directory " + repositoryLocation + " is failed."); } ! else if(repositoryDirectory.isFile()) { ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Location " ! + repositoryLocation + " defined is a file. Directory name is expected."); } --- 72,112 ---- * @throws ConfigurationException If repository-location property is not defined and * the value specified is invalid. + * @throws IllegalArgumentException If given configProps is null. */ protected void init(Map configProps) { logger.trace("Entering init"); + + if(configProps==null) + throw new IllegalArgumentException("Map to call the init cannot be null."); + this.repositoryConfigProperties=new HashMap(configProps); ! String db4oFileName=(String)this.repositoryConfigProperties.get(Db4oRepository.PROPERTY_DB4O_FILENAME); ! if(db4oFileName==null || "".equals(db4oFileName)) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, ! "db4o-filename is required for Db4oReposiotry implementation."); else { ! File repositoryFile=new File(db4oFileName); ! if(!repositoryFile.exists()) { ! try ! { ! boolean created=repositoryFile.createNewFile(); ! if(!created) ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Attempt to create Db4o filename " + db4oFileName + " is failed."); ! } ! catch(IOException exception) ! { ! exception.printStackTrace(); ! logger.fatal("Exception while trying to create not nonexistent file = " + db4oFileName, exception); ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, ! "Exception while trying to create non existing Db4o filename " + db4oFileName + ". Message = " + exception.getMessage()); ! } } ! else if(repositoryFile.isDirectory()) { ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Db4o file name " ! + db4oFileName + " defined is a directory. File name is expected."); } *************** *** 107,114 **** * Just to make sure, would be able to setup the repository. */ ! String completeRepositoryFileName=repositoryDirectory.getAbsolutePath()+File.separator+Db4oRepository.REPOSITORY_FILENAME; ! this.container=Db4o.openFile(completeRepositoryFileName); ! if(this.container==null) ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Unable to create the file " + completeRepositoryFileName + " to setup repository."); } logger.trace("Exiting init"); --- 114,121 ---- * Just to make sure, would be able to setup the repository. */ ! ObjectContainer container=this.createContainer(this.repositoryConfigProperties); ! if(container==null) ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Unable to create the file " + repositoryFile.getAbsoluteFile() + " to setup repository."); ! container.close(); } logger.trace("Exiting init"); *************** *** 116,119 **** --- 123,140 ---- /** + * Creates the container by looking at the configuration from given Map. + * + * @configProps Configuration properties defined in repository configuration. + * + * @return Returns the Db4o object container reference. + */ + protected ObjectContainer createContainer(Map configProps) + { + String db4oFileName=(String)configProps.get(Db4oRepository.PROPERTY_DB4O_FILENAME); + ObjectContainer container=Db4o.openFile(db4oFileName); + return container; + } + + /** * @see org.jmonks.batchserver.framework.repository Repository#sendDataToNextJob(String,String,Object) */ *************** *** 131,135 **** boolean dataSaved=false; ! if(this.container==null) dataSaved=false; else --- 152,157 ---- boolean dataSaved=false; ! ObjectContainer container=this.createContainer(this.repositoryConfigProperties); ! if(container==null) dataSaved=false; else *************** *** 163,166 **** --- 185,189 ---- container.set(dataTransfer); container.commit(); + container.close(); logger.trace("data has been added with the identifier " + dataIdentifier + " from job name " + this.jobName); dataSaved=true; *************** *** 187,190 **** --- 210,214 ---- Object data=null; + ObjectContainer container=this.createContainer(this.repositoryConfigProperties); if(container==null) data=null; *************** *** 198,204 **** finalPreviousJobName.equals(jobDataTransfer.getSourceJobName()) && finalTargetJobName.equals(jobDataTransfer.getTargetJobName())) - { return true; - } else return false; --- 222,226 ---- *************** *** 213,216 **** --- 235,240 ---- else data=null; + + container.close(); } logger.trace("Exiting getDataFromPreviousJob"); *************** *** 227,230 **** --- 251,255 ---- final String finalJobName=this.jobName; boolean dataCleared=false; + ObjectContainer container=this.createContainer(this.repositoryConfigProperties); if(container==null) dataCleared=false; *************** *** 248,251 **** --- 273,277 ---- logger.debug(jobName + " data has been cleared from the repository."); container.commit(); + container.close(); dataCleared=true; } *************** *** 266,270 **** boolean registered=true; ! if(container==null) registered=false; --- 292,296 ---- boolean registered=true; ! ObjectContainer container=this.createContainer(this.repositoryConfigProperties); if(container==null) registered=false; *************** *** 280,283 **** --- 306,310 ---- container.set(new Db4oJobMgmtMntrInfoHolder(this.jobName, registrationInfo)); container.commit(); + container.close(); logger.trace(this.jobName + " mgmt and mntr information has been added to the repository"); registered=true; *************** *** 295,299 **** boolean unregistered=false; ! if(container==null) unregistered=false; --- 322,326 ---- boolean unregistered=false; ! ObjectContainer container=this.createContainer(this.repositoryConfigProperties); if(container==null) unregistered=false; *************** *** 310,313 **** --- 337,342 ---- else unregistered=false; + + container.close(); } logger.trace("Exiting unregisterJobMgmtMntrInfo"); *************** *** 329,332 **** --- 358,362 ---- boolean logged=false; + ObjectContainer container=this.createContainer(this.repositoryConfigProperties); if(container==null) logged=false; *************** *** 337,340 **** --- 367,372 ---- logger.debug(statistics.getJobname() + " has been logged."); logged=true; + + container.close(); } logger.trace("Exiting logStatistics"); |