|
From: <tho...@us...> - 2014-05-15 15:14:58
|
Revision: 8336
http://sourceforge.net/p/bigdata/code/8336
Author: thompsonbry
Date: 2014-05-15 15:14:55 +0000 (Thu, 15 May 2014)
Log Message:
-----------
Added support for setMaxQuery(). This does not yet allow people to (easily) set query timeouts of less than one second (which is the API granularity for openrdf). However, the timeouts ARE communicated in milliseconds using an HTTP header.
Modified Paths:
--------------
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepository.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepositoryConnection.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedQuery.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java
Added Paths:
-----------
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/StringUtil.java
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepository.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepository.java 2014-05-15 14:05:03 UTC (rev 8335)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepository.java 2014-05-15 15:14:55 UTC (rev 8336)
@@ -33,7 +33,6 @@
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.openrdf.model.ValueFactory;
import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import com.bigdata.rdf.sail.webapp.client.DefaultClientConnectionManagerFactory;
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepositoryConnection.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepositoryConnection.java 2014-05-15 14:05:03 UTC (rev 8335)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepositoryConnection.java 2014-05-15 15:14:55 UTC (rev 8336)
@@ -33,6 +33,7 @@
import java.io.Reader;
import java.net.URL;
import java.util.Iterator;
+import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.openrdf.model.Graph;
@@ -95,16 +96,18 @@
*/
public class BigdataSailRemoteRepositoryConnection implements RepositoryConnection {
- private static final transient Logger log = Logger.getLogger(BigdataSailRemoteRepositoryConnection.class);
+ private static final transient Logger log = Logger
+ .getLogger(BigdataSailRemoteRepositoryConnection.class);
+
+ private final BigdataSailRemoteRepository repo;
+
+ public BigdataSailRemoteRepositoryConnection(
+ final BigdataSailRemoteRepository repo) {
+
+ this.repo = repo;
+
+ }
- private final BigdataSailRemoteRepository repo;
-
- public BigdataSailRemoteRepositoryConnection(final BigdataSailRemoteRepository repo) {
-
- this.repo = repo;
-
- }
-
public long count(final Resource s, final URI p, final Value o,
final Resource... c)
throws RepositoryException {
@@ -124,9 +127,9 @@
}
@Override
- public RepositoryResult<Statement> getStatements(Resource s, URI p,
- Value o, boolean includeInferred, Resource... c)
- throws RepositoryException {
+ public RepositoryResult<Statement> getStatements(final Resource s,
+ final URI p, final Value o, final boolean includeInferred,
+ final Resource... c) throws RepositoryException {
try {
@@ -187,8 +190,9 @@
}
@Override
- public boolean hasStatement(Resource s, URI p, Value o,
- boolean includeInferred, Resource... c) throws RepositoryException {
+ public boolean hasStatement(final Resource s, final URI p, final Value o,
+ final boolean includeInferred, final Resource... c)
+ throws RepositoryException {
try {
@@ -205,8 +209,9 @@
}
@Override
- public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String query)
- throws RepositoryException, MalformedQueryException {
+ public BooleanQuery prepareBooleanQuery(final QueryLanguage ql,
+ final String query) throws RepositoryException,
+ MalformedQueryException {
if (ql != QueryLanguage.SPARQL) {
@@ -234,17 +239,32 @@
}
}
- @Override
- public int getMaxQueryTime() {
- throw new UnsupportedOperationException();
- }
-
+ /**
+ * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query)
+ */
+ @Override
+ public int getMaxQueryTime() {
+
+ final long millis = q.getMaxQueryMillis();
+
+ if (millis == -1) {
+ // Note: -1L is returned if the http header is not specified.
+ return -1;
+
+ }
+
+ return (int) TimeUnit.MILLISECONDS.toSeconds(millis);
+
+ }
+
/**
* @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query)
*/
@Override
- public void setMaxQueryTime(int arg0) {
- throw new UnsupportedOperationException();
+ public void setMaxQueryTime(final int seconds) {
+
+ q.setMaxQueryMillis(TimeUnit.SECONDS.toMillis(seconds));
+
}
@Override
@@ -298,9 +318,10 @@
}
@Override
- public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String query,
- String baseURI) throws RepositoryException, MalformedQueryException {
-
+ public BooleanQuery prepareBooleanQuery(final QueryLanguage ql,
+ final String query, final String baseURI)
+ throws RepositoryException, MalformedQueryException {
+
if (baseURI != null)
throw new UnsupportedOperationException("baseURI not supported");
@@ -309,8 +330,9 @@
}
@Override
- public GraphQuery prepareGraphQuery(QueryLanguage ql, String query)
- throws RepositoryException, MalformedQueryException {
+ public GraphQuery prepareGraphQuery(final QueryLanguage ql,
+ final String query) throws RepositoryException,
+ MalformedQueryException {
if (ql != QueryLanguage.SPARQL) {
@@ -338,18 +360,35 @@
}
}
- @Override
- public int getMaxQueryTime() {
- throw new UnsupportedOperationException();
- }
-
/**
- * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query)
+ * @see http://trac.bigdata.com/ticket/914 (Set timeout on
+ * remote query)
*/
- @Override
- public void setMaxQueryTime(int arg0) {
- throw new UnsupportedOperationException();
- }
+ @Override
+ public int getMaxQueryTime() {
+
+ final long millis = q.getMaxQueryMillis();
+
+ if (millis == -1) {
+ // Note: -1L is returned if the http header is not specified.
+ return -1;
+
+ }
+
+ return (int) TimeUnit.MILLISECONDS.toSeconds(millis);
+
+ }
+
+ /**
+ * @see http://trac.bigdata.com/ticket/914 (Set timeout on
+ * remote query)
+ */
+ @Override
+ public void setMaxQueryTime(final int seconds) {
+
+ q.setMaxQueryMillis(TimeUnit.SECONDS.toMillis(seconds));
+
+ }
@Override
public void clearBindings() {
@@ -408,8 +447,9 @@
}
@Override
- public GraphQuery prepareGraphQuery(QueryLanguage ql, String query,
- String baseURI) throws RepositoryException, MalformedQueryException {
+ public GraphQuery prepareGraphQuery(final QueryLanguage ql,
+ final String query, final String baseURI)
+ throws RepositoryException, MalformedQueryException {
if (baseURI != null)
throw new UnsupportedOperationException("baseURI not supported.");
@@ -419,27 +459,29 @@
}
@Override
- public Query prepareQuery(QueryLanguage ql, String query)
- throws RepositoryException, MalformedQueryException {
-
+ public Query prepareQuery(final QueryLanguage ql, final String query)
+ throws RepositoryException, MalformedQueryException {
+
throw new UnsupportedOperationException("please use the specific operation for your query type: prepare[Boolean/Tuple/Graph]Query");
}
@Override
- public Query prepareQuery(QueryLanguage ql, String query, String baseURI)
- throws RepositoryException, MalformedQueryException {
+ public Query prepareQuery(final QueryLanguage ql, final String query,
+ final String baseURI) throws RepositoryException,
+ MalformedQueryException {
if (baseURI != null)
throw new UnsupportedOperationException("baseURI not supported");
return prepareQuery(ql, query);
- }
+ }
- @Override
- public TupleQuery prepareTupleQuery(QueryLanguage ql, String query)
- throws RepositoryException, MalformedQueryException {
+ @Override
+ public TupleQuery prepareTupleQuery(final QueryLanguage ql,
+ final String query) throws RepositoryException,
+ MalformedQueryException {
if (ql != QueryLanguage.SPARQL) {
@@ -466,19 +508,36 @@
throw new QueryEvaluationException(ex);
}
}
-
- @Override
+
+ /**
+ * @see http://trac.bigdata.com/ticket/914 (Set timeout on
+ * remote query)
+ */
+ @Override
public int getMaxQueryTime() {
- throw new UnsupportedOperationException();
+
+ final long millis = q.getMaxQueryMillis();
+
+ if (millis == -1) {
+ // Note: -1L is returned if the http header is not specified.
+ return -1;
+
+ }
+
+ return (int) TimeUnit.MILLISECONDS.toSeconds(millis);
+
}
- /**
- * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query)
- */
- @Override
- public void setMaxQueryTime(int arg0) {
- throw new UnsupportedOperationException();
- }
+ /**
+ * @see http://trac.bigdata.com/ticket/914 (Set timeout on
+ * remote query)
+ */
+ @Override
+ public void setMaxQueryTime(final int seconds) {
+
+ q.setMaxQueryMillis(TimeUnit.SECONDS.toMillis(seconds));
+
+ }
@Override
public void clearBindings() {
@@ -537,8 +596,9 @@
}
@Override
- public TupleQuery prepareTupleQuery(QueryLanguage ql, String query,
- String baseURI) throws RepositoryException, MalformedQueryException {
+ public TupleQuery prepareTupleQuery(final QueryLanguage ql,
+ final String query, final String baseURI)
+ throws RepositoryException, MalformedQueryException {
if (baseURI != null)
throw new UnsupportedOperationException("baseURI not supported.");
@@ -547,17 +607,18 @@
}
@Override
- public boolean hasStatement(Statement s, boolean includeInferred, Resource... c)
- throws RepositoryException {
+ public boolean hasStatement(final Statement s,
+ final boolean includeInferred, final Resource... c)
+ throws RepositoryException {
return hasStatement(s.getSubject(), s.getPredicate(), s.getObject(), includeInferred, c);
}
@Override
- public <E extends Exception> void add(
- Iteration<? extends Statement, E> stmts, Resource... c)
- throws RepositoryException, E {
+ public <E extends Exception> void add(
+ final Iteration<? extends Statement, E> stmts, final Resource... c)
+ throws RepositoryException, E {
final Graph g = new GraphImpl();
while (stmts.hasNext()) {
@@ -569,15 +630,20 @@
}
@Override
- public void add(Resource s, URI p, Value o, Resource... c)
- throws RepositoryException {
+ public void add(final Resource s, final URI p, final Value o,
+ final Resource... c) throws RepositoryException {
add(new StatementImpl(s, p, o), c);
}
+ /**
+ * <strong>single statement updates not recommended</strong>
+ * <p>
+ * {@inheritDoc}
+ */
@Override
- public void add(Statement stmt, Resource... c)
+ public void add(final Statement stmt, final Resource... c)
throws RepositoryException {
log.warn("single statement updates not recommended");
@@ -589,9 +655,9 @@
}
- @Override
- public void add(Iterable<? extends Statement> stmts, Resource... c)
- throws RepositoryException {
+ @Override
+ public void add(final Iterable<? extends Statement> stmts,
+ final Resource... c) throws RepositoryException {
final AddOp op = new AddOp(stmts);
@@ -603,8 +669,9 @@
* TODO support baseURI
*/
@Override
- public void add(Reader input, String baseURI, RDFFormat format, Resource... c)
- throws IOException, RDFParseException, RepositoryException {
+ public void add(final Reader input, final String baseURI,
+ final RDFFormat format, final Resource... c) throws IOException,
+ RDFParseException, RepositoryException {
final AddOp op = new AddOp(input, format);
@@ -616,8 +683,9 @@
* TODO support baseURI
*/
@Override
- public void add(URL input, String baseURI, RDFFormat format, Resource... c)
- throws IOException, RDFParseException, RepositoryException {
+ public void add(final URL input, final String baseURI,
+ final RDFFormat format, final Resource... c) throws IOException,
+ RDFParseException, RepositoryException {
final AddOp op = new AddOp(input.toString());
@@ -629,8 +697,9 @@
* TODO support baseURI
*/
@Override
- public void add(File input, String baseURI, RDFFormat format, Resource... c)
- throws IOException, RDFParseException, RepositoryException {
+ public void add(final File input, final String baseURI,
+ final RDFFormat format, final Resource... c) throws IOException,
+ RDFParseException, RepositoryException {
final AddOp op = new AddOp(input, format);
@@ -641,9 +710,10 @@
/**
* TODO support baseURI
*/
- @Override
- public void add(InputStream input, String baseURI, RDFFormat format, Resource... c)
- throws IOException, RDFParseException, RepositoryException {
+ @Override
+ public void add(final InputStream input, final String baseURI,
+ final RDFFormat format, final Resource... c) throws IOException,
+ RDFParseException, RepositoryException {
final AddOp op = new AddOp(input, format);
@@ -671,9 +741,9 @@
}
@Override
- public <E extends Exception> void remove(
- Iteration<? extends Statement, E> stmts, Resource... c)
- throws RepositoryException, E {
+ public <E extends Exception> void remove(
+ final Iteration<? extends Statement, E> stmts, final Resource... c)
+ throws RepositoryException, E {
final Graph g = new GraphImpl();
while (stmts.hasNext())
@@ -683,8 +753,13 @@
}
- @Override
- public void remove(Statement stmt, Resource... c)
+ /**
+ * <strong>single statement updates not recommended</strong>
+ * <p>
+ * {@inheritDoc}
+ */
+ @Override
+ public void remove(final Statement stmt, final Resource... c)
throws RepositoryException {
log.warn("single statement updates not recommended");
@@ -697,8 +772,8 @@
}
@Override
- public void remove(Iterable<? extends Statement> stmts, Resource... c)
- throws RepositoryException {
+ public void remove(final Iterable<? extends Statement> stmts,
+ final Resource... c) throws RepositoryException {
final RemoveOp op = new RemoveOp(stmts);
@@ -707,8 +782,8 @@
}
@Override
- public void remove(Resource s, URI p, Value o, Resource... c)
- throws RepositoryException {
+ public void remove(final Resource s, URI p, Value o, final Resource... c)
+ throws RepositoryException {
final RemoveOp op = new RemoveOp(s, p, o, c);
@@ -736,11 +811,12 @@
}
@Override
- public void setAutoCommit(boolean autoCommit) throws RepositoryException {
+ public void setAutoCommit(final boolean autoCommit) throws RepositoryException {
- if (autoCommit == false)
- throw new IllegalArgumentException("only auto-commit is currently supported");
-
+ if (autoCommit == false)
+ throw new IllegalArgumentException(
+ "only auto-commit is currently supported");
+
}
@Override
@@ -815,7 +891,7 @@
}
@Override
- public long size(Resource... c) throws RepositoryException {
+ public long size(final Resource... c) throws RepositoryException {
try {
@@ -832,14 +908,14 @@
}
@Override
- public void clear(Resource... c) throws RepositoryException {
+ public void clear(final Resource... c) throws RepositoryException {
remove(null, null, null, c);
}
@Override
- public void export(RDFHandler handler, Resource... c)
+ public void export(final RDFHandler handler, final Resource... c)
throws RepositoryException, RDFHandlerException {
exportStatements(null, null, null, true, handler, c);
@@ -888,8 +964,8 @@
@Override
- public Update prepareUpdate(QueryLanguage ql, String query)
- throws RepositoryException, MalformedQueryException {
+ public Update prepareUpdate(final QueryLanguage ql, final String query)
+ throws RepositoryException, MalformedQueryException {
if (ql != QueryLanguage.SPARQL) {
@@ -967,9 +1043,10 @@
}
- @Override
- public Update prepareUpdate(QueryLanguage ql, String query, String baseURI)
- throws RepositoryException, MalformedQueryException {
+ @Override
+ public Update prepareUpdate(final QueryLanguage ql, final String query,
+ final String baseURI) throws RepositoryException,
+ MalformedQueryException {
if (baseURI != null)
throw new UnsupportedOperationException("baseURI not supported");
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java 2014-05-15 14:05:03 UTC (rev 8335)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java 2014-05-15 15:14:55 UTC (rev 8336)
@@ -95,6 +95,7 @@
import com.bigdata.rdf.sail.ISPARQLUpdateListener;
import com.bigdata.rdf.sail.SPARQLUpdateEvent;
import com.bigdata.rdf.sail.sparql.Bigdata2ASTSPARQLParser;
+import com.bigdata.rdf.sail.webapp.client.StringUtil;
import com.bigdata.rdf.sparql.ast.ASTContainer;
import com.bigdata.rdf.sparql.ast.QueryHints;
import com.bigdata.rdf.sparql.ast.QueryOptimizerEnum;
@@ -211,8 +212,15 @@
*/
protected static final String NAMESPACE = "namespace";
- private final SparqlEndpointConfig m_config;
+ /**
+ * HTTP header may be used to specify the timeout for a query.
+ *
+ * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query)
+ */
+ static private final String HTTP_HEADER_BIGDATA_MAX_QUERY_MILLIS = "BIGDATA_MAX_QUERY_MILLIS";
+ private final SparqlEndpointConfig m_config;
+
/**
* A thread pool for running accepted queries against the
* {@link QueryEngine}.
@@ -1024,14 +1032,36 @@
*/
private AbstractQuery newQuery(final BigdataSailRepositoryConnection cxn) {
- final long queryTimeout = getConfig().queryTimeout;
-
- if (queryTimeout > 0) {
+ /*
+ * Establish the query timeout. This may be set in web.xml, which
+ * overrides all queries and sets a maximum allowed time for query
+ * execution. This may also be set either via setMaxQuery() or
+ * setMaxQueryMillis() which set a HTTP header (in milliseconds).
+ */
+ long queryTimeoutMillis = getConfig().queryTimeout;
+ {
+ final String s = req
+ .getHeader(HTTP_HEADER_BIGDATA_MAX_QUERY_MILLIS);
+ if (s != null) {
+ long tmp = StringUtil.toLong(s);
+ if (tmp != -1L && //
+ (queryTimeoutMillis == 0/* noLimit */
+ || //
+ tmp < queryTimeoutMillis/* shorterLimit */)//
+ ) {
+ // Set based on the http header value.
+ queryTimeoutMillis = tmp;
+ }
+ }
+ }
+
+ if (queryTimeoutMillis > 0) {
+
final QueryRoot originalQuery = astContainer.getOriginalAST();
- originalQuery.setTimeout(queryTimeout);
-
+ originalQuery.setTimeout(queryTimeoutMillis);
+
}
// final ASTContainer astContainer = ((BigdataParsedQuery) parsedQuery)
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedQuery.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedQuery.java 2014-05-15 14:05:03 UTC (rev 8335)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedQuery.java 2014-05-15 15:14:55 UTC (rev 8336)
@@ -61,6 +61,27 @@
void setAcceptHeader(String value);
/**
+ * Specify the maximum time in milliseconds that the query will be permitted
+ * to run. A negative or zero value indicates an unlimited query time (which
+ * is the default).
+ *
+ * @param millis
+ * The timeout in milliseconds.
+ *
+ * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query)
+ */
+ void setMaxQueryMillis(long millis);
+
+ /**
+ * Return the maximum time in milliseconds that the query will be permitted
+ * to run. A negative or zero value indicates an unlimited query time (which
+ * is the default).
+ *
+ * @return The timeout in milliseceonds.
+ */
+ long getMaxQueryMillis();
+
+ /**
* Return the value of the specified HTTP header.
*
* @param name
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java 2014-05-15 14:05:03 UTC (rev 8335)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java 2014-05-15 15:14:55 UTC (rev 8336)
@@ -188,6 +188,13 @@
static public final int DEFAULT_MAX_REQUEST_URL_LENGTH = 1000;
/**
+ * HTTP header may be used to specify the timeout for a query.
+ *
+ * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query)
+ */
+ static private final String HTTP_HEADER_BIGDATA_MAX_QUERY_MILLIS = "BIGDATA_MAX_QUERY_MILLIS";
+
+ /**
* When <code>true</code>, the REST API methods will use the load balancer
* aware requestURLs. The load balancer has essentially zero cost when not
* using HA, so it is recommended to always specify <code>true</code>. When
@@ -1145,8 +1152,38 @@
opts.setHeader(name, value);
}
+
+ @Override
+ public void setMaxQueryMillis(final long timeout) {
+
+ opts.setHeader(HTTP_HEADER_BIGDATA_MAX_QUERY_MILLIS,
+ Long.toString(timeout));
+
+ }
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note: <code>-1L</code> is returned if the http header is not
+ * specified.
+ */
@Override
+ public long getMaxQueryMillis() {
+
+ final String s = opts
+ .getHeader(HTTP_HEADER_BIGDATA_MAX_QUERY_MILLIS);
+
+ if (s == null) {
+
+ return -1L;
+
+ }
+
+ return StringUtil.toLong(s);
+
+ }
+
+ @Override
public String getHeader(final String name) {
return opts.getHeader(name);
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/StringUtil.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/StringUtil.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/StringUtil.java 2014-05-15 15:14:55 UTC (rev 8336)
@@ -0,0 +1,67 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+/*
+ * Note: This class was extracted from org.eclipse.jetty.util.StringUtil.
+ * It contains only those methods that we need that are not already part
+ * of the general servlet API. (We can not rely on jetty being present
+ * since the WAR deployment does not bundle the jetty dependencies.)
+ */
+package com.bigdata.rdf.sail.webapp.client;
+
+/** Fast String Utilities.
+*
+* These string utilities provide both convenience methods and
+* performance improvements over most standard library versions. The
+* main aim of the optimizations is to avoid object creation unless
+* absolutely required.
+*/
+public class StringUtil {
+
+ /**
+ * Convert String to an long. Parses up to the first non-numeric character.
+ * If no number is found an IllegalArgumentException is thrown
+ *
+ * @param string
+ * A String containing an integer.
+ * @return an int
+ */
+ public static long toLong(String string) {
+ long val = 0;
+ boolean started = false;
+ boolean minus = false;
+
+ for (int i = 0; i < string.length(); i++) {
+ char b = string.charAt(i);
+ if (b <= ' ') {
+ if (started)
+ break;
+ } else if (b >= '0' && b <= '9') {
+ val = val * 10L + (b - '0');
+ started = true;
+ } else if (b == '-' && !started) {
+ minus = true;
+ } else
+ break;
+ }
+
+ if (started)
+ return minus ? (-val) : val;
+ throw new NumberFormatException(string);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tho...@us...> - 2014-06-05 12:30:03
|
Revision: 8447
http://sourceforge.net/p/bigdata/code/8447
Author: thompsonbry
Date: 2014-06-05 12:29:44 +0000 (Thu, 05 Jun 2014)
Log Message:
-----------
Added javadoc for the correct handling of the try/finally pattern for BigdataSail.getUnisolatedConnection() and to the BigdataSailRepository getConnection() and getUnisolatedConnection() methods as well.
Modified Paths:
--------------
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepository.java
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java 2014-06-04 20:32:18 UTC (rev 8446)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java 2014-06-05 12:29:44 UTC (rev 8447)
@@ -1269,10 +1269,35 @@
* returns the unisolated view of the database. Note that truth maintenance
* requires only one connection at a time and is therefore not compatible
* with full read/write transactions.
+ * <p>
+ * The correct pattern for obtaining an updatable connection, doing work
+ * with that connection, and committing or rolling back that update is as
+ * follows.
+ *
+ * <pre>
+ *
+ * BigdataSailConnection conn = null;
+ * boolean ok = false;
+ * try {
+ * conn = sail.getConnection();
+ * doWork(conn);
+ * conn.commit();
+ * ok = true;
+ * } finally {
+ * if (conn != null) {
+ * if (!ok) {
+ * conn.rollback();
+ * }
+ * conn.close();
+ * }
+ * }
+ * </pre>
+ *
+ * This pattern can also be used with {@link #getUnisolatedConnection()}.
*/
@Override
public BigdataSailConnection getConnection() throws SailException {
-
+
return (BigdataSailConnection) super.getConnection();
}
@@ -1297,25 +1322,49 @@
*/
final private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false/*fair*/);
- /**
- * Return an unisolated connection to the database. The unisolated
- * connection supports fast, scalable updates against the database. The
- * unisolated connection is ACID when used with a local {@link Journal} and
- * shard-wise ACID when used with an {@link IBigdataFederation}.
- * <p>
- * In order to guarantee that operations against the unisolated connection
- * are ACID, only one of unisolated connection is permitted at a time for a
- * {@link Journal} and this method will block until the connection is
- * available. If there is an open unisolated connection against a local
- * {@link Journal}, then the open connection must be closed before a new
- * connection can be returned by this method.
- * <p>
- * This constraint that there can be only one unisolated connection is not
- * enforced in scale-out since unisolated operations in scale-out are only
- * shard-wise ACID.
- *
- * @return The unisolated connection to the database
- */
+ /**
+ * Return an unisolated connection to the database. The unisolated
+ * connection supports fast, scalable updates against the database. The
+ * unisolated connection is ACID when used with a local {@link Journal} and
+ * shard-wise ACID when used with an {@link IBigdataFederation}.
+ * <p>
+ * In order to guarantee that operations against the unisolated connection
+ * are ACID, only one of unisolated connection is permitted at a time for a
+ * {@link Journal} and this method will block until the connection is
+ * available. If there is an open unisolated connection against a local
+ * {@link Journal}, then the open connection must be closed before a new
+ * connection can be returned by this method.
+ * <p>
+ * This constraint that there can be only one unisolated connection is not
+ * enforced in scale-out since unisolated operations in scale-out are only
+ * shard-wise ACID.
+ * <p>
+ * The correct pattern for obtaining an updatable connection, doing work
+ * with that connection, and committing or rolling back that update is as
+ * follows.
+ *
+ * <pre>
+ * BigdataSailConnection conn = null;
+ * boolean ok = false;
+ * try {
+ * conn = sail.getUnisolatedConnection();
+ * doWork(conn);
+ * conn.commit();
+ * ok = true;
+ * } finally {
+ * if (conn != null) {
+ * if (!ok) {
+ * conn.rollback();
+ * }
+ * conn.close();
+ * }
+ * }
+ * </pre>
+ *
+ * @return The unisolated connection to the database
+ *
+ * @see #getConnection()
+ */
public BigdataSailConnection getUnisolatedConnection()
throws InterruptedException {
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepository.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepository.java 2014-06-04 20:32:18 UTC (rev 8446)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepository.java 2014-06-05 12:29:44 UTC (rev 8447)
@@ -33,6 +33,35 @@
//
// }
+ /**
+ * {@inheritDoc}
+ * <p>
+ * The correct pattern for obtaining an updatable connection, doing work
+ * with that connection, and committing or rolling back that update is as
+ * follows.
+ *
+ * <pre>
+ *
+ * BigdataSailConnection conn = null;
+ * boolean ok = false;
+ * try {
+ * conn = repo.getConnection();
+ * doWork(conn);
+ * conn.commit();
+ * ok = true;
+ * } finally {
+ * if (conn != null) {
+ * if (!ok) {
+ * conn.rollback();
+ * }
+ * conn.close();
+ * }
+ * }
+ * </pre>
+ *
+ * @see BigdataSail#getConnection()
+ * @see #getUnisolatedConnection()
+ */
@Override
public BigdataSailRepositoryConnection getConnection()
throws RepositoryException {
@@ -105,12 +134,36 @@
}
/**
- * Return an unisolated connection to the database. Only one of these
+ * Return an unisolated connection to the database. Only one of these
* allowed at a time.
+ * <p>
+ * The correct pattern for obtaining an updatable connection, doing work
+ * with that connection, and committing or rolling back that update is as
+ * follows.
*
+ * <pre>
+ *
+ * BigdataSailConnection conn = null;
+ * boolean ok = false;
+ * try {
+ * conn = repo.getConnection();
+ * doWork(conn);
+ * conn.commit();
+ * ok = true;
+ * } finally {
+ * if (conn != null) {
+ * if (!ok) {
+ * conn.rollback();
+ * }
+ * conn.close();
+ * }
+ * }
+ * </pre>
+ *
* @return unisolated connection to the database
*
* @see BigdataSail#getUnisolatedConnection()
+ * @see #getConnection()
*/
public BigdataSailRepositoryConnection getUnisolatedConnection()
throws RepositoryException {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|