001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.arcsde.data;
018:
019: import java.io.IOException;
020: import java.util.logging.Level;
021: import java.util.logging.Logger;
022:
023: import org.geotools.arcsde.pool.ArcSDEPooledConnection;
024: import org.geotools.data.Transaction;
025:
026: import com.esri.sde.sdk.client.SeConnection;
027: import com.esri.sde.sdk.client.SeException;
028:
029: /**
030: * Externalizes transactional state for <code>ArcSDEFeatureWriter</code>
031: * instances.
032: *
033: * @author Jake Fear
034: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/main/java/org/geotools/arcsde/data/ArcTransactionState.java $
035: * @version $Id: ArcTransactionState.java 27863 2007-11-12 20:34:34Z desruisseaux $
036: */
037: class ArcTransactionState implements Transaction.State {
038: private static final Logger LOGGER = org.geotools.util.logging.Logging
039: .getLogger(ArcTransactionState.class.getPackage().getName());
040:
041: private ArcSDEPooledConnection connection;
042:
043: private ArcSDEDataStore dataStore;
044:
045: /**
046: * Creates a new ArcTransactionState object.
047: *
048: * @param store
049: * DOCUMENT ME!
050: */
051: public ArcTransactionState(ArcSDEDataStore store) {
052: this .dataStore = store;
053: }
054:
055: /**
056: *
057: */
058: public void commit() throws IOException {
059: try {
060: if (connection != null) {
061: connection.commitTransaction();
062: }
063: } catch (SeException se) {
064: LOGGER.log(Level.WARNING, se.getMessage(), se);
065: throw new IOException(se.getMessage());
066: }
067: }
068:
069: /**
070: *
071: */
072: public void rollback() throws IOException {
073: try {
074: if (connection != null) {
075: connection.rollbackTransaction();
076: }
077: } catch (SeException se) {
078: LOGGER.log(Level.WARNING, se.getMessage(), se);
079: throw new IOException(se.getMessage());
080: }
081: }
082:
083: /**
084: *
085: */
086: public void addAuthorization(String authId) {
087: // intentionally blank
088: }
089:
090: /**
091: *
092: */
093: public void setTransaction(Transaction transaction) {
094: if ((transaction == null) && (this .connection != null)) {
095: this .connection.close();
096: } else if (transaction != null) {
097: try {
098: connection = dataStore.getConnectionPool()
099: .getConnection();
100: connection.setTransactionAutoCommit(0);
101: connection.startTransaction();
102: } catch (Exception e) {
103: LOGGER.log(Level.WARNING, e.getMessage(), e);
104: throw new RuntimeException(e.getMessage());
105: }
106: } else {
107: throw new RuntimeException("Unexpected state.");
108: }
109: }
110:
111: /**
112: * Used only within the package to provide access to a single connection on
113: * which this transaction is being conducted.
114: *
115: * @return DOCUMENT ME!
116: */
117: ArcSDEPooledConnection getConnection() {
118: return connection;
119: }
120: }
|