KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > mem > GraphMem


1 /*
2   (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: GraphMem.java,v 1.49 2005/02/21 12:03:43 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.mem;
8
9 import com.hp.hpl.jena.graph.*;
10 import com.hp.hpl.jena.graph.impl.TripleStore;
11 import com.hp.hpl.jena.graph.query.*;
12 import com.hp.hpl.jena.shared.*;
13 import com.hp.hpl.jena.util.iterator.*;
14
15 /**
16     A memory-backed graph with S/P/O indexes.
17     @author bwm, kers
18 */

19 public class GraphMem extends GraphMemBase implements Graph
20     {
21     protected TripleStore store = new GraphTripleStore( this );
22     
23     /**
24         Initialises a GraphMem with the Minimal reification style
25     */

26     public GraphMem()
27         { this( ReificationStyle.Minimal ); }
28     
29     /**
30         Initialises a GraphMem with the given reification style.
31     */

32     public GraphMem( ReificationStyle style )
33         { super( style ); }
34
35     protected void destroy()
36         { store.close(); }
37
38     public void performAdd( Triple t )
39         { if (!getReifier().handledAdd( t )) store.add( t ); }
40
41     public void performDelete( Triple t )
42         { if (!getReifier().handledRemove( t )) store.delete( t ); }
43
44     public int graphBaseSize()
45         { return store.size(); }
46     
47     public QueryHandler queryHandler()
48         {
49         if (queryHandler == null) queryHandler = new GraphMemQueryHandler( this );
50         return queryHandler;
51         }
52         
53     public BulkUpdateHandler getBulkUpdateHandler()
54         {
55         if (bulkHandler == null) bulkHandler = new GraphMemBulkUpdateHandler( this );
56         return bulkHandler;
57         }
58
59     /**
60          Answer an ExtendedIterator over all the triples in this graph that match the
61          triple-pattern <code>m</code>. Delegated to the store.
62      */

63     public ExtendedIterator graphBaseFind( TripleMatch m )
64         { return store.find( m.asTriple() ); }
65
66     /**
67          Answer true iff this graph contains <code>t</code>. If <code>t</code>
68          happens to be concrete, then we hand responsibility over to the store.
69          Otherwise we use the default implementation.
70     */

71     public boolean graphBaseContains( Triple t )
72         { return t.isConcrete() ? store.contains( t ) : super.graphBaseContains( t ); }
73     
74     /**
75         Clear this GraphMem, ie remove all its triples (delegated to the store).
76     */

77     public void clear()
78         { store.clear(); }
79     }
80
81 /*
82      * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
83      * All rights reserved.
84      *
85      * Redistribution and use in source and binary forms, with or without
86      * modification, are permitted provided that the following conditions
87      * are met:
88      * 1. Redistributions of source code must retain the above copyright
89      * notice, this list of conditions and the following disclaimer.
90      * 2. Redistributions in binary form must reproduce the above copyright
91      * notice, this list of conditions and the following disclaimer in the
92      * documentation and/or other materials provided with the distribution.
93      * 3. The name of the author may not be used to endorse or promote products
94      * derived from this software without specific prior written permission.
95     
96      * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
97      * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
98      * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
99      * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
100      * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
101      * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
102      * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
103      * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
104      * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
105      * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
106  */
Popular Tags