001: /*
002: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: GraphMem.java,v 1.60 2008/01/02 12:09:51 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.mem;
008:
009: import com.hp.hpl.jena.graph.*;
010: import com.hp.hpl.jena.graph.impl.*;
011: import com.hp.hpl.jena.graph.impl.TripleStore;
012: import com.hp.hpl.jena.graph.query.*;
013: import com.hp.hpl.jena.shared.*;
014: import com.hp.hpl.jena.util.iterator.*;
015:
016: /**
017: A memory-backed graph with S/P/O indexes.
018: @author bwm, kers
019: */
020: public class GraphMem extends GraphMemBase implements Graph {
021: public GraphTripleStore forTestingOnly_getStore() {
022: return (GraphTripleStore) store;
023: }
024:
025: /**
026: Initialises a GraphMem with the Minimal reification style. Use the
027: factory if possible; this method is public to allow certain reflective
028: tests.
029: */
030: public GraphMem() {
031: this (ReificationStyle.Minimal);
032: }
033:
034: /**
035: Initialises a GraphMem with the given reification style. Use the
036: factory if possible; this method is public to allow certain reflective
037: tests.
038: */
039: public GraphMem(ReificationStyle style) {
040: super (style);
041: }
042:
043: protected TripleStore createTripleStore() {
044: return new GraphTripleStore(this );
045: }
046:
047: protected void destroy() {
048: store.close();
049: }
050:
051: public void performAdd(Triple t) {
052: if (!getReifier().handledAdd(t))
053: store.add(t);
054: }
055:
056: public void performDelete(Triple t) {
057: if (!getReifier().handledRemove(t))
058: store.delete(t);
059: }
060:
061: public int graphBaseSize() {
062: return store.size();
063: }
064:
065: public QueryHandler queryHandler() {
066: if (queryHandler == null)
067: queryHandler = new GraphMemBaseQueryHandler(this );
068: return queryHandler;
069: }
070:
071: /**
072: Answer an ExtendedIterator over all the triples in this graph that match the
073: triple-pattern <code>m</code>. Delegated to the store.
074: */
075: public ExtendedIterator graphBaseFind(TripleMatch m) {
076: return store.find(m.asTriple());
077: }
078:
079: /**
080: Answer true iff this graph contains <code>t</code>. If <code>t</code>
081: happens to be concrete, then we hand responsibility over to the store.
082: Otherwise we use the default implementation.
083: */
084: public boolean graphBaseContains(Triple t) {
085: return isSafeForEquality(t) ? store.contains(t) : super
086: .graphBaseContains(t);
087: }
088:
089: /**
090: Clear this GraphMem, ie remove all its triples (delegated to the store).
091: */
092: public void clear() {
093: store.clear();
094: ((SimpleReifier) getReifier()).clear();
095: }
096: }
097:
098: /*
099: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
100: * All rights reserved.
101: *
102: * Redistribution and use in source and binary forms, with or without
103: * modification, are permitted provided that the following conditions
104: * are met:
105: * 1. Redistributions of source code must retain the above copyright
106: * notice, this list of conditions and the following disclaimer.
107: * 2. Redistributions in binary form must reproduce the above copyright
108: * notice, this list of conditions and the following disclaimer in the
109: * documentation and/or other materials provided with the distribution.
110: * 3. The name of the author may not be used to endorse or promote products
111: * derived from this software without specific prior written permission.
112:
113: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
114: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
115: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
116: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
117: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
118: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
119: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
120: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
121: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
122: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
123: */
|