001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: GraphMemBase.java,v 1.12 2008/01/02 12:09:51 andy_seaborne Exp $
005: */
006: package com.hp.hpl.jena.mem;
007:
008: import com.hp.hpl.jena.graph.*;
009: import com.hp.hpl.jena.graph.impl.*;
010: import com.hp.hpl.jena.shared.ReificationStyle;
011:
012: /**
013: GraphMemBase - a common base class for GraphMem and SmallGraphMem.
014: Any GraphMemBase maintains a reference count, set to one when it is created,
015: and incremented by the method <code>openAgain()</code>. When the graph
016: is closed, the count is decrememented, and when it reaches 0, the tables are
017: trashed and GraphBase.close() called. Thus in normal use one close is enough,
018: but GraphMakers using GraphMems can arrange to re-use the same named
019: graph.
020:
021: @author kers
022: */
023: public abstract class GraphMemBase extends GraphBase {
024: /**
025: The number-of-times-opened count.
026: */
027: protected int count;
028:
029: /**
030: This Graph's TripleStore. Visible for <i>read-only</i> purposes only.
031: */
032: public final TripleStore store;
033:
034: /**
035: initialise a GraphMemBase withn its count set to 1.
036: */
037: public GraphMemBase(ReificationStyle style) {
038: super (style);
039: store = createTripleStore();
040: count = 1;
041: }
042:
043: protected abstract TripleStore createTripleStore();
044:
045: /**
046: Note a re-opening of this graph by incrementing the count. Answer
047: this Graph.
048: */
049: public GraphMemBase openAgain() {
050: count += 1;
051: return this ;
052: }
053:
054: /**
055: Sub-classes over-ride this method to release any resources they no
056: longer need once fully closed.
057: */
058: protected abstract void destroy();
059:
060: /**
061: Close this graph; if it is now fully closed, destroy its resources and run
062: the GraphBase close.
063: */
064: public void close() {
065: if (--count == 0) {
066: destroy();
067: super .close();
068: }
069: }
070:
071: /**
072: Remove all triples from this graph; used to implement removeAll.
073: */
074: public abstract void clear();
075:
076: public BulkUpdateHandler getBulkUpdateHandler() {
077: if (bulkHandler == null)
078: bulkHandler = new GraphMemBulkUpdateHandler(this );
079: return bulkHandler;
080: }
081:
082: /**
083: Answer true iff this triple can be compared for sameValueAs by .equals(),
084: ie, it is a concrete triple with a non-literal object.
085: */
086: protected final boolean isSafeForEquality(Triple t) {
087: return t.isConcrete() && !t.getObject().isLiteral();
088: }
089: }
090:
091: /*
092: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
093: All rights reserved.
094:
095: Redistribution and use in source and binary forms, with or without
096: modification, are permitted provided that the following conditions
097: are met:
098:
099: 1. Redistributions of source code must retain the above copyright
100: notice, this list of conditions and the following disclaimer.
101:
102: 2. Redistributions in binary form must reproduce the above copyright
103: notice, this list of conditions and the following disclaimer in the
104: documentation and/or other materials provided with the distribution.
105:
106: 3. The name of the author may not be used to endorse or promote products
107: derived from this software without specific prior written permission.
108:
109: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
110: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
111: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
112: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
113: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
114: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
115: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
116: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
117: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
118: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
119: */
|