1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.connector.impl;
24
25 import javax.resource.NotSupportedException;
26 import javax.resource.ResourceException;
27 import javax.resource.cci.ConnectionMetaData;
28 import javax.resource.cci.Interaction;
29 import javax.resource.cci.LocalTransaction;
30 import javax.resource.cci.ResultSetInfo;
31 import javax.resource.spi.ConnectionEvent;
32
33 import de.bea.domingo.DNotesMonitor;
34 import de.bea.domingo.DSession;
35 import de.bea.domingo.connector.DomingoConnection;
36 import de.bea.domingo.i18n.ResourceManager;
37 import de.bea.domingo.i18n.Resources;
38
39 /***
40 * @author <a href=mailto:kurt.riede@bea.de>Kurt Riede</a>
41 */
42 public final class DomingoConnectionImpl implements DomingoConnection, ConnectionMetaData {
43
44 /*** Internationalized resources. */
45 private static final Resources RESOURCES = ResourceManager.getPackageResources(DomingoConnectionFactoryImpl.class);
46
47 /*** Reference to the managed connection. */
48 private DomingoManagedConnection managedConnection;
49
50 /*** Whether the connection is already closed. */
51 private boolean closed = false;
52
53 private String eisProductVersion;
54
55 private String username;
56
57 /***
58 * Constructor.
59 *
60 * @param mc the managed connection
61 * @throws ResourceException if the connection cannot be created
62 */
63 public DomingoConnectionImpl(final DomingoManagedConnection mc) throws ResourceException {
64 if (!(mc instanceof DomingoManagedConnection)) {
65 throw new NotSupportedException(RESOURCES.getString("managedconnection.mustbe.instanceof.1",
66 DomingoManagedConnection.class.getName()));
67 }
68 this.managedConnection = mc;
69 }
70
71 /***
72 * Returns the associated monitor.
73 *
74 * @return a monitor
75 */
76 public DNotesMonitor getMonitor() {
77 return managedConnection.getMonitor();
78 }
79
80 /***
81 * {@inheritDoc}
82 *
83 * @see de.bea.domingo.connector.DomingoConnection#close()
84 */
85 public void close() throws ResourceException {
86 checkIfClosed();
87 closed = true;
88 if (!closed && managedConnection != null) {
89 managedConnection.removeConnection(this);
90 final ConnectionEvent closeEvent = new ConnectionEvent(managedConnection, ConnectionEvent.CONNECTION_CLOSED);
91 closeEvent.setConnectionHandle(this);
92 managedConnection.connectionClosed(closeEvent);
93 managedConnection = null;
94 }
95 }
96
97 /***
98 * Checks if the connection is already closed.
99 *
100 * @throws ResourceException if the connection is already closed
101 */
102 private void checkIfClosed() throws ResourceException {
103 if (closed || managedConnection == null) {
104 throw new ResourceException(RESOURCES.getString("connection.already.closed"));
105 }
106 }
107
108 /***
109 * This method always throw an exception since interaction is not supported.
110 *
111 * {@inheritDoc}
112 *
113 * @see de.bea.domingo.connector.DomingoConnection#createInteraction()
114 */
115 public Interaction createInteraction() throws ResourceException {
116 throw new NotSupportedException("interaction.not.supported");
117 }
118
119 /***
120 * This method always throw an exception since transacctions are not supported.
121 *
122 * {@inheritDoc}
123 *
124 * @see de.bea.domingo.connector.DomingoConnection#getLocalTransaction()
125 */
126 public LocalTransaction getLocalTransaction() throws ResourceException {
127 throw new NotSupportedException(RESOURCES.getString("method.not.supported.1", "getLocalTransaction()"));
128 }
129
130 /***
131
132 * {@inheritDoc}
133 *
134 * @see de.bea.domingo.connector.DomingoConnection#getMetaData()
135 */
136 public ConnectionMetaData getMetaData() throws ResourceException {
137 return this;
138 }
139
140 /***
141 * This method always throw an exception since result-set-inifo is not supported.
142 *
143 * {@inheritDoc}
144 *
145 * @see de.bea.domingo.connector.DomingoConnection#getResultSetInfo()
146 */
147 public ResultSetInfo getResultSetInfo() throws ResourceException {
148 throw new NotSupportedException(RESOURCES.getString("method.not.supported.1", "getResultSetInfo()"));
149 }
150
151 /***
152 * {@inheritDoc}
153 *
154 * @see de.bea.domingo.connector.DomingoConnection#reassociate(de.bea.domingo.connector.impl.DomingoManagedConnection)
155 */
156 public void reassociate(DomingoManagedConnection mc) {
157 if (mc == null) {
158 getMonitor().error(RESOURCES.getString("argument.is.null", "connection"));
159 }
160 this.managedConnection.removeConnection(this);
161 this.managedConnection = mc;
162 this.managedConnection.addConnection(this);
163 }
164
165 /***
166 * {@inheritDoc}
167 *
168 * @see javax.resource.cci.ConnectionMetaData#getEISProductName()
169 */
170 public String getEISProductName() throws ResourceException {
171 return DomingoMetaData.EIS_PRODUCT_NAME;
172 }
173
174 /***
175 * {@inheritDoc}
176 *
177 * @see javax.resource.cci.ConnectionMetaData#getEISProductVersion()
178 */
179 public String getEISProductVersion() throws ResourceException {
180 if (eisProductVersion == null) {
181 eisProductVersion = getSession().getNotesVersion();
182 }
183 return eisProductVersion;
184 }
185
186 /***
187 * {@inheritDoc}
188 *
189 * @see javax.resource.cci.ConnectionMetaData#getUserName()
190 */
191 public String getUserName() throws ResourceException {
192 if (username == null) {
193 username = getSession().getUserName();
194 }
195 return username;
196 }
197
198 /***
199 * {@inheritDoc}
200 *
201 * @see de.bea.domingo.connector.DomingoConnection#getSession()
202 */
203 public DSession getSession() throws ResourceException {
204 if (managedConnection == null) {
205 throw new IllegalStateException(RESOURCES.getString("session.closed"));
206 }
207 return managedConnection.getSession();
208 }
209 }