public static void main(String[] args) throws Exception { File dataDir = new File(args[0]); ValueStore valueStore = new ValueStore(dataDir); int maxID = valueStore.dataStore.getMaxID(); for (int id = 1; id <= maxID; id++) { byte[] data = valueStore.dataStore.getData(id); if (valueStore.isNamespaceData(data)) { String ns = valueStore.data2namespace(data); System.out.println("[" + id + "] " + ns); } else { Value value = valueStore.data2value(id, data); System.out.println("[" + id + "] " + value.toString()); } } } }
private byte[] value2data(Value value, boolean create) throws IOException { if (value instanceof IRI) { return uri2data((IRI)value, create); } else if (value instanceof BNode) { return bnode2data((BNode)value, create); } else if (value instanceof Literal) { return literal2data((Literal)value, create); } else { throw new IllegalArgumentException("value parameter should be a URI, BNode or Literal"); } }
private boolean upgradeStore(File dataDir, String version) throws IOException, SailException { if (version == null) { // either a new store or a pre-2.8.2 store ValueStore valueStore = new ValueStore(dataDir); try { valueStore.checkConsistency(); return true; // good enough } catch (SailException e) { // valueStore is not consistent - possibly contains two entries for // string-literals with the same lexical value (e.g. "foo" and // "foo"^^xsd:string). Log an error and indicate upgrade should // not be executed. logger.error( "VALUE INCONSISTENCY: could not automatically upgrade native store to RDF 1.1-compatibility: {}. Failure to upgrade may result in inconsistent query results when comparing literal values.", e.getMessage()); return false; } finally { valueStore.close(); } } else { return false; // no upgrade needed } } }
private NativeValue data2value(int id, byte[] data) throws IOException { switch (data[0]) { case URI_VALUE: return data2uri(id, data); case BNODE_VALUE: return data2bnode(id, data); case LITERAL_VALUE: return data2literal(id, data); default: throw new IllegalArgumentException( "Namespaces cannot be converted into values: " + data2namespace(data)); } }
for (int id = 1; id <= maxID; id++) { byte[] data = dataStore.getData(id); if (isNamespaceData(data)) { String namespace = data2namespace(data); try { if (id == getNamespaceID(namespace, false) && java.net.URI.create(namespace + "part").isAbsolute()) Value value = this.data2value(id, data); if (id != this.getID(copy(value))) { throw new SailException( "Store must be manually exported and imported to merge values like " + value);
private Value copy(Value value) { if (value instanceof IRI) { return createIRI(value.stringValue()); } else if (value instanceof Literal) { Literal lit = (Literal)value; if (Literals.isLanguageLiteral(lit)) { return createLiteral(value.stringValue(), lit.getLanguage().orElse(null)); } else { return createLiteral(value.stringValue(), lit.getDatatype()); } } else { return createBNode(value.stringValue()); } }
public Statement getNextElement() throws SailException { try { byte[] nextValue = btreeIter.next(); if (nextValue == null) { return null; } int subjID = ByteArrayUtil.getInt(nextValue, TripleStore.SUBJ_IDX); Resource subj = (Resource)valueStore.getValue(subjID); int predID = ByteArrayUtil.getInt(nextValue, TripleStore.PRED_IDX); IRI pred = (IRI)valueStore.getValue(predID); int objID = ByteArrayUtil.getInt(nextValue, TripleStore.OBJ_IDX); Value obj = valueStore.getValue(objID); Resource context = null; int contextID = ByteArrayUtil.getInt(nextValue, TripleStore.CONTEXT_IDX); if (contextID != 0) { context = (Resource)valueStore.getValue(contextID); } return valueStore.createStatement(subj, pred, obj, context); } catch (IOException e) { throw causeIOException(e); } }
/** * Creates a new {@link NativeSailStore}. */ public NativeSailStore(File dataDir, String tripleIndexes, boolean forceSync, int valueCacheSize, int valueIDCacheSize, int namespaceCacheSize, int namespaceIDCacheSize) throws IOException, SailException { boolean initialized = false; try { namespaceStore = new NamespaceStore(dataDir); valueStore = new ValueStore(dataDir, forceSync, valueCacheSize, valueIDCacheSize, namespaceCacheSize, namespaceIDCacheSize); tripleStore = new TripleStore(dataDir, tripleIndexes, forceSync); initialized = true; } finally { if (!initialized) { close(); } } }
@Override public void close() throws SailException { try { try { if (namespaceStore != null) { namespaceStore.close(); } } finally { try { if (valueStore != null) { valueStore.close(); } } finally { if (tripleStore != null) { tripleStore.close(); } } } } catch (IOException e) { logger.warn("Failed to close store", e); throw new SailException(e); } }
for (int id = 1; id <= maxID; id++) { byte[] data = dataStore.getData(id); if (isNamespaceData(data)) { String namespace = data2namespace(data); try { if (id == getNamespaceID(namespace, false) && java.net.URI.create(namespace + "part").isAbsolute()) Value value = this.data2value(id, data); if (id != this.getID(copy(value))) { throw new SailException( "Store must be manually exported and imported to merge values like " + value);
private NativeValue data2value(int id, byte[] data) throws IOException { switch (data[0]) { case URI_VALUE: return data2uri(id, data); case BNODE_VALUE: return data2bnode(id, data); case LITERAL_VALUE: return data2literal(id, data); default: throw new IllegalArgumentException( "Namespaces cannot be converted into values: " + data2namespace(data)); } }
private Value copy(Value value) { if (value instanceof IRI) { return createIRI(value.stringValue()); } else if (value instanceof Literal) { Literal lit = (Literal)value; if (Literals.isLanguageLiteral(lit)) { return createLiteral(value.stringValue(), lit.getLanguage().orElse(null)); } else { return createLiteral(value.stringValue(), lit.getDatatype()); } } else { return createBNode(value.stringValue()); } }
public Statement getNextElement() throws SailException { try { byte[] nextValue = btreeIter.next(); if (nextValue == null) { return null; } int subjID = ByteArrayUtil.getInt(nextValue, TripleStore.SUBJ_IDX); Resource subj = (Resource)valueStore.getValue(subjID); int predID = ByteArrayUtil.getInt(nextValue, TripleStore.PRED_IDX); IRI pred = (IRI)valueStore.getValue(predID); int objID = ByteArrayUtil.getInt(nextValue, TripleStore.OBJ_IDX); Value obj = valueStore.getValue(objID); Resource context = null; int contextID = ByteArrayUtil.getInt(nextValue, TripleStore.CONTEXT_IDX); if (contextID != 0) { context = (Resource)valueStore.getValue(contextID); } return valueStore.createStatement(subj, pred, obj, context); } catch (IOException e) { throw causeIOException(e); } }
/** * Creates a new {@link NativeSailStore}. */ public NativeSailStore(File dataDir, String tripleIndexes, boolean forceSync, int valueCacheSize, int valueIDCacheSize, int namespaceCacheSize, int namespaceIDCacheSize) throws IOException, SailException { boolean initialized = false; try { namespaceStore = new NamespaceStore(dataDir); valueStore = new ValueStore(dataDir, forceSync, valueCacheSize, valueIDCacheSize, namespaceCacheSize, namespaceIDCacheSize); tripleStore = new TripleStore(dataDir, tripleIndexes, forceSync); initialized = true; } finally { if (!initialized) { close(); } } }
@Override public void close() throws SailException { try { try { if (namespaceStore != null) { namespaceStore.close(); } } finally { try { if (valueStore != null) { valueStore.close(); } } finally { if (tripleStore != null) { tripleStore.close(); } } } } catch (IOException e) { logger.warn("Failed to close store", e); throw new SailException(e); } }
public static void main(String[] args) throws Exception { File dataDir = new File(args[0]); ValueStore valueStore = new ValueStore(dataDir); int maxID = valueStore.dataStore.getMaxID(); for (int id = 1; id <= maxID; id++) { byte[] data = valueStore.dataStore.getData(id); if (valueStore.isNamespaceData(data)) { String ns = valueStore.data2namespace(data); System.out.println("[" + id + "] " + ns); } else { Value value = valueStore.data2value(id, data); System.out.println("[" + id + "] " + value.toString()); } } } }
private byte[] value2data(Value value, boolean create) throws IOException { if (value instanceof IRI) { return uri2data((IRI)value, create); } else if (value instanceof BNode) { return bnode2data((BNode)value, create); } else if (value instanceof Literal) { return literal2data((Literal)value, create); } else { throw new IllegalArgumentException("value parameter should be a URI, BNode or Literal"); } }
private boolean upgradeStore(File dataDir, String version) throws IOException, SailException { if (version == null) { // either a new store or a pre-2.8.2 store ValueStore valueStore = new ValueStore(dataDir); try { valueStore.checkConsistency(); return true; // good enough } catch (SailException e) { // valueStore is not consistent - possibly contains two entries for // string-literals with the same lexical value (e.g. "foo" and // "foo"^^xsd:string). Log an error and indicate upgrade should // not be executed. logger.error( "VALUE INCONSISTENCY: could not automatically upgrade native store to RDF 1.1-compatibility: {}. Failure to upgrade may result in inconsistent query results when comparing literal values.", e.getMessage()); return false; } finally { valueStore.close(); } } else { return false; // no upgrade needed } } }