From 3f2b225434959b25e1d405c9ac09343403807160 Mon Sep 17 00:00:00 2001 From: Joshua Shinavier Date: Thu, 29 May 2014 18:46:56 -0400 Subject: [PATCH] Removed some deprecated calls and unnecessary casts --- .../blueprints/oupls/sail/GraphSail.java | 19 +++-- .../oupls/sail/GraphSailConnection.java | 79 +++---------------- 2 files changed, 22 insertions(+), 76 deletions(-) diff --git a/blueprints-graph-sail/src/main/java/com/tinkerpop/blueprints/oupls/sail/GraphSail.java b/blueprints-graph-sail/src/main/java/com/tinkerpop/blueprints/oupls/sail/GraphSail.java index a91ffc57..dfdd0c94 100644 --- a/blueprints-graph-sail/src/main/java/com/tinkerpop/blueprints/oupls/sail/GraphSail.java +++ b/blueprints-graph-sail/src/main/java/com/tinkerpop/blueprints/oupls/sail/GraphSail.java @@ -1,6 +1,5 @@ package com.tinkerpop.blueprints.oupls.sail; -import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.KeyIndexableGraph; import com.tinkerpop.blueprints.TransactionalGraph; @@ -22,7 +21,6 @@ import org.openrdf.sail.SailException; import org.openrdf.sail.helpers.NotifyingSailBase; -import java.io.File; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -138,7 +136,7 @@ public GraphSail(final T graph, final String indexedPatterns) { store.sail = this; store.graph = graph; - store.manualTransactions = store.graph instanceof TransactionalGraph; + store.isTransactional = store.graph instanceof TransactionalGraph; if (!store.graph.getIndexedKeys(Vertex.class).contains(VALUE)) { store.graph.createKeyIndex(VALUE, Vertex.class); @@ -154,7 +152,7 @@ public GraphSail(final T graph, final String indexedPatterns) { try { store.namespaces = store.addVertex(NAMESPACES_VERTEX_ID); } finally { - if (store.manualTransactions) { + if (store.isTransactional) { ((TransactionalGraph) graph).commit(); } } @@ -236,7 +234,7 @@ class DataStore { // A triple pattern matcher for each spoc combination public final Matcher[] matchers = new Matcher[16]; - public boolean manualTransactions; + public boolean isTransactional; public boolean volatileStatements = false; public boolean uniqueStatements = false; @@ -293,8 +291,8 @@ public Vertex findVertex(final Value value) { public boolean matches(final Vertex vertex, final Value value) { - String kind = (String) vertex.getProperty(KIND); - String val = (String) vertex.getProperty(VALUE); + String kind = vertex.getProperty(KIND); + String val = vertex.getProperty(VALUE); if (value instanceof URI) { return kind.equals(URI) && val.equals(value.stringValue()); } else if (value instanceof Literal) { @@ -303,8 +301,8 @@ public boolean matches(final Vertex vertex, return false; } - String type = (String) vertex.getProperty(TYPE); - String lang = (String) vertex.getProperty(LANG); + String type = vertex.getProperty(TYPE); + String lang = vertex.getProperty(LANG); URI vType = ((Literal) value).getDatatype(); String vLang = ((Literal) value).getLanguage(); @@ -528,6 +526,7 @@ private void createIndexingMatcher(final String pattern) { store.indexers.add(m); } + /* private static void debugEdge(final Edge e) { System.out.println("edge " + e + ":"); for (String key : e.getPropertyKeys()) { @@ -553,5 +552,5 @@ private static void debugVertex(final Vertex v) { while (i.hasNext()) { System.out.println("\t\t" + i.next()); } - } + }*/ } diff --git a/blueprints-graph-sail/src/main/java/com/tinkerpop/blueprints/oupls/sail/GraphSailConnection.java b/blueprints-graph-sail/src/main/java/com/tinkerpop/blueprints/oupls/sail/GraphSailConnection.java index 91cbdf7e..1e7d049d 100644 --- a/blueprints-graph-sail/src/main/java/com/tinkerpop/blueprints/oupls/sail/GraphSailConnection.java +++ b/blueprints-graph-sail/src/main/java/com/tinkerpop/blueprints/oupls/sail/GraphSailConnection.java @@ -16,25 +16,9 @@ import org.openrdf.query.BindingSet; import org.openrdf.query.Dataset; import org.openrdf.query.QueryEvaluationException; -import org.openrdf.query.algebra.QueryRoot; import org.openrdf.query.algebra.TupleExpr; -import org.openrdf.query.algebra.Var; -import org.openrdf.query.algebra.evaluation.EvaluationStrategy; import org.openrdf.query.algebra.evaluation.TripleSource; -import org.openrdf.query.algebra.evaluation.impl.BindingAssigner; -import org.openrdf.query.algebra.evaluation.impl.CompareOptimizer; -import org.openrdf.query.algebra.evaluation.impl.ConjunctiveConstraintSplitter; -import org.openrdf.query.algebra.evaluation.impl.ConstantOptimizer; -import org.openrdf.query.algebra.evaluation.impl.DisjunctiveConstraintOptimizer; import org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl; -import org.openrdf.query.algebra.evaluation.impl.FilterOptimizer; -import org.openrdf.query.algebra.evaluation.impl.IterativeEvaluationOptimizer; -import org.openrdf.query.algebra.evaluation.impl.OrderLimitOptimizer; -import org.openrdf.query.algebra.evaluation.impl.QueryJoinOptimizer; -import org.openrdf.query.algebra.evaluation.impl.QueryModelNormalizer; -import org.openrdf.query.algebra.evaluation.impl.SameTermFilterOptimizer; -import org.openrdf.query.algebra.helpers.QueryModelVisitorBase; -import org.openrdf.query.impl.EmptyBindingSet; import org.openrdf.sail.SailException; import org.openrdf.sail.helpers.DefaultSailChangedEvent; import org.openrdf.sail.helpers.NotifyingSailConnectionBase; @@ -82,7 +66,7 @@ protected void startTransactionInternal() throws SailException { } public void commitInternal() throws SailException { - if (store.manualTransactions) { + if (store.isTransactional) { ((TransactionalGraph) store.graph).commit(); } @@ -95,15 +79,16 @@ public void commitInternal() throws SailException { } public void rollbackInternal() throws SailException { - if (store.manualTransactions) { - ((TransactionalGraph) store.graph).stopTransaction(TransactionalGraph.Conclusion.FAILURE); + if (store.isTransactional) { + + ((TransactionalGraph) store.graph).rollback(); } } public void closeInternal() throws SailException { // Roll back any uncommitted operations. - if (store.manualTransactions) { - ((TransactionalGraph) store.graph).stopTransaction(TransactionalGraph.Conclusion.FAILURE); + if (store.isTransactional) { + ((TransactionalGraph) store.graph).rollback(); } } @@ -118,44 +103,6 @@ public CloseableIteration evalua } catch (QueryEvaluationException e) { throw new SailException(e); } - - /* - // Clone the tuple expression to allow for more aggressive optimizations - tupleExpr = tupleExpr.clone(); - - if (!(tupleExpr instanceof QueryRoot)) { - // Add a dummy root node to the tuple expressions to allow the - // optimizers to modify the actual root node - tupleExpr = new QueryRoot(tupleExpr); - } - - try { - //replaceValues(tupleExpr); - - TripleSource tripleSource = new SailConnectionTripleSource(this, store.valueFactory, includeInferred); - EvaluationStrategy strategy = new EvaluationStrategyImpl(tripleSource, dataset); - - new BindingAssigner().optimize(tupleExpr, dataset, bindings); - new ConstantOptimizer(strategy).optimize(tupleExpr, dataset, bindings); - new CompareOptimizer().optimize(tupleExpr, dataset, bindings); - new ConjunctiveConstraintSplitter().optimize(tupleExpr, dataset, bindings); - new DisjunctiveConstraintOptimizer().optimize(tupleExpr, dataset, bindings); - new SameTermFilterOptimizer().optimize(tupleExpr, dataset, bindings); - new QueryModelNormalizer().optimize(tupleExpr, dataset, bindings); - // new SubSelectJoinOptimizer().optimize(tupleExpr, dataset, bindings); - //new QueryJoinOptimizer(new NativeEvaluationStatistics(nativeStore)).optimize(tupleExpr, dataset, bindings); - new IterativeEvaluationOptimizer().optimize(tupleExpr, dataset, bindings); - new FilterOptimizer().optimize(tupleExpr, dataset, bindings); - new OrderLimitOptimizer().optimize(tupleExpr, dataset, bindings); - - logger.trace("Optimized query model:\n{}", tupleExpr); - - return strategy.evaluate(tupleExpr, EmptyBindingSet.getInstance()); - } - catch (QueryEvaluationException e) { - throw new SailException(e); - } - */ } public CloseableIteration getContextIDsInternal() throws SailException { @@ -368,7 +315,7 @@ private void removeStatementsInternal(final boolean inferred, //System.out.println("matcher: " + indexes.matchers[index]); Iterable i = store.matchers[index].match(subject, predicate, object, context, inferred); for (Edge e : i) { - Boolean b = (Boolean) e.getProperty(GraphSail.INFERRED); + Boolean b = e.getProperty(GraphSail.INFERRED); if ((!inferred && null == b) || (inferred && null != b && b)) { edgesToRemove.add(e); @@ -436,7 +383,7 @@ private void deleteEdgesInIterator(final boolean inferred, while (iter.hasNext()) { Edge e = iter.next(); - Boolean b = (Boolean) e.getProperty(GraphSail.INFERRED); + Boolean b = e.getProperty(GraphSail.INFERRED); if ((!inferred && null == b) || (inferred && null != b && b)) { SimpleStatement s; @@ -505,7 +452,7 @@ public boolean hasNext() throws SailException { public Namespace next() throws SailException { String prefix = prefixes.next(); - String uri = (String) store.namespaces.getProperty(prefix); + String uri = store.namespaces.getProperty(prefix); return new NamespaceImpl(fromNativePrefixKey(prefix), uri); } @@ -802,13 +749,13 @@ private String fromNativePrefixKey(final String prefix) { } private Value toSesame(final Vertex v) { - String value = (String) v.getProperty(GraphSail.VALUE); - String kind = (String) v.getProperty(GraphSail.KIND); + String value = v.getProperty(GraphSail.VALUE); + String kind = v.getProperty(GraphSail.KIND); if (kind.equals(GraphSail.URI)) { return store.valueFactory.createURI(value); } else if (kind.equals(GraphSail.LITERAL)) { - String datatype = (String) v.getProperty(GraphSail.TYPE); - String lang = (String) v.getProperty(GraphSail.LANG); + String datatype = v.getProperty(GraphSail.TYPE); + String lang = v.getProperty(GraphSail.LANG); return null != datatype ? store.valueFactory.createLiteral(value, store.valueFactory.createURI(datatype)) : null != lang