001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.sail.memory.model;
007:
008: import org.openrdf.model.impl.ContextStatementImpl;
009:
010: /**
011: * A MemStatement is a Statement which contains context information and a flag
012: * indicating whether the statement is explicit or inferred.
013: */
014: public class MemStatement extends ContextStatementImpl {
015:
016: /*-----------*
017: * Constants *
018: *-----------*/
019:
020: private static final long serialVersionUID = -3073275483628334134L;
021:
022: /*-----------*
023: * Variables *
024: *-----------*/
025:
026: /**
027: * Flag indicating whether or not this statement has been added explicitly or
028: * that it has been inferred.
029: */
030: private boolean explicit;
031:
032: /**
033: * Identifies the snapshot in which this statement was introduced.
034: */
035: private int sinceSnapshot;
036:
037: /**
038: * Identifies the snapshot in which this statement was revoked, defaults to
039: * {@link Integer#MAX_VALUE}.
040: */
041: private int tillSnapshot = Integer.MAX_VALUE;
042:
043: /**
044: * Flag indicating the status of of this statement during a transaction.
045: */
046: private TxnStatus txnStatus;
047:
048: /*--------------*
049: * Constructors *
050: *--------------*/
051:
052: /**
053: * Creates a new MemStatement with the supplied subject, predicate, object
054: * and context and marks it as 'explicit'.
055: */
056: public MemStatement(MemResource subject, MemURI predicate,
057: MemValue object, MemResource context, int sinceSnapshot) {
058: this (subject, predicate, object, context, true, sinceSnapshot);
059: }
060:
061: /**
062: * Creates a new MemStatement with the supplied subject, predicate, object
063: * and context and marks it as 'explicit'.
064: */
065: public MemStatement(MemResource subject, MemURI predicate,
066: MemValue object, MemResource context, boolean explicit,
067: int sinceSnapshot) {
068: this (subject, predicate, object, context, explicit,
069: sinceSnapshot, TxnStatus.NEUTRAL);
070: }
071:
072: /**
073: * Creates a new MemStatement with the supplied subject, predicate, object
074: * and context. The value of the <tt>explicit</tt> parameter determines if
075: * this statement is marked as 'explicit' or not.
076: */
077: public MemStatement(MemResource subject, MemURI predicate,
078: MemValue object, MemResource context, boolean explicit,
079: int sinceSnapshot, TxnStatus txnStatus) {
080: super (subject, predicate, object, context);
081: setExplicit(explicit);
082: setSinceSnapshot(sinceSnapshot);
083: setTxnStatus(txnStatus);
084: }
085:
086: /*---------*
087: * Methods *
088: *---------*/
089:
090: @Override
091: public MemResource getSubject() {
092: return (MemResource) super .getSubject();
093: }
094:
095: @Override
096: public MemURI getPredicate() {
097: return (MemURI) super .getPredicate();
098: }
099:
100: @Override
101: public MemValue getObject() {
102: return (MemValue) super .getObject();
103: }
104:
105: @Override
106: public MemResource getContext() {
107: return (MemResource) super .getContext();
108: }
109:
110: public void setSinceSnapshot(int snapshot) {
111: sinceSnapshot = snapshot;
112: }
113:
114: public int getSinceSnapshot() {
115: return sinceSnapshot;
116: }
117:
118: public void setTillSnapshot(int snapshot) {
119: tillSnapshot = snapshot;
120: }
121:
122: public int getTillSnapshot() {
123: return tillSnapshot;
124: }
125:
126: public boolean isInSnapshot(int snapshot) {
127: return snapshot >= sinceSnapshot && snapshot < tillSnapshot;
128: }
129:
130: public void setExplicit(boolean explicit) {
131: this .explicit = explicit;
132: }
133:
134: public boolean isExplicit() {
135: return explicit;
136: }
137:
138: public void setTxnStatus(TxnStatus txnStatus) {
139: this .txnStatus = txnStatus;
140: }
141:
142: public TxnStatus getTxnStatus() {
143: return txnStatus;
144: }
145:
146: /**
147: * Lets this statement add itself to the appropriate statement lists of its
148: * subject, predicate, object and context. The transaction status will be set
149: * to {@link TxnStatus#NEW}.
150: */
151: public void addToComponentLists() {
152: getSubject().addSubjectStatement(this );
153: getPredicate().addPredicateStatement(this );
154: getObject().addObjectStatement(this );
155: MemResource context = getContext();
156: if (context != null) {
157: context.addContextStatement(this );
158: }
159: }
160:
161: /**
162: * Lets this statement remove itself from the appropriate statement lists of
163: * its subject, predicate, object and context. The transaction status will be
164: * set to <tt>null</tt>.
165: */
166: public void removeFromComponentLists() {
167: getSubject().removeSubjectStatement(this );
168: getPredicate().removePredicateStatement(this );
169: getObject().removeObjectStatement(this );
170: MemResource context = getContext();
171: if (context != null) {
172: context.removeContextStatement(this);
173: }
174: }
175: }
|