view geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEPoolableObjectFactory.java @ 130:e4eacd613356

Implementierung Datenzugriff auf die ArcSDE über java.sql. Methodiken ChangeLog wird nachgereicht da SubversionClientincompatiblitäten vorhanden sind. geo-backend/trunk@7 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Wed, 02 Sep 2009 15:15:52 +0000
parents
children e5379e129799
line wrap: on
line source
/**
 * 
 */
package de.intevation.gnv.geobackend.sde.connectionpool;

import java.sql.Connection;
import java.util.Properties;

import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.log4j.Logger;

import com.esri.sde.sdk.client.SeConnection;

import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException;
import de.intevation.gnv.geobackend.sde.datasources.ArcSDEConnection;

/**
 * @author Tim Englich <tim.englich@intevation.de>
 *
 */
public class ArcSDEPoolableObjectFactory implements PoolableObjectFactory {

	/**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class);
	
	/**
	 * The URL to the ArcSDE Server
	 */
	private String server = null;
	/**
	 * The Port the ArcSDE Server is connected to.
	 */
	private String port = null;
	/**
	 * The Name of the Database
	 */
	private String database = null;
	/**
	 * The Username for the Authentication
	 */
	private String username = null;
	/**
	 * The Credentials which belongs to the User
	 */
	private String credentials = null;
      
    
	/**
	 * Constructor of this Class
	 * @param properties the Properties which includes the ConnectionParams to the Database
	 */
	public ArcSDEPoolableObjectFactory(Properties properties) {
		
		this.server = properties.getProperty("server");
		this.port = properties.getProperty("port");
		this.database = properties.getProperty("database");
		this.username = properties.getProperty("username");
		this.credentials = properties.getProperty("credentials");
		
		log.info("ArcSDEPoolableObjectFactory initialized");
		log.info("Server: "+this.server);
		log.info("Port: "+this.port);
		log.info("Database: "+this.database);
		log.info("User: "+this.username);
	}

	/**
	 * @see org.apache.commons.pool.PoolableObjectFactory#activateObject(java.lang.Object)
	 */
	public void activateObject(Object arg0) throws Exception {
		log.debug("ArcSDEPoolableObjectFactory.activateObject");
		// TODO Was muss hier passieren?
	}

	/**
	 * @see org.apache.commons.pool.PoolableObjectFactory#destroyObject(java.lang.Object)
	 */
	public void destroyObject(Object arg0) throws Exception {
		log.debug("ArcSDEPoolableObjectFactory.destroyObjectb");
		if (arg0 instanceof SeConnection){
			((SeConnection)arg0).close();
		}else{
			log.warn("Object cannot be handled");
		}
	}

	/**
	 * @see org.apache.commons.pool.PoolableObjectFactory#makeObject()
	 */
	public Object makeObject() throws Exception {
		log.debug("ArcSDEPoolableObjectFactory.makeObject");
		Connection con;
		try {
            con = new ArcSDEConnection(this.server, this.port, this.database, this.username, this.credentials);
        }
        catch (ConnectionException e) {
            throw new ConnectionException("Establishing a connection to database failed: " + e.toString(), e);
        }
        return con;
	}

	/**
	 * @see org.apache.commons.pool.PoolableObjectFactory#passivateObject(java.lang.Object)
	 */
	public void passivateObject(Object arg0) throws Exception {
		log.debug("ArcSDEPoolableObjectFactory.passivateObject");
		// TODO Was muss hier passieren?
	}

	/**
	 * @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object)
	 */
	public boolean validateObject(Object arg0) {
		// TODO Was muss hier passieren?
		log.debug("ArcSDEPoolableObjectFactory.validateObject");
		return true;
	}
}

http://dive4elements.wald.intevation.org