001: package org.ontoware.rdf2go.model;
002:
003: import java.util.Iterator;
004:
005: import org.ontoware.aifbcommons.collection.ClosableIterable;
006: import org.ontoware.rdf2go.exception.ModelRuntimeException;
007: import org.ontoware.rdf2go.model.node.Node;
008: import org.ontoware.rdf2go.model.node.NodeOrVariable;
009: import org.ontoware.rdf2go.model.node.Resource;
010: import org.ontoware.rdf2go.model.node.ResourceOrVariable;
011: import org.ontoware.rdf2go.model.node.URI;
012: import org.ontoware.rdf2go.model.node.UriOrVariable;
013:
014: /**
015: * Allows to add and removes statements from a ModelSet. Statements without a
016: * context are added/removed from the default model.
017: *
018: * For plain triples models, this is modeled as a number of interfaces:
019: * ClosableIterable<Statement>, ModelWriter, Lockable
020: *
021: * @author voelkel
022: *
023: */
024: public interface ModelSetAddRemove extends ClosableIterable<Statement>,
025: Lockable {
026:
027: /**
028: * This method creates a Model named 'contextURI' if needed. Then the
029: * statement (s,p,o) is inserted into that model.
030: *
031: * @param contextURI
032: * a URI
033: * @param subject
034: * a Resource (URI or BlankNode)
035: * @param predicate
036: * @param object
037: * a Node
038: * @throws ModelRuntimeException
039: * if any internal (I/O related) exception occurs
040: */
041: void addStatement(URI contextURI, Resource subject, URI predicate,
042: Node object) throws ModelRuntimeException;
043:
044: /**
045: * This method creates a Model named statement.getContextURI if needed. Then
046: * the statement (s,p,o) is inserted into that model.
047: *
048: * @param statement
049: * @throws ModelRuntimeException
050: * if any internal (I/O related) exception occurs
051: */
052: void addStatement(Statement statement) throws ModelRuntimeException;
053:
054: /**
055: * For each statement in the iterator, this method creates a Model named
056: * statement.getContextURI if needed. Then the statement (s,p,o) is inserted
057: * into that model.
058: *
059: * @param statement
060: * @throws ModelRuntimeException
061: * if any internal (I/O related) exception occurs
062: */
063: void addAll(Iterator<? extends Statement> statement)
064: throws ModelRuntimeException;
065:
066: /**
067: * Removes the statement (s,p,o) from a model named contextURI. If the model
068: * named 'contextURI' becomes empty, it remains in the ModelSet.
069: *
070: * @param context
071: * a URI
072: * @param subject
073: * a Resource (URI or BlankNode)
074: * @param predicate
075: * @param object
076: * a Node
077: * @throws ModelRuntimeException
078: * if any internal (I/O related) exception occurs
079: */
080: void removeStatement(URI contextURI, Resource subject,
081: URI predicate, Node object) throws ModelRuntimeException;
082:
083: /**
084: * Removes the statement (s,p,o) from a model named statement.getContext().
085: * If the model named statement.getContext() becomes empty, it remains in
086: * the ModelSet.
087: *
088: * @param statement
089: * a Statement
090: * @throws ModelRuntimeException
091: * if any internal (I/O related) exception occurs
092: */
093: void removeStatement(Statement statement)
094: throws ModelRuntimeException;
095:
096: /**
097: * For each statement in the iterator, the statement is removed form the
098: * model named statement.getContext(); If the model named
099: * statement.getContext() becomes empty, it remains in the ModelSet.
100: *
101: * @param statement
102: * @throws ModelRuntimeException
103: * if any internal (I/O related) exception occurs
104: */
105: void removeAll(Iterator<? extends Statement> statement)
106: throws ModelRuntimeException;
107:
108: /**
109: * Find all models matching the context of the pattern and remove all
110: * matching triple patterms from them
111: *
112: * @param quadPattern
113: * @throws ModelRuntimeException
114: */
115: void removeStatements(QuadPattern quadPattern)
116: throws ModelRuntimeException;
117:
118: /**
119: * Find all models matching the context, and remove all (subject, property
120: * ,object)-statements from these model
121: *
122: * @throws ModelRuntimeException
123: */
124: void removeStatements(UriOrVariable context,
125: ResourceOrVariable subject, UriOrVariable predicate,
126: NodeOrVariable object) throws ModelRuntimeException;
127:
128: /**
129: * Apply the changes given by this diff <emph>in one atomic operation</emph>
130: *
131: * Implementations must check that all statements to be removed are still in
132: * the Model. Otherwise an exception is thrown.
133: *
134: * First all triples to be removed are removed, then triples to be added are
135: * added.
136: *
137: * In this modelset, this means (s,p,o) is removed from the graph named c,
138: * for all statements (c,s,p,o). Note: Models becoming empty are not
139: * removed.
140: *
141: * @param diff
142: * @throws ModelRuntimeException
143: * if a model or statement in a model to be removed does not
144: * exist.
145: */
146: void update(DiffReader diff) throws ModelRuntimeException;
147:
148: // /**
149: // * Adds all statements contained in 'model' to this ModelSet. Set the
150: // * context to all these statements to 'contextURI'.
151: // *
152: // * If the model belongs to the same implementation family as the ModelSet,
153: // * this add might be very fast.
154: // *
155: // * @param context
156: // * @param model
157: // */
158: // void addModel(URI contextURI, Model model);
159:
160: }
|