001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 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: package org.geotools.data.store;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020: import org.opengis.feature.type.TypeName;
021: import org.geotools.data.Transaction;
022:
023: /**
024: * An entry for a type provided by a datastore.
025: * <p>
026: * A content entry maintains the "state" of an entry for a particular
027: * transaction.
028: * </p>
029: *
030: * @author Jody Garnett, Refractions Research Inc.
031: * @author Justin Deoliveira, The Open Planning Project
032: */
033: public final class ContentEntry {
034: /**
035: * Qualified name of the entry.
036: */
037: TypeName typeName;
038:
039: /**
040: * Map<Transaction,ContentState> state according to Transaction.
041: */
042: Map state;
043:
044: /**
045: * Backpointer to datastore
046: */
047: ContentDataStore dataStore;
048:
049: public ContentEntry(ContentDataStore dataStore, TypeName typeName) {
050: this .typeName = typeName;
051: this .dataStore = dataStore;
052:
053: this .state = new HashMap();
054:
055: //create a state for the auto commit transaction
056: ContentState autoState = dataStore.createContentState(null);
057: this .state.put(Transaction.AUTO_COMMIT, autoState);
058: }
059:
060: /**
061: * Qualified name of the entry.
062: */
063: public TypeName getName() {
064: return typeName;
065: }
066:
067: /**
068: * Unqualified name of the entry.
069: * <p>
070: * Equivalent to: <code>getName().getLocalPart()</code>.
071: * </p>
072: */
073: public String getTypeName() {
074: return typeName.getLocalPart();
075: }
076:
077: /**
078: * Backpointer to datastore.
079: */
080: public ContentDataStore getDataStore() {
081: return dataStore;
082: }
083:
084: /**
085: * Returns state for the entry for a particular transaction.
086: * <p>
087: * In the event that no state exists for the supplied transaction one will
088: * be created by copying the state of {@link Transaction#AUTO_COMMIT}.
089: * </p>
090: * @param transaction A transaction.
091: *
092: * @return The state for the transaction.
093: */
094: public ContentState getState(Transaction transaction) {
095: if (state.containsKey(transaction)) {
096: return (ContentState) state.get(transaction);
097: } else {
098: ContentState auto = (ContentState) state
099: .get(Transaction.AUTO_COMMIT);
100: ContentState copy = (ContentState) auto.copy();
101: state.put(transaction, copy);
102:
103: return copy;
104: }
105: }
106:
107: public String toString() {
108: return getTypeName();
109: }
110: }
|