tim@130: /** tim@130: * tim@130: */ tim@130: package de.intevation.gnv.geobackend.sde.connectionpool; tim@130: tim@130: import java.sql.Connection; tim@265: import java.sql.SQLException; tim@130: import java.util.Properties; tim@130: tim@130: import org.apache.commons.pool.PoolableObjectFactory; tim@130: import org.apache.log4j.Logger; tim@130: tim@130: import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; tim@130: import de.intevation.gnv.geobackend.sde.datasources.ArcSDEConnection; tim@130: tim@130: /** tim@130: * @author Tim Englich tim@130: * tim@130: */ tim@130: public class ArcSDEPoolableObjectFactory implements PoolableObjectFactory { tim@130: tim@274: /** tim@130: * the logger, used to log exceptions and additonaly information tim@130: */ tim@130: private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); tim@274: /** tim@274: * The URL to the ArcSDE Server tim@274: */ tim@274: private String server = null; tim@274: /** tim@274: * The Port the ArcSDE Server is connected to. tim@274: */ tim@274: private String port = null; tim@274: /** tim@274: * The Name of the Database tim@274: */ tim@274: private String database = null; tim@274: /** tim@274: * The Username for the Authentication tim@274: */ tim@274: private String username = null; tim@274: /** tim@274: * The Credentials which belongs to the User tim@274: */ tim@274: private String credentials = null; tim@130: tim@274: /** tim@274: * Constructor of this Class tim@274: * @param properties the Properties which includes the ConnectionParams to the Database tim@274: */ tim@274: public ArcSDEPoolableObjectFactory(Properties properties) { tim@274: log.debug("ArcSDEPoolableObjectFactory.Constructor"); tim@274: this.server = properties.getProperty("server"); tim@274: this.port = properties.getProperty("port"); tim@274: this.database = properties.getProperty("database"); tim@274: this.username = properties.getProperty("username"); tim@274: this.credentials = properties.getProperty("credentials"); tim@274: tim@274: log.info("ArcSDEPoolableObjectFactory initialized"); tim@274: log.info("Server: "+this.server); tim@274: log.info("Port: "+this.port); tim@274: log.info("Database: "+this.database); tim@274: log.info("User: "+this.username); tim@274: } tim@130: tim@274: /** tim@274: * @see org.apache.commons.pool.PoolableObjectFactory#activateObject(java.lang.Object) tim@274: */ tim@274: public void activateObject(Object arg0) throws Exception { tim@274: log.debug("ArcSDEPoolableObjectFactory.activateObject"); tim@274: } tim@130: tim@274: /** tim@274: * @see org.apache.commons.pool.PoolableObjectFactory#destroyObject(java.lang.Object) tim@274: */ tim@274: public void destroyObject(Object arg0) throws Exception { tim@274: log.debug("ArcSDEPoolableObjectFactory.destroyObjectb"); tim@274: if (arg0 instanceof ArcSDEConnection) { tim@274: ((ArcSDEConnection)arg0).close(); tim@274: }else{ tim@274: log.warn("Object cannot be handled"); tim@274: } tim@274: } tim@130: tim@274: /** tim@274: * @see org.apache.commons.pool.PoolableObjectFactory#makeObject() tim@274: */ tim@274: public Object makeObject() throws Exception { tim@274: log.debug("ArcSDEPoolableObjectFactory.makeObject"); tim@274: Connection con; tim@274: try { tim@130: con = new ArcSDEConnection(this.server, this.port, this.database, this.username, this.credentials); tim@130: } tim@130: catch (ConnectionException e) { tim@130: throw new ConnectionException("Establishing a connection to database failed: " + e.toString(), e); tim@130: } tim@130: return con; tim@274: } tim@130: tim@274: /** tim@274: * @see org.apache.commons.pool.PoolableObjectFactory#passivateObject(java.lang.Object) tim@274: */ tim@274: public void passivateObject(Object arg0) throws Exception { tim@274: log.debug("ArcSDEPoolableObjectFactory.passivateObject"); tim@274: } tim@130: tim@274: /** tim@274: * @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object) tim@274: */ tim@274: public boolean validateObject(Object arg0) { tim@274: log.debug("ArcSDEPoolableObjectFactory.validateObject"); tim@265: boolean returnValue = false; tim@274: try { tim@274: returnValue = arg0 instanceof ArcSDEConnection tim@265: ? !((ArcSDEConnection)arg0).isClosed() tim@265: : false; tim@265: } tim@265: catch (SQLException sqle) {} tim@265: return returnValue; tim@274: } tim@265: }