KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > db > impl > SpecializedGraph_TripleStore


1 /*
2  * (c) Copyright 2003 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  */

6
7 package com.hp.hpl.jena.db.impl;
8
9 import java.util.List JavaDoc;
10
11 import com.hp.hpl.jena.graph.*;
12 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
13
14 /**
15  * @author hkuno
16  * @version $Version$
17  *
18  * TripleStoreGraph is an abstract superclass for TripleStoreGraph
19  * implementations. By "triple store," we mean that the subjects, predicate
20  * and object URI's are stored in a single collection (denormalized).
21  *
22  */

23 public abstract class SpecializedGraph_TripleStore extends SpecializedGraphBase {
24
25     /**
26      * holds PSet
27      */

28     public IPSet m_pset;
29     
30     /**
31      * caches a copy of LSet properties
32      */

33     public DBPropLSet m_dbPropLSet;
34     
35     /**
36      * holds ID of graph in database (defaults to "0")
37      */

38     public IDBID my_GID = null;
39     
40     // constructors
41

42     /**
43      * Constructor
44      * Create a new instance of a TripleStore graph.
45      */

46     SpecializedGraph_TripleStore(DBPropLSet lProp, IPSet pSet, Integer JavaDoc dbGraphID) {
47         m_pset = pSet;
48         m_dbPropLSet = lProp;
49         my_GID = new DBIDInt(dbGraphID);
50     }
51     
52     /**
53      * Constructor
54      *
55      * Create a new instance of a TripleStore graph, taking
56      * DBPropLSet and a PSet as arguments
57      */

58     public SpecializedGraph_TripleStore(IPSet pSet, Integer JavaDoc dbGraphID) {
59         m_pset = pSet;
60         my_GID = new DBIDInt(dbGraphID);
61     }
62     
63     /**
64      * Attempt to add all the triples from a graph to the specialized graph
65      *
66      * Caution - this call changes the graph passed in, deleting from
67      * it each triple that is successfully added.
68      *
69      * Node that when calling add, if complete is true, then the entire
70      * graph was added successfully and the graph g will be empty upon
71      * return. If complete is false, then some triples in the graph could
72      * not be added. Those triples remain in g after the call returns.
73      *
74      * If the triple can't be stored for any reason other than incompatability
75      * (for example, a lack of disk space) then the implemenation should throw
76      * a runtime exception.
77      *
78      * @param g is a graph containing triples to be added
79      * @param complete is true if a subsequent call to contains(triple) will return true for any triple in g.
80      */

81     public void add(Graph g, CompletionFlag complete) {
82         ExtendedIterator it = GraphUtil.findAll( g );
83         while (it.hasNext()) add( (Triple)it.next(), complete );
84         complete.setDone();
85     }
86     
87     
88     /* (non-Javadoc)
89      * @see com.hp.hpl.jena.db.impl.SpecializedGraph#add(com.hp.hpl.jena.graph.Triple, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
90      */

91     public void add(Triple t, CompletionFlag complete) {
92         m_pset.storeTriple(t, my_GID);
93         complete.setDone();
94     }
95
96
97     /* (non-Javadoc)
98      * @see com.hp.hpl.jena.db.impl.SpecializedGraph#add(java.util.List, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
99      */

100     public void add(List JavaDoc triples, CompletionFlag complete) {
101         m_pset.storeTripleList(triples,my_GID);
102         complete.setDone();
103     }
104
105     /* (non-Javadoc)
106      * @see com.hp.hpl.jena.db.impl.SpecializedGraph#delete(com.hp.hpl.jena.graph.Triple, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
107      */

108     public void delete(Triple t, CompletionFlag complete) {
109         m_pset.deleteTriple(t, my_GID);
110         complete.setDone();
111     }
112
113     /* (non-Javadoc)
114      * @see com.hp.hpl.jena.db.impl.SpecializedGraph#delete(java.util.List, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
115      */

116     public void delete(List JavaDoc triples, CompletionFlag complete) {
117         m_pset.deleteTripleList(triples,my_GID);
118         complete.setDone();
119     }
120     
121     /* (non-Javadoc)
122      * @see com.hp.hpl.jena.db.impl.SpecializedGraph#tripleCount()
123      */

124     public int tripleCount() {
125         return(m_pset.tripleCount());
126     }
127     
128     /* (non-Javadoc)
129     * @see com.hp.hpl.jena.db.impl.SpecializedGraph#contains(com.hp.hpl.jena.graph.Triple, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
130     */

131     public boolean contains(Triple t, CompletionFlag complete) {
132         complete.setDone();
133         return (m_pset.statementTableContains(my_GID, t));
134     }
135     
136     /* (non-Javadoc)
137      * @see com.hp.hpl.jena.db.impl.SpecializedGraph#find(com.hp.hpl.jena.graph.TripleMatch, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
138      */

139     public ExtendedIterator find(TripleMatch t, CompletionFlag complete) {
140         complete.setDone();
141         return (ExtendedIterator)m_pset.find(t, my_GID);
142         }
143
144     /*
145      * @see com.hp.hpl.jena.db.impl.SpecializedGraph#close()
146      */

147     public void close() {
148         m_pset.close();
149     }
150
151     /*
152      * @see com.hp.hpl.jena.db.impl.SpecializedGraph#clear()
153      */

154     public void clear() {
155         m_pset.removeStatementsFromDB(my_GID);
156     }
157
158     /* (non-Javadoc)
159      * @see com.hp.hpl.jena.db.impl.SpecializedGraphReifier#graphIdGet()
160      */

161     public int getGraphId() {
162         return ((DBIDInt)my_GID).getIntID();
163     }
164     
165     /* (non-Javadoc)
166      * @see com.hp.hpl.jena.db.impl.SpecializedGraphReifier#PSetGet()
167      */

168     public IPSet getPSet() {
169         return m_pset;
170     }
171         
172     /* (non-Javadoc)
173      * @see com.hp.hpl.jena.db.impl.SpecializedGraphReifier#DBPropLSetGet()
174      */

175     public DBPropLSet getDBPropLSet() {
176         return m_dbPropLSet;
177     }
178
179 }
180
181 /*
182  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
183  * All rights reserved.
184  *
185  * Redistribution and use in source and binary forms, with or without
186  * modification, are permitted provided that the following conditions
187  * are met:
188  * 1. Redistributions of source code must retain the above copyright
189  * notice, this list of conditions and the following disclaimer.
190  * 2. Redistributions in binary form must reproduce the above copyright
191  * notice, this list of conditions and the following disclaimer in the
192  * documentation and/or other materials provided with the distribution.
193  * 3. The name of the author may not be used to endorse or promote products
194  * derived from this software without specific prior written permission.
195
196  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
197  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
198  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
199  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
200  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
202  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
203  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
204  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
205  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
206  */

207
Popular Tags