[Batchserver-cvs] batchserver/src/org/jmonks/batch/framework/repository/db4o Db4oRepository.java,
Brought to you by:
suresh_pragada
|
From: Suresh <sur...@us...> - 2006-09-15 22:04:25
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/repository/db4o In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv5825/framework/repository/db4o Modified Files: Db4oRepository.java Log Message: no message Index: Db4oRepository.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/repository/db4o/Db4oRepository.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Db4oRepository.java 15 Sep 2006 20:07:22 -0000 1.1 --- Db4oRepository.java 15 Sep 2006 22:04:23 -0000 1.2 *************** *** 24,28 **** * <pre> * <repository-config repository-class-name="org.jmonks.batch.framework.repository.db4o.Db4oRepository"> ! * <property key="db4o-filename">/batchserver/repository/batchserver_repository.db</property> * </repository-config> * </pre> --- 24,28 ---- * <pre> * <repository-config repository-class-name="org.jmonks.batch.framework.repository.db4o.Db4oRepository"> ! * <property key="db4o-directory">/batchserver/repository</property> * </repository-config> * </pre> *************** *** 32,35 **** --- 32,36 ---- * shown in the above XML configuration snippet. * </p> + * * @author Suresh Pragada * @version 1.0 *************** *** 40,46 **** 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. --- 41,51 ---- private static Logger logger=Logger.getLogger(Db4oRepository.class); /** ! * Property identifies the db4o directory name which is <code>db4o-directory</code>. */ ! public static final String PROPERTY_DB4O_DIRECTORY = "db4o-directory"; ! /** ! * Name of the DB4O repository file name which is <code>batchserver_repository.db</code>. ! */ ! public static final String DB4O_REPOSITORY_FILENAME = "batchserver_repository.db"; /** * Map holds the configuration properties of repository. *************** *** 65,75 **** * <p> * Initializes the Db4oRepository by accepting the map consist of properties ! * needed to setup the repository. This make sure repository-location property ! * has been defined and the value defined for this property is valid. * </p> * @param configProps Map contains the configuration properties. * ! * @throws ConfigurationException If repository-location property is not defined and ! * the value specified is invalid. * @throws IllegalArgumentException If given configProps is null. */ --- 70,81 ---- * <p> * Initializes the Db4oRepository by accepting the map consist of properties ! * needed to setup the repository. This validates for db4o-directory property ! * has been defined and the value defined for this property is valid. If the ! * configured directory name is not exists, it tries to create that directory. * </p> * @param configProps Map contains the configuration properties. * ! * @throws ConfigurationException If db4o-directory property is not defined and ! * the value specified is a file and not existing directory could not be created. * @throws IllegalArgumentException If given configProps is null. */ *************** *** 82,112 **** 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."); } --- 88,118 ---- this.repositoryConfigProperties=new HashMap(configProps); ! String db4oDirectoryName=(String)this.repositoryConfigProperties.get(Db4oRepository.PROPERTY_DB4O_DIRECTORY); ! if(db4oDirectoryName==null || "".equals(db4oDirectoryName)) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, ! "db4o-directory is required for Db4oReposiotry implementation."); else { ! File db4oDirectory=new File(db4oDirectoryName); ! if(!db4oDirectory.exists()) { try { ! boolean created=db4oDirectory.mkdirs(); if(!created) ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Attempt to create the directory for Db4o repository = " + db4oDirectoryName + " is failed."); } ! catch(SecurityException exception) { exception.printStackTrace(); ! logger.fatal("SecurityException while trying to create not nonexistent directory = " + db4oDirectoryName, exception); throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, ! "SecurityException while trying to create non existing Db4o directory " + db4oDirectoryName + ". Message = " + exception.getMessage()); } } ! else if(db4oDirectory.isFile()) { ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Configured value for db4o-directory property = " ! + db4oDirectoryName + " is a file. Directory name is expected."); } *************** *** 116,120 **** 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(); } --- 122,126 ---- ObjectContainer container=this.createContainer(this.repositoryConfigProperties); if(container==null) ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Unable to create the file " + (db4oDirectoryName+File.separator+Db4oRepository.DB4O_REPOSITORY_FILENAME) + " to setup repository."); container.close(); } *************** *** 131,136 **** protected ObjectContainer createContainer(Map configProps) { ! String db4oFileName=(String)configProps.get(Db4oRepository.PROPERTY_DB4O_FILENAME); ! ObjectContainer container=Db4o.openFile(db4oFileName); return container; } --- 137,142 ---- protected ObjectContainer createContainer(Map configProps) { ! String db4oDirectoryName=(String)configProps.get(Db4oRepository.PROPERTY_DB4O_DIRECTORY); ! ObjectContainer container=Db4o.openFile(db4oDirectoryName+File.separator+Db4oRepository.DB4O_REPOSITORY_FILENAME); return container; } |