KickJava   Java API By Example, From Geeks To Geeks.

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


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

6
7 package com.hp.hpl.jena.mem;
8
9 import com.hp.hpl.jena.graph.Node;
10 import com.hp.hpl.jena.graph.query.SimpleQueryHandler;
11 import com.hp.hpl.jena.util.iterator.*;
12
13 /**
14    A GraphMemQueryHandler is an extension of the SimpleQueryHandler which
15    implements some of the query code more efficiently by exploiting the
16    GraphMem's indexes.
17    
18     @author hedgehog
19 */

20 public class GraphMemQueryHandler extends SimpleQueryHandler
21     {
22     GraphMemQueryHandler( GraphMem graph )
23         {
24         super( graph );
25         }
26     
27     public ExtendedIterator objectsFor( Node p, Node o )
28         { return bothANY( p, o ) ? findObjects() : super.objectsFor( p, o ); }
29
30     public ExtendedIterator predicatesFor( Node s, Node o )
31         { return bothANY( s, o ) ? findPredicates() : super.predicatesFor( s, o ); }
32     
33     public ExtendedIterator subjectsFor( Node p, Node o )
34         { return bothANY( p, o ) ? findSubjects() : super.subjectsFor( p, o ); }
35
36     /**
37          Answer true iff both <code>a</code> and <code>b</code> are ANY wildcards
38          or are null (legacy).
39     */

40     private boolean bothANY( Node a, Node b )
41         { return (a == null || a.equals( Node.ANY )) && (b == null || b.equals( Node.ANY )); }
42
43     public ExtendedIterator findPredicates()
44         { return ((GraphMem) graph).store.listPredicates(); }
45
46     public ExtendedIterator findObjects()
47         { return ((GraphMem) graph).store.listObjects(); }
48     
49     public ExtendedIterator findSubjects()
50         { return ((GraphMem) graph).store.listSubjects(); }
51     }
52
53 /*
54     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
55     All rights reserved.
56     
57     Redistribution and use in source and binary forms, with or without
58     modification, are permitted provided that the following conditions
59     are met:
60     
61     1. Redistributions of source code must retain the above copyright
62        notice, this list of conditions and the following disclaimer.
63     
64     2. Redistributions in binary form must reproduce the above copyright
65        notice, this list of conditions and the following disclaimer in the
66        documentation and/or other materials provided with the distribution.
67     
68     3. The name of the author may not be used to endorse or promote products
69        derived from this software without specific prior written permission.
70     
71     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
72     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
73     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
74     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
75     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
76     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
77     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
78     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
79     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
80     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
81 */
Popular Tags