Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENA-1773: Remove any previous prefix setting. #625

Merged
merged 2 commits into from Oct 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,4 +39,9 @@ public String getPrefix() {
public String getUri() {
return uri;
}

@Override
public String toString() {
return "PrefixEntry["+prefix+": <"+uri+">]";
}
}
Expand Up @@ -17,6 +17,8 @@

package org.apache.jena.dboe.storage.prefixes;

import java.util.Objects;

import org.apache.jena.atlas.lib.Pair;
import org.apache.jena.dboe.storage.StoragePrefixes;
import org.apache.jena.graph.Node;
Expand All @@ -40,11 +42,23 @@ public static String canonicalPrefix(String prefix) {

/** Canonical name for graphs */
public static Node canonicalGraphName(Node graphName) {
if ( graphName == StoragePrefixes.nodeDefaultGraph)
return graphName;
if ( graphName == null || Quad.isDefaultGraph(graphName) )
return StoragePrefixes.nodeDefaultGraph;
return graphName;
}

/**
* Is this the canonical, internal marker for the default graph for storage
* prefixes? ({@link StoragePrefixes#nodeDefaultGraph})
*
* @param graphName
*/
public static boolean isNodeDefaultGraph(Node graphName) {
return Objects.equals(StoragePrefixes.nodeDefaultGraph, graphName);
}

/** abbreviate a uriStr, giving a string as a short form. If not possible return null.
* This does not guarantee that the result is suitable for all RDF syntaxes.
* Further checking for the rules of a particular syntax are necessary.
Expand Down
Expand Up @@ -136,7 +136,7 @@ class PrefixMapTDB2 extends PrefixMapBase {
@Override
protected StoragePrefixMap spm() {
StoragePrefixes prefixes = getDSG().getPrefixes();
StoragePrefixMap view = Quad.isDefaultGraph(graphName)
StoragePrefixMap view = PrefixLib.isNodeDefaultGraph(graphName)
? StoragePrefixesView.viewDefaultGraph(prefixes)
: StoragePrefixesView.viewGraph(prefixes, graphName);
return view;
Expand Down
Expand Up @@ -91,6 +91,8 @@ public void add_ext(Node graphNode, String prefix, String iriStr) {
graphNode = PrefixLib.canonicalGraphName(graphNode);
Node p = NodeFactory.createLiteral(prefix);
Node u = NodeFactory.createURI(iriStr);
// Delete any existing old mapping of prefix.
remove_ext(graphNode, p, Node.ANY);
prefixTable.addRow(graphNode,p,u);
}

Expand All @@ -111,7 +113,7 @@ private void remove(Node g, Node p, Node u) {
}

/** Remove without checks - used by the bulkloader when it takes control of the transaction. */
public void remove_ext(Node g, Node p, Node u) {
private void remove_ext(Node g, Node p, Node u) {
// See add_ext
g = PrefixLib.canonicalGraphName(g);
Iterator<Tuple<Node>> iter = prefixTable.find(g, p, u);
Expand Down