tim@130: /** tim@130: * tim@130: */ tim@130: package de.intevation.gnv.geobackend.sde.connectionpool; tim@130: tim@130: import java.sql.Connection; 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 com.esri.sde.sdk.client.SeConnection; 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@130: /** tim@130: * the logger, used to log exceptions and additonaly information tim@130: */ tim@130: private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); tim@130: tim@130: /** tim@130: * The URL to the ArcSDE Server tim@130: */ tim@130: private String server = null; tim@130: /** tim@130: * The Port the ArcSDE Server is connected to. tim@130: */ tim@130: private String port = null; tim@130: /** tim@130: * The Name of the Database tim@130: */ tim@130: private String database = null; tim@130: /** tim@130: * The Username for the Authentication tim@130: */ tim@130: private String username = null; tim@130: /** tim@130: * The Credentials which belongs to the User tim@130: */ tim@130: private String credentials = null; tim@130: tim@130: tim@130: /** tim@130: * Constructor of this Class tim@130: * @param properties the Properties which includes the ConnectionParams to the Database tim@130: */ tim@130: public ArcSDEPoolableObjectFactory(Properties properties) { tim@130: tim@130: this.server = properties.getProperty("server"); tim@130: this.port = properties.getProperty("port"); tim@130: this.database = properties.getProperty("database"); tim@130: this.username = properties.getProperty("username"); tim@130: this.credentials = properties.getProperty("credentials"); tim@130: tim@130: log.info("ArcSDEPoolableObjectFactory initialized"); tim@130: log.info("Server: "+this.server); tim@130: log.info("Port: "+this.port); tim@130: log.info("Database: "+this.database); tim@130: log.info("User: "+this.username); tim@130: } tim@130: tim@130: /** tim@130: * @see org.apache.commons.pool.PoolableObjectFactory#activateObject(java.lang.Object) tim@130: */ tim@130: public void activateObject(Object arg0) throws Exception { tim@130: log.debug("ArcSDEPoolableObjectFactory.activateObject"); tim@130: // TODO Was muss hier passieren? tim@130: } tim@130: tim@130: /** tim@130: * @see org.apache.commons.pool.PoolableObjectFactory#destroyObject(java.lang.Object) tim@130: */ tim@130: public void destroyObject(Object arg0) throws Exception { tim@130: log.debug("ArcSDEPoolableObjectFactory.destroyObjectb"); tim@130: if (arg0 instanceof SeConnection){ tim@130: ((SeConnection)arg0).close(); tim@130: }else{ tim@130: log.warn("Object cannot be handled"); tim@130: } tim@130: } tim@130: tim@130: /** tim@130: * @see org.apache.commons.pool.PoolableObjectFactory#makeObject() tim@130: */ tim@130: public Object makeObject() throws Exception { tim@130: log.debug("ArcSDEPoolableObjectFactory.makeObject"); tim@130: Connection con; tim@130: 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@130: } tim@130: tim@130: /** tim@130: * @see org.apache.commons.pool.PoolableObjectFactory#passivateObject(java.lang.Object) tim@130: */ tim@130: public void passivateObject(Object arg0) throws Exception { tim@130: log.debug("ArcSDEPoolableObjectFactory.passivateObject"); tim@130: // TODO Was muss hier passieren? tim@130: } tim@130: tim@130: /** tim@130: * @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object) tim@130: */ tim@130: public boolean validateObject(Object arg0) { tim@130: // TODO Was muss hier passieren? tim@130: log.debug("ArcSDEPoolableObjectFactory.validateObject"); tim@130: return true; tim@130: } tim@130: }