001: /*
002: * (c) Copyright 2003 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: *
005: */
006:
007: package com.hp.hpl.jena.db.impl;
008:
009: import java.util.List;
010:
011: import com.hp.hpl.jena.graph.*;
012: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
013:
014: /**
015: * @author hkuno
016: * @version $Version$
017: *
018: * TripleStoreGraph is an abstract superclass for TripleStoreGraph
019: * implementations. By "triple store," we mean that the subjects, predicate
020: * and object URI's are stored in a single collection (denormalized).
021: *
022: */
023: public abstract class SpecializedGraph_TripleStore extends
024: SpecializedGraphBase {
025:
026: /**
027: * holds PSet
028: */
029: public IPSet m_pset;
030:
031: /**
032: * caches a copy of LSet properties
033: */
034: public DBPropLSet m_dbPropLSet;
035:
036: /**
037: * holds ID of graph in database (defaults to "0")
038: */
039: public IDBID my_GID = null;
040:
041: // constructors
042:
043: /**
044: * Constructor
045: * Create a new instance of a TripleStore graph.
046: */
047: SpecializedGraph_TripleStore(DBPropLSet lProp, IPSet pSet,
048: Integer dbGraphID) {
049: m_pset = pSet;
050: m_dbPropLSet = lProp;
051: my_GID = new DBIDInt(dbGraphID);
052: }
053:
054: /**
055: * Constructor
056: *
057: * Create a new instance of a TripleStore graph, taking
058: * DBPropLSet and a PSet as arguments
059: */
060: public SpecializedGraph_TripleStore(IPSet pSet, Integer dbGraphID) {
061: m_pset = pSet;
062: my_GID = new DBIDInt(dbGraphID);
063: }
064:
065: /**
066: * Attempt to add all the triples from a graph to the specialized graph
067: *
068: * Caution - this call changes the graph passed in, deleting from
069: * it each triple that is successfully added.
070: *
071: * Node that when calling add, if complete is true, then the entire
072: * graph was added successfully and the graph g will be empty upon
073: * return. If complete is false, then some triples in the graph could
074: * not be added. Those triples remain in g after the call returns.
075: *
076: * If the triple can't be stored for any reason other than incompatability
077: * (for example, a lack of disk space) then the implemenation should throw
078: * a runtime exception.
079: *
080: * @param g is a graph containing triples to be added
081: * @param complete is true if a subsequent call to contains(triple) will return true for any triple in g.
082: */
083: public void add(Graph g, CompletionFlag complete) {
084: ExtendedIterator it = GraphUtil.findAll(g);
085: while (it.hasNext())
086: add((Triple) it.next(), complete);
087: complete.setDone();
088: }
089:
090: /* (non-Javadoc)
091: * @see com.hp.hpl.jena.db.impl.SpecializedGraph#add(com.hp.hpl.jena.graph.Triple, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
092: */
093: public void add(Triple t, CompletionFlag complete) {
094: m_pset.storeTriple(t, my_GID);
095: complete.setDone();
096: }
097:
098: /* (non-Javadoc)
099: * @see com.hp.hpl.jena.db.impl.SpecializedGraph#add(java.util.List, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
100: */
101: public void add(List triples, CompletionFlag complete) {
102: m_pset.storeTripleList(triples, my_GID);
103: complete.setDone();
104: }
105:
106: /* (non-Javadoc)
107: * @see com.hp.hpl.jena.db.impl.SpecializedGraph#delete(com.hp.hpl.jena.graph.Triple, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
108: */
109: public void delete(Triple t, CompletionFlag complete) {
110: m_pset.deleteTriple(t, my_GID);
111: complete.setDone();
112: }
113:
114: /* (non-Javadoc)
115: * @see com.hp.hpl.jena.db.impl.SpecializedGraph#delete(java.util.List, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
116: */
117: public void delete(List triples, CompletionFlag complete) {
118: m_pset.deleteTripleList(triples, my_GID);
119: complete.setDone();
120: }
121:
122: /* (non-Javadoc)
123: * @see com.hp.hpl.jena.db.impl.SpecializedGraph#tripleCount()
124: */
125: public int tripleCount() {
126: return (m_pset.tripleCount(my_GID));
127: }
128:
129: /* (non-Javadoc)
130: * @see com.hp.hpl.jena.db.impl.SpecializedGraph#contains(com.hp.hpl.jena.graph.Triple, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
131: */
132: public boolean contains(Triple t, CompletionFlag complete) {
133: complete.setDone();
134: return (m_pset.statementTableContains(my_GID, t));
135: }
136:
137: /* (non-Javadoc)
138: * @see com.hp.hpl.jena.db.impl.SpecializedGraph#find(com.hp.hpl.jena.graph.TripleMatch, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
139: */
140: public ExtendedIterator find(TripleMatch t, CompletionFlag complete) {
141: complete.setDone();
142: return (ExtendedIterator) m_pset.find(t, my_GID);
143: }
144:
145: /*
146: * @see com.hp.hpl.jena.db.impl.SpecializedGraph#close()
147: */
148: public void close() {
149: m_pset.close();
150: }
151:
152: /*
153: * @see com.hp.hpl.jena.db.impl.SpecializedGraph#clear()
154: */
155: public void clear() {
156: m_pset.removeStatementsFromDB(my_GID);
157: }
158:
159: /* (non-Javadoc)
160: * @see com.hp.hpl.jena.db.impl.SpecializedGraphReifier#graphIdGet()
161: */
162: public int getGraphId() {
163: return ((DBIDInt) my_GID).getIntID();
164: }
165:
166: /* (non-Javadoc)
167: * @see com.hp.hpl.jena.db.impl.SpecializedGraphReifier#PSetGet()
168: */
169: public IPSet getPSet() {
170: return m_pset;
171: }
172:
173: /* (non-Javadoc)
174: * @see com.hp.hpl.jena.db.impl.SpecializedGraphReifier#DBPropLSetGet()
175: */
176: public DBPropLSet getDBPropLSet() {
177: return m_dbPropLSet;
178: }
179:
180: }
181:
182: /*
183: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
184: * All rights reserved.
185: *
186: * Redistribution and use in source and binary forms, with or without
187: * modification, are permitted provided that the following conditions
188: * are met:
189: * 1. Redistributions of source code must retain the above copyright
190: * notice, this list of conditions and the following disclaimer.
191: * 2. Redistributions in binary form must reproduce the above copyright
192: * notice, this list of conditions and the following disclaimer in the
193: * documentation and/or other materials provided with the distribution.
194: * 3. The name of the author may not be used to endorse or promote products
195: * derived from this software without specific prior written permission.
196:
197: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
199: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
200: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
201: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
202: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
203: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
204: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
205: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
206: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
207: */
|