01: /*
02: * Geotools2 - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package org.geotools.arcsde.pool;
18:
19: import java.util.logging.Level;
20: import java.util.logging.Logger;
21:
22: import org.apache.commons.pool.ObjectPool;
23:
24: import com.esri.sde.sdk.client.SeConnection;
25: import com.esri.sde.sdk.client.SeException;
26:
27: /**
28: * An SeConnection that returns itself to the connection pool instead of
29: * closing on each call to close().
30: *
31: * @author Gabriel Roldan, Axios Engineering
32: * @version $Id: ArcSDEPooledConnection.java 27863 2007-11-12 20:34:34Z desruisseaux $
33: * @since 2.3.x
34: *
35: */
36: public class ArcSDEPooledConnection extends SeConnection {
37:
38: private static final Logger LOGGER = org.geotools.util.logging.Logging
39: .getLogger(ArcSDEPooledConnection.class.getPackage()
40: .getName());
41:
42: private ObjectPool pool;
43:
44: private ArcSDEConnectionConfig config;
45:
46: public ArcSDEPooledConnection(ObjectPool pool,
47: ArcSDEConnectionConfig config) throws SeException {
48: super (config.getServerName(),
49: config.getPortNumber().intValue(), config
50: .getDatabaseName(), config.getUserName(),
51: config.getUserPassword());
52: this .config = config;
53: this .pool = pool;
54: this .setConcurrency(SeConnection.SE_UNPROTECTED_POLICY);
55: }
56:
57: /**
58: * Doesn't close the connection, but returns itself to the
59: * connection pool.
60: * @see #destroy()
61: */
62: public void close() {
63: try {
64: this .pool.returnObject(this );
65: } catch (Exception e) {
66: LOGGER.log(Level.SEVERE, e.getMessage(), e);
67: }
68: }
69:
70: /**
71: * Actually closes the connection
72: */
73: void destroy() {
74: try {
75: super .close();
76: } catch (SeException e) {
77: LOGGER.info("closing connection: " + e.getMessage());
78: }
79: }
80:
81: /**
82: * Compares for reference equality
83: */
84: public boolean equals(Object other) {
85: return other == this ;
86: }
87:
88: public int hashCode() {
89: return 17 ^ this.config.hashCode();
90: }
91: }
|