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:00 UTC
[048/100] [abbrv] [partial] jena git commit: JENA-1397: Rename
modules and set versions
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/ChannelManager.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/ChannelManager.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/ChannelManager.java
deleted file mode 100644
index 6cdf88b..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/ChannelManager.java
+++ /dev/null
@@ -1,115 +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.base.file;
-
-import java.io.IOException ;
-import java.io.RandomAccessFile ;
-import java.nio.channels.FileChannel ;
-import java.util.ArrayList ;
-import java.util.HashMap ;
-import java.util.List ;
-import java.util.Map ;
-
-public class ChannelManager
-{
- // Make per "location"?
-
- // Because "FileManager" is already in use
- // ChannelManager
-
- // FileBase ==> OpenFileRef, ChannelRef
-
- public static FileChannel acquire(String filename) {
- return acquire(filename, "rw") ;
- }
-
- public static FileChannel acquire(String filename, String mode) {
- return openref$(filename, mode) ;
- }
-
- static private Map<String, FileChannel> name2channel = new HashMap<>() ;
- static private Map<FileChannel, String> channel2name = new HashMap<>() ;
-
- private static FileChannel openref$(String filename, String mode) {
- // Temp - for now, only journal files are tracked.
- if ( !filename.endsWith(".jrnl") ) {
- return open$(filename, mode) ;
- }
-
- FileChannel chan = name2channel.get(filename) ;
- if ( chan != null ) {
- // Scream - it's currently open.
- throw new FileException("Already open: " + filename) ;
- }
- chan = open$(filename, mode) ;
- name2channel.put(filename, chan) ;
- channel2name.put(chan, filename) ;
- return chan ;
- }
-
- private static FileChannel open$(String filename, String mode) {
- try {
- // "rwd" - Syncs only the file contents
- // "rws" - Syncs the file contents and metadata
- // "rw" - OS write behind possible
- // "r" - read only
- @SuppressWarnings("resource")
- RandomAccessFile out = new RandomAccessFile(filename, mode) ;
- FileChannel channel = out.getChannel() ;
- return channel ;
- } catch (IOException ex) { throw new FileException("Failed to open: "+filename+" (mode="+mode+")", ex) ; }
- }
-
- public static void release(String filename) {
- FileChannel channel = name2channel.get(filename) ;
- if ( channel != null )
- release(channel) ;
- }
-
- public static void release(FileChannel chan) {
- // Always close even if not managed.
- try {
- chan.close() ;
- }
- catch (Exception ex) {}
- String name = channel2name.remove(chan) ;
- if ( name != null )
- name2channel.remove(name) ;
- }
-
- public static void reset() {
- releaseAll(null) ;
- }
-
- /** Shutdown all the files matching the prefix (typically a directory) */
- public static void releaseAll(String prefix) {
- // Use an iterator explicitly so we can remove from the map.
- List<FileChannel> x = new ArrayList<>() ;
- for ( String fn : name2channel.keySet() ) {
- if ( prefix == null || fn.startsWith(prefix) ) {
- x.add(name2channel.get(fn)) ;
- // Don't call release here - potential CME problems.
- // Could use an explicit iterator on teh keySet and .remove from that but
- // then we nearly duplicate the code in release.
- }
- }
- for ( FileChannel chan : x )
- release(chan) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileException.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileException.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileException.java
deleted file mode 100644
index b98c9c4..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileException.java
+++ /dev/null
@@ -1,29 +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.base.file;
-
-import org.seaborne.dboe.DBOpEnvException ;
-
-public class FileException extends DBOpEnvException
-{
- public FileException() { super() ; }
- public FileException(String msg) { super(msg) ; }
- public FileException(Throwable th) { super(th) ; }
- public FileException(String msg, Throwable th) { super(msg, th) ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileFactory.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileFactory.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileFactory.java
deleted file mode 100644
index d3bb825..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileFactory.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.file ;
-
-public class FileFactory {
-
- public static BinaryDataFile createBinaryDataFile(FileSet fileset, String ext) {
- String x = fileset.filename(ext) ;
- if ( fileset.isMem() ) {
- return new BinaryDataFileMem() ;
- } else {
- BinaryDataFile bdf = new BinaryDataFileRandomAccess(x) ;
- bdf = new BinaryDataFileWriteBuffered(bdf) ;
- return bdf ;
- }
- }
-
- public static BinaryDataFile createBinaryDataFile() {
- return new BinaryDataFileMem() ;
- }
-
- public static BufferChannel createBufferChannel(FileSet fileset, String ext) {
- String x = fileset.filename(ext) ;
- if ( fileset.isMem() )
- return BufferChannelMem.create(x) ;
- else
- return BufferChannelFile.create(x) ;
- }
-
- public static BufferChannel createBufferChannelMem() {
- return createBufferChannel(FileSet.mem(), null) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileSet.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileSet.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileSet.java
deleted file mode 100644
index d919617..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/FileSet.java
+++ /dev/null
@@ -1,116 +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.base.file ;
-
-import java.io.File ;
-
-import org.apache.jena.atlas.lib.FileOps ;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-/**
- * Naming metadata management to a collection of related files (same directory,
- * same basename within directory, various extensions).
- */
-public class FileSet {
- // Cope with "in-memory" fileset (location == null)
-
- private static Logger log = LoggerFactory.getLogger(FileSet.class) ;
-
- private Location location ;
- private String basename ;
-
- /** FileSet for "in-memory" */
- public static FileSet mem() {
- FileSet fs = new FileSet(Location.mem(), "mem") ;
- return fs ;
- }
-
- // private FileSet() {} // Uninitialized.
-
- /**
- * Create a FileSet given Location (directory) and name within the directory
- */
- public FileSet(String directory, String basename) {
- initFileSet(Location.create(directory), basename) ;
- }
-
- /**
- * Create a FileSet given Location (directory) and name within the directory
- */
- public FileSet(String filename) {
- Tuple<String> t = FileOps.splitDirFile(filename) ;
- String dir = t.get(0) ;
- String fn = t.get(1) ;
- if ( dir == null )
- dir = "." ;
- initFileSet(Location.create(dir), fn) ;
- }
-
- /**
- * Create a FileSet given Location (directory) and name within the directory
- */
- public FileSet(Location directory, String basename) {
- initFileSet(directory, basename) ;
- }
-
- private void initFileSet(Location directory, String basename) {
- // Default - don't use the locations metadata
- initFileSet(directory, basename, false) ;
- }
-
- private void initFileSet(Location directory, String basename, boolean useLocationMetadata) {
- this.location = directory ;
- this.basename = basename ;
- }
-
- public Location getLocation() {
- return location ;
- }
-
- public String getBasename() {
- return basename ;
- }
-
- // public MetaFile getMetaFile() { return metafile ; }
-
- public boolean isMem() {
- return location.isMem() ;
- }
-
- public boolean exists(String ext) {
- if ( location.isMem() )
- return true ;
- String fn = filename(ext) ;
- File f = new File(fn) ;
- if ( f.isDirectory() )
- log.warn("File clashes with a directory") ;
- return f.exists() && f.isFile() ;
- }
-
- @Override
- public String toString() {
- return "FileSet:" + filename(null) ;
- }
-
- public String filename(String ext) {
- return location.getPath(basename, ext) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/Location.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/Location.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/Location.java
deleted file mode 100644
index faeaa80..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/Location.java
+++ /dev/null
@@ -1,265 +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.base.file ;
-
-import java.io.File ;
-import java.io.IOException ;
-import java.nio.file.Path;
-import java.util.Objects ;
-
-import org.seaborne.dboe.sys.Names ;
-
-/**
- * Wrapper for a file system directory; can create filenames in that directory.
- * Enforces some simple consistency policies and provides a "typed string" for a
- * filename to reduce errors.
- */
-
-public class Location {
- static String pathSeparator = File.separator ; // Or just "/"
-
- private static String memNamePath = Names.memName+pathSeparator ;
-
- private String pathname ;
- private MetaFile metafile = null ;
- private boolean isMem = false ;
- private boolean isMemUnique = false ;
-
- static int memoryCount = 0 ;
-
- /**
- * Return a fresh memory location : always unique, never .equals to another
- * location.
- */
- static public Location mem() {
- return mem(null) ;
- }
-
- /** Return a memory location with a name */
- static public Location mem(String name) {
- Location loc = new Location() ;
- memInit(loc, name) ;
- return loc ;
- }
-
- /** Return a location for a directory on disk */
- static public Location create(String directoryName) {
- if ( directoryName == null )
- // Fresh, anonymous, memory area
- return mem() ;
- Location loc = new Location(directoryName) ;
- return loc ;
- }
-
- /** Return a location for a directory on disk */
- static public Location create(Path directoryName) {
- if ( directoryName == null )
- // Fresh, anonymous, memory area
- return mem() ;
- Location loc = new Location(directoryName.toString()) ;
- return loc ;
- }
-
- private Location() {}
-
- private static void memInit(Location location, String name) {
- location.pathname = Names.memName ;
- if ( name != null ) {
- name = name.replace('\\', '/') ;
- location.pathname = location.pathname + '/' + name ;
- } else
- location.isMemUnique = true ;
- if ( !location.pathname.endsWith(pathSeparator) )
- location.pathname = location.pathname + '/' ;
- location.isMem = true ;
- location.metafile = new MetaFile(Names.memName, Names.memName) ;
- }
-
- private Location(String rootname) {
- super() ;
- if ( rootname.equals(Names.memName) ) {
- memInit(this, null) ;
- return ;
- }
- if ( rootname.startsWith(memNamePath) ) {
- String name = rootname.substring(memNamePath.length()) ;
- memInit(this, name) ;
- return ;
- }
-
- ensure(rootname) ;
- pathname = fixupName(rootname) ;
- // Metafilename for a directory.
- String metafileName = getPath(Names.directoryMetafile, Names.extMeta) ;
-
- metafile = new MetaFile("Location: " + rootname, metafileName) ;
- }
-
- // MS Windows:
- // getCanonicalPath is only good enough for existing files.
- // It leaves the case as it finds it (upper, lower) and lower cases
- // not-existing segments. But later creation of a segment with uppercase
- // changes the exact string returned.
- private String fixupName(String fsName) {
- if ( isMem() )
- return fsName ;
- File file = new File(fsName) ;
- try {
- fsName = file.getCanonicalPath() ;
- } catch (IOException ex) {
- throw new FileException("Failed to get canoncial path: " + file.getAbsolutePath(), ex) ;
- }
-
- if ( !fsName.endsWith(File.separator) && !fsName.endsWith(pathSeparator) )
- fsName = fsName + pathSeparator ;
- return fsName ;
- }
-
- public String getDirectoryPath() {
- return pathname ;
- }
-
- public MetaFile getMetaFile() {
- return metafile ;
- }
-
- public boolean isMem() {
- return isMem ;
- }
-
- public boolean isMemUnique() {
- return isMemUnique ;
- }
-
- public Location getSubLocation(String dirname) {
- String newName = pathname + dirname ;
- ensure(newName) ;
- return Location.create(newName) ;
- }
-
- private void ensure(String dirname) {
- if ( isMem() )
- return ;
- File file = new File(dirname) ;
- if ( file.exists() && !file.isDirectory() )
- throw new FileException("Existing file: " + file.getAbsolutePath()) ;
- if ( !file.exists() )
- file.mkdir() ;
- }
-
- public String getSubDirectory(String dirname) {
- return getSubLocation(dirname).getDirectoryPath() ;
- }
-
- /**
- * Return an absolute filename where relative names are resolved from the
- * location
- */
- public String absolute(String filename, String extension) {
- return (extension == null) ? absolute(filename) : absolute(filename + "." + extension) ;
- }
-
- /**
- * Return an absolute filename where relative names are resolved from the
- * location
- */
- public String absolute(String filename) {
- File f = new File(filename) ;
- // Location relative.
- if ( !f.isAbsolute() )
- filename = pathname + filename ;
- return filename ;
- }
-
- /** Does the location exist (and it a directory, and is accessible) */
- public boolean exists() {
- File f = new File(getDirectoryPath()) ;
- return f.exists() && f.isDirectory() && f.canRead() ;
- }
-
- public boolean exists(String filename) {
- return exists(filename, null) ;
- }
-
- public boolean exists(String filename, String ext) {
- String fn = getPath(filename, ext) ;
- File f = new File(fn) ;
- return f.exists() ;
- }
-
- /** Return the name of the file relative to this location */
- public String getPath(String filename) {
- return getPath(filename, null) ;
- }
-
- /** Return the name of the file, and extension, relative to this location */
- public String getPath(String filename, String ext) {
- check(filename, ext) ;
- if ( ext == null )
- return pathname + filename ;
- return pathname + filename + "." + ext ;
- }
-
- private void check(String filename, String ext) {
- if ( filename == null )
- throw new FileException("Location: null filename") ;
- if ( filename.contains("/") || filename.contains("\\") )
- throw new FileException("Illegal file component name: " + filename) ;
- if ( filename.contains(".") && ext != null )
- throw new FileException("Filename has an extension: " + filename) ;
- if ( ext != null ) {
- if ( ext.contains(".") )
- throw new FileException("Extension has an extension: " + filename) ;
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 31 ;
- int result = isMem ? 1 : 2 ;
- result = prime * result + ((pathname == null) ? 0 : pathname.hashCode()) ;
- return result ;
- }
-
- @Override
- public boolean equals(Object obj) {
- if ( this == obj )
- return true ;
- if ( obj == null )
- return false ;
- if ( getClass() != obj.getClass() )
- return false ;
-
- Location other = (Location)obj ;
- if ( isMem && !other.isMem )
- return false ;
- if ( !isMem && other.isMem )
- return false ;
- // Not == so ...
- if ( isMemUnique )
- return false ;
-
- return Objects.equals(pathname, other.pathname) ;
- }
-
- @Override
- public String toString() {
- return "location:" + pathname ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/MetaFile.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/MetaFile.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/MetaFile.java
deleted file mode 100644
index b379f40..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/MetaFile.java
+++ /dev/null
@@ -1,365 +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.base.file;
-
-import java.io.* ;
-import java.util.* ;
-
-import org.apache.jena.atlas.lib.* ;
-import org.apache.jena.atlas.lib.Closeable ;
-import org.seaborne.dboe.DBOpEnvException ;
-import org.seaborne.dboe.sys.Names ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-/** Abstraction and many convenience operations on metadata.
- * Metadata is recorded in Java properties style - not RDF - because it's relative to the file or context used.
- * Keys and values are always strings.
- */
-public class MetaFile implements Sync, Closeable
-{
- private static Comparator<String> comparator = new ComparatorKeys() ;
- private static Logger log = LoggerFactory.getLogger(MetaFile.class) ;
- private String metaFilename = null ;
- private Properties properties = null ;
- private String label = null ;
- private boolean changed = false ;
- private boolean closed = false ;
-
- /** Create a MetaFile
- *
- * @param label Convenience label.
- * @param fn On disk filename; {@link Names#memName} for in-memory
- */
- public MetaFile(String label, String fn)
- {
- this.label = label ;
- this.metaFilename = fn ;
-
- if ( fn == null || Names.isMem(fn) )
- // In-memory.
- return ;
-
- // Make absolute (current directory may change later)
- if ( ! fn.endsWith(Names.extMeta) )
- fn = fn+"."+Names.extMeta ;
- File f = new File(fn) ;
- this.metaFilename = f.getAbsolutePath() ;
- // Does not load the details yet.
- // JDI
- ensureInit() ;
- }
-
- private void ensureInit()
- {
- if ( properties == null )
- {
- properties = new PropertiesSorted(comparator) ;
- if ( metaFilename != null )
- loadProperties() ;
- }
- }
-
- /** Does this metafile exist on disk? (In-memory MetaFiles always exist) */
- public boolean existsMetaData()
- {
- if ( isMem() )
- return true ;
- File f = new File(metaFilename) ;
- if ( f.isDirectory() )
- log.warn("Metadata file clashes with a directory") ;
- return f.exists() && f.isFile() ;
- }
-
- public String getFilename() { return metaFilename ; }
-
- /** Test for the presence of a property */
- public boolean hasProperty(String key)
- {
- return _getProperty(key, null) != null ;
- }
-
- /** Get the property value or null. */
- public String getProperty(String key)
- {
- return _getProperty(key, null) ;
- }
-
- /** Get the property value or return supplied default. */
- public String getProperty(String key, String defaultString)
- {
- return _getProperty(key, defaultString) ;
- }
-
- /** Get the property value and parse as an integer */
- public int getPropertyAsInteger(String key)
- {
- return Integer.parseInt(_getProperty(key, null)) ;
- }
-
- /** Get the property value and parse as an integer or return default value. */
- public int getPropertyAsInteger(String key, int defaultValue)
- {
- String x = getProperty(key) ;
- if ( x == null )
- return defaultValue ;
- return Integer.parseInt(x) ;
- }
-
- /** Get property as a string and split on ",". */
- public String[] getPropertySplit(String key)
- {
- String str = getProperty(key) ;
- if ( str == null )
- return null ;
- return str.split(",") ;
- }
-
- /** Get property as a string and split on ",", using the default string if not present in the MetaFile. */
- public String[] getPropertySplit(String key, String defaultString)
- {
- String str = getProperty(key, defaultString) ;
- return str.split(",") ;
- }
-
- /** Set property */
- public void setProperty(String key, String value)
- {
- _setProperty(key, value) ;
- }
-
- /** Set property, turning integer into a string. */
- public void setProperty(String key, int value)
- {
- _setProperty(key, Integer.toString(value)) ;
- }
-
- /** Test whether a property has a value. Null tests equal to not present. */
- public boolean propertyEquals(String key, String value)
- {
- return Objects.equals(getProperty(key), value) ;
- }
-
- /** Set property if not already set. */
- public void ensurePropertySet(String key, String expected)
- {
- getOrSetDefault(key, expected) ;
- }
-
- /** Get property or the default value - also set the default value if not present */
- public String getOrSetDefault(String key, String expected)
- {
- String x = getProperty(key) ;
- if ( x == null )
- {
- setProperty(key, expected) ;
- x = expected ;
- }
- return x ;
- }
-
- /** Check property is an expected value or set if missing */
- public void checkOrSetMetadata(String key, String expected)
- {
- String x = getProperty(key) ;
- if ( x == null )
- {
- setProperty(key, expected) ;
- return ;
- }
- if ( x.equals(expected) )
- return ;
-
- inconsistent(key, x, expected) ;
- }
-
- /** Check property has the value given - throw exception if not. */
- public void checkMetadata(String key, String expected)
- {
- String value = getProperty(key) ;
-
- if ( !Objects.equals(value, value) )
- inconsistent(key, value, expected) ;
- }
-
- private static void inconsistent(String key, String actual, String expected)
- {
- String msg = String.format("Inconsistent: key=%s value=%s expected=%s",
- key,
- (actual==null?"<null>":actual),
- (expected==null?"<null>":expected) ) ;
- throw new MetaFileException(msg) ;
- }
-
- /** Clear all properties. */
- public void clear()
- {
- _clear() ;
- }
-
- // ---- All get/set access through these operations
- private String _getProperty(String key, String dft)
- {
- ensureInit() ;
- return properties.getProperty(key, dft) ;
- }
-
- private void _setProperty(String key, String value)
- {
- ensureInit() ;
- properties.setProperty(key, value) ;
- changedEvent() ;
- }
-
- /** Clear all properties. */
- private void _clear()
- {
- ensureInit() ;
- properties.clear() ;
- changedEvent() ;
- }
-
- private void changedEvent() { changed = true ; }
- // ----
-
- private boolean isMem() { return Names.isMem(metaFilename) ; }
-
- /** Write to backing file if changed */
- public void flush()
- {
- if ( log.isDebugEnabled() )
- log.debug("Flush metadata ("+changed+"): "+this.label) ;
- if ( ! changed )
- return ;
-
-
- if ( log.isDebugEnabled() )
- {
- ByteArrayOutputStream out = new ByteArrayOutputStream() ;
- PrintStream ps = new PrintStream(out) ;
- properties.list(ps) ;
- ps.flush() ;
- log.debug("\n"+out.toString()) ;
- }
-
- //properties.list(System.out) ;
-
- saveProperties() ;
- changed = false ;
- }
-
- private void saveProperties()
- {
- if ( isMem() )
- return ;
- String str = label ;
- if ( str == null )
- str = metaFilename ;
- str = "Metadata: "+str ;
-
- try {
- PropertyUtils.storeToFile(properties, str, metaFilename) ;
- }
- catch (IOException ex)
- {
- log.error("Failed to store properties: "+metaFilename, ex) ;
- }
- }
-
-
- private void loadProperties()
- {
- if ( isMem() )
- {
- properties = new Properties() ;
- return ;
- }
-
- if ( properties == null )
- properties = new Properties() ;
-
- // if ( metaFilename == null )
- InputStream in = null ;
- try {
- // Copes with UTF-8 for Java5.
- PropertyUtils.loadFromFile(properties, metaFilename) ;
- }
- catch (FileNotFoundException ex) {}
- catch (IOException ex)
- {
- log.error("Failed to load properties: "+metaFilename, ex) ;
- }
- }
-
- /** Debugging */
- public void dump(PrintStream output)
- {
- output.println("Metafile: "+metaFilename) ;
- output.println("Label: "+label) ;
- output.println("Status: "+(changed?"changed":"unchanged")) ;
-
- if ( properties == null )
- {
- output.println("#<null>") ;
- return ;
- }
- // properties.list() ;
- SortedSet<Object> x = new TreeSet<>() ;
- x.addAll(properties.keySet()) ;
-
- for ( Object k : x )
- {
- String key = (String)k ;
- String value = properties.getProperty(key) ;
- output.print(key) ;
- output.print("=") ;
- output.print(value) ;
- output.println() ;
- }
- }
-
- @Override
- public void sync() { flush() ; }
-
- @Override
- public void close()
- {
- flush() ;
- closed = true ;
- metaFilename = null ;
- properties = null ;
-
- }
-
- private static class ComparatorKeys implements Comparator<String>
- {
- @Override
- public int compare(String o1, String o2)
- {
- return - o1.compareTo(o2) ;
- }
-
- }
-
- private static class MetaFileException extends DBOpEnvException
- {
- MetaFileException(String msg) { super(msg) ; }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/ProcessFileLock.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/ProcessFileLock.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/ProcessFileLock.java
deleted file mode 100644
index 990dcab..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/ProcessFileLock.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.file;
-
-import static java.nio.file.StandardOpenOption.CREATE;
-import static java.nio.file.StandardOpenOption.DSYNC;
-import static java.nio.file.StandardOpenOption.READ;
-import static java.nio.file.StandardOpenOption.WRITE;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.jena.atlas.RuntimeIOException;
-import org.apache.jena.atlas.io.IO;
-import org.apache.jena.atlas.lib.StrUtils;
-import org.apache.jena.atlas.logging.Log;
-import org.seaborne.dboe.DBOpEnvException;
-import org.seaborne.dboe.sys.ProcessUtils;
-
-/** A simple packaging around a {@link java.nio.channels.FileLock}.
- * {@code ProcessFileLock} are not reentrant.
- */
-public class ProcessFileLock {
-
- // Static (process-wide) sync.
- private static Object sync = new Object();
-
- // Map from path of the file to a ProcessFileLock
- private static ConcurrentHashMap<Path, ProcessFileLock> locks = new ConcurrentHashMap<>();
-
- private final Path filepath;
- private final FileChannel fileChannel;
- private FileLock fileLock;
-
- // Different variations for what to do when a lock can not be taken.
- private enum NoLockAction { EXCEPTION, RETURN, WAIT }
-
- /** Create a {@code ProcessFileLock} using the named file.
- * Locks are JVM-wide; each filename is assocauted with one lock object.
- */
- public static ProcessFileLock create(String filename) {
- try {
- Path abspath = Paths.get(filename).toRealPath();
- return locks.computeIfAbsent(abspath, ProcessFileLock::new);
- }
- catch (IOException e) { IO.exception(e); return null; }
- }
-
- /** Return the lock, unlocking the file if this process has it locked. */
- public static void release(ProcessFileLock lockFile) {
- if ( lockFile == null )
- return ;
- if ( lockFile.isLockedHere() )
- lockFile.unlock();
- locks.remove(lockFile.getPath());
- }
- /** Create the structure for a ProcessFileLock on file {@code filename}.
- * This does not take the lock
- *
- * @see #lockEx()
- * @see #tryLock()
- * @see #unlock()
- */
- private ProcessFileLock(Path filename) {
- try {
- this.filepath = filename ;
- // Much the same as ...
-// randomAccessFile = new RandomAccessFile(filename, "rw");
-// fileChannel = randomAccessFile.getChannel();
- // Quite heavy weight but only used to lock long-term objects.
- this.fileChannel = FileChannel.open(filename, CREATE, WRITE, READ, DSYNC);
- fileLock = null;
- }
- catch (NoSuchFileException | FileNotFoundException ex) {
- // The path does not name a possible file in an exists directory.
- throw new RuntimeIOException("No such file '"+filename+"'", ex);
- }
- catch (IOException ex) {
- throw new RuntimeIOException("Failed to open '"+filename+"'", ex);
- }
- }
-
- /** Lock the file or throw {@link DBOpEnvException} */
- public void lockEx() {
- lockOperation(NoLockAction.EXCEPTION);
- }
-
- /** Lock the file or wait. */
- public void lockWait() {
- lockOperation(NoLockAction.EXCEPTION);
- }
-
- /** Lock a file, return true on success else false. */
- public boolean tryLock() {
- return lockOperation(NoLockAction.RETURN);
- }
-
- /** Release the lock - this must be paired with a "lock" operation. */
- public void unlock() {
- synchronized(sync) {
- try {
- fileLock.release();
- } catch (IOException ex) { throw new RuntimeIOException("Failed to unlock '"+filepath+"'", ex); }
- }
- }
-
- /** Return true if this process holds the lock. */
- public boolean isLockedHere() {
- if ( fileLock == null )
- return false;
- return fileLock.isValid();
- }
-
- public Path getPath() {
- return filepath;
- }
-
- /** Take the lock.
- * <p>
- * Write our PID into the file and return true if it succeeds.
- * <p>
- * Try to get the existing PID if it fails.
- */
- private boolean lockOperation(NoLockAction action) {
- synchronized(sync) {
- if ( fileLock != null )
- throw new AlreadyLocked("Failed to get a lock: file='"+filepath+"': Lock already held");
-
- try {
- fileLock = (action == NoLockAction.WAIT) ? fileChannel.lock() : fileChannel.tryLock();
- if ( fileLock == null ) {
- if ( action == NoLockAction.RETURN )
- return false ;
- // Read without the lock.
- // This isn't perfect but it is only providing helpful information.
- int pid = readProcessId(-99);
- if ( pid >= 0 )
- throw new DBOpEnvException("Failed to get a lock: file='"+filepath+"': held by process "+pid);
- throw new DBOpEnvException("Failed to get a lock: file='"+filepath+"': failed to get the holder's process id");
- }
- // Got the lock. Record our process id.
- int pid = ProcessUtils.getPid(-1);
- writeProcessId(pid);
- return true;
- } catch (IOException ex) {
- if ( action == NoLockAction.RETURN )
- return false;
- throw new DBOpEnvException("Failed to get a lock: file='"+filepath+"'", ex);
- }
- }
- }
-
- // I/O for a process id.
- /** Read the file to get a process id */
- private int readProcessId(int dft) throws IOException {
- ByteBuffer bb = ByteBuffer.allocate(128);
- fileChannel.position(0);
- int len = fileChannel.read(bb);
- fileChannel.position(0);
- if ( len == 0 )
- return dft;
- if ( len == 128 )
- // Too much.
- return dft;
- // Bug in Jena 3.3.0
- //byte[] b = ByteBufferLib.bb2array(bb, 0, len);
- bb.flip();
- byte[] b = new byte[len];
- bb.get(b);
-
- String pidStr = StrUtils.fromUTF8bytes(b);
- // Remove all leadign and trailing (vertical and horizontal) whitespace.
- pidStr = pidStr.replaceAll("[\\s\\t\\n\\r]+$", "");
- pidStr = pidStr.replaceAll("^[\\s\\t\\n\\r]+", "");
- try {
- // Process id.
- return Integer.parseInt(pidStr);
- } catch (NumberFormatException ex) {
- ex.printStackTrace();
- Log.warn(this, "Bad process id: file='"+filepath+"': read='"+pidStr+"'");
- return dft;
- }
- }
-
- /** Write the process id to the file. */
- private void writeProcessId(int pid) throws IOException {
- byte b[] = StrUtils.asUTF8bytes(Integer.toString(pid)+"\n");
- fileChannel.truncate(0);
- int len = fileChannel.write(ByteBuffer.wrap(b));
- fileChannel.position(0);
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/SegmentedMemBuffer.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/SegmentedMemBuffer.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/SegmentedMemBuffer.java
deleted file mode 100644
index 00ae2ba..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/file/SegmentedMemBuffer.java
+++ /dev/null
@@ -1,280 +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.base.file;
-
-import java.nio.ByteBuffer ;
-import java.util.ArrayList ;
-import java.util.List ;
-
-import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.lib.ByteBufferLib ;
-import org.apache.jena.atlas.logging.FmtLog ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-/** A segmented, expanding buffer of bytes.
- * This class does not copy the underlying bytes when the file grows.
- * Hence, the performance is more predictable.
- * (Resizing a fixed size buffer is a copy c.f. performance issues with
- * {@code ArrayList} or {@code ByteArrayOutputStream}
- * as they go from small to large.
- */
-public class SegmentedMemBuffer {
- private static Logger log = LoggerFactory.getLogger(SegmentedMemBuffer.class) ;
-
- // See java.nio.channels.FileChannel
- private static int DFT_CHUNK = 1024*1024 ;
- private static int DFT_SEGMENTS = 1000 ;
- private final int CHUNK ;
- // The file pointer and marker of the allocated end point.
- private long dataLength = 0 ;
- private List<byte[]> space = null ;
- private boolean isOpen ;
- private final boolean TRACKING = false ;
-
- public SegmentedMemBuffer() { this(DFT_CHUNK) ; }
-
- public SegmentedMemBuffer(int chunk) {
- this.CHUNK = chunk ;
- space = new ArrayList<>(DFT_SEGMENTS) ;
- // "Auto open"
- isOpen = true ;
- }
-
- public void open() {
- isOpen = true ;
-// if ( storage != null )
-// throw new RuntimeIOException("Already open") ;
-// storage = new ArrayList<>(DFT_SEGMENTS) ;
- }
-
- public boolean isOpen() {
- return space != null ;
- }
-
- public int read(long posn, ByteBuffer bb) {
- if ( TRACKING )
- log("read<<%s", ByteBufferLib.details(bb));
- checkOpen() ;
- checkPosition(posn) ;
- int len = bb.remaining() ;
- if ( posn+dataLength > dataLength )
- len = (int)(dataLength-posn) ;
- arrayCopyOut(space, posn, bb);
- return len ;
- }
-
- public int read(long posn, byte[] b) {
- if ( TRACKING )
- log("read<<[%d]", b.length) ;
- return read$(posn, b, 0, b.length) ;
- }
-
- public int read(long posn, byte[] b, int start, int length) {
- if ( TRACKING )
- log("read<<[%d],%s,%s", b.length, start, length) ;
- return read$(posn, b, start, length) ;
- }
-
- private int read$(long posn, byte[] b, int start, int length) {
- checkOpen() ;
- if ( posn >= dataLength )
- return -1 ;
- checkPosition(posn) ;
- if ( length == 0 )
- return 0 ;
- checkByteArray(b, start, length) ;
- int len = length ;
- if ( posn+length > dataLength )
- len = (int)(dataLength-posn) ;
- arrayCopyOut(space, posn, b, start, len) ;
- return len ;
- }
-
- public void write(long posn, ByteBuffer bb ) {
- if ( TRACKING )
- log("read<<%s", ByteBufferLib.details(bb));
- checkOpen() ;
- if ( posn != dataLength )
- checkPosition(posn) ;
- arrayCopyIn(bb, space, posn) ;
- }
-
- public void write(long posn, byte[] b ) {
- if ( TRACKING )
- log("read<<[%d]", b.length) ;
- write$(posn, b, 0, b.length) ;
- }
-
- public void write(long posn, byte[] b, int start, int length) {
- if ( TRACKING )
- log("read<<[%d],%d,%d", b.length, start, length) ;
- write$(posn, b, start, length);
- }
-
- private void write$(long posn, byte[] b, int start, int length) {
- checkOpen() ;
- checkPosition(posn) ;
- if ( length == 0 )
- return ;
- checkByteArray(b,start,length) ;
- arrayCopyIn(b, start, space, dataLength, length) ;
- }
-
- public void truncate(long length) {
- if ( TRACKING )
- log("truncate(%d)", length) ;
- if ( length < 0 )
- IO.exception(String.format("truncate: bad length : %d", length)) ;
- checkOpen() ;
- dataLength = Math.min(dataLength, length) ;
- // clear above?
- }
-
- public void sync() {
- checkOpen() ;
- }
-
- public void close() {
- if ( ! isOpen() )
- return ;
- isOpen = false ;
- space.clear() ;
- space = null ;
- }
-
- public long length() {
- return dataLength ;
- }
-
- private void checkOpen() {
- if ( ! isOpen )
- IO.exception("Not open") ;
- }
-
- private void checkPosition(long posn) {
- // Allows posn to be exactly the byte beyond the end
- if ( posn < 0 || posn > dataLength )
- IO.exception(String.format("Position out of bounds: %d in [0,%d]", posn, dataLength)) ;
- }
-
- private void checkByteArray(byte[] b, int start, int length) {
- if ( start < 0 || start >= b.length )
- IO.exception(String.format("Start point out of bounds of byte array: %d in [0,%d)", start, b.length)) ;
- if ( length < 0 || start+length > b.length )
- IO.exception(String.format("Start/length out of bounds of byte array: %d/%d in [0,%d)", start, length, b.length)) ;
- }
-
- private int getSegment(long posn) { return (int)(posn / CHUNK) ; }
-
- private int getOffset(long posn) { return (int) (posn % CHUNK) ; }
-
- // c.f. System.arrayCopy
- private void arrayCopyIn(byte[] src, final int srcStart, List<byte[]> dest, final long destStart, final int length) {
- if ( length == 0 )
- return ;
- int len = length ;
- int srcPosn = srcStart ;
- int seg = getSegment(destStart) ;
- int offset = getOffset(destStart) ;
- while( len > 0 ) {
- int z = Math.min(len, CHUNK-offset) ;
- // Beyond end of file?
- if ( seg >= dest.size() ) {
- byte[] buffer = new byte[CHUNK] ;
- space.add(buffer) ;
- }
- System.arraycopy(src, srcPosn, dest.get(seg), offset, z);
- srcPosn += z ;
- len -= z ;
- seg += 1 ;
- offset += z ;
- offset %= CHUNK ;
- }
- dataLength = Math.max(dataLength, destStart+length) ;
- }
-
- private void arrayCopyOut(List<byte[]> src, final long srcStart, byte[] dest, final int destStart, final int length) {
- int len = length ;
- len = Math.min(len, (int)(dataLength-srcStart)) ;
- int dstPosn = destStart ;
- int seg = getSegment(srcStart) ;
- int offset = getOffset(srcStart) ;
- while( len > 0 ) {
- int z = Math.min(len, CHUNK-offset) ;
- System.arraycopy(src.get(seg), offset, dest, dstPosn, z);
- dstPosn += z ;
- len -= z ;
- seg += 1 ;
- offset += z ;
- offset %= CHUNK ;
- }
- }
-
- private void arrayCopyIn(ByteBuffer bb, List<byte[]> dest, long destStart) {
- if ( bb.remaining() == 0 )
- return ;
- int length = bb.remaining() ;
- int len = bb.remaining() ;
- int srcPosn = bb.position() ;
- int seg = getSegment(destStart) ;
- int offset = getOffset(destStart) ;
- while( len > 0 ) {
- int z = Math.min(len, CHUNK-offset) ;
- // Beyond end of file?
- if ( seg >= dest.size() ) {
- byte[] buffer = new byte[CHUNK] ;
- space.add(buffer) ;
- }
- byte[] bytes = dest.get(seg) ;
- bb.get(bytes, offset, z) ;
- srcPosn += z ;
- len -= z ;
- seg += 1 ;
- offset += z ;
- offset %= CHUNK ;
- }
- dataLength = Math.max(dataLength, destStart+length) ;
- }
-
- private void arrayCopyOut(List<byte[]> src, long srcStart, ByteBuffer bb) {
- int len = bb.remaining() ;
- len = Math.min(len, (int)(dataLength-srcStart)) ;
- int dstPosn = bb.position() ;
- int seg = getSegment(srcStart) ;
- int offset = getOffset(srcStart) ;
- while( len > 0 ) {
- int z = Math.min(len, CHUNK-offset) ;
- byte[] bytes = src.get(seg) ;
- bb.put(bytes, offset, z) ;
- dstPosn += z ;
- len -= z ;
- seg += 1 ;
- offset += z ;
- offset %= CHUNK ;
- }
- }
-
- private void log(String fmt, Object... args) {
- if ( TRACKING )
- FmtLog.debug(log, fmt, args);
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/BlockConverter.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/BlockConverter.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/BlockConverter.java
deleted file mode 100644
index e809604..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/BlockConverter.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.dboe.base.page;
-
-import org.seaborne.dboe.base.block.Block ;
-import org.seaborne.dboe.base.block.BlockType ;
-
-/** Convert between Blocks and typed Pages */
-public interface BlockConverter<T extends Page>
-{
- /** Create a T, given an existing Block */
- public T fromBlock(Block block) ;
-
- /** Make a block, given a T */
- public Block toBlock(T t) ;
-
- /** Create a new T from an uninitialized Block */
- public T createFromBlock(Block block, BlockType bType) ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/Page.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/Page.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/Page.java
deleted file mode 100644
index d39d8d2..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/Page.java
+++ /dev/null
@@ -1,45 +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.base.page;
-
-import org.apache.jena.atlas.io.Printable ;
-import org.seaborne.dboe.base.block.Block ;
-
-public interface Page extends Printable
-{
- public static final int NO_ID = -1 ;
-
- /** Pages are addressed ints (a page ref does in on-disk blocks)
- * although block are address in longs
- */
- public int getId() ;
-
- /** Return a string for display that identifies this Page */
- public String getRefStr() ;
-
- /** Return the block associated with this page */
- public Block getBackingBlock() ;
-
- /**
- * The underlying block for this page has changed (e.g. it's been
- * promoted and the promotion may have caused the block to change.
- */
- public abstract void reset(Block block) ;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/PageBase.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/PageBase.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/PageBase.java
deleted file mode 100644
index 0482b73..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/PageBase.java
+++ /dev/null
@@ -1,58 +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.base.page;
-
-import org.seaborne.dboe.DBOpEnvException ;
-import org.seaborne.dboe.base.block.Block ;
-
-/** A page with a byte buffer */
-public abstract class PageBase implements Page
-{
- private int id ;
- private Block block ;
-
- protected PageBase(Block block)
- {
- this.block = block ;
- long x = block.getId() ;
- if ( x < 0 )
- throw new DBOpEnvException("Page id is negative: "+x) ;
- if ( x > Integer.MAX_VALUE )
- throw new DBOpEnvException("Page id is large than MAX_INT: "+x) ;
- this.id = block.getId().intValue() ;
- }
-
- @Override
- final public void reset(Block block2)
- {
-// if ( block2.getId() != id )
-// Log.warn(this, "Block id changed: "+id+" => "+block2.getId()) ;
- id = block2.getId().intValue() ;
- _reset(block2) ;
- this.block = block2 ;
- }
-
- protected abstract void _reset(Block block) ;
-
- @Override
- final public Block getBackingBlock() { return block ; }
-
- @Override
- final public int getId() { return id ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/PageBlockMgr.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/PageBlockMgr.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/PageBlockMgr.java
deleted file mode 100644
index 38b93f1..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/page/PageBlockMgr.java
+++ /dev/null
@@ -1,213 +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.base.page;
-
-import org.apache.jena.atlas.lib.Closeable ;
-import org.apache.jena.atlas.lib.InternalErrorException ;
-import org.apache.jena.atlas.logging.Log ;
-import org.seaborne.dboe.base.block.Block ;
-import org.seaborne.dboe.base.block.BlockMgr ;
-import org.seaborne.dboe.base.block.BlockType ;
-
-/** Engine that wraps from blocks to typed pages. */
-
-public class PageBlockMgr<T extends Page> implements Closeable
-{
- protected final BlockMgr blockMgr ;
- protected BlockConverter<T> pageFactory ;
-
- protected PageBlockMgr(BlockConverter<T> pageFactory, BlockMgr blockMgr) {
- this.pageFactory = pageFactory ;
- this.blockMgr = blockMgr ;
- }
-
- // Sometimes, the subclass must pass null to the constructor then call this.
- protected void setConverter(BlockConverter<T> pageFactory) { this.pageFactory = pageFactory ; }
-
- public BlockMgr getBlockMgr() { return blockMgr ; }
-
- public long allocLimit() { return blockMgr.allocLimit() ; }
-
- public void resetAlloc(long boundary) {
- blockMgr.resetAlloc(boundary) ;
- }
-
- /** Allocate a new thing */
- public T create(BlockType bType) {
- Block block = blockMgr.allocate(-1) ;
- block.setModified(true) ;
- T page = pageFactory.createFromBlock(block, bType) ;
- return page ;
- }
-
- /**
- * Fetch a block for reading.
- * @param id Block to fetch
- */
- public T getRead(int id) {
- return getRead$(id) ;
- }
-
- /**
- * Fetch a block for reading.
- *
- * @param id Block to fetch
- * @param referencingId
- * Id of block referring to this one.
- * For example, a parent in a tree.
- * May be negative for "none" or "meaningless".
- */
- public T getRead(int id, int referencingId) {
- return getRead$(id) ;
- }
-
- /**
- * Fetch a block for writing.
- * @param id Block to fetch
- */
- public T getWrite(int id) {
- return getWrite$(id) ;
- }
-
- /**
- * Fetch a block for writing.
- *
- * @param id Block to fetch
- * @param referencingId
- * Id of block referring to this one.
- * For example, a parent in a tree.
- * May be -1 for "none" or "meaningless".
- */
- public T getWrite(int id, int referencingId) {
- return getWrite$(id) ;
- }
-
- // ---- The read and write worker operations.
-
- final protected T getRead$(int id) {
- Block block = blockMgr.getRead(id) ;
- // Blocks from the BlockMgrCache may be write-dirty so this test
- // is wrong in that situation. It is better to use the block as-is
- // otherwise we'd have two blocks of a given id with different flags
- // that confuse the block caching.
-// if ( block.isModified() ) {
-// System.err.println("getRead - isModified - "+blockMgr.getLabel()+"["+id+"]") ;
-//// block = new Block(block.getId(), block.getByteBuffer());
-//// block.setModified(false);
-// // Debug.
-// //blockMgr.getRead(id) ;
-// }
- T page = pageFactory.fromBlock(block) ;
- return page ;
- }
-
- final protected T getWrite$(int id) {
- Block block = blockMgr.getWrite(id) ;
- block.setReadOnly(false) ;
- T page = pageFactory.fromBlock(block) ;
- return page ;
- }
-
- // ----
-
- public void put(T page) {
- write(page) ;
- release(page) ;
- }
-
- public void write(T page) {
- Block blk = pageFactory.toBlock(page) ;
- blockMgr.write(blk) ;
- }
-
- public void release(Page page) {
- Block block = page.getBackingBlock() ;
- blockMgr.release(block) ;
- }
-
- private void warn(String string) {
- Log.warn(this, string) ;
- }
-
- public void free(Page page) {
- Block block = page.getBackingBlock() ;
- blockMgr.free(block) ;
- }
-
-
- /** Promote a page to be writable in-place (block id does not change, hnce page does not change id). */
- public void promoteInPlace(Page page) {
- Block block = page.getBackingBlock() ;
- block.getByteBuffer().rewind() ;
- Block block2 = blockMgr.promote(block) ;
- block2.setReadOnly(false) ;
- if ( block2.getId() != block.getId() )
- throw new InternalErrorException("Block id changed") ;
- if ( block2 == block )
- return ;
- // Change - reset Block in page.
- // The details should not have changed.
- // page.reset(block2) ;
- }
-
- /** Promote a page - return 'true' if the block changed (.reset()) will have been called */
- public boolean promoteDuplicate(Page page) {
- Block block = page.getBackingBlock() ;
- block.getByteBuffer().rewind() ;
-
- // --- TODO Always new
- Block block2 = blockMgr.allocate(-1) ;
- block2.getByteBuffer().put(block.getByteBuffer()) ;
- block2.getByteBuffer().rewind() ;
- block2.setReadOnly(false) ;
-
- if ( block2 == block )
- return false ;
- // Change - reset Block in page.
- page.reset(block2) ;
- return true ;
- }
-
- public boolean valid(int id) {
- return blockMgr.valid(id) ;
- }
-
- public void dump() {
- for ( int idx = 0 ; valid(idx) ; idx++ ) {
- T page = getRead(idx, -1) ;
- System.out.println(page) ;
- release(page) ;
- }
- }
-
- /** Signal the start of an update operation */
- public void startUpdate() { blockMgr.beginUpdate() ; }
-
- /** Signal the completion of an update operation */
- public void finishUpdate() { blockMgr.endUpdate() ; }
-
- /** Signal the start of an update operation */
- public void startRead() { blockMgr.beginRead() ; }
-
- /** Signal the completeion of an update operation */
- public void finishRead() { blockMgr.endRead() ; }
-
- @Override
- public void close() { blockMgr.close(); }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/Record.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/Record.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/Record.java
deleted file mode 100644
index f06d383..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/Record.java
+++ /dev/null
@@ -1,189 +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.base.record;
-
-import static java.lang.String.format ;
-
-import java.util.Arrays ;
-
-import org.apache.jena.atlas.lib.Bytes ;
-import org.seaborne.dboe.sys.SystemIndex ;
-
-/** A record is pair of key and value. It may be all key, in which case value is null. */
-
-final
-public class Record //implements Comparable<Record>
-{
- /*
- * Records of fixed size (controlled by the factory).
- */
- public static final Record NO_REC = null ;
-
- final private byte[] key ;
- final private byte[] value ;
-
- public Record(byte[] key, byte[] value)
- {
- this.key = key ;
- this.value = value ;
- if ( SystemIndex.Checking )
- {
- if ( value != null && value.length == 0 )
- throw new RecordException("Zero length value") ;
- }
- }
-
- public byte[] getKey() { return key ; }
- public byte[] getValue() { return value ; }
-
- public boolean hasSeparateValue() { return value!=null ; }
-
- @Override
- public int hashCode()
- {
- return Arrays.hashCode(key) ^ Arrays.hashCode(value) ;
- }
-
- @Override
- public boolean equals(Object other)
- {
- if ( this == other ) return true ;
- if ( ! ( other instanceof Record ) ) return false ;
- Record r = (Record)other ;
- return compareByKeyValue(this, r) == 0 ;
- }
-
- @Override
- public String toString()
- {
- if ( value == null )
- return str(key) ;
- return str(key)+":"+str(value) ;
- }
-
- /** Is the key of record1 == key of record2 */
- public static boolean keyEQ(Record record1, Record record2)
- {
- int x = compareByKey(record1, record2) ;
- return x == 0 ;
- }
-
- /** Is the key of record1 != key of record2 */
- public static boolean keyNE(Record record1, Record record2)
- {
- int x = compareByKey(record1, record2) ;
- return x != 0 ;
- }
-
- /** Is the key of record1 < key of record2 */
- public static boolean keyLT(Record record1, Record record2)
- {
- int x = compareByKey(record1, record2) ;
- return x < 0 ;
- }
-
- /** Is the key of record1 <= key of record2 */
- public static boolean keyLE(Record record1, Record record2)
- {
- int x = compareByKey(record1, record2) ;
- return x <= 0 ;
- }
-
- /** Is the key of record1 >= key of record2 */
- public static boolean keyGE(Record record1, Record record2)
- {
- int x = compareByKey(record1, record2) ;
- return x >= 0 ;
- }
-
- /** Is the key of record1 > key of record2 */
- public static boolean keyGT(Record record1, Record record2)
- {
- int x = compareByKey(record1, record2) ;
- return x > 0 ;
- }
-
- /** Is (key, value) of record1 equal to (key,value) of record2 */
- public static boolean equals(Record record1, Record record2)
- {
- int x = compareByKeyValue(record1, record2) ;
- return x == 0 ;
- }
-
-
-
- static public String str(byte[] b)
- {
- StringBuilder str = new StringBuilder() ;
- for ( byte aB : b )
- {
- str.append( format( "%02x", aB ) );
- }
- return str.toString() ;
- }
-
- public static int compareByKey(Record record1, Record record2)
- {
- checkKeyCompatible(record1, record2) ;
- return Bytes.compare(record1.key, record2.key) ;
- }
-
- public static int compareByKeyValue(Record record1, Record record2)
- {
- checkCompatible(record1, record2) ;
- int x = Bytes.compare(record1.key, record2.key) ;
- if ( x == 0 )
- {
- if ( record1.value != null )
- x = Bytes.compare(record1.value, record2.value) ;
- }
- return x ;
- }
-
- static void checkCompatible(Record record1, Record record2)
- {
- if ( ! compatible(record1, record2, true) )
- throw new RecordException(format("Incompatible: %s, %s", record1, record2)) ;
- }
-
- static void checkKeyCompatible(Record record1, Record record2)
- {
- if ( ! compatible(record1, record2, false) )
- throw new RecordException(format("Incompatible: %s, %s", record1, record2)) ;
- }
-
- static boolean compatible(Record record1, Record record2, boolean checkValue)
- {
- if ( record1.key.length != record2.key.length )
- return false ;
-
- if ( checkValue )
- {
- if ( record1.value == null && record2.value == null )
- return true ;
- if ( record1.value == null )
- return false ;
- if ( record2.value == null )
- return false ;
- if ( record1.value.length != record2.value.length )
- return false;
- }
- return true ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordException.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordException.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordException.java
deleted file mode 100644
index 4b0301a..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordException.java
+++ /dev/null
@@ -1,27 +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.base.record;
-
-import org.seaborne.dboe.DBOpEnvException ;
-
-public class RecordException extends DBOpEnvException
-{
- public RecordException() {}
- public RecordException(String msg) { super(msg) ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordFactory.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordFactory.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordFactory.java
deleted file mode 100644
index a4c9cbb..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordFactory.java
+++ /dev/null
@@ -1,184 +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.base.record;
-
-import static java.lang.String.format;
-
-import java.nio.ByteBuffer;
-
-/** Record creator */
-final
-public class RecordFactory
-{
- private final int keyLength;
- private final int valueLength;
- private final int slotLen;
- private final boolean checking = false;
-
- public RecordFactory(int keyLength, int valueLength) {
- if ( keyLength <= 0 )
- throw new IllegalArgumentException("Bad key length: " + keyLength);
- if ( valueLength < 0 )
- throw new IllegalArgumentException("Bad value length: " + valueLength);
-
- this.keyLength = keyLength;
- this.valueLength = valueLength;
- this.slotLen = keyLength + valueLength;
- }
-
- /** Return a RecordFactory that makes key-only records of the same key size */
- public RecordFactory keyFactory() {
- return new RecordFactory(keyLength, 0);
- }
-
- /** Create a key-only record, allocating blank space for the key */
- public Record createKeyOnly() {
- return create(new byte[keyLength], null);
- }
-
- /** Create a key-only record */
- public Record createKeyOnly(Record record) {
- checkKey(record.getKey());
- if ( record.getValue() == null )
- return record;
-
- return create(record.getKey(), null);
- }
-
- /** Create a key and value record (value uninitialized) */
- public Record create(byte[] key) {
- checkKey(key);
- byte[] v = null;
- if ( valueLength > 0 )
- v = new byte[valueLength];
- return create(key, v);
- }
-
- /** Create a record, allocating space for the key and value (if any) */
- public Record create() {
- return create(new byte[keyLength], (valueLength > 0) ? new byte[valueLength] : null);
- }
-
- /** Create a key and value record */
- public Record create(byte[] key, byte[] value) {
- check(key, value);
- return new Record(key, value);
- }
-
- public void insertInto(Record record, ByteBuffer bb, int idx) {
- check(record);
- bb.position(idx * slotLen);
- bb.put(record.getKey(), 0, keyLength);
- if ( hasValue() && record.getValue() != null )
- bb.put(record.getValue(), 0, valueLength);
- }
-
- public static final RecordMapper<Record> mapperRecord = new RecordMapper<Record>() {
- /*
- * RecordRangeIterator calls getRecordBuffer().get(slotidx);
- */
- @Override
- public Record map(ByteBuffer bb, int idx, byte[] keyBytes, RecordFactory factory) {
- byte[] key = new byte[factory.keyLength];
- byte[] value = (factory.hasValue() ? new byte[factory.valueLength] :null );
- // Is it better to avoid the synchronize needed for bb.position./bb.get
- // but not use a (relative) bulk bb.get(byte[],,) which may be a native operation?
-
-// int posnKey = idx*slotLen;
-// // Avoid using position() so we can avoid needing synchronized.
-// copyInto(key, bb, posnKey, keyLength);
-// if ( value != null )
-// {
-// int posnValue = idx*slotLen+keyLength;
-// copyInto(value, bb, posnValue, valueLength);
-// }
-
- // Using bb.get(byte[],,) may be potentially faster but requires the synchronized
- // There's no absolute version.
- synchronized(bb)
- {
- bb.position(idx*factory.slotLen);
- bb.get(key, 0, factory.keyLength);
- if ( value != null )
- bb.get(value, 0, factory.valueLength);
- }
- if ( keyBytes != null )
- System.arraycopy(key, 0, keyBytes, 0, factory.keyLength);
- return factory.create(key, value);
- }
- };
-
- public <X> X access(ByteBuffer bb, int idx, byte[] keyBytes, RecordMapper<X> mapper) {
- return mapper.map(bb, idx, keyBytes, this);
- }
-
- public Record buildFrom(ByteBuffer bb, int idx) {
- return access(bb, idx, null, mapperRecord);
- }
-
- private final void copyInto(byte[] dst, ByteBuffer src, int start, int length) {
- // Thread safe.
- for ( int i = 0; i < length; i++ )
- dst[i] = src.get(start+i);
- // Would otherwise be ...
-// src.position(start);
-// src.get(dst, 0, length);
- }
-
- public boolean hasValue() { return valueLength > 0; }
-
- public int recordLength() { return keyLength + valueLength; }
-
- public int keyLength() { return keyLength; }
-
- public int valueLength() { return valueLength; }
-
- @Override
- public String toString() {
- return format("<RecordFactory k=%d v=%d>", keyLength, valueLength);
- }
-
- private final void check(Record record) {
- if ( ! checking ) return;
- check(record.getKey(), record.getValue());
- }
-
- private final void checkKey(byte[] k) {
- if ( ! checking ) return;
- if ( k == null )
- throw new RecordException("Null key byte[]");
- if ( keyLength != k.length )
- throw new RecordException(format("Key length error: This RecordFactory manages records of key length %d, not %d", keyLength,
- k.length));
- }
-
- private final void check(byte[] k, byte[] v) {
- if ( ! checking ) return;
- checkKey(k);
- if ( valueLength <= 0 ) {
- if ( v != null )
- throw new RecordException("Value array error: This RecordFactory manages records that are all key");
- } else {
- // v == null for a key-only record from this factory.
- if ( v != null && v.length != valueLength )
- throw new RecordException(format("This RecordFactory manages record of value length %d, not (%d,-)", valueLength,
- v.length));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordMapper.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordMapper.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordMapper.java
deleted file mode 100644
index faf3037..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/record/RecordMapper.java
+++ /dev/null
@@ -1,31 +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.base.record;
-
-import java.nio.ByteBuffer ;
-
-/** Allow bytes to pull directly out of storage with no copy to record;
- * also extract the key bytes into an array.
- * This operation MUST not retain any references to the ByteBuffer storage space.
- * All in order to avoid remapping Records to higher level objects,
- * which churns objects (GC issue) and avoids a copy.
- */
-public interface RecordMapper<X> {
- X map(ByteBuffer bb, int entryIdx, byte key[], RecordFactory recFactory) ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/recordbuffer/RecordBufferPage.java
----------------------------------------------------------------------
diff --git a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/recordbuffer/RecordBufferPage.java b/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/recordbuffer/RecordBufferPage.java
deleted file mode 100644
index db93043..0000000
--- a/jena-db/dboe-base/src/main/java/org/seaborne/dboe/base/recordbuffer/RecordBufferPage.java
+++ /dev/null
@@ -1,101 +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.base.recordbuffer;
-
-import org.seaborne.dboe.base.block.Block ;
-import org.seaborne.dboe.base.page.Page ;
-import org.seaborne.dboe.base.record.RecordFactory ;
-import org.seaborne.dboe.sys.Sys ;
-
-/**
- * B+Tree records nodes and hash buckets.
- * Add link field to a RecordBufferPageBase
- */
-
-public final class RecordBufferPage extends RecordBufferPageBase
-{
- // Why not straight to BPlusTreeRecords?
- // 1 - this may be useful in its own right as a sequence of records on-disk.
- // 2 - BPlusTreeRecords inherits from BPlusTreePage
-
-
- // To Constants
- // Offsets
- // final public static int COUNT = 0 ;
- // Adds this field over RecordBufferPageBase
- final public static int LINK = 4 ;
- final private static int FIELD_LENGTH = Sys.SizeOfInt ; // Length of the space needed here (not count)
-
- private int link = Page.NO_ID ;
-
- public final int getLink() { return link ; }
-
- public void setLink(int link)
- {
- this.link = link ;
- getBackingBlock().getByteBuffer().putInt(LINK, link) ;
- }
-
- @Override
- protected void _reset(Block block)
- {
- // TODO -- should this be format?
- // Print this
- super.rebuild(block, this.getCount()) ;
- //?? use .format
-// // TODO WRONG : block is overlying.
-// this.link = block.getByteBuffer().getInt(LINK) ;
- }
-
- public static int calcRecordSize(RecordFactory factory, int blkSize)
- { return RecordBufferPageBase.calcRecordSize(factory, blkSize, FIELD_LENGTH) ; }
-
- public static int calcBlockSize(RecordFactory factory, int maxRec)
- { return RecordBufferPageBase.calcBlockSize(factory, maxRec, FIELD_LENGTH) ; }
-
- /** The construction methods */
- public static RecordBufferPage createBlank(Block block,RecordFactory factory)
- {
- int count = 0 ;
- int linkId = NO_ID ;
- return new RecordBufferPage(block, factory, count, linkId) ;
- }
-
- public static RecordBufferPage format(Block block, RecordFactory factory)
- {
- int count = block.getByteBuffer().getInt(COUNT) ;
- int linkId = block.getByteBuffer().getInt(LINK) ;
- return new RecordBufferPage(block, factory, count, linkId) ;
- }
-
- private RecordBufferPage(Block block, RecordFactory factory, int count, int linkId)
- {
- super(block, FIELD_LENGTH, factory, count) ;
- this.link = linkId ;
- }
-
- @Override
- public String toString()
- { return String.format("RecordBufferPage[id=%d,link=%d]: %s", getBackingBlock().getId(), getLink(), recBuff) ; }
-
- @Override
- public String getRefStr() {
- return String.format("RecordBufferPage[id=%d]", getBackingBlock().getId()) ;
- }
-}