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/09/28 16:06:39 UTC
[087/100] [abbrv] jena git commit: JENA-1397: Rename java packages
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexConst.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexConst.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexConst.java
new file mode 100644
index 0000000..7e07cda
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexConst.java
@@ -0,0 +1,53 @@
+/*
+ * 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.apache.jena.dboe.index;
+
+import org.apache.jena.dboe.base.block.FileMode;
+import org.apache.jena.dboe.sys.SystemIndex;
+
+public class IndexConst {
+
+ private static IndexParams stdParams = new IndexParamsStd() ;
+ public static IndexParams getDftParams() { return stdParams ; }
+
+ private static class IndexParamsStd implements IndexParams {
+
+ @Override
+ public FileMode getFileMode() {
+ return SystemIndex.fileMode() ;
+ }
+
+ @Override
+ public Integer getBlockSize() {
+ return SystemIndex.BlockSize ;
+ }
+
+ @Override
+ public Integer getBlockReadCacheSize() {
+ return SystemIndex.BlockReadCacheSize ;
+ }
+
+ @Override
+ public Integer getBlockWriteCacheSize() {
+ return SystemIndex.BlockWriteCacheSize ;
+ }
+
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexLogger.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexLogger.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexLogger.java
new file mode 100644
index 0000000..04ca573
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexLogger.java
@@ -0,0 +1,65 @@
+/*
+ * 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.apache.jena.dboe.index;
+
+import java.util.Iterator ;
+
+import org.apache.jena.dboe.base.record.Record;
+import org.slf4j.Logger ;
+
+public final class IndexLogger extends IndexWrapper
+{
+ private final Logger log ;
+
+ public IndexLogger(RangeIndex rIdx, Logger log)
+ {
+ super(rIdx) ;
+ this.log = log ;
+ }
+
+ @Override
+ public boolean insert(Record record)
+ {
+ log.info("Add: {}", record) ;
+ return super.insert(record) ;
+ }
+
+ @Override
+ public boolean delete(Record record)
+ {
+ log.info("Delete: {}", record) ;
+ return super.delete(record) ;
+ }
+
+ @Override
+ public Record find(Record record)
+ {
+ log.info("Find: {}", record) ;
+ Record r2 = super.find(record) ;
+ log.info("Find: "+record+" ==> "+r2) ;
+ return r2 ;
+ }
+
+ @Override
+ public Iterator<Record> iterator()
+ {
+ log.info("iterator()") ;
+ return super.iterator() ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexMap.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexMap.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexMap.java
new file mode 100644
index 0000000..47fffe5
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexMap.java
@@ -0,0 +1,172 @@
+/*
+ * 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.apache.jena.dboe.index;
+
+import java.util.Arrays ;
+import java.util.HashMap ;
+import java.util.Iterator ;
+import java.util.Map ;
+
+import org.apache.jena.atlas.lib.Bytes ;
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.dboe.base.record.RecordFactory;
+
+/** A simple implementation of {@link Index} for testing */
+public class IndexMap implements Index
+{
+ private final Map<ByteArray, ByteArray> index = new HashMap<>() ;
+ private final RecordFactory recordFactory ;
+
+ public IndexMap(RecordFactory recordFactory)
+ {
+ this.recordFactory = recordFactory ;
+ }
+
+ @Override
+ public Record find(Record record)
+ {
+ ByteArray k = wrap(record.getKey()) ;
+ ByteArray v = index.get(k) ;
+ if ( v == null )
+ return null ;
+ return record(k, v) ;
+ }
+
+ @Override
+ public boolean contains(Record record)
+ {
+ Record r = find(record) ;
+ if ( r == null )
+ return false ;
+ if ( ! recordFactory.hasValue() )
+ return true ;
+ return Bytes.compare(record.getValue(), r.getValue()) == 0 ;
+ }
+
+ @Override
+ public boolean insert(Record record)
+ {
+ Record r = find(record) ;
+ if ( r != null && r.equals(record) )
+ return false ;
+ index.put(wrap(record.getKey()), wrap(record.getValue())) ;
+ return true ;
+ }
+
+ @Override
+ public boolean delete(Record record)
+ {
+ ByteArray x = index.remove(wrap(record.getKey())) ;
+ if ( x == null )
+ return false ;
+ return true ;
+ }
+
+ @Override
+ public Iterator<Record> iterator()
+ {
+ return new Iterator<Record>() {
+
+ Iterator<Map.Entry<ByteArray, ByteArray>> iter = index.entrySet().iterator() ;
+
+ @Override
+ public boolean hasNext()
+ {
+ return iter.hasNext() ;
+ }
+
+ @Override
+ public Record next()
+ {
+ Map.Entry<ByteArray, ByteArray> e = iter.next() ;
+ return record(e.getKey(), e.getValue()) ;
+ }
+
+ @Override
+ public void remove()
+ { throw new UnsupportedOperationException() ;}
+ } ;
+
+ }
+
+ @Override
+ public RecordFactory getRecordFactory()
+ {
+ return recordFactory ;
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ return index.isEmpty() ;
+ }
+
+ @Override
+ public void clear()
+ {
+ index.clear() ;
+ }
+
+ @Override
+ public void check()
+ {}
+
+ @Override
+ public long size()
+ {
+ return index.size() ;
+ }
+
+ @Override
+ public void sync()
+ {}
+
+ @Override
+ public void close()
+ {}
+
+ private static ByteArray wrap(byte[] b) { return new ByteArray(b) ; }
+ private Record record(ByteArray k, ByteArray v) { return recordFactory.create(k.bytes, v.bytes) ; }
+
+ private static class ByteArray
+ {
+ byte[] bytes ;
+ ByteArray(byte[] bytes) { this.bytes = bytes ; }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31 ;
+ int result = 1 ;
+ result = prime * result + Arrays.hashCode(bytes) ;
+ return result ;
+ }
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj) return true ;
+ if (obj == null) return false ;
+ if (getClass() != obj.getClass()) return false ;
+ ByteArray other = (ByteArray)obj ;
+ if (!Arrays.equals(bytes, other.bytes)) return false ;
+ return true ;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexParams.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexParams.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexParams.java
new file mode 100644
index 0000000..d2a077e
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexParams.java
@@ -0,0 +1,38 @@
+/*
+ * 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.apache.jena.dboe.index;
+
+import org.apache.jena.dboe.base.block.BlockParams;
+import org.apache.jena.dboe.base.block.FileMode;
+
+public interface IndexParams extends BlockParams {
+ /** File Mode */
+ @Override public FileMode getFileMode() ;
+
+ /** Block size - this is only configurable when the on-disk are created.
+ * After that, the same value as at creation must be used each time.
+ */
+ @Override public Integer getBlockSize() ;
+
+ /** Block read cache size (mmap'ed files do not have a block cache)*/
+ @Override public Integer getBlockReadCacheSize() ;
+
+ /** Block write cache size (mmap'ed files do not have a block cache)*/
+ @Override public Integer getBlockWriteCacheSize() ;
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexWrapper.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexWrapper.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexWrapper.java
new file mode 100644
index 0000000..5439831
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexWrapper.java
@@ -0,0 +1,92 @@
+/*
+ * 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.apache.jena.dboe.index ;
+
+import java.util.Iterator ;
+
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.dboe.base.record.RecordFactory;
+
+public class IndexWrapper implements Index {
+ protected final Index index ;
+
+ public IndexWrapper(Index idx) {
+ this.index = idx ;
+ }
+
+ @Override
+ public Record find(Record record) {
+ return index.find(record) ;
+ }
+
+ @Override
+ public boolean contains(Record record) {
+ return index.contains(record) ;
+ }
+
+ @Override
+ public boolean insert(Record record) {
+ return index.insert(record) ;
+ }
+
+ @Override
+ public boolean delete(Record record) {
+ return index.delete(record) ;
+ }
+
+ @Override
+ public Iterator<Record> iterator() {
+ return index.iterator() ;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return index.isEmpty() ;
+ }
+
+ @Override
+ public void clear() {
+ index.clear() ;
+ }
+
+ @Override
+ public void sync() {
+ index.sync() ;
+ }
+
+ @Override
+ public void close() {
+ index.close() ;
+ }
+
+ @Override
+ public RecordFactory getRecordFactory() {
+ return index.getRecordFactory() ;
+ }
+
+ @Override
+ public void check() {
+ index.check() ;
+ }
+
+ @Override
+ public long size() {
+ return index.size() ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndex.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndex.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndex.java
new file mode 100644
index 0000000..a09611b
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndex.java
@@ -0,0 +1,39 @@
+/*
+ * 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.apache.jena.dboe.index;
+
+import java.util.Iterator ;
+
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.dboe.base.record.RecordMapper;
+
+
+public interface RangeIndex extends Index
+{
+ /** Return records between min (inclusive) and max (exclusive), based on the record keys */
+ public Iterator<Record> iterator(Record recordMin, Record recordMax) ;
+
+ public <X> Iterator<X> iterator(Record recordMin, Record recordMax, RecordMapper<X> mapper) ;
+
+ /** Return the record containing the least key - may or may not have the associated value */
+ public Record minKey() ;
+
+ /** Return the record containing the greatest key - may or may not have the associated value */
+ public Record maxKey() ;
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndexLogger.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndexLogger.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndexLogger.java
new file mode 100644
index 0000000..20960e4
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndexLogger.java
@@ -0,0 +1,72 @@
+/*
+ * 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.apache.jena.dboe.index;
+
+import java.util.Iterator ;
+
+import org.apache.jena.dboe.base.record.Record;
+import org.slf4j.Logger ;
+
+public final class RangeIndexLogger extends RangeIndexWrapper
+{
+ private final Logger log ;
+
+ public RangeIndexLogger(RangeIndex rIdx, Logger log)
+ {
+ super(rIdx) ;
+ this.log = log ;
+ }
+
+ @Override
+ public boolean insert(Record record)
+ {
+ log.info("Add: "+record) ;
+ return super.insert(record) ;
+ }
+
+ @Override
+ public boolean delete(Record record)
+ {
+ log.info("Delete: "+record) ;
+ return super.delete(record) ;
+ }
+
+ @Override
+ public Record find(Record record)
+ {
+ log.info("Find: "+record) ;
+ Record r2 = super.find(record) ;
+ log.info("Find: "+record+" ==> "+r2) ;
+ return r2 ;
+ }
+
+ @Override
+ public Iterator<Record> iterator()
+ {
+ log.info("iterator()") ;
+ return super.iterator() ;
+ }
+
+ @Override
+ public Iterator<Record> iterator(Record minRec, Record maxRec)
+ {
+ log.info("iterator("+minRec+", "+maxRec+")") ;
+ return super.iterator(minRec, maxRec) ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndexWrapper.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndexWrapper.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndexWrapper.java
new file mode 100644
index 0000000..964db14
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/RangeIndexWrapper.java
@@ -0,0 +1,106 @@
+/*
+ * 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.apache.jena.dboe.index;
+
+import java.util.Iterator ;
+
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.dboe.base.record.RecordFactory;
+import org.apache.jena.dboe.base.record.RecordMapper;
+
+public class RangeIndexWrapper implements RangeIndex
+{
+ // Could extend IndexWrapper but it's nice to have one place to look and set breakpoints.
+ protected final RangeIndex rIndex ;
+
+ public RangeIndexWrapper(RangeIndex rIdx) { this.rIndex = rIdx ; }
+
+ @Override
+ public Record find(Record record)
+ { return rIndex.find(record) ; }
+
+ @Override
+ public boolean contains(Record record)
+ { return rIndex.contains(record) ; }
+
+ @Override
+ public Record minKey()
+ { return rIndex.minKey() ; }
+
+ @Override
+ public Record maxKey()
+ { return rIndex.maxKey() ; }
+
+ @Override
+ public boolean insert(Record record)
+ { return rIndex.insert(record) ; }
+
+ @Override
+ public boolean delete(Record record)
+ { return rIndex.delete(record) ; }
+
+// public Record addAndReturnOld(Record record)
+// { return bpt.addAndReturnOld(record) ; }
+
+// public Record deleteAndReturnOld(Record record)
+// { return bpt.deleteAndReturnOld(record) ; }
+
+ @Override
+ public Iterator<Record> iterator()
+ { return rIndex.iterator() ; }
+
+ @Override
+ public Iterator<Record> iterator(Record minRec, Record maxRec)
+ { return rIndex.iterator(minRec, maxRec) ; }
+
+ @Override
+ public <X> Iterator<X> iterator(Record minRec, Record maxRec, RecordMapper<X> mapper)
+ { return rIndex.iterator(minRec, maxRec, mapper) ; }
+
+ @Override
+ public boolean isEmpty()
+ { return rIndex.isEmpty() ; }
+
+ @Override
+ public void clear()
+ { rIndex.clear() ; }
+
+ @Override
+ public void sync()
+ { rIndex.sync() ; }
+
+ @Override
+ public void close()
+ { rIndex.close() ; }
+
+ public RangeIndex getWrapped()
+ { return rIndex ; }
+
+ @Override
+ public RecordFactory getRecordFactory()
+ { return rIndex.getRecordFactory() ; }
+
+ @Override
+ public void check()
+ { rIndex.check() ; }
+
+ @Override
+ public long size()
+ { return rIndex.size() ; }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/Index.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/Index.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/Index.java
deleted file mode 100644
index c6b3919..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/Index.java
+++ /dev/null
@@ -1,92 +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.dboe.index;
-
-import java.util.Iterator ;
-import java.util.stream.Stream ;
-
-import org.apache.jena.atlas.lib.Closeable ;
-import org.apache.jena.atlas.lib.Sync ;
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.base.record.RecordFactory ;
-
-public interface Index extends Iterable<Record>, Sync, Closeable
-{
- /** Find one record - and return the record actually in the index (may have a value part) */
- public Record find(Record record) ;
-
- /** Return whether the index contains the record or not. */
- public boolean contains(Record record) ;
-
- /** Insert a record - return true if an insertion was actually needed */
- public boolean insert(Record record) ;
-
- /** Delete a record - Return true if a record was actually removed */
- public boolean delete(Record record) ;
-
-// public default void bulkInsert(Collection<Record> inserts) {
-// for ( Record r : inserts )
-// insert(r) ;
-// }
-//
-// public default void bulkDelete(Collection<Record> inserts) {
-// for ( Record r : inserts )
-// delete(r) ;
-// }
-
- /** Bulk changes as given by a stream of changes.
- * This is operations consumes the stream.
- * @param changes
- */
- public default void bulkChanges(Stream<IndexChange> changes) {
- changes.forEach(chg -> {
- switch (chg.action) {
- case ADD :
- insert(chg.record) ;
- break ;
- case DELETE :
- delete(chg.record) ;
- break ;
- }
- }) ;
- }
-
- /** Iterate over the whole index */
- @Override
- public Iterator<Record> iterator() ;
-
- /** Get the Record factory associated with this index */
- public RecordFactory getRecordFactory() ;
-
- /** Close the index - can not be used again through this object */
- @Override
- public void close() ;
-
- /** Answer whether the index is empty or not. May return false for unknown or meaningless */
- public boolean isEmpty() ;
-
- /** Clear the index */
- public void clear() ;
-
- /** Perform checks on this index */
- public void check() ;
-
- /** Return size if known else return -1 : does not count the peristent storage */
- public long size() ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexChange.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexChange.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexChange.java
deleted file mode 100644
index 444fcfd..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexChange.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.dboe.index;
-
-import java.util.Objects ;
-
-import org.seaborne.dboe.base.record.Record ;
-
-import org.apache.jena.sparql.core.DatasetChanges ;
-
-/** Temporary class to refine what to put into Jena itself.
- * @see DatasetChanges
- */
-public class IndexChange {
- enum Action { ADD, DELETE }
- final Action action ;
- final Record record ;
- public IndexChange(Action action, Record record) {
- Objects.requireNonNull(action, "Action can not be null") ;
- Objects.requireNonNull(record, "Record can not be null") ;
- this.action = action ;
- this.record = record ;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexConst.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexConst.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexConst.java
deleted file mode 100644
index a6e9722..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexConst.java
+++ /dev/null
@@ -1,53 +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.dboe.index;
-
-import org.seaborne.dboe.base.block.FileMode ;
-import org.seaborne.dboe.sys.SystemIndex ;
-
-public class IndexConst {
-
- private static IndexParams stdParams = new IndexParamsStd() ;
- public static IndexParams getDftParams() { return stdParams ; }
-
- private static class IndexParamsStd implements IndexParams {
-
- @Override
- public FileMode getFileMode() {
- return SystemIndex.fileMode() ;
- }
-
- @Override
- public Integer getBlockSize() {
- return SystemIndex.BlockSize ;
- }
-
- @Override
- public Integer getBlockReadCacheSize() {
- return SystemIndex.BlockReadCacheSize ;
- }
-
- @Override
- public Integer getBlockWriteCacheSize() {
- return SystemIndex.BlockWriteCacheSize ;
- }
-
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexLogger.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexLogger.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexLogger.java
deleted file mode 100644
index 212a99f..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexLogger.java
+++ /dev/null
@@ -1,65 +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.dboe.index;
-
-import java.util.Iterator ;
-
-import org.seaborne.dboe.base.record.Record ;
-import org.slf4j.Logger ;
-
-public final class IndexLogger extends IndexWrapper
-{
- private final Logger log ;
-
- public IndexLogger(RangeIndex rIdx, Logger log)
- {
- super(rIdx) ;
- this.log = log ;
- }
-
- @Override
- public boolean insert(Record record)
- {
- log.info("Add: {}", record) ;
- return super.insert(record) ;
- }
-
- @Override
- public boolean delete(Record record)
- {
- log.info("Delete: {}", record) ;
- return super.delete(record) ;
- }
-
- @Override
- public Record find(Record record)
- {
- log.info("Find: {}", record) ;
- Record r2 = super.find(record) ;
- log.info("Find: "+record+" ==> "+r2) ;
- return r2 ;
- }
-
- @Override
- public Iterator<Record> iterator()
- {
- log.info("iterator()") ;
- return super.iterator() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexMap.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexMap.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexMap.java
deleted file mode 100644
index f47ed95..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexMap.java
+++ /dev/null
@@ -1,172 +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.dboe.index;
-
-import java.util.Arrays ;
-import java.util.HashMap ;
-import java.util.Iterator ;
-import java.util.Map ;
-
-import org.apache.jena.atlas.lib.Bytes ;
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.base.record.RecordFactory ;
-
-/** A simple implementation of {@link Index} for testing */
-public class IndexMap implements Index
-{
- private final Map<ByteArray, ByteArray> index = new HashMap<>() ;
- private final RecordFactory recordFactory ;
-
- public IndexMap(RecordFactory recordFactory)
- {
- this.recordFactory = recordFactory ;
- }
-
- @Override
- public Record find(Record record)
- {
- ByteArray k = wrap(record.getKey()) ;
- ByteArray v = index.get(k) ;
- if ( v == null )
- return null ;
- return record(k, v) ;
- }
-
- @Override
- public boolean contains(Record record)
- {
- Record r = find(record) ;
- if ( r == null )
- return false ;
- if ( ! recordFactory.hasValue() )
- return true ;
- return Bytes.compare(record.getValue(), r.getValue()) == 0 ;
- }
-
- @Override
- public boolean insert(Record record)
- {
- Record r = find(record) ;
- if ( r != null && r.equals(record) )
- return false ;
- index.put(wrap(record.getKey()), wrap(record.getValue())) ;
- return true ;
- }
-
- @Override
- public boolean delete(Record record)
- {
- ByteArray x = index.remove(wrap(record.getKey())) ;
- if ( x == null )
- return false ;
- return true ;
- }
-
- @Override
- public Iterator<Record> iterator()
- {
- return new Iterator<Record>() {
-
- Iterator<Map.Entry<ByteArray, ByteArray>> iter = index.entrySet().iterator() ;
-
- @Override
- public boolean hasNext()
- {
- return iter.hasNext() ;
- }
-
- @Override
- public Record next()
- {
- Map.Entry<ByteArray, ByteArray> e = iter.next() ;
- return record(e.getKey(), e.getValue()) ;
- }
-
- @Override
- public void remove()
- { throw new UnsupportedOperationException() ;}
- } ;
-
- }
-
- @Override
- public RecordFactory getRecordFactory()
- {
- return recordFactory ;
- }
-
- @Override
- public boolean isEmpty()
- {
- return index.isEmpty() ;
- }
-
- @Override
- public void clear()
- {
- index.clear() ;
- }
-
- @Override
- public void check()
- {}
-
- @Override
- public long size()
- {
- return index.size() ;
- }
-
- @Override
- public void sync()
- {}
-
- @Override
- public void close()
- {}
-
- private static ByteArray wrap(byte[] b) { return new ByteArray(b) ; }
- private Record record(ByteArray k, ByteArray v) { return recordFactory.create(k.bytes, v.bytes) ; }
-
- private static class ByteArray
- {
- byte[] bytes ;
- ByteArray(byte[] bytes) { this.bytes = bytes ; }
-
- @Override
- public int hashCode()
- {
- final int prime = 31 ;
- int result = 1 ;
- result = prime * result + Arrays.hashCode(bytes) ;
- return result ;
- }
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj) return true ;
- if (obj == null) return false ;
- if (getClass() != obj.getClass()) return false ;
- ByteArray other = (ByteArray)obj ;
- if (!Arrays.equals(bytes, other.bytes)) return false ;
- return true ;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexParams.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexParams.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexParams.java
deleted file mode 100644
index cca36f1..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexParams.java
+++ /dev/null
@@ -1,38 +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.dboe.index;
-
-import org.seaborne.dboe.base.block.BlockParams ;
-import org.seaborne.dboe.base.block.FileMode ;
-
-public interface IndexParams extends BlockParams {
- /** File Mode */
- @Override public FileMode getFileMode() ;
-
- /** Block size - this is only configurable when the on-disk are created.
- * After that, the same value as at creation must be used each time.
- */
- @Override public Integer getBlockSize() ;
-
- /** Block read cache size (mmap'ed files do not have a block cache)*/
- @Override public Integer getBlockReadCacheSize() ;
-
- /** Block write cache size (mmap'ed files do not have a block cache)*/
- @Override public Integer getBlockWriteCacheSize() ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexWrapper.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexWrapper.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexWrapper.java
deleted file mode 100644
index 3eda876..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/IndexWrapper.java
+++ /dev/null
@@ -1,92 +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.dboe.index ;
-
-import java.util.Iterator ;
-
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.base.record.RecordFactory ;
-
-public class IndexWrapper implements Index {
- protected final Index index ;
-
- public IndexWrapper(Index idx) {
- this.index = idx ;
- }
-
- @Override
- public Record find(Record record) {
- return index.find(record) ;
- }
-
- @Override
- public boolean contains(Record record) {
- return index.contains(record) ;
- }
-
- @Override
- public boolean insert(Record record) {
- return index.insert(record) ;
- }
-
- @Override
- public boolean delete(Record record) {
- return index.delete(record) ;
- }
-
- @Override
- public Iterator<Record> iterator() {
- return index.iterator() ;
- }
-
- @Override
- public boolean isEmpty() {
- return index.isEmpty() ;
- }
-
- @Override
- public void clear() {
- index.clear() ;
- }
-
- @Override
- public void sync() {
- index.sync() ;
- }
-
- @Override
- public void close() {
- index.close() ;
- }
-
- @Override
- public RecordFactory getRecordFactory() {
- return index.getRecordFactory() ;
- }
-
- @Override
- public void check() {
- index.check() ;
- }
-
- @Override
- public long size() {
- return index.size() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndex.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndex.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndex.java
deleted file mode 100644
index e72a3d6..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndex.java
+++ /dev/null
@@ -1,39 +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.dboe.index;
-
-import java.util.Iterator ;
-
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.base.record.RecordMapper ;
-
-
-public interface RangeIndex extends Index
-{
- /** Return records between min (inclusive) and max (exclusive), based on the record keys */
- public Iterator<Record> iterator(Record recordMin, Record recordMax) ;
-
- public <X> Iterator<X> iterator(Record recordMin, Record recordMax, RecordMapper<X> mapper) ;
-
- /** Return the record containing the least key - may or may not have the associated value */
- public Record minKey() ;
-
- /** Return the record containing the greatest key - may or may not have the associated value */
- public Record maxKey() ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexLogger.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexLogger.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexLogger.java
deleted file mode 100644
index f797fc2..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexLogger.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.dboe.index;
-
-import java.util.Iterator ;
-
-import org.seaborne.dboe.base.record.Record ;
-import org.slf4j.Logger ;
-
-public final class RangeIndexLogger extends RangeIndexWrapper
-{
- private final Logger log ;
-
- public RangeIndexLogger(RangeIndex rIdx, Logger log)
- {
- super(rIdx) ;
- this.log = log ;
- }
-
- @Override
- public boolean insert(Record record)
- {
- log.info("Add: "+record) ;
- return super.insert(record) ;
- }
-
- @Override
- public boolean delete(Record record)
- {
- log.info("Delete: "+record) ;
- return super.delete(record) ;
- }
-
- @Override
- public Record find(Record record)
- {
- log.info("Find: "+record) ;
- Record r2 = super.find(record) ;
- log.info("Find: "+record+" ==> "+r2) ;
- return r2 ;
- }
-
- @Override
- public Iterator<Record> iterator()
- {
- log.info("iterator()") ;
- return super.iterator() ;
- }
-
- @Override
- public Iterator<Record> iterator(Record minRec, Record maxRec)
- {
- log.info("iterator("+minRec+", "+maxRec+")") ;
- return super.iterator(minRec, maxRec) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexWrapper.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexWrapper.java b/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexWrapper.java
deleted file mode 100644
index a2169be..0000000
--- a/jena-db/jena-dboe-index/src/main/java/org/seaborne/dboe/index/RangeIndexWrapper.java
+++ /dev/null
@@ -1,106 +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.dboe.index;
-
-import java.util.Iterator ;
-
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.base.record.RecordFactory ;
-import org.seaborne.dboe.base.record.RecordMapper ;
-
-public class RangeIndexWrapper implements RangeIndex
-{
- // Could extend IndexWrapper but it's nice to have one place to look and set breakpoints.
- protected final RangeIndex rIndex ;
-
- public RangeIndexWrapper(RangeIndex rIdx) { this.rIndex = rIdx ; }
-
- @Override
- public Record find(Record record)
- { return rIndex.find(record) ; }
-
- @Override
- public boolean contains(Record record)
- { return rIndex.contains(record) ; }
-
- @Override
- public Record minKey()
- { return rIndex.minKey() ; }
-
- @Override
- public Record maxKey()
- { return rIndex.maxKey() ; }
-
- @Override
- public boolean insert(Record record)
- { return rIndex.insert(record) ; }
-
- @Override
- public boolean delete(Record record)
- { return rIndex.delete(record) ; }
-
-// public Record addAndReturnOld(Record record)
-// { return bpt.addAndReturnOld(record) ; }
-
-// public Record deleteAndReturnOld(Record record)
-// { return bpt.deleteAndReturnOld(record) ; }
-
- @Override
- public Iterator<Record> iterator()
- { return rIndex.iterator() ; }
-
- @Override
- public Iterator<Record> iterator(Record minRec, Record maxRec)
- { return rIndex.iterator(minRec, maxRec) ; }
-
- @Override
- public <X> Iterator<X> iterator(Record minRec, Record maxRec, RecordMapper<X> mapper)
- { return rIndex.iterator(minRec, maxRec, mapper) ; }
-
- @Override
- public boolean isEmpty()
- { return rIndex.isEmpty() ; }
-
- @Override
- public void clear()
- { rIndex.clear() ; }
-
- @Override
- public void sync()
- { rIndex.sync() ; }
-
- @Override
- public void close()
- { rIndex.close() ; }
-
- public RangeIndex getWrapped()
- { return rIndex ; }
-
- @Override
- public RecordFactory getRecordFactory()
- { return rIndex.getRecordFactory() ; }
-
- @Override
- public void check()
- { rIndex.check() ; }
-
- @Override
- public long size()
- { return rIndex.size() ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/AccessPath.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/AccessPath.java b/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/AccessPath.java
new file mode 100644
index 0000000..6e40e84
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/AccessPath.java
@@ -0,0 +1,70 @@
+/*
+ * 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.apache.jena.dboe.trans.bplustree;
+
+import java.util.ArrayList ;
+import java.util.List ;
+import java.util.stream.Collectors ;
+
+import org.apache.jena.atlas.lib.InternalErrorException ;
+
+public class AccessPath {
+ static class AccessStep {
+ final BPTreeNode node ;
+ final int idx ;
+ final BPTreePage page ;
+ AccessStep(BPTreeNode node, int idx, BPTreePage page) {
+ this.node = node ;
+ this.idx = idx ;
+ this.page = page ;
+ }
+
+ @Override
+ public String toString() {
+ return "("+node.label()+", "+idx+")->"+page.getId() ;
+ }
+ }
+
+ private final BPTreeNode root ;
+ private List<AccessStep> traversed = new ArrayList<>() ;
+
+ public AccessPath(BPTreeNode root) {
+ this.root = root ;
+ }
+
+ public void add(BPTreeNode node, int idx, BPTreePage page) {
+ traversed.add(new AccessStep(node, idx, page)) ;
+ }
+
+ public void reset(BPTreeNode node, int idx, BPTreePage page) {
+ AccessStep s = traversed.remove(traversed.size()-1) ;
+ AccessStep s2 = new AccessStep(node, idx, page) ;
+ if ( s.node != s2.node )
+ throw new InternalErrorException("Bad attempt to reset: "+this+" with "+s2) ;
+ traversed.add(new AccessStep(node, idx, page)) ;
+ }
+
+ public List<AccessStep> getPath() { return traversed ; }
+
+ @Override
+ public String toString() {
+ return traversed.stream().map(x-> x.toString()).collect(Collectors.toList()).toString() ;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPT.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPT.java b/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPT.java
new file mode 100644
index 0000000..b2b461a
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPT.java
@@ -0,0 +1,249 @@
+/*
+ * 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.apache.jena.dboe.trans.bplustree;
+
+import static java.lang.String.format ;
+import static org.apache.jena.atlas.lib.Alg.decodeIndex ;
+
+import java.util.List ;
+import java.util.Optional ;
+
+import org.apache.jena.atlas.lib.InternalErrorException ;
+import org.apache.jena.atlas.logging.FmtLog ;
+import org.apache.jena.dboe.base.block.BlockMgr;
+import org.apache.jena.dboe.base.file.BufferChannel;
+import org.apache.jena.dboe.sys.SystemIndex;
+import org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep;
+import org.slf4j.Logger ;
+
+/** B+Tree assist functions */
+public final class BPT {
+ public static boolean Logging = false ; // Turn on/off logging
+
+ public static boolean forcePromoteModes = false ;
+ public static boolean promoteDuplicateRecords = false ;
+ public static boolean promoteDuplicateNodes = false ;
+
+ // Check within BPTreeNode
+ public static boolean CheckingNode = false ;
+ // Check on exit of B+Tree modifiying operations
+ // Not done?
+ public static boolean CheckingConcurrency = SystemIndex.Checking ;
+
+ /** Enable detailed internal consistency checking */
+ public static void checking(boolean onOrOff) {
+ CheckingNode = onOrOff ;
+ }
+
+ /** Dump before and after top level update operations **/
+ public static boolean DumpTree = false ;
+
+ /** Output a lot of detailed information. */
+ public static void infoAll(boolean onOrOff) {
+ DumpTree = true ;
+ Logging = true ;
+ }
+
+ static boolean logging(Logger log) {
+ return Logging && log.isDebugEnabled() ;
+ }
+
+ static void log(Logger log, String fmt, Object... args) {
+ if ( logging(log) ) {
+ FmtLog.debug(log, fmt, args);
+ }
+ }
+
+ static void warning(String msg, Object... args) {
+ msg = format(msg, args) ;
+ System.out.println("Warning: " + msg) ;
+ System.out.flush() ;
+ }
+
+ static void error(String msg, Object... args) {
+ msg = format(msg, args) ;
+ System.out.println() ;
+ System.out.println(msg) ;
+ System.out.flush() ;
+ throw new BPTreeException(msg) ;
+ }
+
+ /** Convert a find index return to the insert location in the array */
+ static int apply(int idx) {
+ if ( idx >= 0 )
+ return idx ;
+ return decodeIndex(idx) ;
+ }
+
+ // ---- Promotion of pages.
+
+ /** Promote a single page. Assumes the path to this page has been handled in some way elsewhere */
+ static boolean promote1(BPTreePage page, BPTreeNode node, int idx) {
+ //System.out.println("promote1: "+page.getBlockMgr().getLabel()+" "+page.getBackingBlock().getId()) ;
+ boolean changed = page.promote() ;
+ node.ptrs.set(idx, page.getId()) ;
+ return changed ;
+ }
+
+ /** Promote a B+Tree root */
+ static boolean promoteRoot(BPTreeNode root) {
+ if ( ! root.isRoot() )
+ throw new InternalErrorException("Not a root") ;
+ boolean changed = root.promote() ;
+ root.bpTree.newRoot(root) ;
+ return changed ;
+ }
+
+ /** Promote a B+Tree page */
+ static void promotePage(AccessPath path, BPTreePage page) {
+ Logger pageLog = page.getLogger() ;
+ boolean loggingCall = logging(pageLog) ;
+ if ( loggingCall )
+ log(pageLog, "Promote :: Path=%s Page=%s", path, page) ;
+ // ---- Checking if the access path is consistent.
+ if ( BPT.CheckingNode && path != null ) {
+ if ( path.getPath().size() > 2) {
+ // Check every one except the last is not a leaf node.
+ List<AccessStep> y = path.getPath().subList(0, path.getPath().size()-2) ;
+ Optional<AccessStep> z = y.stream().filter(e -> e.node.isLeaf() ).findFirst() ;
+ if ( z.isPresent() )
+ error("promote: Leaf %s found in path but not at the tail: %s") ;
+ }
+ // Check the page/index pointers
+ Optional<AccessStep> z2 = path.getPath().stream().filter(e -> e.node.ptrs.get(e.idx) != e.page.getId()).findFirst() ;
+ if ( z2.isPresent() )
+ error("promote: path error: %s in %s", z2.get(), path) ;
+ }
+
+ // ---- Clone the access path nodes.
+ // Path is the route to this page - it does not include this page.
+ // Work from the bottom to the top, the reverse order of AccessPath
+ if ( loggingCall )
+ log(pageLog, " page>> %s", page.label()) ;
+ boolean changed = page.promote();
+ if ( loggingCall ) {
+ if ( changed )
+ log(pageLog, " page<< %s", page.label()) ;
+ else
+ log(pageLog, " .. no change") ;
+ }
+
+ if ( changed )
+ page.write() ; // Being careful.
+
+ // Even if the page did not change, make sure the chain is dealt with.
+ // e.g. promote in place policies.
+ //if ( changed ) {
+ if ( path != null ) {
+ // Sequence of promote1 calls? + root.
+
+ List<AccessStep> steps = path.getPath() ;
+
+ int newPtr = page.getId() ;
+ BPTreePage newPage = null ;
+ boolean previousChanged = changed ;
+ BPTreeNode newRoot = null ;
+
+ if ( logging(pageLog) )
+ log(pageLog, "Path: %s", path) ;
+ // Duplicate from bottom to top.
+ for ( int i = steps.size() - 1 ; i >= 0 ; i-- ) {
+ AccessStep s = steps.get(i) ;
+ // duplicate
+ BPTreeNode n = s.node ;
+ if ( logging(pageLog) )
+ log(pageLog, " >> %s", n) ;
+
+ changed = n.promote() ;
+
+ if ( previousChanged ) {
+ // Even if n did not change, if it's sub changed, need to update s.idx.
+ n.ptrs.set(s.idx, newPtr) ;
+ } else {
+ if ( ! changed ) {
+ if ( logging(pageLog) )
+ log(pageLog, " .. no change") ;
+ continue ;
+ }
+ }
+
+ previousChanged = changed ;
+
+ if ( logging(pageLog) )
+ log(pageLog, " << %s", n) ;
+
+ if ( n.isRoot() ) {
+ if ( newRoot != null)
+ throw new InternalErrorException("New root already found") ;
+ newRoot = n ;
+ }
+ newPtr = n.getId() ;
+ n.write() ;
+
+ }
+ if ( newRoot != null ) {
+ if ( loggingCall )
+ log(pageLog, " new root %s", newRoot) ;
+ page.bpTree.newRoot(newRoot) ;
+ }
+ } // end of "if ( path != null )"
+ }
+
+ /**
+ * The initial tree is a single root node with no records block below it. It
+ * is an illegal tree. We make it by creating a real tree, deleting and
+ * freeing the records block from the root, then resetting the records block
+ * manager. This is to avoid having specialized creating code in
+ * BPlusTreeFactory solely for the rewriter.
+ */
+ public static BPlusTree createRootOnlyBPTree(BPlusTreeParams bptParams,
+ BufferChannel bptState,
+ BlockMgr blkMgrNodes,
+ BlockMgr blkMgrRecords) {
+ BPlusTree bpt = BPlusTreeFactory.createNonTxn(bptParams, bptState, blkMgrNodes, blkMgrRecords) ;
+
+ BPTreeRecordsMgr recordsMgr = bpt.getRecordsMgr() ;
+
+ BPTreeRecords recordsPage = recordsMgr.getWrite(0) ;
+// recordsPage.getRecordBuffer().clear();
+// recordsMgr.write(recordsPage) ;
+ recordsMgr.free(recordsPage);
+// recordsMgr.release(recordsPage);
+ recordsMgr.resetAlloc(0);
+
+ BPTreeNodeMgr nodeMgr = bpt.getNodeManager() ;
+
+ // Alter the root node.
+ BPTreeNode root = nodeMgr.getWrite(BPlusTreeParams.RootId, BPlusTreeParams.RootParent) ;
+ int rootId = root.getId() ;
+ if ( rootId != 0 )
+ throw new BPTreeException("**** Not the root: " + rootId) ;
+
+ // Undo the records block.
+ root.getPtrBuffer().clear() ;
+ root.getRecordBuffer().clear() ;
+ //root.setCount(-1);
+ nodeMgr.write(root);
+ nodeMgr.release(root);
+
+ // Now a broken tree of one root block and no records.
+ return bpt ;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPTStateMgr.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPTStateMgr.java b/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPTStateMgr.java
new file mode 100644
index 0000000..b8d1212
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPTStateMgr.java
@@ -0,0 +1,90 @@
+/*
+ * 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.apache.jena.dboe.trans.bplustree;
+
+import org.apache.jena.atlas.logging.FmtLog ;
+import org.apache.jena.dboe.base.file.BufferChannel;
+import org.apache.jena.dboe.transaction.txn.StateMgrData;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+/** Manage the persistent state of the tree
+ *
+ * This consists of last commited root, and the limits on the blocks for both
+ * nodes and records.
+ *
+ * (rootId/int-as-long, nodeAllocLimit/long, recordsAllocLimit/long)
+ */
+public class BPTStateMgr extends StateMgrData {
+ private static Logger log = LoggerFactory.getLogger(BPTStateMgr.class) ;
+
+ private static int idxRoot = 0 ;
+ private static int idxNodeBlocksLimit = 1 ;
+ private static int idxRecordsBlocksLimit = 2 ;
+
+ private int currentRoot() { return (int)super.get(idxRoot) ; }
+ private long nodeBlocksLimit() { return super.get(idxNodeBlocksLimit) ; }
+ private long recordsBlocksLimit() { return super.get(idxRecordsBlocksLimit) ; }
+
+ private void currentRoot(int x) { super.set(idxRoot, x) ; }
+ private void nodeBlocksLimit(long x) { super.set(idxNodeBlocksLimit, x) ; }
+ private void recordsBlocksLimit(long x) { super.set(idxRecordsBlocksLimit, x) ; }
+
+ private boolean LOGGING = BPT.Logging ;
+
+ public BPTStateMgr(BufferChannel storage) {
+ // These values are the values for a null tree (no blocks).
+ super(storage, 0L, 0L, 0L) ;
+ }
+
+ /*package*/ void setState(int rootIdx, long nodeBlkLimit, long recordsBlkLimit) {
+ currentRoot(rootIdx) ;
+ nodeBlocksLimit(nodeBlkLimit) ;
+ recordsBlocksLimit(recordsBlkLimit) ;
+ log("Set") ;
+ setDirtyFlag() ;
+ // But don't write it.
+ }
+ @Override
+ protected void writeStateEvent() {
+ log("Write") ;
+ }
+
+ @Override
+ protected void readStateEvent() {
+ log("Read") ;
+ }
+
+ private void log(String operation) {
+ if ( LOGGING )
+ FmtLog.info(log, "%s state: root=%d // node block limit = %d // records block limit %d", operation, currentRoot(), nodeBlocksLimit(), recordsBlocksLimit()) ;
+ }
+
+ public int getRoot() {
+ return currentRoot() ;
+ }
+
+ public long getNodeBlocksLimit() {
+ return nodeBlocksLimit() ;
+ }
+
+ public long getRecordsBlocksLimit() {
+ return recordsBlocksLimit() ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPTreeException.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPTreeException.java b/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPTreeException.java
new file mode 100644
index 0000000..0bb6a80
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/main/java/org/apache/jena/dboe/trans/bplustree/BPTreeException.java
@@ -0,0 +1,27 @@
+/*
+ * 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.apache.jena.dboe.trans.bplustree;
+
+import org.apache.jena.dboe.DBOpEnvException;
+
+public class BPTreeException extends DBOpEnvException
+{
+ public BPTreeException() {}
+ public BPTreeException(String msg) { super(msg) ; }
+}