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:57 UTC
[11/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/DatasetGraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphTDB.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphTDB.java
deleted file mode 100644
index 47d9c25..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphTDB.java
+++ /dev/null
@@ -1,481 +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.apache.jena.sparql.util.graph.GraphUtils.triples2quads ;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.Closeable ;
-import org.apache.jena.atlas.lib.InternalErrorException ;
-import org.apache.jena.atlas.lib.Sync ;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.GraphUtil ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.query.ReadWrite ;
-import org.apache.jena.sparql.core.* ;
-import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
-import org.seaborne.dboe.base.file.Location ;
-import org.seaborne.dboe.transaction.TransactionalMonitor ;
-import org.seaborne.dboe.transaction.txn.Transaction ;
-import org.seaborne.dboe.transaction.txn.TransactionException ;
-import org.seaborne.dboe.transaction.txn.TransactionalSystem ;
-import org.seaborne.dboe.transaction.txn.TxnId;
-import org.seaborne.tdb2.TDBException ;
-import org.seaborne.tdb2.lib.NodeLib ;
-import org.seaborne.tdb2.setup.StoreParams ;
-import org.seaborne.tdb2.store.nodetupletable.NodeTupleTable ;
-import org.seaborne.tdb2.sys.StoreConnection ;
-/** This is the class that provides creates a dataset over the storage via
- * TripleTable, QuadTable and prefixes.
- * This is the coordination of the storage.
- * @see DatasetGraphTxn for the Transaction form.
- */
-final
-public class DatasetGraphTDB extends DatasetGraphTriplesQuads
- implements DatasetGraphTxn, Sync, Closeable
-{
- private StorageTDB storage;
-// // SWITCHING.
-// private TripleTable tripleTable ;
-// private QuadTable quadTable ;
-// private DatasetPrefixStorage prefixes ;
-// private Location location ;
-// private StoreParams storeParams ;
-// // SWITCHING.
- private TransactionalSystem txnSystem ;
- private final ReorderTransformation transform ;
-
- private GraphTDB defaultGraphTDB ;
- private final boolean checkForChange = false ;
- private boolean closed = false ;
-
- /** Application should not create a {@code DatasetGraphTDB} directly */
- public DatasetGraphTDB(TransactionalSystem txnSystem,
- TripleTable tripleTable, QuadTable quadTable, DatasetPrefixStorage prefixes,
- ReorderTransformation transform, Location location, StoreParams params) {
- reset(txnSystem, tripleTable, quadTable, prefixes, location, params) ;
- this.transform = transform ;
- this.defaultGraphTDB = getDefaultGraphTDB() ;
- }
-
- public void reset(TransactionalSystem txnSystem,
- TripleTable tripleTable, QuadTable quadTable, DatasetPrefixStorage prefixes,
- Location location, StoreParams params) {
-// this.tripleTable = tripleTable ;
-// this.quadTable = quadTable ;
-// this.location = location ;
-// this.prefixes = prefixes ;
-// this.storeParams = params ;
- this.txnSystem = txnSystem ;
- // XXX Threading?
- // XXX (re)set transaction components in TransactionCoordinator??
- this.storage = new StorageTDB(tripleTable, quadTable, prefixes, location, params);
- this.defaultGraphTDB = getDefaultGraphTDB();
- }
-
- public QuadTable getQuadTable() { checkNotClosed(); return storage.quadTable; }
- public TripleTable getTripleTable() { checkNotClosed(); return storage.tripleTable; }
-
- /** Low level manipulation. */
- public StorageTDB getStorage() { return storage; }
- /** Low level manipulation.
- * <b>Do not use unless in exclusive mode.</b>
- */
- public void setStorage(StorageTDB storage) { this.storage = storage; }
-
- @Override
- protected Iterator<Quad> findInDftGraph(Node s, Node p, Node o) {
- checkNotClosed() ;
- return isolate(triples2quadsDftGraph(getTripleTable().find(s, p, o))) ;
- }
-
- @Override
- protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node o) {
- checkNotClosed();
- return isolate(getQuadTable().find(g, s, p, o));
- }
-
- @Override
- protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) {
- checkNotClosed();
- return isolate(getQuadTable().find(Node.ANY, s, p, o));
- }
-
- protected Iterator<Quad> triples2quadsDftGraph(Iterator<Triple> iter)
- { return isolate(triples2quads(Quad.defaultGraphIRI, iter)); }
-
- private static final boolean CHECK_TXN = true;
-
- private <T> Iterator<T> isolate(Iterator<T> iterator) {
- if ( txnSystem.isInTransaction() ) {
- TxnId txnId = txnSystem.getThreadTransaction().getTxnId();
- // Add transaction protection.
- return new IteratorTxnTracker<>(iterator, txnSystem, txnId);
- }
- // Risk the hidden arraylist is copied on growth.
- return Iter.iterator(iterator);
- }
-
- @Override
- protected void addToDftGraph(Node s, Node p, Node o) {
- checkNotClosed() ;
- requireWriteTxn() ;
- notifyAdd(null, s, p, o) ;
- getTripleTable().add(s,p,o) ;
- }
-
- @Override
- protected void addToNamedGraph(Node g, Node s, Node p, Node o) {
- checkNotClosed() ;
- requireWriteTxn() ;
- notifyAdd(g, s, p, o) ;
- getQuadTable().add(g, s, p, o) ;
- }
-
- @Override
- protected void deleteFromDftGraph(Node s, Node p, Node o) {
- checkNotClosed() ;
- requireWriteTxn() ;
- notifyDelete(null, s, p, o) ;
- getTripleTable().delete(s, p, o) ;
- }
-
- @Override
- protected void deleteFromNamedGraph(Node g, Node s, Node p, Node o) {
- checkNotClosed() ;
- requireWriteTxn() ;
- notifyDelete(g, s, p, o) ;
- getQuadTable().delete(g, s, p, o) ;
- }
-
- // Promotion
- private void requireWriteTxn() {
- Transaction txn = txnSystem.getThreadTransaction() ;
- if ( txn == null )
- throw new TransactionException("Not in a transaction") ;
-
- if ( txn.isWriteTxn() )
- return ;
- // Transaction.promoteOrException
- boolean b = txn.promote() ;
- if ( !b )
- throw new TransactionException("Can't write") ;
- }
-
- // TODO ?? Optimize by integrating with add/delete operations.
- private final void notifyAdd(Node g, Node s, Node p, Node o) {
- if ( monitor == null )
- return ;
- QuadAction action = QuadAction.ADD ;
- if ( checkForChange ) {
- if ( contains(g,s,p,o) )
- action = QuadAction.NO_ADD ;
- }
- monitor.change(action, g, s, p, o);
- }
-
- private final void notifyDelete(Node g, Node s, Node p, Node o) {
- if ( monitor == null )
- return ;
- QuadAction action = QuadAction.DELETE ;
- if ( checkForChange ) {
- if ( ! contains(g,s,p,o) )
- action = QuadAction.NO_DELETE ;
- }
- monitor.change(action, g, s, p, o);
- }
-
- /** No-op. There is no need to close datasets.
- * Use {@link StoreConnection#release(Location)}.
- * (Datasets can not be reopened on MS Windows).
- */
- @Override
- public void close() {
- if ( closed )
- return ;
- closed = true ;
- }
-
- private void checkNotClosed() {
- if ( closed )
- throw new TDBException("dataset closed") ;
- }
-
- /** Release resources.
- * Do not call directly - this is called from StoreConnection.
- * Use {@link StoreConnection#release(Location)}.
- */
- public void shutdown() {
- close();
- storage.tripleTable.close() ;
- storage.quadTable.close() ;
- storage.prefixes.close();
- txnSystem.getTxnMgr().shutdown();
- }
-
- @Override
- // Empty graphs don't "exist"
- public boolean containsGraph(Node graphNode) {
- checkNotClosed() ;
- if ( Quad.isDefaultGraphExplicit(graphNode) || Quad.isUnionGraph(graphNode) )
- return true ;
- return _containsGraph(graphNode) ;
- }
-
- private boolean _containsGraph(Node graphNode) {
- // Have to look explicitly, which is a bit of a nuisance.
- // But does not normally happen for GRAPH <g> because that's rewritten to quads.
- // Only pattern with complex paths go via GRAPH.
- Iterator<Tuple<NodeId>> x = storage.quadTable.getNodeTupleTable().findAsNodeIds(graphNode, null, null, null) ;
- if ( x == null )
- return false ;
- boolean result = x.hasNext() ;
- return result ;
- }
-
- @Override
- public void addGraph(Node graphName, Graph graph) {
- checkNotClosed() ;
- removeGraph(graphName) ;
- GraphUtil.addInto(getGraph(graphName), graph) ;
- }
-
- @Override
- public final void removeGraph(Node graphName) {
- checkNotClosed() ;
- deleteAny(graphName, Node.ANY, Node.ANY, Node.ANY) ;
- }
-
- @Override
- public Graph getDefaultGraph() {
- checkNotClosed() ;
- return new GraphTDB(this, null) ;
- }
-
- public GraphTDB getDefaultGraphTDB() {
- checkNotClosed();
- return (GraphTDB)getDefaultGraph();
- }
-
- @Override
- public Graph getGraph(Node graphNode) {
- checkNotClosed();
- return new GraphTDB(this, graphNode);
- }
-
- public GraphTDB getGraphTDB(Node graphNode) {
- checkNotClosed();
- return (GraphTDB)getGraph(graphNode);
- }
-
- public StoreParams getStoreParams() {
- checkNotClosed();
- return storage.storeParams;
- }
-
- public ReorderTransformation getReorderTransform() {
- checkNotClosed();
- return transform;
- }
-
- public DatasetPrefixStorage getPrefixes() {
- checkNotClosed();
- return storage.prefixes;
- }
-
- @Override
- public Iterator<Node> listGraphNodes() {
- checkNotClosed();
- Iterator<Tuple<NodeId>> x = storage.quadTable.getNodeTupleTable().findAll();
- Iterator<NodeId> z = Iter.iter(x).map(t -> t.get(0)).distinct();
- return NodeLib.nodes(storage.quadTable.getNodeTupleTable().getNodeTable(), z);
- }
-
- @Override
- public long size() {
- checkNotClosed();
- return Iter.count(listGraphNodes());
- }
-
- @Override
- public boolean isEmpty() {
- checkNotClosed();
- return getTripleTable().isEmpty() && getQuadTable().isEmpty();
- }
-
- @Override
- public void clear() {
- checkNotClosed() ;
- // Leave the node table alone.
- getTripleTable().clearTriples() ;
- getQuadTable().clearQuads() ;
- }
-
- public NodeTupleTable chooseNodeTupleTable(Node graphNode) {
- checkNotClosed() ;
-
- if ( graphNode == null || Quad.isDefaultGraph(graphNode) )
- return getTripleTable().getNodeTupleTable() ;
- else
- // Includes Node.ANY and union graph
- return getQuadTable().getNodeTupleTable() ;
- }
-
- private static final int sliceSize = 1000 ;
-
- @Override
- public void deleteAny(Node g, Node s, Node p, Node o) {
- // Delete in batches.
- // That way, there is no active iterator when a delete
- // from the indexes happens.
- checkNotClosed() ;
-
- if ( monitor != null ) {
- // Need to do by nodes because we will log the deletes.
- super.deleteAny(g, s, p, o);
- return ;
- }
-
- // Not logging - do by working as NodeIds.
- NodeTupleTable t = chooseNodeTupleTable(g) ;
- @SuppressWarnings("unchecked")
- Tuple<NodeId>[] array = (Tuple<NodeId>[])new Tuple<?>[sliceSize] ;
-
- while (true) { // Convert/cache s,p,o?
- // The Node Cache will catch these so don't worry unduely.
- Iterator<Tuple<NodeId>> iter = null ;
- if ( g == null )
- iter = t.findAsNodeIds(s, p, o) ;
- else
- iter = t.findAsNodeIds(g, s, p, o) ;
-
- if ( iter == null || ! iter.hasNext() )
- return ;
-
- // Get a slice
- int len = 0 ;
- for (; len < sliceSize; len++) {
- if ( !iter.hasNext() )
- break ;
- array[len] = iter.next() ;
- }
-
- // Delete the NodeId Tuples
- for (int i = 0; i < len; i++) {
- t.getTupleTable().delete(array[i]) ;
- array[i] = null ;
- }
- // Finished?
- if ( len < sliceSize )
- break ;
- }
- }
-
- public Location getLocation() { return storage.location ; }
-
- @Override
- public void sync() {
- checkNotClosed();
- storage.tripleTable.sync();
- storage.quadTable.sync();
- storage.prefixes.sync();
- }
-
- @Override
- public void setDefaultGraph(Graph g) {
- throw new UnsupportedOperationException("Can't set default graph on a TDB-backed dataset") ;
- }
-
- @Override
- public boolean isInTransaction() {
- return txnSystem.isInTransaction() ;
- }
-
- // txnSystem with monitor?
- @Override
- public void begin(ReadWrite readWrite) {
- if ( txnMonitor != null ) txnMonitor.startBegin(readWrite);
- txnSystem.begin(readWrite) ;
- if ( txnMonitor != null ) txnMonitor.finishBegin(readWrite);
- }
-
- @Override
- public boolean promote() {
- if ( txnMonitor != null ) txnMonitor.startPromote();
- try {
- return txnSystem.promote() ;
- } finally { if ( txnMonitor != null ) txnMonitor.finishPromote(); }
- }
-
- @Override
- public void commit() {
- if ( txnMonitor != null ) txnMonitor.startCommit();
- txnSystem.commit() ;
- if ( txnMonitor != null ) txnMonitor.finishCommit();
- }
-
- @Override
- public void abort() {
- if ( txnMonitor != null ) txnMonitor.startAbort() ;
- txnSystem.abort() ;
- if ( txnMonitor != null ) txnMonitor.finishAbort() ;
- }
-
- @Override
- public void end() {
- if ( txnMonitor != null ) txnMonitor.startEnd();
- txnSystem.end() ;
- if ( txnMonitor != null ) txnMonitor.finishEnd();
- }
-
- public TransactionalSystem getTxnSystem() {
- return txnSystem ;
- }
-
- // Watching changes (add, delete, deleteAny)
-
- private DatasetChanges monitor = null ;
- public void setMonitor(DatasetChanges changes) {
- monitor = changes ;
- }
-
- public void removeMonitor(DatasetChanges changes) {
- if ( monitor != changes )
- throw new InternalErrorException() ;
- monitor = null ;
- }
-
- // Watching Transactional
-
- private TransactionalMonitor txnMonitor = null ;
- public void setTransactionalMonitor(TransactionalMonitor changes) {
- txnMonitor = changes ;
- }
-
- public void removeTransactionalMonitor(TransactionalMonitor changes) {
- if ( txnMonitor != changes )
- throw new InternalErrorException() ;
- txnMonitor = null ;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphTxn.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphTxn.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphTxn.java
deleted file mode 100644
index bd98dd9..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphTxn.java
+++ /dev/null
@@ -1,35 +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.DatasetGraph ;
-import org.seaborne.dboe.transaction.Transactional ;
-
-/** Transaction representation of a DatasetGraph */
-public interface DatasetGraphTxn extends DatasetGraph, Transactional {
- // Combines org.seaborne.dboe.transaction.Transactional and org.apache.jena.sparql.core.Transactional.
- // o.s.dboe.Transactional add promote()
-
- @Override
- public default boolean supportsTransactions() { return true ; }
-
- @Override
- public default boolean supportsTransactionAbort() { return true ; }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphWrapperTxn.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphWrapperTxn.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphWrapperTxn.java
deleted file mode 100644
index e172c90..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetGraphWrapperTxn.java
+++ /dev/null
@@ -1,34 +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.DatasetGraphWrapper ;
-
-public class DatasetGraphWrapperTxn extends DatasetGraphWrapper implements DatasetGraphTxn {
-
- public DatasetGraphWrapperTxn(DatasetGraphTxn dsg) {
- super(dsg) ;
- }
-
- @Override
- public boolean promote() {
- return ((DatasetGraphTxn)get()).promote() ;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetPrefixesTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetPrefixesTDB.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetPrefixesTDB.java
deleted file mode 100644
index 0d5468f..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/DatasetPrefixesTDB.java
+++ /dev/null
@@ -1,174 +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.* ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.sparql.core.DatasetPrefixStorage ;
-import org.seaborne.dboe.base.record.RecordFactory ;
-import org.seaborne.tdb2.store.nodetupletable.NodeTupleTable ;
-
-/**
- * Dataset prefixes; a table of nodes with prefix-centric operations. The table
- * is G-P-U where G is a graph name ("" is used for the default graph), P is a
- * string (the prefix) and U is the IRI.
- */
-public class DatasetPrefixesTDB implements DatasetPrefixStorage
-{
- // Consider a cache - like PrefixMappingCache was - but needs to respect transactions.
- // See getPrefixMapping.
-
- static final RecordFactory factory = new RecordFactory(3*NodeId.SIZE, 0) ;
- static final String unamedGraphURI = "" ;
-
- private final NodeTupleTable nodeTupleTable ;
-
- public DatasetPrefixesTDB(NodeTupleTable nodeTupleTable) {
- this.nodeTupleTable = nodeTupleTable ;
- }
-
- @Override
- public void loadPrefixMapping(String graphName, PrefixMapping pmap) {
- Node g = NodeFactory.createURI(graphName) ;
- Iterator<Tuple<Node>> iter = nodeTupleTable.find(g, null, null) ;
- iter.forEachRemaining(tuple->{
- Node prefix = tuple.get(1) ;
- Node uri = tuple.get(2) ;
- pmap.setNsPrefix(prefix.getLiteralLexicalForm(), uri.getURI()) ;
- }) ;
- }
-
- @Override
- public synchronized void insertPrefix(String graphName, String prefix, String uri) {
- Node g = NodeFactory.createURI(graphName) ;
- Node p = NodeFactory.createLiteral(prefix) ;
- Node u = NodeFactory.createURI(uri) ;
-
- nodeTupleTable.addRow(g,p,u) ;
- }
-
- @Override
- public Set<String> graphNames() {
- Iterator<Tuple<Node>> iter = nodeTupleTable.find((Node)null, null, null) ;
- Set <String> x = new HashSet<>() ;
- for ( ; iter.hasNext() ; )
- x.add(iter.next().get(0).getURI()) ;
- Iter.close(iter) ;
- return x ;
- }
-
- @Override
- public synchronized String readPrefix(String graphName, String prefix) {
- Node g = NodeFactory.createURI(graphName) ;
- Node p = NodeFactory.createLiteral(prefix) ;
-
- Iterator<Tuple<Node>> iter = nodeTupleTable.find(g, p, null) ;
- try {
- if ( ! iter.hasNext() )
- return null ;
- Tuple<Node> t = iter.next() ;
- Node uri = t.get(2) ;
- return uri.getURI() ;
- } finally { Iter.close(iter) ; }
- }
-
- @Override
- public synchronized String readByURI(String graphName, String uriStr) {
- Node g = NodeFactory.createURI(graphName) ;
- Node u = NodeFactory.createURI(uriStr) ;
- Iterator<Tuple<Node>> iter = nodeTupleTable.find(g, null, u) ;
- if ( ! iter.hasNext() )
- return null ;
- Node prefix = iter.next().get(1) ;
- Iter.close(iter) ;
- return prefix.getLiteralLexicalForm() ;
- }
-
- @Override
- public synchronized Map<String, String> readPrefixMap(String graphName) {
- Map<String, String> map = new HashMap<>() ;
- Node g = NodeFactory.createURI(graphName) ;
- Iterator<Tuple<Node>> iter = nodeTupleTable.find(g, null, null) ;
- for ( ; iter.hasNext() ; ) {
- try {
- Tuple<Node> t = iter.next() ;
- String prefix = t.get(1).getLiteralLexicalForm() ;
- String uri = t.get(2).getURI() ;
- map.put(prefix, uri) ;
- }
- catch (Exception ex) {
- Log.warn(this, "Mangled prefix map: graph name=" + graphName, ex) ;
- }
- }
- Iter.close(iter) ;
- return map ;
- }
-
- @Override
- public void removeFromPrefixMap(String graphName, String prefix) {
- Node g = NodeFactory.createURI(graphName) ;
- Node p = NodeFactory.createLiteral(prefix) ;
- removeAll(g, p, null) ;
- }
-
- @Override
- public void removeAllFromPrefixMap(String graphName) {
- Node g = NodeFactory.createURI(graphName) ;
- removeAll(g, null, null) ;
- }
-
- /** Remove by pattern */
- private synchronized void removeAll(Node g, Node p, Node uri) {
- Iterator<Tuple<Node>> iter = nodeTupleTable.find(g, p, uri) ;
- List<Tuple<Node>> list = Iter.toList(iter) ; // Materialize.
- Iter.close(iter) ;
- for ( Tuple<Node> tuple : list )
- nodeTupleTable.deleteRow(tuple.get(0), tuple.get(1), tuple.get(2)) ;
- }
-
- public NodeTupleTable getNodeTupleTable() { return nodeTupleTable ; }
-
- /** Return a PrefixMapping for the unamed graph */
- @Override
- public PrefixMapping getPrefixMapping()
- { return getPrefixMapping(unamedGraphURI) ; }
-
- /** Return a PrefixMapping for a named graph */
- @Override
- public PrefixMapping getPrefixMapping(String graphName) {
- PrefixMapping pm = new GraphPrefixesProjectionTDB(graphName, this) ;
- return pm ;
- }
-
- @Override
- public void close() {
- nodeTupleTable.close() ;
- }
-
- @Override
- public void sync() {
- nodeTupleTable.sync() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphPrefixesProjectionTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphPrefixesProjectionTDB.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphPrefixesProjectionTDB.java
deleted file mode 100644
index 92fae0e..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphPrefixesProjectionTDB.java
+++ /dev/null
@@ -1,164 +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.Map.Entry ;
-import java.util.Optional ;
-
-import org.apache.jena.rdf.model.impl.Util ;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.sparql.core.DatasetPrefixStorage ;
-
-public class GraphPrefixesProjectionTDB implements PrefixMapping {
- // Despite the name "TDB" this is general replacement for
- // PrefixMapping over DatasetPrefixStorage.
- private final String graphName ;
- private final DatasetPrefixStorage prefixes ;
-
- public GraphPrefixesProjectionTDB(String graphName, DatasetPrefixStorage prefixes)
- {
- this.graphName = graphName ;
- this.prefixes = prefixes ;
- }
-
- @Override
- public PrefixMapping setNsPrefix(String prefix, String uri) {
- prefixes.insertPrefix(graphName, prefix, uri);
- return this ;
- }
-
- @Override
- public PrefixMapping removeNsPrefix(String prefix) {
- prefixes.removeFromPrefixMap(graphName, prefix);
- return this ;
- }
-
- @Override
- public PrefixMapping clearNsPrefixMap() {
- prefixes.removeAllFromPrefixMap(graphName);
- return this ;
- }
-
- @Override
- public PrefixMapping setNsPrefixes(PrefixMapping other) {
- setNsPrefixes(other.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 other) {
- other.getNsPrefixMap().entrySet().forEach(entry->{
- String prefix = entry.getKey() ;
- String uri = entry.getValue();
- if (getNsPrefixURI( prefix ) == null && getNsURIPrefix( uri ) == null)
- setNsPrefix( prefix, uri );
- }) ;
- return this ;
- }
-
- @Override
- public String getNsPrefixURI(String prefix) {
- return prefixes.readPrefix(graphName, prefix) ;
- }
-
- @Override
- public String getNsURIPrefix(String uri) {
- return prefixes.readByURI(graphName, uri) ;
- }
-
- @Override
- public Map<String, String> getNsPrefixMap() {
- return prefixes.readPrefixMap(graphName) ;
- }
-
- // From PrefixMappingImpl
- @Override
- public String expandPrefix(String prefixed) {
- {
- int colon = prefixed.indexOf(':') ;
- if ( colon < 0 )
- return prefixed ;
- else {
- String prefix = prefixed.substring(0, colon) ;
- String uri = prefixes.readPrefix(graphName, 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 = prefixes.readByURI(graphName, 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()) ;
- }
-
- // Do better?
-
- @Override
- public boolean hasNoMappings() { return getNsPrefixMap().isEmpty() ; }
-
- @Override
- public int numPrefixes() {
- return getNsPrefixMap().size() ;
- }
-
- 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 PrefixMapping lock() {
- return this ;
- }
-
- @Override
- public boolean samePrefixMappingAs(PrefixMapping other) {
- return this.getNsPrefixMap().equals(other.getNsPrefixMap()) ;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphTDB.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphTDB.java
deleted file mode 100644
index 9805146..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphTDB.java
+++ /dev/null
@@ -1,181 +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 java.util.function.Function;
-
-import org.apache.jena.atlas.iterator.Iter ;
-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.atlas.lib.tuple.TupleFactory ;
-import org.apache.jena.graph.* ;
-import org.apache.jena.riot.other.GLib ;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.sparql.core.GraphView ;
-import org.apache.jena.sparql.core.Quad ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-import org.seaborne.tdb2.TDBException ;
-import org.seaborne.tdb2.graph.TransactionHandlerTDB ;
-import org.seaborne.tdb2.store.nodetupletable.NodeTupleTable ;
-
-/**
- * General operations for TDB graphs (free-standing graph, default graph and
- * named graphs)
- */
-public class GraphTDB extends GraphView implements Closeable, Sync {
- private final TransactionHandler transactionHandler = new TransactionHandlerTDB(this) ;
-
- // Switch this to DatasetGraphTransaction
- private final DatasetGraphTDB dataset ;
-
- public GraphTDB(DatasetGraphTDB dataset, Node graphName) {
- super(dataset, graphName) ;
- this.dataset = dataset ;
- }
-
- /** get the current TDB dataset graph - changes for transactions */
- public DatasetGraphTDB getDSG() {
- return dataset ;
- }
-
- /** The NodeTupleTable for this graph */
- public NodeTupleTable getNodeTupleTable() {
- return getDSG().chooseNodeTupleTable(getGraphName()) ;
- }
-
- @Override
- protected PrefixMapping createPrefixMapping() {
- if ( isDefaultGraph() )
- return getDSG().getPrefixes().getPrefixMapping() ;
- if ( isUnionGraph() )
- return getDSG().getPrefixes().getPrefixMapping() ;
- return getDSG().getPrefixes().getPrefixMapping(getGraphName().getURI()) ;
- }
-
- @Override
- public final void sync() {
- dataset.sync() ;
- }
-
- @Override
- final public void close() {
- sync() ;
- // Don't close the GraphBase.
- //super.close() ;
- }
-
- protected static ExtendedIterator<Triple> graphBaseFindDft(DatasetGraphTDB dataset, Triple triple) {
- Iterator<Quad> iterQuads = dataset.find(Quad.defaultGraphIRI, triple.getSubject(), triple.getPredicate(), triple.getObject()) ;
- if ( iterQuads == null )
- return org.apache.jena.util.iterator.NullIterator.instance() ;
- // Can't be duplicates - fixed graph node..
- Iterator<Triple> iterTriples = projectQuadsToTriples(Quad.defaultGraphIRI, iterQuads) ;
- return WrappedIterator.createNoRemove(iterTriples) ;
- }
-
- protected static ExtendedIterator<Triple> graphBaseFindNG(DatasetGraphTDB dataset, Node graphNode, Triple m) {
- Node gn = graphNode ;
- // Explicitly named union graph.
- if ( isUnionGraph(gn) )
- gn = Node.ANY ;
-
- Iterator<Quad> iter = dataset.getQuadTable().find(gn, m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject()) ;
- if ( iter == null )
- return org.apache.jena.util.iterator.NullIterator.instance() ;
-
- Iterator<Triple> iterTriples = projectQuadsToTriples((gn == Node.ANY ? null : gn), iter) ;
-
- if ( gn == Node.ANY )
- iterTriples = Iter.distinct(iterTriples) ;
- return WrappedIterator.createNoRemove(iterTriples) ;
- }
-
- @Override
- protected ExtendedIterator<Triple> graphUnionFind(Node s, Node p, Node o) {
- Node g = Quad.unionGraph ;
- Iterator<Quad> iterQuads = getDSG().find(g, s, p, o) ;
- Iterator<Triple> iter = GLib.quads2triples(iterQuads) ;
- // Suppress duplicates after projecting to triples.
- // TDB guarantees that duplicates are adjacent.
- // See SolverLib.
- iter = Iter.distinctAdjacent(iter) ;
- return WrappedIterator.createNoRemove(iter) ;
- }
-
- @Override
- protected final int graphBaseSize() {
- if ( isDefaultGraph() )
- return (int)getNodeTupleTable().size() ;
-
- Node gn = getGraphName() ;
- boolean unionGraph = isUnionGraph(gn) ;
- gn = unionGraph ? Node.ANY : gn ;
- Iterator<Tuple<NodeId>> iter = getDSG().getQuadTable().getNodeTupleTable().findAsNodeIds(gn, null, null, null) ;
- if ( unionGraph ) {
- iter = Iter.map(iter, project4TupleTo3Tuple) ;
- iter = Iter.distinctAdjacent(iter) ;
- }
- return (int)Iter.count(iter) ;
- }
-
- private static Function<Tuple<NodeId>, Tuple<NodeId>> project4TupleTo3Tuple = item -> {
- if (item.len() != 4)
- throw new TDBException("Expected a Tuple of 4, got: " + item);
- return TupleFactory.tuple(item.get(1), item.get(2), item.get(3));
- };
-
- private static Iterator<Triple> projectQuadsToTriples(Node graphNode, Iterator<Quad> iter) {
- // Checking.
- Function<Quad, Triple> f = (q) -> {
- if ( graphNode != null && !q.getGraph().equals(graphNode) )
- throw new InternalError("projectQuadsToTriples: Quads from unexpected graph (expected=" + graphNode + ", got=" + q.getGraph() + ")");
- return q.asTriple();
- };
- // Without.
- //Function<Quad, Triple> f = (q) -> q.asTriple();
- return Iter.map(iter, f);
- }
-
- @Override
- public TransactionHandler getTransactionHandler() {
- return transactionHandler ;
- }
-
- @Override
- public void clear() {
- dataset.deleteAny(getGraphName(), Node.ANY, Node.ANY, Node.ANY) ;
- getEventManager().notifyEvent(this, GraphEvents.removeAll) ;
- }
-
- @Override
- public void remove(Node s, Node p, Node o) {
- if ( getEventManager().listening() ) {
- // Have to do it the hard way so that triple events happen.
- super.remove(s, p, o) ;
- return ;
- }
-
- dataset.deleteAny(getGraphName(), s, p, o) ;
- // We know no one is listening ...
- // getEventManager().notifyEvent(this, GraphEvents.remove(s, p, o) ) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphViewSwitchable.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphViewSwitchable.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphViewSwitchable.java
deleted file mode 100644
index d52f7a0..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/GraphViewSwitchable.java
+++ /dev/null
@@ -1,139 +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 org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.shared.impl.PrefixMappingImpl ;
-import org.apache.jena.sparql.core.DatasetPrefixStorage ;
-import org.apache.jena.sparql.core.GraphView ;
-import org.apache.jena.sparql.core.Quad ;
-
-/** A GraphView that is sensitive to {@link DatasetGraphSwitchable} switching.
- */
-public class GraphViewSwitchable extends GraphView {
- // Fixups for GraphView
- // Prefixes.
- // Transaction handler.
- // Long term - ensure that GraphView uses get() always, inc prefixes, transaction handlers
-
- // Factory style.
- public static GraphViewSwitchable createDefaultGraph(DatasetGraphSwitchable dsg)
- { return new GraphViewSwitchable(dsg, Quad.defaultGraphNodeGenerated) ; }
-
- public static GraphView createNamedGraph(DatasetGraphSwitchable dsg, Node graphIRI)
- { return new GraphViewSwitchable(dsg, graphIRI) ; }
-
- public static GraphViewSwitchable createUnionGraph(DatasetGraphSwitchable dsg)
- { return new GraphViewSwitchable(dsg, Quad.unionGraph) ; }
-
- private final DatasetGraphSwitchable dsgx;
- protected DatasetGraphSwitchable getx() { return dsgx; }
-
- protected GraphViewSwitchable(DatasetGraphSwitchable dsg, Node gn) {
- super(dsg, gn) ;
- this.dsgx = dsg;
- }
-
-// @Override
-// public TransactionHandler getTransactionHandler() {
-// // XXX Awiting for promote to be enabled.
-// return super.getTransactionHandler();
-// }
-
- @Override
- protected PrefixMapping createPrefixMapping() {
- Node gn = super.getGraphName();
- if ( gn == Quad.defaultGraphNodeGenerated )
- gn = null;
- if ( Quad.isUnionGraph(gn) ) {
- // Read-only wrapper would be better that a copy.
- PrefixMapping pmap = new PrefixMappingImpl();
- pmap.setNsPrefixes(prefixMapping(null));
- return pmap;
- }
- return prefixMapping(gn);
- }
-
- /** Return the {@code DatasetGraphSwitchable} we are viewing. */
- @Override
- public DatasetGraphSwitchable getDataset() {
- return getx() ;
- }
-
- // TDB2 specific.
- // Does not cope with blank nodes.
- // A PrefixMapping sending operations via the switchable.
- // Long term, rework as PrefixMapping over PrefixMap over DatasetPrefixStorage
- private PrefixMapping prefixMapping(Node graphName) {
-
- String gn = (graphName == null) ? "" : graphName.getURI();
-
- return new PrefixMappingImpl() {
-
- DatasetPrefixStorage dps() {
- return ((DatasetGraphTDB)(getx().get())).getPrefixes();
- }
-
- Graph graph() {
- DatasetGraphTDB dsg = (DatasetGraphTDB)getx().get();
- if ( gn == null )
- return dsg.getDefaultGraph();
- else
- return dsg.getGraph(graphName);
- }
-
- PrefixMapping prefixMapping() {
- if ( gn == null )
- return dps().getPrefixMapping();
- else
- return dps().getPrefixMapping(gn);
- }
-
- @Override
- protected void set(String prefix, String uri) {
- dps().insertPrefix(gn, prefix, uri);
- super.set(prefix, uri);
- }
-
- @Override
- protected String get(String prefix) {
- //Ignore. String x = super.get(prefix);
- // (Ignore more?)
- return dps().readPrefix(gn, prefix);
- }
-
- @Override
- protected void remove(String prefix) {
- dps().getPrefixMapping().removeNsPrefix(prefix);
- super.remove(prefix);
- }
-
- @Override
- public Map<String, String> getNsPrefixMap() {
- return prefixMapping().getNsPrefixMap();
- //return graph().getPrefixMapping().getNsPrefixMap();
- }
- };
- }
-
-}
\ 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/Hash.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/Hash.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/Hash.java
deleted file mode 100644
index ed86f3f..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/Hash.java
+++ /dev/null
@@ -1,57 +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.Arrays;
-
-import org.apache.jena.atlas.lib.Bytes ;
-
-
-/** Hash values. */
-public class Hash
-{
- private byte [] bytes ;
- public Hash(int len) { bytes = new byte[len] ; }
- public int getLen() { return bytes.length ; }
- public byte [] getBytes() { return bytes ; }
-
- @Override
- public int hashCode()
- {
- return Arrays.hashCode(bytes) ;
- }
-
- @Override
- public boolean equals(Object other)
- {
- if ( this == other ) return true ;
- if ( ! (other instanceof Hash) )
- return false ;
- boolean b = Arrays.equals(bytes, ((Hash)other).bytes) ;
- return b ;
- }
-
- @Override
- public String toString()
- {
- return "hash:"+Bytes.asHex(bytes) ;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/IteratorCheckNotConcurrent.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/IteratorCheckNotConcurrent.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/IteratorCheckNotConcurrent.java
deleted file mode 100644
index 0aa4182..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/IteratorCheckNotConcurrent.java
+++ /dev/null
@@ -1,93 +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 java.lang.String.format ;
-
-import java.util.ConcurrentModificationException ;
-import java.util.Iterator ;
-import java.util.NoSuchElementException ;
-import java.util.concurrent.atomic.AtomicLong ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.Closeable ;
-
-/** Wrapper to check an iterator has not been used across some write operation. */
-class IteratorCheckNotConcurrent<T> implements Iterator<T>, Closeable
-{
- private Iterator<T> iter ;
- private AtomicLong eCount ; // Needs fixing to be per thera in some way - either from the caller or here.
- private boolean finished = false ;
- private long startEpoch ;
-
- IteratorCheckNotConcurrent(Iterator<T> iter, AtomicLong eCount) {
- // Assumes correct locking to set up, i.e. eCount not changing
- // (writer on separate thread).
- this.iter = iter ;
- this.eCount = eCount ;
- this.startEpoch = eCount.get() ;
- }
-
- private void checkConcurrentModification() {
- if ( finished )
- return ;
-
- long now = eCount.get() ;
- if ( now != startEpoch ) {
- policyError(format("Iterator: started at %d, now %d", startEpoch, now)) ;
- }
- }
-
- private static void policyError(String message) {
- throw new ConcurrentModificationException(message) ;
- }
-
- @Override
- public boolean hasNext() {
- checkConcurrentModification() ;
- boolean b = iter.hasNext() ;
- if ( !b )
- close() ;
- return b ;
- }
-
- @Override
- public T next() {
- checkConcurrentModification() ;
- try { return iter.next() ; }
- catch (NoSuchElementException ex) {
- close() ;
- throw ex ;
- }
- }
-
- @Override
- public void remove() {
- checkConcurrentModification() ;
- iter.remove() ;
- // Reset the epoch.
- startEpoch = eCount.get() ;
- }
-
- @Override
- public void close() {
- finished = true ;
- Iter.close(iter) ;
- }
-}
\ 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/IteratorTxnTracker.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/IteratorTxnTracker.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/IteratorTxnTracker.java
deleted file mode 100644
index d56fb0d..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/IteratorTxnTracker.java
+++ /dev/null
@@ -1,55 +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 java.util.Objects;
-
-import org.apache.jena.atlas.iterator.IteratorWrapper;
-import org.seaborne.dboe.transaction.txn.Transaction;
-import org.seaborne.dboe.transaction.txn.TransactionException;
-import org.seaborne.dboe.transaction.txn.TransactionalSystem;
-import org.seaborne.dboe.transaction.txn.TxnId;
-
-/** Wrapper to check that an iterator is used inside its originating transaction. */
-public class IteratorTxnTracker<T> extends IteratorWrapper<T> {
- private final TransactionalSystem txnSystem;
- private final TxnId txnId;
-
- public IteratorTxnTracker(Iterator<T> iterator, TransactionalSystem txnSystem, TxnId txnId) {
- super(iterator);
- this.txnSystem = Objects.requireNonNull(txnSystem, "TransactionalSystem");
- this.txnId = Objects.requireNonNull(txnId, "TxnId") ;
- }
-
- @Override public boolean hasNext() { check() ; return super.hasNext() ; }
-
- @Override public T next() { check() ; return super.next() ; }
-
- @Override public void remove() { check() ; super.remove() ; }
-
- private void check() {
- Transaction txn = txnSystem.getThreadTransaction();
- if ( txn == null )
- throw new TransactionException("Iterator used outside its original transaction");
- if ( txn != null && txnId.equals(txn.getTxnId()) )
- return ;
- throw new TransactionException("Iterator used inside a different transaction");
- }
-}
\ 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/NodeId.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeId.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeId.java
deleted file mode 100644
index 34dc111..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeId.java
+++ /dev/null
@@ -1,220 +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.apache.jena.sparql.expr.Expr.CMP_EQUAL;
-import static org.seaborne.tdb2.store.NodeIdType.PTR;
-import static org.seaborne.tdb2.store.NodeIdType.*;
-
-import org.apache.jena.atlas.lib.BitsLong;
-import org.apache.jena.atlas.logging.FmtLog;
-import org.apache.jena.graph.Node;
-import org.seaborne.dboe.sys.Sys;
-import org.seaborne.tdb2.sys.SystemTDB;
-
-final
-public class NodeId implements Comparable<NodeId>
-{
- public static final int SIZE = Sys.SizeOfLong ;
-
- public static final NodeId NodeIdInvalid = makeSpecial(0xA1);
- public static final NodeId NodeDoesNotExist = makeSpecial(0xA3);
- public static final NodeId NodeIdAny = makeSpecial(0xA4);
- public static final NodeId NodeIdDefined = makeSpecial(0xA5);
- public static final NodeId NodeIdUndefined = makeSpecial(0xA6);
-
- private static NodeId makeSpecial(long v) {
- // Careful of an initialzer loop (create(type, v1, v2) looks at specials).
- return NodeIdFactory.createValue(SPECIAL, v);
- }
-
- /*package*/ static final boolean enableInlineLiterals = SystemTDB.enableInlineLiterals;
-
- // Internal consistency checks.
- private static final boolean CHECKING = true;
-
- // Code search:
- // [64 bits]
-
-
- // Encoding:
- // 8 bits type, except PTR which is 0 high bit.
- // 24 bits int
- // 64 bit value
- // The high byte of value1==type as integer value
- // In-memory:
- // Long:
- // type PTR high bit zero, then 31+64 bits of value.
- // Inlines:
- // type is 8 bits
- // value1 is 24 bits
- // value2 is 64 bits
- // type is a type and is OR'ed into value1 to store.
- // Short: 64 bit:
- // type PTR high bit zero, then 63 bits of value.
- // Inlines:
- // value1 is not used.
- // value2 is 56 bits
- // type is a type and is OR'ed into value2 to store.
-
- final NodeIdType type;
- final int value1;
- final long value2;
-
- private NodeId(NodeIdType type, int v1, long v2) {
- if ( CHECKING ) check(type, v1, v2);
- this.type = type;
- value1 = v1; // Zero for 64 bit.
- value2 = v2;
- }
-
- private final void check(NodeIdType type, int v1, long v2) {
- if ( type == PTR )
- return;
- if ( type == SPECIAL )
- return;
- // 64 bit NodeId.
- int x = ( type == XSD_DOUBLE )
- ? (int)BitsLong.unpack(v2, 62, 64) // High two bits
- : (int)BitsLong.unpack(v2, 56, 64); // else
- if ( x != 0 )
- FmtLog.warn(getClass(), "Type set in long: type=%s value=%016X", type, v2);
- }
-
- public boolean isPtr() { return type == PTR; }
-
-// public long getPtrLocation() { return value2; }
-// public long getPtrLo() { return value2; }
-// public int getPtrHi() { return value1 & 0x00FFFFFF; }
-
- // 64 bit
- public long getPtrLocation() { return value2; }
- // Long.
-// public long getPtrLo() { return value2; }
-// public int getPtrHi() { return value1; }
-
- public int getTypeValue() { return type.type(); }
-
- public boolean isInline() {
- return isInline(this);
- }
-
- public static boolean isInline(NodeId nodeId) {
- return NodeIdType.isInline(nodeId.type);
- }
-
- public boolean isValue() {
- return type != PTR && NodeIdType.isStorable(type);
- }
-
- // Migration
- public static NodeId inline(Node node) { return NodeIdInline.inline(node); }
- public static boolean hasInlineDatatype(Node node) { return NodeIdInline.hasInlineDatatype(node); }
- public static Node extract(NodeId nodeId) { return NodeIdInline.extract(nodeId); }
-
- // XXX Later.
-// //Static forms only?
-// public boolean isAny() { return isAny(this); }
-// public boolean isDoesNotExist() { return isDoesNotExist(this); }
-// public boolean isDefined() { return isDefined(this); }
-// public boolean isUndefined() { return isDefined(this); }
-//
- public static final boolean isAny(NodeId nodeId) { return nodeId == NodeIdAny || nodeId == null; }
- public static final boolean isDoesNotExist(NodeId nodeId) { return nodeId == NodeDoesNotExist; }
-// public static boolean isDefined(NodeId nodeId) { return nodeId == NodeIdDefined; }
-// public static boolean isUndefined(NodeId nodeId) { return nodeId == NodeIdUndefined; }
-
- /** Create from a long-encoded value */
- /*package*/ static NodeId createRaw(NodeIdType type, long value) {
- return new NodeId(type, 0, value);
- }
-
- /** Create from a (int,long)-encoded value */
- /*package*/ static NodeId createRaw(NodeIdType type, int value1, long value2) {
- return new NodeId(type, value1, value2);
- }
-
- public NodeIdType type() { return type; }
-
- /*package*/ int getValue1() { return value1; }
- /*package*/ long getValue2() { return value2; }
-
- @Override
- public int hashCode() {
- // Ensure all parts have an effect on the 32 bit hash value.
- return value1 ^ ((int)value2) ^ ((int)(value2 >> 32));
- }
-
- @Override
- public boolean equals(Object other) {
- if ( this == other ) return true;
- if ( other == null ) return false;
- if ( !(other instanceof NodeId) ) return false;
- NodeId nOther = ((NodeId)other);
- return equals(nOther, value1, value2);
- }
-
- public boolean equals(NodeId nodeIdOther) {
- if ( nodeIdOther == null ) return false;
- if ( this == nodeIdOther ) return true;
- return equals(nodeIdOther, value1, value2);
- }
-
- /*package*/ static boolean equals(NodeId nodeId, int v1, long v2) {
- return v2 == nodeId.value2 && v1 == nodeId.value1;
- }
- @Override
- public String toString() {
- if ( this == NodeDoesNotExist ) return "[DoesNotExist]";
- if ( this == NodeIdAny ) return "[Any]";
- if ( this == NodeIdInvalid ) return "[Invalid]";
- if ( this == NodeIdDefined ) return "[Defined]";
- if ( this == NodeIdUndefined ) return "[Undefined]";
-
- if ( this.isInline() ) {
- String displayName = this.type().toString();
- return String.format("[%s 0x%014X]", displayName, value2);
- }
- // [64 bits]
- //return String.format("[%08X-%016X]", value1, value2);
- return String.format("[0x%16X]", value2);
- }
-
- // ---- Encoding special - inlines.
-
- /** Compare - provides an ordering of {@code NodeIds}. */
- @Override
- public int compareTo(NodeId other) {
- return compare(this, other);
- }
-
- /** Compare - provides an ordering of {@code NodeIds}. */
- public static int compare(NodeId n1, NodeId n2) {
- int x = Integer.compare(n1.value1, n2.value1);
- if ( x == 0 )
- return CMP_EQUAL;
- return Long.compare(n1.value2, n2.value2);
- }
-
- public final boolean isConcrete() { return isConcrete(this); }
-
- public static final boolean isConcrete(NodeId nodeId) {
- return ! NodeIdType.isSpecial(nodeId.type);
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdFactory.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdFactory.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdFactory.java
deleted file mode 100644
index d8796dd..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdFactory.java
+++ /dev/null
@@ -1,261 +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.PTR;
-import static org.seaborne.tdb2.store.NodeIdType.isSpecial;
-
-import java.nio.ByteBuffer;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.jena.atlas.lib.BitsInt;
-import org.apache.jena.atlas.lib.BitsLong;
-import org.apache.jena.atlas.lib.Bytes;
-import org.seaborne.tdb2.TDBException;
-import org.seaborne.tdb2.store.value.DoubleNode62;
-
-/** Factory for NodeIds, including to/from disk forms via ByteBuffers and byte[].*/
-final
-public class NodeIdFactory
-{
- // On-disk: may be shorter (controlled by get/set ByteBuffer and byte[]).
- // In-memory - always int-long
-
- // XXX Chance for a cache?
-
- private static NodeId create(NodeIdType type, int v1, long v2) {
- if ( isSpecial(type) ) {
- if ( NodeId.equals(NodeId.NodeDoesNotExist, v1, v2) )
- return NodeId.NodeDoesNotExist;
- if ( NodeId.equals(NodeId.NodeIdAny, v1, v2) )
- return NodeId.NodeIdAny;
- if ( NodeId.equals(NodeId.NodeIdDefined, v1, v2) )
- return NodeId.NodeIdDefined;
- if ( NodeId.equals(NodeId.NodeIdDefined, v1, v2) )
- return NodeId.NodeIdDefined;
- if ( NodeId.equals(NodeId.NodeIdUndefined, v1, v2) )
- return NodeId.NodeIdUndefined;
- //throw new IllegalArgumentException("Special not recognized");
- }
- return createNew(type, v1, v2);
- }
-
- public static NodeId createValue(NodeIdType type, long value) {
- // 64 bit.
- return createNew(type, 0, value);
- }
-
- private static NodeId createNew(NodeIdType type, int v1, long v2) {
- return NodeId.createRaw(type, v1, v2);
- }
-
- public static NodeId createPtr(long lo) {
- return createNew(PTR, 0, lo);
- }
-
- /*package*/ /*long*/ static NodeId createPtrLong(int hi, long lo) {
- return create(PTR, hi, lo);
- }
-
- // ---- Create from binary.
-
- // 64 bit create
- private static NodeId create(long value2) {
- if ( !BitsLong.isSet(value2, 63) )
- return createPtr(value2);
- // Inline.
- long v2 = value2;
- if ( BitsLong.isSet(v2, 62) ) {
- // XSD_DOUBLE
- v2 = DoubleNode62.removeType(v2);
- return NodeId.createRaw(NodeIdType.XSD_DOUBLE, v2);
- }
- int t = (int)BitsLong.unpack(v2, 56, 63); // 7 bits
- v2 = BitsLong.clear(v2, 56, 64);
- NodeIdType type = NodeIdType.intToEnum(t);
- if ( type == NodeIdType.SPECIAL )
- throw new TDBException(String.format("Attempt to create a special from a long: 0x%016", v2));
- return NodeId.createRaw(type, v2);
- }
-
- // Long create.
- private static NodeId create(int v1, long v2) {
- if ( !BitsInt.isSet(v1, 32) )
- return createPtrLong(v1, v2);
- int t = v1 >> 24;
- NodeIdType type = NodeIdType.intToEnum(t);
- if ( type == NodeIdType.SPECIAL )
- throw new TDBException(String.format("Attempt to create a special from a long: 0x%016", v2));
- return createNew(type, 0, v2);
- }
-
- // ------- On-disk forms.
- //
-
- /** Not relative - get from position zero */
- public static NodeId get(byte[] b) { return get(b,0); }
-
- // **** 64 bit NodeId ****
- /** Relative {@code ByteBuffer} {@code get} */
- public static NodeId get(ByteBuffer b) {
- long value2 = b.getLong();
- return decode(value2);
- }
-
- public static NodeId get(byte[] b, int idx) {
- long value2 = Bytes.getLong(b, idx);
- return decode(value2);
- }
-
- public static NodeId get(ByteBuffer b, int idx) {
- long value2 = b.getLong(idx);
- return decode(value2);
- }
-
- // 64 bit version
- private static NodeId decode(long value2) {
- return NodeIdFactory.create(value2);
- }
-
- /** Not relative - set at position zero */
- public static void set(NodeId nodeId, byte[] b) {
- long v2 = encode(nodeId);
- Bytes.setLong(v2, b, 0);
- }
-
- private static long encode(NodeId nodeId) {
- long x = nodeId.value2;
- switch(nodeId.type()) {
- case PTR:
- return x;
- case XSD_DOUBLE:
- // XSD_DOUBLE is special.
- // Set value bit (63) and bit 62
- x = DoubleNode62.insertType(x);
- return x ;
- default:
- // Bit 62 is zero - tagt is for doubles.
- x = BitsLong.pack(x, nodeId.getTypeValue(), 56, 62);
- // Set the high, value bit.
- x = BitsLong.set(x, 63);
- return x;
- }
- }
-
- /** Relative {@code set} */
- public static void set(NodeId nodeId, ByteBuffer b) {
- long v2 = encode(nodeId);
- b.putLong(v2);
- }
-
- public static void set(NodeId nodeId, byte[] b, int idx) {
- long v2 = encode(nodeId);
- Bytes.setLong(v2, b, idx);
- }
-
- public static void set(NodeId nodeId, ByteBuffer b, int idx) {
- long v2 = encode(nodeId);
- b.putLong(idx, v2);
- }
-
- public static void setNext(NodeId nodeId, byte[] b, int idx) {
- long v2 = encode(nodeId);
- Bytes.setLong(v2+1, b, idx);
- }
-
- // (int,long) versions : check before use
-// /** Relative {@code ByteBuffer} {@code get} */
-// public static NodeId get(ByteBuffer b) {
-// int value1 = b.getInt();
-// long value2 = b.getLong();
-// return decode(value1,value2);
-// }
-//
-// public static NodeId get(byte[] b, int idx) {
-// int value1 = Bytes.getInt(b, idx);
-// long value2 = Bytes.getLong(b, idx+SystemTDB.SizeOfInt);
-// return decode(value1, value2);
-// }
-//
-// public static NodeId get(ByteBuffer b, int idx) {
-// int value1 = b.getInt(idx);
-// long value2 = b.getLong(idx+SystemTDB.SizeOfInt);
-// return decode(value1,value2);
-// }
-//
-// private static NodeId decode(int value1, long value2) {
-// return NodeIdFactory.create(value1, value2);
-// }
-//
-// /** Not relative - set at position zero */
-// public static void set(NodeId nodeId, byte[] b) {
-// int v1 = encode(nodeId.value1);
-// Bytes.setInt(v1, b, 0);
-// Bytes.setLong(nodeId.value2, b, SystemTDB.SizeOfInt);
-// }
-//
-// /** Relative {@code set} */
-// public static void set(NodeId nodeId, ByteBuffer b) {
-// int v1 = encode(nodeId.value1);
-// b.putInt(v1);
-// b.putLong(nodeId.value2);
-// }
-//
-// public static void set(NodeId nodeId, byte[] b, int idx) {
-// int v1 = encode(nodeId.value1);
-// Bytes.setInt(v1, b, idx);
-// Bytes.setLong(nodeId.value2, b, idx+SystemTDB.SizeOfInt);
-// }
-//
-// public static void set(NodeId nodeId, ByteBuffer b, int idx) {
-// int v1 = encode(nodeId.value1);
-// b.putInt(idx, v1);
-// b.putLong(idx+SystemTDB.SizeOfInt, nodeId.value2);
-// }
-//
-// public static void setNext(NodeId nodeId, byte[] b, int idx) {
-// int v1 = encode(nodeId.value1);
-// long v2 = nodeId.value2;
-// // Unsigned 96 bit add!
-// if ( v2 < 0 ) {
-// if ( v2 == Long.MIN_VALUE )
-// v1++ ;
-// else
-// v2--;
-// } else
-// v2++ ;
-// Bytes.setInt(v1, b, idx);
-// Bytes.setLong(v2, b, idx+Integer.SIZE);
-// }
-// private int encode(NodeId nodeId) {
-// long x = nodeId.value1;
-// if ( nodeId.isPtr() )
-// return x;
-// x = BitsInt.pack(x, nodeId.getTypeValue(), 24, 32);
-// return x;
-// }
-
-
-
-
- private static AtomicInteger counter = new AtomicInteger(0xB0);
- public static NodeId genUnique() {
- return NodeIdFactory.create(NodeIdType.SPECIAL, counter.incrementAndGet(), 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdInline.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdInline.java b/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdInline.java
deleted file mode 100644
index f2b8c22..0000000
--- a/jena-db/jena-tdb2/src/main/java/org/seaborne/tdb2/store/NodeIdInline.java
+++ /dev/null
@@ -1,329 +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.PTR;
-import static org.seaborne.tdb2.store.NodeIdType.*;
-import static org.seaborne.tdb2.store.NodeIdType.XSD_DATE;
-import static org.seaborne.tdb2.store.NodeIdType.XSD_DATETIME;
-import static org.seaborne.tdb2.store.NodeIdType.XSD_DECIMAL;
-import static org.seaborne.tdb2.store.NodeIdType.XSD_FLOAT;
-
-import java.math.BigDecimal;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.jena.atlas.logging.Log;
-import org.apache.jena.datatypes.RDFDatatype;
-import org.apache.jena.datatypes.xsd.XSDDatatype;
-import org.apache.jena.ext.com.google.common.collect.BiMap;
-import org.apache.jena.ext.com.google.common.collect.EnumHashBiMap;
-import org.apache.jena.graph.Node;
-import org.apache.jena.graph.NodeFactory;
-import org.apache.jena.graph.impl.LiteralLabel;
-import org.apache.jena.sparql.graph.NodeConst;
-import org.apache.jena.sparql.util.NodeUtils;
-import org.apache.jena.sparql.util.Utils;
-import org.seaborne.tdb2.TDBException;
-import org.seaborne.tdb2.store.value.*;
-
-/** Encoding values in a {@link NodeId}.
- *
- * TDB2 encoding:
- * <ul>
- * <li>High bit (bit 63) 0 means the node is in the object table (PTR).
- * <li>High bit (bit 63) 1, bit 62 1: double as 62 bits. See {@link DoubleNode62}.
- * <li>High bit (bit 63) 1, bit 62 0: 6 bits of type, 56 bits of value.
- * </ul>
- *
- * If a value would not fit, it will be stored externally so there is no
- * guarantee that all integers, say, are store inline.
- *
- * <ul>
- * <li>Integer format: signed 56 bit number, the type filed has the XSD type.
- * <li>Decimal format: 8 bits scale, 48bits of signed valued. See {@link DecimalNode56}.
- * <li>Date and DateTime
- * <li>Boolean
- * <li>Float
- * </ul>
- *
- * @see IntegerNode
- * @see DecimalNode56
- * @see DoubleNode62
- * @see DateTimeNode DateTimeNode for xsd:date and xsd:DateTime
- * @see FloatNode
- */
-public class NodeIdInline {
- /** Datatypes that are candidates for inlining */
- private static Set<RDFDatatype> datatypes = new HashSet<>();
- static {
- datatypes.add(XSDDatatype.XSDdecimal);
- datatypes.add(XSDDatatype.XSDinteger);
- datatypes.add(XSDDatatype.XSDdouble);
- datatypes.add(XSDDatatype.XSDfloat);
-
- datatypes.add(XSDDatatype.XSDlong);
- datatypes.add(XSDDatatype.XSDint);
- datatypes.add(XSDDatatype.XSDshort);
- datatypes.add(XSDDatatype.XSDbyte);
-
- datatypes.add(XSDDatatype.XSDpositiveInteger);
- datatypes.add(XSDDatatype.XSDnonPositiveInteger);
- datatypes.add(XSDDatatype.XSDnegativeInteger);
- datatypes.add(XSDDatatype.XSDnonNegativeInteger);
-
- datatypes.add(XSDDatatype.XSDunsignedLong);
- datatypes.add(XSDDatatype.XSDunsignedInt);
- datatypes.add(XSDDatatype.XSDunsignedShort);
- datatypes.add(XSDDatatype.XSDunsignedByte);
- datatypes.add(XSDDatatype.XSDdateTimeStamp);
- datatypes.add(XSDDatatype.XSDdateTime);
- datatypes.add(XSDDatatype.XSDdate);
- datatypes.add(XSDDatatype.XSDboolean);
- };
-
- // Integer derived types.
- private static BiMap<NodeIdType, RDFDatatype> derivedTypeMap = EnumHashBiMap.create(NodeIdType.class);
- static {
- derivedTypeMap.put(NodeIdType.XSD_LONG, XSDDatatype.XSDlong);
- derivedTypeMap.put(NodeIdType.XSD_INT, XSDDatatype.XSDint);
- derivedTypeMap.put(NodeIdType.XSD_SHORT, XSDDatatype.XSDshort);
- derivedTypeMap.put(NodeIdType.XSD_BYTE, XSDDatatype.XSDbyte);
-
- derivedTypeMap.put(NodeIdType.XSD_POSITIVE_INTEGER, XSDDatatype.XSDpositiveInteger);
- derivedTypeMap.put(NodeIdType.XSD_NON_POSITIVE_INTEGER, XSDDatatype.XSDnonPositiveInteger);
- derivedTypeMap.put(NodeIdType.XSD_NEGATIVE_INTEGER, XSDDatatype.XSDnegativeInteger);
- derivedTypeMap.put(NodeIdType.XSD_NON_NEGATIVE_INTEGER, XSDDatatype.XSDnonNegativeInteger);
-
- derivedTypeMap.put(NodeIdType.XSD_UNSIGNEDLONG, XSDDatatype.XSDunsignedLong);
- derivedTypeMap.put(NodeIdType.XSD_UNSIGNEDINT, XSDDatatype.XSDunsignedInt);
- derivedTypeMap.put(NodeIdType.XSD_UNSIGNEDSHORT, XSDDatatype.XSDunsignedShort);
- derivedTypeMap.put(NodeIdType.XSD_UNSIGNEDBYTE, XSDDatatype.XSDunsignedByte);
- }
-
- /** Encode a node as an inline literal. Return null if it can't be done */
- public static NodeId inline(Node node) {
- if ( node == null ) {
- Log.warn(NodeId.class, "Null node: " + node);
- return null;
- }
-
- if ( !NodeId.enableInlineLiterals )
- return null;
-
- if ( !node.isLiteral() )
- return null;
-
- if ( NodeUtils.isSimpleString(node) || NodeUtils.isLangString(node) )
- return null;
-
- try { return inline$(node); }
- catch (Throwable th) {
- Log.warn(NodeId.class, "Failed to process "+node);
- return null;
- }
- }
-
- /** Return true if this node has a datatype that look like it is inlineable.
- * The node may still be out of range (e.g. very large integer).
- * Only inline(Node)->NodeId can determine that.
- */
- public static boolean hasInlineDatatype(Node node) {
- if ( ! node.isLiteral() )
- return false;
- RDFDatatype dtn = node.getLiteralDatatype();
- return datatypes.contains(dtn);
- }
-
- private static NodeId inline$(Node node) {
- if ( ! hasInlineDatatype(node) )
- return null;
- LiteralLabel lit = node.getLiteral();
- // Decimal is a valid supertype of integer but we handle integers and decimals
- // differently.
-
- if ( node.getLiteralDatatype().equals(XSDDatatype.XSDdecimal) ) {
- // Check lexical form.
- if ( !XSDDatatype.XSDdecimal.isValidLiteral(lit) )
- return null;
-
- // Not lit.getValue() because that may be a narrower type e.g. Integer.
- // .trim is how Jena does it but it rather savage. spc, \n \r \t.
- // But at this point we know it's a valid literal so the excessive
- // chopping by .trim is safe.
- BigDecimal decimal = new BigDecimal(lit.getLexicalForm().trim());
-
- // Does range checking.
- DecimalNode56 dn = DecimalNode56.valueOf(decimal);
- // null is "does not fit"
- if ( dn != null )
- // setType
- return NodeId.createRaw(XSD_DECIMAL, dn.pack());
- else
- return null;
- } else {
- // Not decimal.
- if ( XSDDatatype.XSDinteger.isValidLiteral(lit) ) {
- // Check length of lexical form to see if it's in range of a long.
- // Long.MAX_VALUE = 9223372036854775807
- // Long.MIN_VALUE = -9223372036854775808
- // 9,223,372,036,854,775,807 is 19 digits.
-
- // Quick check.
- if ( lit.getLexicalForm().length() > 19 )
- return null;
-
- // Derived types.
- NodeIdType type = derivedTypeMap.inverse().getOrDefault(lit.getDatatype(), NodeIdType.XSD_INTEGER);
-
- try {
- long v = ((Number)lit.getValue()).longValue();
- v = IntegerNode.pack56(v);
- // Value -1 is "does not fit"
- if ( v == -1 )
- return null;
- return NodeId.createRaw(type, v);
- }
- // Out of range for the type, not a long etc etc.
- catch (Throwable ex) { return null; }
- }
- }
-
- if ( XSDDatatype.XSDdouble.isValidLiteral(lit) ) {
- double d = ((Number)lit.getValue()).doubleValue();
- long v = DoubleNode62.pack(d);
- if ( v == DoubleNode62.NO_ENCODING )
- return null ;
- // The special encoding of XSD_DOUBLE is handling in the "toBytes" and "toByteBuffer" operations.
- return NodeId.createRaw(XSD_DOUBLE, v);
- }
-
- if ( XSDDatatype.XSDfloat.isValidLiteral(lit) ) {
- float f = ((Number)lit.getValue()).floatValue();
- long v = FloatNode.pack(f);
- return NodeId.createRaw(XSD_FLOAT, v);
- }
-
- if ( lit.getDatatype().equals(XSDDatatype.XSDdateTimeStamp) && XSDDatatype.XSDdateTimeStamp.isValidLiteral(lit) ) {
- long v = DateTimeNode.packDateTime(lit.getLexicalForm());
- if ( v == -1 )
- return null;
- return NodeId.createRaw(XSD_DATETIMESTAMP, v);
- }
- if ( XSDDatatype.XSDdateTime.isValidLiteral(lit) ) {
- // Could use the Jena/XSDDateTime object here rather than reparse the lexical form.
- // But this works and it's close to a release ...
- long v = DateTimeNode.packDateTime(lit.getLexicalForm());
- if ( v == -1 )
- return null;
- return NodeId.createRaw(XSD_DATETIME, v);
- }
-
- if ( XSDDatatype.XSDdate.isValidLiteral(lit) ) {
- long v = DateTimeNode.packDate(lit.getLexicalForm());
- if ( v == -1 )
- return null;
- return NodeId.createRaw(XSD_DATE, v);
- }
-
- if ( XSDDatatype.XSDboolean.isValidLiteral(lit) ) {
- long v = 0;
- boolean b = (Boolean)lit.getValue();
- // return new NodeValueBoolean(b, node);
- if ( b )
- v = v | 0x01;
- return NodeId.createRaw(XSD_BOOLEAN, v);
- }
-
- return null;
- }
-
- /** Decode an inline nodeID, return null if not an inline node */
- public static Node extract(NodeId nodeId) {
- if ( nodeId == NodeId.NodeDoesNotExist )
- return null;
-
- NodeIdType type = nodeId.type();
- if ( type == PTR || type == NodeIdType.SPECIAL)
- return null;
- switch (type) {
-// case PTR: return null;
-// case SPECIAL: return null;
- case XSD_INTEGER :
- // Derived from 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:
- {
- long val = IntegerNode.unpack56(nodeId.value2);
- RDFDatatype dt = derivedTypeMap.getOrDefault(type, XSDDatatype.XSDinteger);
- Node n = NodeFactory.createLiteral(Long.toString(val), dt);
- return n;
- }
- case XSD_DECIMAL : {
- BigDecimal d = DecimalNode56.unpackAsBigDecimal(nodeId.value2);
- String x = d.toPlainString();
- return NodeFactory.createLiteral(x, XSDDatatype.XSDdecimal);
- }
- case XSD_DOUBLE: {
- double d = DoubleNode62.unpack(nodeId.value2);
- String xsdStr = Utils.stringForm(d);
- Node n = NodeFactory.createLiteral(xsdStr, XSDDatatype.XSDdouble);
- return n ;
- }
- case XSD_FLOAT: {
- float f = FloatNode.unpack(nodeId.value2);
- String xsdStr = Utils.stringForm(f);
- Node n = NodeFactory.createLiteral(xsdStr, XSDDatatype.XSDfloat);
- return n ;
- }
- case XSD_DATETIMESTAMP:
- case XSD_DATETIME: {
- RDFDatatype dt = (type==XSD_DATETIMESTAMP) ? XSDDatatype.XSDdateTimeStamp : XSDDatatype.XSDdateTime;
- long val = nodeId.getValue2();
- String lex = DateTimeNode.unpackDateTime(val);
- return NodeFactory.createLiteral(lex, dt);
- }
- case XSD_DATE : {
- long val = nodeId.getValue2();
- String lex = DateTimeNode.unpackDate(val);
- return NodeFactory.createLiteral(lex, XSDDatatype.XSDdate);
- }
- case XSD_BOOLEAN : {
- long val = nodeId.getValue2();
- if ( val == 0 )
- return NodeConst.nodeFalse;
- if ( val == 1 )
- return NodeConst.nodeTrue;
- throw new TDBException("Unrecognized boolean node id : " + val);
- }
- default :
- throw new TDBException("Unrecognized node id type: " + type);
- }
- }
-}