Thread: [Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/repository/db4o ClientServerDb4
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-15 06:21:56
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/repository/db4o In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17089 Added Files: ClientServerDb4oRepository.java Log Message: no message --- NEW FILE: ClientServerDb4oRepository.java --- /* * ClientServerDb4oRepository.java * * Created on September 14, 2006, 11:13 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.batchserver.framework.repository.db4o; import com.db4o.Db4o; import com.db4o.ObjectContainer; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.ConfigurationException; /** * <p> * ClientServerDb4oRepository access the Db4o Server and use it as a repository. * This requires the db4o server configuration in the repository configuration. * Framework provides a utility shell script to start the server. Following is an * example repository configuration to use Db4o in client and server mode. * <br><br> * <pre> * <repository-config repository-class-name="org.jmonks.batchserver.framework.repository.db4o.ClientServerDb4oRepository"> * <property key="db4o-server-name">server name or IP Address</property> * <property key="db4o-server-port">4545</property> * <property key="db4o-server-username">scott</property> * <property key="db4o-server-password">tiger</property> * </repository-config> * </pre> * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class ClientServerDb4oRepository extends Db4oRepository { private static Logger logger=Logger.getLogger(ClientServerDb4oRepository.class); /** * Property identifies the Db4o Server name which is <code>db4o-server-name</code>. */ public static final String PROPERTY_DB4O_SERVER_NAME = "db4o-server-name"; /** * Property identifies the Db4o Server port which is <code>db4o-server-port</code>. */ public static final String PROPERTY_DB4O_SERVER_PORT = "db4o-server-port"; /** * Property identifies the Db4o Server user name which is <code>db4o-server-username</code>. */ public static final String PROPERTY_DB4O_SERVER_USERNAME = "db4o-server-username"; /** * Property identifies the Db4o Server password which is <code>db4o-server-password</code>. */ public static final String PROPERTY_DB4O_SERVER_PASSWORD = "db4o-server-password"; /** * Enables the creation of the ClientServerDb4oRepository instance from the factory method. */ public ClientServerDb4oRepository() { } /** * <p> * Initializes the ClientServerDb4oRepository by accepting the map consist of properties * needed to access Db4o server. This make sure required properties like * <code>db4o-server-name</code>, <code>db4o-server-port</code>, * <code>db4o-server-username</code> and <code>db4o-server-password</code> have been defined * and the value defined for this property is valid. * </p> * * @param configProps Map contains the configuration properties. * * @throws ConfigurationException If any one of the required properties are 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."); super.repositoryConfigProperties=new HashMap(configProps); String db4oServerName=(String)this.repositoryConfigProperties.get(ClientServerDb4oRepository.PROPERTY_DB4O_SERVER_NAME); String db4oServerPort=(String)this.repositoryConfigProperties.get(ClientServerDb4oRepository.PROPERTY_DB4O_SERVER_PORT); String db4oServerUserName=(String)this.repositoryConfigProperties.get(ClientServerDb4oRepository.PROPERTY_DB4O_SERVER_USERNAME); String db4oServerPassword=(String)this.repositoryConfigProperties.get(ClientServerDb4oRepository.PROPERTY_DB4O_SERVER_PASSWORD); if(db4oServerName==null || "".equals(db4oServerName) || db4oServerPort==null || "".equals(db4oServerPort) || db4oServerUserName==null || "".equals(db4oServerUserName) || db4oServerPassword==null || "".equals(db4oServerPassword)) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Required properties to access Db4o server are missing."); else { /** * Just to make sure, would be able to setup the repository. */ ObjectContainer container=createContainer(super.repositoryConfigProperties); if(container==null) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Unable to access the db4o server using given properites = " + super.repositoryConfigProperties); container.close(); } logger.trace("Exiting init"); } /** * @see org.jmonks.batchserver.framework.repository.db4o.Db4oRepository#createContainer(Map) */ protected ObjectContainer createContainer(Map configProps) { ObjectContainer container=null; try { String db4oServerName=(String)this.repositoryConfigProperties.get(ClientServerDb4oRepository.PROPERTY_DB4O_SERVER_NAME); int db4oServerPort=Integer.parseInt((String)this.repositoryConfigProperties.get(ClientServerDb4oRepository.PROPERTY_DB4O_SERVER_PORT)); String db4oServerUserName=(String)this.repositoryConfigProperties.get(ClientServerDb4oRepository.PROPERTY_DB4O_SERVER_USERNAME); String db4oServerPassword=(String)this.repositoryConfigProperties.get(ClientServerDb4oRepository.PROPERTY_DB4O_SERVER_PASSWORD); container=Db4o.openClient(db4oServerName, db4oServerPort, db4oServerUserName, db4oServerPassword); } catch(IOException exception) { exception.printStackTrace(); logger.fatal("IOException while opening the client with the configuration = " + configProps.toString(), exception); } return container; } } |