You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2017/10/03 19:33:56 UTC
[10/65] [abbrv] jena git commit: JENA-1397: Rename java packages
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdType.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdType.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdType.java
deleted file mode 100644
index b1a4557..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdType.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store;
-
-import static org.seaborne.tdb2.store.NodeIdType.TYPES.*;
-
-/** Constants for NodeIds.
- * Note that "PTR" is special - it uses the high bit only set to zero.
- * Note that "XSD_DOUBLE" is special - it sets the high bit (value/ptr)
- * and the next bit only, leaving 62 bits of value.
- * Otherwise a type is encoded as the high byte.
- *
- * @see NodeIdInline
- */
-public enum NodeIdType {
- PTR(T_PTR, null),
-
- XSD_INTEGER(T_INTEGER, "Integer"),
- XSD_DECIMAL(T_DECIMAL, "Decimal"),
- XSD_FLOAT(T_FLOAT, "Float"),
- XSD_DOUBLE(T_DOUBLE, "Double"),
- XSD_DATETIME(T_DATETIME, "DateTime"),
- XSD_DATETIMESTAMP(T_DATETIMESTAMP, "DateTimeStamp"),
- XSD_DATE(T_DATE, "Date"),
- XSD_BOOLEAN(T_BOOLEAN, "Boolean"),
- XSD_SHORTSTRING(T_SHORTSTRING, "ShortString"),
- // 1 and greater
- XSD_POSITIVE_INTEGER(T_POSITIVE_INTEGER, "Positive Integer"),
- // -1 and down
- XSD_NEGATIVE_INTEGER(T_NEGATIVE_INTEGER, "Negative Integer"),
- // postive and zero
- XSD_NON_NEGATIVE_INTEGER(T_NON_NEGATIVE_INTEGER, "Non-negative Integer"),
- // negative or zero
- XSD_NON_POSITIVE_INTEGER(T_NON_POSITIVE_INTEGER, "Non-positive Integer"),
- XSD_LONG(T_LONG, "Long"),
- XSD_INT(T_INT, "Int"),
- XSD_SHORT(T_SHORT, "Short"),
- XSD_BYTE(T_BYTE, "Byte"),
- XSD_UNSIGNEDLONG(T_UNSIGNEDLONG, "UnsignedLong"),
- XSD_UNSIGNEDINT(T_UNSIGNEDINT, "UnsignedInt"),
- XSD_UNSIGNEDSHORT(T_UNSIGNEDSHORT, "UnsignedShort"),
- XSD_UNSIGNEDBYTE(T_UNSIGNEDBYTE, "UnsignedByte"),
-
- // Never stored.
- SPECIAL(T_SPECIAL, "Special"),
- // Used here only.
- INVALID$(T_INVALID, "Invalid")
-
- //, EXTENSION(T_EXTENSION, "Extension")
- ;
- /** The type values - must be stable as many of these go on disk.
- * enum ordinals are not enough.
- *
- * Encode as:
- * <ul>
- * <li>PTR : high bit zero, everything else written with a high bit one (done in {@link NodeIdFactory#encode}
- * <li>T_DOUBLE : Special case: next bit one. 01?? ???? i.e. 11?? on disk (value bit, double bit).
- * This leaves 62 bits for encoding doubles in the future.
- * <li>Otherwise, a number in the low byte of the constant, high bits "10".
- * </ul>
- * The {@code T_*} constants do not include the high bit.
- */
- public static class TYPES {
- public static final int T_PTR = 0 ;
-
- public static final int T_DOUBLE = enc(0x40);
-
- // Value types : 1 to 100
- public static final int T_INTEGER = enc(1);
- public static final int T_DECIMAL = enc(2);
- public static final int T_FLOAT = enc(3);
- //private static final int T_DOUBLE_X = enc(4);
-
- public static final int T_DATETIME = enc(5);
- public static final int T_DATETIMESTAMP = enc(6);
- public static final int T_DATE = enc(7);
- public static final int T_BOOLEAN = enc(8);
- public static final int T_SHORTSTRING = enc(9);
-
- public static final int T_POSITIVE_INTEGER = enc(10);
- public static final int T_NEGATIVE_INTEGER = enc(11);
- public static final int T_NON_NEGATIVE_INTEGER = enc(12);
- public static final int T_NON_POSITIVE_INTEGER = enc(13);
- public static final int T_LONG = enc(14);
- public static final int T_INT = enc(15);
- public static final int T_SHORT = enc(16);
- public static final int T_BYTE = enc(17);
- public static final int T_UNSIGNEDLONG = enc(18);
- public static final int T_UNSIGNEDINT = enc(19);
- public static final int T_UNSIGNEDSHORT = enc(20);
- public static final int T_UNSIGNEDBYTE = enc(21);
- // 21 is 00010101
-
- // Never stored : bits 1011 0000 so as not to look like a double.
- public static final int T_SPECIAL = enc(0x30);
- public static final int T_INVALID = enc(0x31);
- public static final int T_EXTENSION = enc(0x3F);
-
- // Encode/decode of the type value.
- static int enc(int v) { return v; }
- static int dec(int v) { return v; }
- }
-
- // We provide lots of natural questions to ask of an NodeId type.
- // All are efficient. There is redundancy but limited to this file.
-
- static boolean isStorable(NodeIdType type) {
- return !isSpecial(type);
- }
-
- // For numbers, an out-of-range number maybe stored a PTR.
-
- static boolean isInteger(NodeIdType type) {
- switch(type) {
- case XSD_INTEGER:
- case XSD_POSITIVE_INTEGER:
- case XSD_NEGATIVE_INTEGER:
- case XSD_NON_NEGATIVE_INTEGER:
- case XSD_NON_POSITIVE_INTEGER:
- case XSD_LONG:
- case XSD_INT:
- case XSD_SHORT:
- case XSD_BYTE:
- case XSD_UNSIGNEDLONG:
- case XSD_UNSIGNEDINT:
- case XSD_UNSIGNEDSHORT:
- case XSD_UNSIGNEDBYTE:
- return true;
- default:
- return false;
- }
- }
-
- static boolean isDecimal(NodeIdType type) {
- return type == XSD_DECIMAL;
- }
-
- static boolean isDouble(NodeIdType type) {
- return type == XSD_DOUBLE;
- }
-
- static boolean isFloat(NodeIdType type) {
- return type == XSD_FLOAT;
- }
-
- static boolean isNumber(NodeIdType type) {
- return isInteger(type) || isDecimal(type) || isDouble(type) || isFloat(type);
- }
-
- static boolean isSpecial(NodeIdType type) {
- return type == SPECIAL;
- }
-
- static boolean isInline(NodeIdType type) {
- switch(type) {
- case XSD_INTEGER:
- case XSD_DECIMAL:
- case XSD_DOUBLE:
- case XSD_FLOAT:
-
- case XSD_DATETIME:
- case XSD_DATETIMESTAMP:
- case XSD_DATE:
- case XSD_BOOLEAN:
- case XSD_SHORTSTRING:
-
- case XSD_POSITIVE_INTEGER:
- case XSD_NEGATIVE_INTEGER:
- case XSD_NON_NEGATIVE_INTEGER:
- case XSD_NON_POSITIVE_INTEGER:
- case XSD_LONG:
- case XSD_INT:
- case XSD_SHORT:
- case XSD_BYTE:
- case XSD_UNSIGNEDLONG:
- case XSD_UNSIGNEDINT:
- case XSD_UNSIGNEDSHORT:
- case XSD_UNSIGNEDBYTE:
- return true;
- default:
- return false;
- }
- }
-
- private final int value;
- private final String displayName;
-
- public int type() { return TYPES.dec(value); }
-
- @Override
- public String toString() { return displayName != null ? displayName : name(); }
-
- private NodeIdType(int value, String displayName){
-// if ( value != 0 )
-// // Set high bit.
-// value = TYPES.enc(value);
- this.value = value;
- this.displayName = displayName;
- }
-
- public static NodeIdType intToEnum(int x) {
- if ( x >= 0x80 )
- throw new IllegalArgumentException("Value '"+x+"' not legal: too large");
- if ( x != 0 )
- x = TYPES.enc(x);
- NodeIdType t = intToEnum$(x);
- if ( t == INVALID$ )
- throw new IllegalArgumentException("Value '"+x+"' not legal for "+NodeIdType.class.getSimpleName());
- return t ;
- }
-
- private static NodeIdType intToEnum$(int x) {
- //x = TYPES.enc(x);
- if (x == PTR.value ) return PTR;
- // XSD_DOUBL is special encoded - handled elsewhere.
- if (x == XSD_DOUBLE.value ) return XSD_DOUBLE ;
- if (x == XSD_INTEGER.value ) return XSD_INTEGER ;
- if (x == XSD_DECIMAL.value ) return XSD_DECIMAL ;
- if (x == XSD_FLOAT.value ) return XSD_FLOAT ;
-
- if (x == XSD_DATETIME.value ) return XSD_DATETIME ;
- if (x == XSD_DATETIMESTAMP.value ) return XSD_DATETIMESTAMP ;
- if (x == XSD_DATE.value ) return XSD_DATE ;
-
- if (x == XSD_BOOLEAN.value ) return XSD_BOOLEAN ;
- if (x == XSD_SHORTSTRING.value ) return XSD_SHORTSTRING ;
-
- if (x == XSD_POSITIVE_INTEGER.value ) return XSD_POSITIVE_INTEGER;
- if (x == XSD_NEGATIVE_INTEGER.value ) return XSD_NEGATIVE_INTEGER ;
- if (x == XSD_NON_NEGATIVE_INTEGER.value ) return XSD_NON_NEGATIVE_INTEGER ;
- if (x == XSD_NON_POSITIVE_INTEGER.value ) return XSD_NON_POSITIVE_INTEGER ;
-
- if (x == XSD_LONG.value ) return XSD_LONG ;
- if (x == XSD_INT.value ) return XSD_INT ;
- if (x == XSD_SHORT.value ) return XSD_SHORT ;
- if (x == XSD_BYTE.value ) return XSD_BYTE ;
- if (x == XSD_UNSIGNEDLONG.value ) return XSD_UNSIGNEDLONG ;
- if (x == XSD_UNSIGNEDINT.value ) return XSD_UNSIGNEDINT ;
- if (x == XSD_UNSIGNEDSHORT.value ) return XSD_UNSIGNEDSHORT ;
- if (x == XSD_UNSIGNEDBYTE.value ) return XSD_UNSIGNEDBYTE ;
- //if (x == EXTENSION.value ) return EXTENSION ;
- return INVALID$;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/PrefixMappingCache.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/PrefixMappingCache.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/PrefixMappingCache.java
deleted file mode 100644
index 75556d2..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/PrefixMappingCache.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store;
-
-import java.util.Map ;
-import java.util.Optional ;
-import java.util.Map.Entry ;
-
-import org.apache.jena.atlas.iterator.Iter;
-import org.apache.jena.atlas.lib.Cache ;
-import org.apache.jena.atlas.lib.CacheFactory ;
-import org.apache.jena.rdf.model.impl.Util ;
-import org.apache.jena.shared.PrefixMapping ;
-
-// Unsafe. Non-transactional cache.
-public class PrefixMappingCache implements PrefixMapping {
-
- private final PrefixMapping other ;
- private Cache<String, String> prefixToUri = CacheFactory.createCache(100) ;
- private Cache<String, String> uriToPrefix = CacheFactory.createCache(100) ;
-
- public PrefixMappingCache(PrefixMapping other) {
- this.other = other ;
- }
-
- private void add(String prefix, String uri) {
- prefixToUri.put(prefix, uri) ;
- uriToPrefix.put(uri, prefix);
- }
-
- private void remove(String prefix, String uri) {
- prefixToUri.remove(prefix) ;
- uriToPrefix.remove(uri);
- }
-
- private void clear() {
- prefixToUri.clear() ;
- uriToPrefix.clear() ;
- }
-
- @Override
- public PrefixMapping setNsPrefix(String prefix, String uri) {
- other.setNsPrefix(prefix, uri) ;
- add(prefix, uri);
- return this ;
- }
-
- @Override
- public PrefixMapping removeNsPrefix(String prefix) {
- String uri = getNsPrefixURI(prefix) ;
- if ( uri != null )
- remove(prefix, uri);
- other.removeNsPrefix(prefix) ;
- return this ;
- }
-
- @Override
- public PrefixMapping clearNsPrefixMap() {
- prefixToUri.clear() ;
- uriToPrefix.clear();
- other.clearNsPrefixMap() ;
- return this ;
- }
-
- @Override
- public PrefixMapping setNsPrefixes(PrefixMapping pmap) {
- setNsPrefixes(pmap.getNsPrefixMap()) ;
- return this ;
- }
-
- @Override
- public PrefixMapping setNsPrefixes(Map<String, String> map) {
- map.entrySet().forEach(entry->{
- setNsPrefix(entry.getKey(), entry.getValue()) ;
- });
- return this ;
- }
-
- @Override
- public PrefixMapping withDefaultMappings(PrefixMapping map) {
- other.withDefaultMappings(map) ;
- clear() ;
- return this ;
- }
-
- @Override
- public String getNsPrefixURI(String prefix) {
- String x = prefixToUri.getIfPresent(prefix) ;
- if ( x == null ) {
- x = other.getNsPrefixURI(prefix) ;
- if ( x != null )
- prefixToUri.put(prefix, x);
- }
- return x ;
- }
-
- @Override
- public String getNsURIPrefix(String uri) {
- String x = uriToPrefix.getIfPresent(uri) ;
- if ( x == null ) {
- x = other.getNsURIPrefix(uri) ;
- if ( x != null )
- uriToPrefix.put(uri, x);
- }
- return x ;
- }
-
- @Override
- public Map<String, String> getNsPrefixMap() {
- // Ignore cache - get everything from the provider.
- return other.getNsPrefixMap() ;
- }
-
- // From PrefixMappingImpl
- // Libraryize?
- @Override
- public String expandPrefix(String prefixed) {
- int colon = prefixed.indexOf(':');
- if ( colon < 0 )
- return prefixed;
- else {
- String prefix = prefixed.substring(0, colon);
- String uri = getNsPrefixURI(prefix);
- return uri == null ? prefixed : uri + prefixed.substring(colon + 1);
- }
- }
-
- @Override
- public String qnameFor(String uri) {
- int split = Util.splitNamespaceXML(uri) ;
- String ns = uri.substring(0, split);
- String local = uri.substring(split) ;
- if ( local.equals("") )
- return null ;
- String prefix = getNsURIPrefix(ns) ;
- return prefix == null ? null : prefix + ":" + local ;
- }
-
- @Override
- public String shortForm(String uri) {
- Optional<Entry<String, String>> e = findMapping(uri, true) ;
- if ( ! e.isPresent() )
- return uri ;
- return e.get().getKey() + ":" + uri.substring((e.get().getValue()).length()) ;
- }
-
- private Optional<Entry<String, String>> findMapping( String uri, boolean partial ) {
- return getNsPrefixMap().entrySet().stream().sequential().filter(e->{
- String ss = e.getValue();
- if (uri.startsWith( ss ) && (partial || ss.length() == uri.length()))
- return true;
- return false ;
- }).findFirst() ;
- }
-
- @Override
- public boolean samePrefixMappingAs(PrefixMapping other) {
- return other.samePrefixMappingAs(other) ;
- }
-
- @Override
- public PrefixMapping lock() {
- return this ;
- }
-
- @Override
- public boolean hasNoMappings() {
- return other.hasNoMappings() ;
- }
-
- @Override
- public int numPrefixes() {
- return other.numPrefixes() ;
- }
-
- private static String str(PrefixMapping pmap) {
- return pmap.getNsPrefixMap().toString();
- }
-
- @Override
- public String toString() {
- // Problem : only prints the cache.
- String x = Iter.iter(prefixToUri.keys()).map(k->k+"->"+prefixToUri.getIfPresent(k)).asString(", ");
- return "pm cache: ["+prefixToUri.size()+"] "+x+" : " + str(other);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/QuadTable.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/QuadTable.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/QuadTable.java
deleted file mode 100644
index 5521601..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/QuadTable.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store ;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.iterator.Iter;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.sparql.core.Quad ;
-import org.seaborne.tdb2.lib.TupleLib ;
-import org.seaborne.tdb2.store.nodetable.NodeTable ;
-import org.seaborne.tdb2.store.tupletable.TupleIndex ;
-
-/**
- * Quad table - a collection of TupleIndexes for 4-tuples together with a node
- * table.
- */
-
-public class QuadTable extends TableBase {
- public QuadTable(TupleIndex[] indexes, NodeTable nodeTable) {
- super(4, indexes, nodeTable) ;
- }
-
- /** Add a quad - return true if it was added, false if it already existed */
- public void add(Quad quad) {
- add(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
- }
-
- /**
- * Add a quad (as graph node and triple) - return true if it was added,
- * false if it already existed
- */
- public void add(Node gn, Triple triple) {
- add(gn, triple.getSubject(), triple.getPredicate(), triple.getObject()) ;
- }
-
- /** Add a quad - return true if it was added, false if it already existed */
- public void add(Node g, Node s, Node p, Node o) {
- table.addRow(g, s, p, o) ;
- }
-
- /** Delete a quad - return true if it was deleted, false if it didn't exist */
- public void delete(Quad quad) {
- delete(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
- }
-
- /**
- * Delete a quad (as graph node and triple) - return true if it was deleted,
- * false if it didn't exist
- */
- public void delete(Node gn, Triple triple) {
- delete(gn, triple.getSubject(), triple.getPredicate(), triple.getObject()) ;
- }
-
- /** Delete a quad - return true if it was deleted, false if it didn't exist */
- public void delete(Node g, Node s, Node p, Node o) {
- table.deleteRow(g, s, p, o) ;
- }
-
- /** Find matching quads */
- public Iterator<Quad> find(Node g, Node s, Node p, Node o) {
- Iterator<Tuple<NodeId>> iter = table.findAsNodeIds(g, s, p, o) ;
- if ( iter == null )
- return Iter.nullIterator() ;
- Iterator<Quad> iter2 = TupleLib.convertToQuads(table.getNodeTable(), iter) ;
- return iter2 ;
- }
-
- /** Clear - does not clear the associated node tuple table */
- public void clearQuads() {
- table.clear() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/StorageTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/StorageTDB.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/StorageTDB.java
deleted file mode 100644
index f9b39ec..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/StorageTDB.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store;
-
-import org.apache.jena.sparql.core.DatasetPrefixStorage;
-import org.seaborne.dboe.base.file.Location;
-import org.seaborne.tdb2.setup.StoreParams;
-
-public class StorageTDB {
-
- /*package*/ final TripleTable tripleTable;
- /*package*/ final QuadTable quadTable;
- /*package*/ final DatasetPrefixStorage prefixes;
- /*package*/ final Location location;
- /*package*/ final StoreParams storeParams;
-
- public StorageTDB(TripleTable tripleTable, QuadTable quadTable, DatasetPrefixStorage prefixes, Location location, StoreParams params) {
- super();
- this.tripleTable = tripleTable;
- this.quadTable = quadTable;
- this.prefixes = prefixes;
- this.location = location;
- this.storeParams = params;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/TableBase.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/TableBase.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/TableBase.java
deleted file mode 100644
index 8d885d19..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/TableBase.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store;
-
-import org.apache.jena.atlas.lib.Closeable ;
-import org.apache.jena.atlas.lib.Sync ;
-import org.seaborne.tdb2.store.nodetable.NodeTable ;
-import org.seaborne.tdb2.store.nodetupletable.NodeTupleTable ;
-import org.seaborne.tdb2.store.nodetupletable.NodeTupleTableConcrete ;
-import org.seaborne.tdb2.store.tupletable.TupleIndex ;
-
-public class TableBase implements Sync, Closeable
-{
- final protected NodeTupleTable table ;
-
- protected TableBase(int N, TupleIndex[] indexes, NodeTable nodeTable) {
- table = new NodeTupleTableConcrete(N, indexes, nodeTable) ;
- }
-
- public NodeTupleTable getNodeTupleTable() { return table ; }
-
- @Override
- public void sync() {
- table.sync() ;
- }
-
- @Override
- public void close()
- { table.close() ; }
-
- public boolean isEmpty() { return table.isEmpty() ; }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/TripleTable.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/TripleTable.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/TripleTable.java
deleted file mode 100644
index 8066ae5..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/TripleTable.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store ;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.iterator.Iter;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.seaborne.tdb2.lib.TupleLib ;
-import org.seaborne.tdb2.store.nodetable.NodeTable ;
-import org.seaborne.tdb2.store.tupletable.TupleIndex ;
-
-/**
- * TripleTable - a collection of TupleIndexes for 3-tuples together with a node
- * table. Normally, based on 3 indexes (SPO, POS, OSP) but other indexing
- * structures can be configured.
- */
-
-public class TripleTable extends TableBase {
- public TripleTable(TupleIndex[] indexes, NodeTable nodeTable) {
- super(3, indexes, nodeTable) ;
- }
-
- /** Add triple */
- public void add(Triple triple) {
- add(triple.getSubject(), triple.getPredicate(), triple.getObject()) ;
- }
-
- /** Add triple */
- public void add(Node s, Node p, Node o) {
- table.addRow(s, p, o) ;
- }
-
- /** Delete a triple */
- public void delete(Triple triple) {
- delete(triple.getSubject(), triple.getPredicate(), triple.getObject()) ;
- }
-
- /** Delete a triple */
- public void delete(Node s, Node p, Node o) {
- table.deleteRow(s, p, o) ;
- }
-
- /** Find matching triples */
- public Iterator<Triple> find(Node s, Node p, Node o) {
- Iterator<Tuple<NodeId>> iter = table.findAsNodeIds(s, p, o) ;
- if ( iter == null )
- return Iter.nullIterator() ;
- Iterator<Triple> iter2 = TupleLib.convertToTriples(table.getNodeTable(), iter) ;
- return iter2 ;
- }
-
- /** Clear - does not clear the associated node tuple table */
- public void clearTriples() {
- table.clear() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTable.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTable.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTable.java
deleted file mode 100644
index 60e1bfe..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTable.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetable;
-
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.lib.Closeable ;
-import org.apache.jena.atlas.lib.Pair ;
-import org.apache.jena.atlas.lib.Sync ;
-import org.apache.jena.graph.Node ;
-import org.seaborne.tdb2.store.NodeId ;
-
-/** Node table - conceptually a two way mapping of Node<->NodeId
- * where Nodes can be staored and a NodeId allocated
- * @see NodeId
- */
-
-public interface NodeTable extends Sync, Closeable
-{
- /** Store the node in the node table (if not already present) and return the allocated Id. */
- public NodeId getAllocateNodeId(Node node) ;
-
- /** Look up node and return the NodeId - return NodeId.NodeDoesNotExist if not found */
- public NodeId getNodeIdForNode(Node node) ;
-
- /** Look up node id and return the Node - return null if not found */
- public Node getNodeForNodeId(NodeId id) ;
-
- /** Test whether the node table contains an entry for node */
- public boolean containsNode(Node node) ;
-
- /** Test whether the node table contains an entry for node */
- public boolean containsNodeId(NodeId nodeId) ;
-
- /** Bulk mapping from {@code Node} to {@code NodeId}, with allocation
- * if the {@code withAllocation} is true.
- * The returned list aligns with the input list.
- */
- public List<NodeId> bulkNodeToNodeId(List<Node> nodes, boolean withAllocation) ;
-
- /** Bulk mapping from {@code NodeId} to {@code Node} */
- public List<Node> bulkNodeIdToNode(List<NodeId> nodeIds) ;
-
- /** Bulk lookup
- public List<NodeId> getAllocateNodeIdBulk(List<Node> nodes) ;
-
- /** Iterate over all nodes (not necessarily fast). Does not include inlined NodeIds */
- public Iterator<Pair<NodeId, Node>> all() ;
-
- /** Anything there? */
- public boolean isEmpty() ;
-
- /** Return a NodeTable if this instance wraps another, else return null */
- public NodeTable wrapped() ;
-
- /** Return the base NodeTable, the end of the wrapped chain */
- default public NodeTable baseNodeTable() {
- NodeTable nt = this ;
- NodeTable nt2 = null ;
- while ( (nt2 = nt.wrapped()) != null ) {
- nt = nt2 ;
- }
- return nt ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableCache.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableCache.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableCache.java
deleted file mode 100644
index 94dcf55..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableCache.java
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetable ;
-
-import java.util.ArrayList ;
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.Cache ;
-import org.apache.jena.atlas.lib.CacheFactory ;
-import org.apache.jena.atlas.lib.CacheSet ;
-import org.apache.jena.atlas.lib.Pair ;
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.graph.Node ;
-import org.seaborne.tdb2.TDBException ;
-import org.seaborne.tdb2.setup.StoreParams ;
-import org.seaborne.tdb2.store.NodeId ;
-
-/**
- * Cache wrapper around a NodeTable. Assumes all access goes through this
- * wrapper. Read-cache - write caching is done via the object file used by the
- * base NodeTable.
- */
-public class NodeTableCache implements NodeTable {
- // These caches are updated together.
- // See synchronization in _retrieveNodeByNodeId and _idForNode
- // The cache is assumed to be single operation-thread-safe.
- private Cache<Node, NodeId> node2id_Cache = null ;
- private Cache<NodeId, Node> id2node_Cache = null ;
-
- // A small cache of "known unknowns" to speed up searching for impossible
- // things.
- // Cache update needed on NodeTable changes because a node may become
- // "known"
- private CacheSet<Node> notPresent = null ;
- private NodeTable baseTable ;
- private final Object lock = new Object() ;
-
- public static NodeTable create(NodeTable nodeTable, StoreParams params) {
- int nodeToIdCacheSize = params.getNode2NodeIdCacheSize() ;
- int idToNodeCacheSize = params.getNodeId2NodeCacheSize() ;
- if ( nodeToIdCacheSize <= 0 && idToNodeCacheSize <= 0 )
- return nodeTable ;
- return new NodeTableCache(nodeTable, nodeToIdCacheSize, idToNodeCacheSize, params.getNodeMissCacheSize()) ;
- }
-
- public static NodeTable create(NodeTable nodeTable, int nodeToIdCacheSize, int idToNodeCacheSize, int nodeMissesCacheSize) {
- if ( nodeToIdCacheSize <= 0 && idToNodeCacheSize <= 0 )
- return nodeTable ;
- return new NodeTableCache(nodeTable, nodeToIdCacheSize, idToNodeCacheSize, nodeMissesCacheSize) ;
- }
-
- private NodeTableCache(NodeTable baseTable, int nodeToIdCacheSize, int idToNodeCacheSize, int nodeMissesCacheSize) {
- this.baseTable = baseTable ;
- if ( nodeToIdCacheSize > 0 )
- node2id_Cache = CacheFactory.createCache(nodeToIdCacheSize) ;
- if ( idToNodeCacheSize > 0 )
- id2node_Cache = CacheFactory.createCache(idToNodeCacheSize) ;
- if ( nodeMissesCacheSize > 0 )
- notPresent = CacheFactory.createCacheSet(nodeMissesCacheSize) ;
- }
-
- // ---- Cache access, no going to underlying table.
-
- public Node getNodeForNodeIdCache(NodeId id) {
- return id2node_Cache.getIfPresent(id) ;
- }
-
- public NodeId getNodeIdForNodeCache(Node node) {
- return node2id_Cache.getIfPresent(node) ;
- }
-
- public boolean isCachedNodeId(NodeId id) {
- return getNodeForNodeIdCache(id) != null ;
- }
-
- public boolean isCachedNode(Node node) {
- return getNodeIdForNodeCache(node) != null ;
- }
-
- // ---- Cache access
-
- @Override
- public final NodeTable wrapped() {
- return baseTable ;
- }
-
- /** Get the Node for this NodeId, or null if none */
- @Override
- public Node getNodeForNodeId(NodeId id) {
- return _retrieveNodeByNodeId(id) ;
- }
-
- /** Find the NodeId for a node, or return NodeId.NodeDoesNotExist */
- @Override
- public NodeId getNodeIdForNode(Node node) {
- return _idForNode(node, false) ;
- }
-
- /**
- * Find the NodeId for a node, allocating a new NodeId if the Node does not
- * yet have a NodeId
- */
- @Override
- public NodeId getAllocateNodeId(Node node) {
- return _idForNode(node, true) ;
- }
-
- @Override
- public boolean containsNode(Node node) {
- NodeId x = getNodeIdForNode(node) ;
- return NodeId.isDoesNotExist(x) ;
- }
-
- @Override
- public boolean containsNodeId(NodeId nodeId) {
- Node x = getNodeForNodeId(nodeId) ;
- return x == null ;
- }
-
- // If LRU cache is larger than the bulk unit, all allocated nodes are in the cache.
-// @Override
-// public List<NodeId> bulkNodeToNodeId(List<Node> nodes, boolean withAllocation) {
-// return NodeTable.super.bulkNodeToNodeId(nodes, withAllocation) ;
-// }
-//
-// @Override
-// public List<Node> bulkNodeIdToNode(List<NodeId> nodeIds) {
-// return NodeTable.super.bulkNodeIdToNode(nodeIds) ;
-// }
-
- @Override
- public List<NodeId> bulkNodeToNodeId(List<Node> required, boolean withAllocation) {
- synchronized(lock) {
- List<Node> nodes = new ArrayList<>() ;
- for ( Node n : required ) {
- //
- if ( getNodeIdForNodeCache(n) == null )
- nodes.add(n) ;
- }
- // Check bulk access.
- List<NodeId> x = baseTable.bulkNodeToNodeId(nodes, true) ;
- for ( int i = 0 ; i < nodes.size() ; i++ ) {
- Node n = nodes.get(i) ;
- NodeId nid = x.get(i) ;
- cacheUpdate(n ,nid) ;
- }
- return x ;
- }
- }
-
- @Override
- public List<Node> bulkNodeIdToNode(List<NodeId> nodeIds) {
- return NodeTableOps.bulkNodeIdToNodeImpl(this, nodeIds) ;
- }
-
- // ---- The worker functions
- // NodeId ==> Node
- private Node _retrieveNodeByNodeId(NodeId id) {
- if ( NodeId.isDoesNotExist(id) )
- return null ;
- if ( NodeId.isAny(id) )
- return null ;
- // Try once outside the synchronized
- // (Cache access is thread-safe)
- Node n = cacheLookup(id) ;
- if ( n != null )
- return n ;
-
- synchronized (lock) {
- // Lock to update two caches consisently.
- // Verify cache miss
- n = cacheLookup(id) ;
- if ( n != null )
- return n ;
-
- if ( baseTable == null )
- System.err.println("" + this) ;
-
- n = baseTable.getNodeForNodeId(id) ;
- cacheUpdate(n, id) ;
- return n ;
- }
- }
-
- // Node ==> NodeId
- private NodeId _idForNode(Node node, boolean allocate) {
- if ( node == Node.ANY )
- return NodeId.NodeIdAny ;
- // Try once outside the synchronized
- // (Cache access is thread-safe.)
- NodeId nodeId = cacheLookup(node) ;
- if ( nodeId != null )
- return nodeId ;
- synchronized (lock) {
- // Update two caches inside synchronized.
- // Check stil valid.
- nodeId = cacheLookup(node) ;
- if ( nodeId != null )
- return nodeId ;
-
- if ( allocate )
- nodeId = baseTable.getAllocateNodeId(node) ;
- else
- nodeId = baseTable.getNodeIdForNode(node) ;
- // Ensure caches have it. Includes recording "no such node"
- cacheUpdate(node, nodeId) ;
- return nodeId ;
- }
- }
-
- // ----------------
- // ---- Only places that the caches are touched
-
- /**
- * Check caches to see if we can map a NodeId to a Node. Returns null on no
- * cache entry.
- */
- private Node cacheLookup(NodeId id) {
- if ( id2node_Cache == null )
- return null ;
- return id2node_Cache.getIfPresent(id) ;
- }
-
- /**
- * Check caches to see if we can map a Node to a NodeId. Returns null on no
- * cache entry.
- */
- private NodeId cacheLookup(Node node) {
- // Remember things known (currently) not to exist.
- // Does not matter if notPresent is being updated elsewhere.
- if ( notPresent != null && notPresent.contains(node) )
- return null ;
- if ( node2id_Cache == null )
- return null ;
- return node2id_Cache.getIfPresent(node) ;
- }
-
- /** Update the Node->NodeId caches */
- private void cacheUpdate(Node node, NodeId id) {
- if ( node == null )
- return ;
-
- // synchronized is further out.
- // The "notPresent" cache is used to note whether a node
- // is known not to exist.
- // This must be specially handled later if the node is added.
- if ( NodeId.isDoesNotExist(id) ) {
- if ( notPresent != null )
- notPresent.add(node) ;
- return ;
- }
-
- if ( id == NodeId.NodeIdAny ) {
- Log.warn(this, "Attempt to cache NodeIdAny - ignored") ;
- return ;
- }
-
- if ( node2id_Cache != null )
- node2id_Cache.put(node, id) ;
- if ( id2node_Cache != null )
- id2node_Cache.put(id, node) ;
- // Remove if previously marked "not present"
- if ( notPresent != null && notPresent.contains(node) )
- notPresent.remove(node) ;
- }
-
- // ----
-
- @Override
- public boolean isEmpty() {
- synchronized (lock) {
- if ( node2id_Cache != null )
- return node2id_Cache.isEmpty() ;
- if ( id2node_Cache != null )
- id2node_Cache.isEmpty() ;
- // Write through.
- return baseTable.isEmpty() ;
- }
- }
-
- @Override
- public synchronized void close() {
- if ( baseTable == null )
- // Already closed (NodeTables can be shared so .close via two
- // routes).
- return ;
-
- baseTable.close() ;
- node2id_Cache = null ;
- id2node_Cache = null ;
- notPresent = null ;
- baseTable = null ;
- }
-
- @Override
- public void sync() {
- baseTable.sync() ;
- }
-
- @Override
- public Iterator<Pair<NodeId, Node>> all() {
- if ( false )
- testForConsistency() ;
- return baseTable.all() ;
- }
-
- private void testForConsistency() {
- Iterator<Node> iter1 = Iter.toList(node2id_Cache.keys()).iterator() ;
-
- for ( ; iter1.hasNext() ; ) {
- Node n = iter1.next() ;
-
- NodeId nId = node2id_Cache.getIfPresent(n) ;
- if ( !id2node_Cache.containsKey(nId) )
- throw new TDBException("Inconsistent: " + n + " => " + nId) ;
- if ( notPresent.contains(n) )
- throw new TDBException("Inconsistent: " + n + " in notPresent cache (1)") ;
- }
- Iterator<NodeId> iter2 = Iter.toList(id2node_Cache.keys()).iterator() ;
- for ( ; iter2.hasNext() ; ) {
- NodeId nId = iter2.next() ;
- Node n = id2node_Cache.getIfPresent(nId) ;
- if ( !node2id_Cache.containsKey(n) )
- throw new TDBException("Inconsistent: " + nId + " => " + n) ;
- if ( notPresent.contains(n) )
- throw new TDBException("Inconsistent: " + n + " in notPresent cache (2)") ;
- }
-
- }
-
- @Override
- public String toString() {
- return "Cache(" + baseTable.toString() + ")" ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableInline.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableInline.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableInline.java
deleted file mode 100644
index 2836d9c..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableInline.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetable;
-
-
-import org.apache.jena.graph.Node ;
-import org.seaborne.tdb2.store.NodeId ;
-
-/** NodeTable wrapper to handle inline node ids.
- * If a node can be made inline, then the underlying table never sees it.
- * If an inline Nodeid is seen, it is decoded and returned without
- * the underlying table being called.
- */
-
-public class NodeTableInline extends NodeTableWrapper
-{
- // Stack order: Inline > Cache > Actual
-
- public static NodeTable create(NodeTable nodeTable)
- {
- return new NodeTableInline(nodeTable) ;
- }
-
- private NodeTableInline(NodeTable nodeTable)
- {
- super(nodeTable) ;
- }
-
- @Override
- public final NodeId getAllocateNodeId(Node node)
- {
- NodeId nid = NodeId.inline(node) ;
- if ( nid != null ) return nid ;
- return super.getAllocateNodeId(node) ;
- }
-
- @Override
- public final NodeId getNodeIdForNode(Node node)
- {
- NodeId nid = NodeId.inline(node) ;
- if ( nid != null ) return nid ;
- return super.getNodeIdForNode(node) ;
- }
- @Override
- public final Node getNodeForNodeId(NodeId id)
- {
- Node n = NodeId.extract(id) ;
- if ( n != null )
- return n ;
- return super.getNodeForNodeId(id) ;
- }
-
- @Override
- public String toString() { return "Inline("+nodeTable.toString()+")" ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableNative.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableNative.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableNative.java
deleted file mode 100644
index 4910ffd..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableNative.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetable ;
-
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.lib.NotImplemented ;
-import org.apache.jena.atlas.lib.Pair ;
-import org.apache.jena.graph.Node ;
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.index.Index ;
-import org.seaborne.tdb2.TDBException ;
-import org.seaborne.tdb2.lib.NodeLib ;
-import org.seaborne.tdb2.store.Hash ;
-import org.seaborne.tdb2.store.NodeId ;
-import org.seaborne.tdb2.store.NodeIdFactory;
-
-/** A framework for a NodeTable based on native storage (string file and an index).
- * This class manages the index, and delegates the node storage.
- */
-public abstract class NodeTableNative implements NodeTable
-{
- protected Index nodeHashToId ; // hash -> int
- private boolean syncNeeded = false ;
-
- public NodeTableNative(Index nodeToId) {
- this.nodeHashToId = nodeToId ;
- }
- // ---- Public interface for Node <==> NodeId
-
- /** Get the Node for this NodeId, or null if none */
- @Override
- public Node getNodeForNodeId(NodeId id)
- {
- return _retrieveNodeByNodeId(id) ;
- }
-
- /** Find the NodeId for a node, or return NodeId.NodeDoesNotExist */
- @Override
- public NodeId getNodeIdForNode(Node node) { return _idForNode(node, false) ; }
-
- /** Find the NodeId for a node, allocating a new NodeId if the Node does not yet have a NodeId */
- @Override
- public NodeId getAllocateNodeId(Node node) { return _idForNode(node, true) ; }
-
- @Override
- public boolean containsNode(Node node) {
- NodeId x = getNodeIdForNode(node) ;
- return NodeId.isDoesNotExist(x) ;
- }
-
- @Override
- public boolean containsNodeId(NodeId nodeId) {
- Node x = getNodeForNodeId(nodeId) ;
- return x == null ;
- }
-
- @Override
- public List<NodeId> bulkNodeToNodeId(List<Node> nodes, boolean withAllocation) {
- return NodeTableOps.bulkNodeToNodeIdImpl(this, nodes, withAllocation) ;
- }
-
- @Override
- public List<Node> bulkNodeIdToNode(List<NodeId> nodeIds) {
- return NodeTableOps.bulkNodeIdToNodeImpl(this, nodeIds) ;
- }
-
- // ---- The worker functions
- // Synchronization:
- // accessIndex and readNodeFromTable
-
- // Cache around this class further out in NodeTableCache are synchronized
- // to maintain cache validatity which indirectly sync access to the NodeTable.
- // But to be sure, we provide MRSW guarantees on this class.
- // (otherwise if no cache => disaster)
- // synchonization happens in accessIndex() and readNodeByNodeId
-
- // NodeId to Node worker.
- private Node _retrieveNodeByNodeId(NodeId id)
- {
- if ( NodeId.isDoesNotExist(id) )
- return null ;
- if ( NodeId.isAny(id) )
- return null ;
- synchronized (this) {
- Node n = readNodeFromTable(id) ;
- return n ;
- }
- }
-
- // ----------------
-
- // Node to NodeId worker
- // Find a node, possibly placing it in the node file as well
- private NodeId _idForNode(Node node, boolean allocate)
- {
- if ( node == Node.ANY )
- return NodeId.NodeIdAny ;
-
- // synchronized in accessIndex
- NodeId nodeId = accessIndex(node, allocate) ;
- return nodeId ;
- }
-
- protected final NodeId accessIndex(Node node, boolean create)
- {
- Hash hash = new Hash(nodeHashToId.getRecordFactory().keyLength()) ;
- NodeLib.setHash(hash, node) ;
- byte k[] = hash.getBytes() ;
- // Key only.
- Record r = nodeHashToId.getRecordFactory().create(k) ;
-
- synchronized (this) // Pair to readNodeFromTable.
- {
- // Key and value, or null
- Record r2 = nodeHashToId.find(r) ;
- if ( r2 != null )
- {
- // Found. Get the NodeId.
- NodeId id = NodeIdFactory.get(r2.getValue(), 0) ;
- return id ;
- }
-
- // Not found.
- if ( ! create )
- return NodeId.NodeDoesNotExist ;
- // Write the node, which allocates an id for it.
- syncNeeded = true ;
- NodeId id = writeNodeToTable(node) ;
-
- // Update the r record with the new id.
- // r.value := id bytes ;
- NodeIdFactory.set(id, r.getValue(), 0) ;
-
- // Put in index - may appear because of concurrency
- if ( ! nodeHashToId.insert(r) )
- throw new TDBException("NodeTableBase::nodeToId - record mysteriously appeared") ;
- return id ;
- }
- }
-
- // -------- NodeId<->Node
- // Synchronization:
- // write: in accessIndex
- // read: in _retrieveNodeByNodeId
- // Only places for accessing the StringFile.
-
- abstract protected NodeId writeNodeToTable(Node node) ;
- abstract protected Node readNodeFromTable(NodeId id) ;
- abstract protected void syncSub() ;
- abstract protected void closeSub() ;
-
- // -------- NodeId<->Node
-
- @Override
- public synchronized void close()
- {
- // Close once. This may be shared (e.g. triples table and quads table).
- if ( nodeHashToId != null )
- {
- nodeHashToId.close() ;
- closeSub() ;
- nodeHashToId = null ;
- }
- }
-
- // Not synchronized
- @Override
- public Iterator<Pair<NodeId, Node>> all() { return all2() ; }
-
- private Iterator<Pair<NodeId, Node>> all2()
- {
- throw new NotImplemented() ;
- }
-
- @Override
- public void sync()
- {
- if ( syncNeeded )
- {
- syncSub() ;
- if ( nodeHashToId != null )
- nodeHashToId.sync() ;
- syncNeeded = false ;
- }
- }
-
- @Override
- public boolean isEmpty()
- {
- return nodeHashToId.isEmpty() ;
- }
-
- @Override
- public NodeTable wrapped() {
- return null ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableOps.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableOps.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableOps.java
deleted file mode 100644
index 73b03a3..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableOps.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetable;
-
-import java.util.ArrayList ;
-import java.util.List ;
-
-import org.apache.jena.graph.Node ;
-import org.seaborne.tdb2.store.NodeId ;
-
-public class NodeTableOps {
-
- /** Convert a bulk operation into a loop */
- public static List<NodeId> bulkNodeToNodeIdImpl(NodeTable nt, List<Node> nodes, boolean withAllocation) {
- List<NodeId> nodeIds = new ArrayList<>(nodes.size()) ;
- for ( Node node : nodes ) {
- NodeId nid = withAllocation ? nt.getAllocateNodeId(node) : nt.getNodeIdForNode(node) ;
- nodeIds.add(nid) ;
- }
- return nodeIds ;
- }
-
- /** Convert a bulk operation into a loop */
- public static List<Node> bulkNodeIdToNodeImpl(NodeTable nt, List<NodeId> nodeIds) {
- List<Node> nodes = new ArrayList<>(nodeIds.size()) ;
- for ( NodeId nodeId : nodeIds ) {
- Node n = nt.getNodeForNodeId(nodeId) ;
- nodes.add(n) ;
- }
- return nodes ;
- }
-
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableTRDF.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableTRDF.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableTRDF.java
deleted file mode 100644
index f14bb7e..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableTRDF.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetable ;
-
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.riot.thrift.RiotThriftException ;
-import org.apache.jena.riot.thrift.TRDF ;
-import org.apache.jena.riot.thrift.ThriftConvert ;
-import org.apache.jena.riot.thrift.wire.RDF_Term ;
-import org.apache.thrift.TException ;
-import org.apache.thrift.protocol.TProtocol ;
-import org.seaborne.dboe.base.file.BinaryDataFile ;
-import org.seaborne.dboe.index.Index ;
-import org.seaborne.tdb2.TDBException ;
-import org.seaborne.tdb2.store.NodeId ;
-import org.seaborne.tdb2.store.NodeIdFactory;
-
-/** NodeTable using Thrift for the I/O and storage. */
-
-public class NodeTableTRDF extends NodeTableNative {
- // Write buffering is done in the underlying BinaryDataFile
- BinaryDataFile diskFile ;
- private TReadAppendFileTransport transport ;
- private final TProtocol protocol ;
-
- public NodeTableTRDF(Index nodeToId, BinaryDataFile objectFile) {
- super(nodeToId) ;
- try {
- this.diskFile = objectFile ;
- transport = new TReadAppendFileTransport(diskFile) ;
- if ( ! transport.isOpen() )
- transport.open();
- this.protocol = TRDF.protocol(transport) ;
- }
- catch (Exception ex) {
- throw new TDBException("NodeTableTRDF", ex) ;
- }
- }
-
- @Override
- protected NodeId writeNodeToTable(Node node) {
- RDF_Term term = ThriftConvert.convert(node, true) ;
- try {
- long x = diskFile.length() ;
- // Paired : [*]
- NodeId nid = NodeIdFactory.createPtr(x);
- term.write(protocol) ;
- //transport.flush() ;
- return nid ;
- }
- catch (Exception ex) {
- throw new TDBException("NodeTableThrift/Write", ex) ;
- }
- }
-
- @Override
- protected Node readNodeFromTable(NodeId id) {
- try {
- // Paired : [*]
- long x = id.getPtrLocation();
- transport.readPosition(x) ;
- RDF_Term term = new RDF_Term() ;
- term.read(protocol) ;
- Node n = ThriftConvert.convert(term) ;
- return n ;
- }
- catch (TException ex) {
- throw new TDBException("NodeTableTRDF/Read", ex) ;
- }
- catch (RiotThriftException ex) {
- Log.error(this, "Bad encoding: NodeId = "+id) ;
- throw ex ;
- }
- }
-
- @Override
- protected void syncSub() {
- try { transport.flush(); }
- catch (Exception ex) { throw new TDBException("NodeTableTRDF", ex) ; }
- }
-
- @Override
- protected void closeSub() {
- if ( transport.isOpen() ) {
- try { transport.close() ; }
- catch (Exception ex) { throw new TDBException("NodeTableTRDF", ex) ; }
- }
- }
-
- public Index getIndex() { return nodeHashToId ; }
- public BinaryDataFile getData() { return diskFile ; }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableWrapper.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableWrapper.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableWrapper.java
deleted file mode 100644
index e13dafa..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/NodeTableWrapper.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetable ;
-
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.lib.Pair ;
-import org.apache.jena.graph.Node ;
-import org.seaborne.tdb2.store.NodeId ;
-
-public class NodeTableWrapper implements NodeTable {
- protected final NodeTable nodeTable ;
-
- @Override
- public final NodeTable wrapped() {
- return nodeTable ;
- }
-
- protected NodeTableWrapper(NodeTable nodeTable) {
- this.nodeTable = nodeTable ;
- }
-
- @Override
- public NodeId getAllocateNodeId(Node node) {
- return nodeTable.getAllocateNodeId(node) ;
- }
-
- @Override
- public NodeId getNodeIdForNode(Node node) {
- return nodeTable.getNodeIdForNode(node) ;
- }
-
- @Override
- public Node getNodeForNodeId(NodeId id) {
- return nodeTable.getNodeForNodeId(id) ;
- }
-
- @Override
- public boolean containsNode(Node node) {
- return nodeTable.containsNode(node) ;
- }
-
- @Override
- public boolean containsNodeId(NodeId nodeId) {
- return nodeTable.containsNodeId(nodeId) ;
- }
-
- @Override
- public List<NodeId> bulkNodeToNodeId(List<Node> nodes, boolean withAllocation) {
- return nodeTable.bulkNodeToNodeId(nodes, withAllocation) ;
- }
-
- @Override
- public List<Node> bulkNodeIdToNode(List<NodeId> nodeIds) {
- return nodeTable.bulkNodeIdToNode(nodeIds) ;
- }
-
- @Override
- public Iterator<Pair<NodeId, Node>> all() {
- return nodeTable.all() ;
- }
-
- @Override
- public boolean isEmpty() {
- return nodeTable.isEmpty() ;
- }
-
- @Override
- public void sync() {
- nodeTable.sync() ;
- }
-
- @Override
- public void close() {
- nodeTable.close() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/TReadAppendFileTransport.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/TReadAppendFileTransport.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/TReadAppendFileTransport.java
deleted file mode 100644
index 7ae7eb0..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetable/TReadAppendFileTransport.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetable;
-
-import java.util.Objects ;
-
-import org.apache.thrift.transport.TTransport ;
-import org.seaborne.dboe.base.file.BinaryDataFile ;
-
-/** A file transport that supports random access read and
- * buffered append write.
- * <p>
- * Adapter TTransport -> BinaryDataFile
- */
-public class TReadAppendFileTransport extends TTransport {
- private BinaryDataFile file ;
- private long readPosn = -1 ;
-
- public TReadAppendFileTransport(BinaryDataFile file) {
- Objects.requireNonNull(file) ;
- this.file = file ;
- }
-
- @Override
- public boolean isOpen() {
- return file.isOpen() ;
- }
-
- @Override
- public void open() {
- file.open() ;
- }
-
- @Override
- public void close() {
- file.close() ;
- }
-
- public void truncate(long posn) {
- file.truncate(posn);
- }
-
- public BinaryDataFile getBinaryDataFile() { return file ; }
-
- public long readPosition() {
- return readPosn ;
- }
-
- public void readPosition(long posn) {
- readPosn = posn ;
- }
-
- @Override
- public int read(byte[] buf, int off, int len) {
- int x = file.read(readPosn, buf, off, len) ;
- readPosn += x ;
- return x ;
- }
-
- @Override
- public void write(byte[] buf, int off, int len) {
- file.write(buf, off, len) ;
- }
-
- @Override
- public void flush() {
- file.sync();
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTable.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTable.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTable.java
deleted file mode 100644
index 58eecbd..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTable.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetupletable ;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.Closeable ;
-import org.apache.jena.atlas.lib.Sync ;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.graph.Node ;
-import org.seaborne.tdb2.store.NodeId ;
-import org.seaborne.tdb2.store.nodetable.NodeTable ;
-import org.seaborne.tdb2.store.tupletable.TupleTable ;
-
-public interface NodeTupleTable extends Sync, Closeable
-{
- public void addRow(Node... nodes) ;
-
- public void deleteRow(Node... nodes) ;
-
- /** Find by node. */
- public Iterator<Tuple<Node>> find(Node... nodes) ;
-
- /** Find by node - return an iterator of NodeIds. Can return "null" for not found as well as NullIterator */
- public Iterator<Tuple<NodeId>> findAsNodeIds(Node... nodes) ;
-
- /** Find by NodeId. */
- public Iterator<Tuple<NodeId>> find(NodeId... ids) ;
-
- /** Find by NodeId. */
- public Iterator<Tuple<NodeId>> find(Tuple<NodeId> ids) ;
-
- /** Find all tuples */
- public Iterator<Tuple<NodeId>> findAll() ;
-
- /** Return the undelying tuple table - used with great care by tools
- * that directly manipulate internal structures.
- */
- public TupleTable getTupleTable() ;
-
- /** Return the node table */
- public NodeTable getNodeTable() ;
-
- public boolean isEmpty() ;
-
- /** Clear the tuple table. After this operation, find* will find nothing.
- * This does not mean all data has been removed - for example, it does not mean
- * that any node table has been emptied.
- */
- public void clear() ;
-
- // No clear operation - need to manage the tuple table
- // and node tables separately.
-
- public long size() ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableConcrete.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableConcrete.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableConcrete.java
deleted file mode 100644
index 766ae7a..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableConcrete.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetupletable ;
-
-import static java.lang.String.format ;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.atlas.lib.tuple.TupleFactory ;
-import org.apache.jena.graph.Node ;
-import org.seaborne.tdb2.TDBException ;
-import org.seaborne.tdb2.lib.TupleLib ;
-import org.seaborne.tdb2.store.NodeId ;
-import org.seaborne.tdb2.store.nodetable.NodeTable ;
-import org.seaborne.tdb2.store.tupletable.TupleIndex ;
-import org.seaborne.tdb2.store.tupletable.TupleTable ;
-
-/** Group a tuple table and node table together to provide a real NodeTupleTable */
-public class NodeTupleTableConcrete implements NodeTupleTable
-{
- protected final NodeTable nodeTable ;
- protected final TupleTable tupleTable ;
-
- /*
- * Concurrency checking: Everything goes through one of
- * addRow, deleteRow or find*
- */
-
- public NodeTupleTableConcrete(int N, TupleIndex[] indexes, NodeTable nodeTable)
- {
- if (indexes.length == 0 || indexes[0] == null) throw new TDBException("A primary index is required") ;
- for (TupleIndex index : indexes)
- {
- if (N != index.getTupleLength())
- throw new TDBException(format("Inconsistent: TupleTable width is %d but index %s is %d",
- N, index.getMappingStr(), index.getTupleLength())) ;
- }
-
- this.tupleTable = new TupleTable(N, indexes) ;
- this.nodeTable = nodeTable ;
- }
-
- private void startWrite() { }
-
- private void finishWrite() { }
-
- private void startRead() { }
-
- private void finishRead() { }
-
- @Override
- public void addRow(Node... nodes)
- {
- try {
- startWrite() ;
- NodeId n[] = new NodeId[nodes.length] ;
- for (int i = 0; i < nodes.length; i++)
- n[i] = nodeTable.getAllocateNodeId(nodes[i]) ;
-
- Tuple<NodeId> t = TupleFactory.create(n) ;
- tupleTable.add(t) ;
- } finally
- {
- finishWrite() ;
- }
- }
-
- @Override
- public void deleteRow(Node... nodes)
- {
- try
- {
- startWrite() ;
- NodeId n[] = new NodeId[nodes.length] ;
- for (int i = 0; i < nodes.length; i++)
- {
- NodeId id = idForNode(nodes[i]) ;
- if (NodeId.isDoesNotExist(id)) return ;
- n[i] = id ;
- }
-
- Tuple<NodeId> t = TupleFactory.create(n) ;
- tupleTable.delete(t) ;
- } finally
- {
- finishWrite() ;
- }
- }
-
- /** Find by node. */
- @Override
- public Iterator<Tuple<Node>> find(Node... nodes)
- {
- try {
- startRead() ;
- Iterator<Tuple<NodeId>> iter1 = findAsNodeIds(nodes) ; // **public call
- if (iter1 == null)
- return Iter.nullIterator() ;
- Iterator<Tuple<Node>> iter2 = TupleLib.convertToNodes(nodeTable, iter1) ;
- return iteratorControl(iter2) ;
- } finally { finishRead() ; }
- }
-
- /**
- * Find by node - return an iterator of NodeIds.
- * Can return "null" (when a node is known to be unknown)
- * for not found as well as NullIterator (when
- * no tuples are found (unknown unknown).
- */
- @Override
- public Iterator<Tuple<NodeId>> findAsNodeIds(Node... nodes)
- {
- NodeId n[] = new NodeId[nodes.length] ;
- try {
- startRead() ;
- for (int i = 0; i < nodes.length; i++)
- {
- NodeId id = idForNode(nodes[i]) ;
- if (NodeId.isDoesNotExist(id))
- return Iter.nullIterator() ;
- n[i] = id ;
- }
- return find(n) ; // **public call
- } finally { finishRead() ; }
- }
-
- /** Find by NodeId. */
- @Override
- public Iterator<Tuple<NodeId>> find(NodeId... ids)
- {
- Tuple<NodeId> tuple = TupleFactory.create(ids) ;
- return find(tuple) ;
- }
-
- /** Find by NodeId. */
- @Override
- public Iterator<Tuple<NodeId>> find(Tuple<NodeId> tuple)
- {
- // All find/*, except findAll, comes through this operation so startRead/finishRead/checkIterator only needs to happen here.
- try {
- startRead() ;
- // find worker - need also protect iterators that access the node table.
- Iterator<Tuple<NodeId>> iter = tupleTable.find(tuple) ;
- return iteratorControl(iter) ;
- } finally { finishRead() ; }
- }
-
- @Override
- public Iterator<Tuple<NodeId>> findAll()
- {
- try {
- startRead() ;
- return iteratorControl(tupleTable.getIndex(0).all()) ;
- } finally { finishRead() ; }
- }
-
- // ==== Node
-
- protected final NodeId idForNode(Node node) {
- if ( node == null || node == Node.ANY )
- return NodeId.NodeIdAny ;
- if ( node.isVariable() )
- throw new TDBException("Can't pass variables to NodeTupleTable.find*") ;
- return nodeTable.getNodeIdForNode(node) ;
- }
-
- // ==== Accessors
-
- /**
- * Return the undelying tuple table - used with great care by tools that directly
- * manipulate internal structures.
- */
- @Override
- public final TupleTable getTupleTable() {
- return tupleTable ;
- }
-
- /** Return the node table */
- @Override
- public final NodeTable getNodeTable() {
- return nodeTable ;
- }
-
- @Override
- public boolean isEmpty() {
- return tupleTable.isEmpty() ;
- }
-
- /** Clear the tuple table - does not clear the node table */
- @Override
- public void clear() {
- try {
- startWrite() ;
- tupleTable.clear() ;
- } finally { finishWrite() ; }
- }
-
- @Override
- public long size() {
- return tupleTable.size() ;
- }
-
- @Override
- public final void close() {
- try {
- startWrite() ;
- tupleTable.close() ;
- nodeTable.close() ;
- } finally { finishWrite() ; }
- }
-
- @Override
- public final void sync() {
- try {
- startWrite() ;
- tupleTable.sync() ;
- nodeTable.sync() ;
- } finally { finishWrite() ; }
- }
-
- // Add any iterator checking.
- private <T> Iterator<T> iteratorControl(Iterator<T> iter) { return iter; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableView.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableView.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableView.java
deleted file mode 100644
index 5e24ab9..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableView.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetupletable;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.ArrayUtils ;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.graph.Node ;
-import org.seaborne.tdb2.store.NodeId ;
-import org.seaborne.tdb2.store.tupletable.TupleTable ;
-
-/** (Read-only?) projection of another NodeTupleTable.
- * This will not reduce a N-wide tuple to N-1 when find*() used.
- */
-public class NodeTupleTableView extends NodeTupleTableWrapper
-{
- private Node prefix ;
- private NodeId prefixId ;
- //private boolean readOnly = false ;
-
- public NodeTupleTableView(NodeTupleTable ntt, Node prefix)
- {
- super(ntt) ;
- this.prefix = prefix ;
- this.prefixId = ntt.getNodeTable().getNodeIdForNode(prefix) ;
- }
-
- @Override
- public void addRow(Node... nodes)
- {
- nodes = push(Node.class, prefix, nodes) ;
- super.addRow(nodes) ;
- }
-
- @Override
- public void deleteRow(Node... nodes)
- {
- nodes = push(Node.class, prefix, nodes) ;
- super.deleteRow(nodes) ;
- }
-
- @Override
- public Iterator<Tuple<Node>> find(Node... nodes)
- {
- nodes = push(Node.class, prefix, nodes) ;
- return nodeTupleTable.find(nodes) ;
- }
-
- private static <T> T[] push(Class<T> cls, T x, T[] array)
- {
- T[] array2 = ArrayUtils.alloc(cls, array.length+1) ;
- System.arraycopy(array, 0, array2, 1, array.length) ;
- array2[0] = x ;
- return array2 ;
- }
-
- private static <T> T[] push(Class<T> cls, T x, Tuple<T> tuple)
- {
- T[] array2 = ArrayUtils.alloc(cls, tuple.len()+1) ;
- tuple.copyInto(array2, 1);
- array2[0] = x ;
- return array2 ;
- }
-
- @Override
- public Iterator<Tuple<NodeId>> find(NodeId... ids)
- {
- ids = push(NodeId.class, prefixId, ids) ;
- return nodeTupleTable.find(ids) ;
- }
-
- @Override
- public Iterator<Tuple<NodeId>> find(Tuple<NodeId> ids)
- {
- NodeId[] ids2 = push(NodeId.class, prefixId, ids) ;
- return nodeTupleTable.find(ids2) ;
- }
-
- @Override
- public Iterator<Tuple<NodeId>> findAsNodeIds(Node... nodes)
- {
- nodes = push(Node.class, prefix, nodes) ;
- return nodeTupleTable.findAsNodeIds(nodes) ;
- }
-
-// @Override
-// public boolean isReadOnly() { return readOnly ; }
-//
-// @Override
-// public void setReadOnly(boolean mode) { readOnly = mode ; }
-
- @Override
- public TupleTable getTupleTable()
- // Need a projection of this?
- { return super.getTupleTable() ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableWrapper.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableWrapper.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableWrapper.java
deleted file mode 100644
index c34697b..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/nodetupletable/NodeTupleTableWrapper.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.tdb2.store.nodetupletable;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.graph.Node ;
-import org.seaborne.tdb2.store.NodeId ;
-import org.seaborne.tdb2.store.nodetable.NodeTable ;
-import org.seaborne.tdb2.store.tupletable.TupleTable ;
-
-public class NodeTupleTableWrapper implements NodeTupleTable
-{
- protected NodeTupleTable nodeTupleTable ;
-
- public NodeTupleTableWrapper(NodeTupleTable ntt) {
- setNodeTupleTable(ntt) ;
- }
-
- protected NodeTupleTable setNodeTupleTable(NodeTupleTable ntt) {
- NodeTupleTable old = nodeTupleTable ;
- nodeTupleTable = ntt ;
- return old ;
- }
-
- @Override
- public void addRow(Node... nodes)
- { nodeTupleTable.addRow(nodes) ; }
-
- @Override
- public void deleteRow(Node... nodes)
- { nodeTupleTable.deleteRow(nodes) ; }
-
- @Override
- public Iterator<Tuple<Node>> find(Node... nodes)
- { return nodeTupleTable.find(nodes) ; }
-
- @Override
- public Iterator<Tuple<NodeId>> find(NodeId... ids)
- { return nodeTupleTable.find(ids) ; }
-
- @Override
- public Iterator<Tuple<NodeId>> find(Tuple<NodeId> tuple)
- { return nodeTupleTable.find(tuple) ; }
-
- @Override
- public Iterator<Tuple<NodeId>> findAsNodeIds(Node... nodes)
- { return nodeTupleTable.findAsNodeIds(nodes) ; }
-
- @Override
- public Iterator<Tuple<NodeId>> findAll()
- { return nodeTupleTable.findAll() ; }
-
- @Override
- public NodeTable getNodeTable()
- { return nodeTupleTable.getNodeTable() ; }
-
- @Override
- public TupleTable getTupleTable()
- { return nodeTupleTable.getTupleTable() ; }
-
- @Override
- public boolean isEmpty()
- { return nodeTupleTable.isEmpty() ; }
-
- @Override
- public void clear()
- { nodeTupleTable.clear(); }
-
- @Override
- public long size()
- { return nodeTupleTable.size() ; }
-
- @Override
- public void sync()
- { nodeTupleTable.sync() ; }
-
- @Override
- public void close()
- { nodeTupleTable.close() ; }
-}