Permalink
Browse files

made batch-transactions configurable

  • Loading branch information...
1 parent 5258bf6 commit b77fda7d6c93ca206bddbeef6792c9222d8de529 @jexp jexp committed Aug 28, 2012
View
@@ -70,4 +70,6 @@ _timeouts in seconds_
* org.neo4j.rest.connect_timeout=30
* org.neo4j.rest.driver="neo4j-rest-graphdb/1.8M07"
* org.neo4j.rest.stream=true
+* org.neo4j.rest.batch_transactions=true (convert transaction scope into batch-rest-operations)
+
@@ -24,11 +24,11 @@
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
import javax.ws.rs.core.MediaType;
import org.neo4j.helpers.collection.MapUtil;
+import org.neo4j.rest.graphdb.util.Config;
import org.neo4j.rest.graphdb.util.JsonHelper;
import com.sun.jersey.api.client.Client;
@@ -42,16 +42,6 @@
public class ExecutingRestRequest implements RestRequest {
- public final static String CONFIG_PREFIX = "org.neo4j.rest.";
-
- public static final int CONNECT_TIMEOUT = getTimeout("connect_timeout", 30);
- public static final int READ_TIMEOUT = getTimeout("read_timeout", 30);
- public static final boolean STREAM_ENABLED = Boolean.parseBoolean(System.getProperty(CONFIG_PREFIX+"stream","true"));
-
- private static int getTimeout(final String param, final int defaultValue) {
- return (int) TimeUnit.SECONDS.toMillis(Integer.parseInt(System.getProperty(CONFIG_PREFIX + param, "" + defaultValue)));
- }
-
public static final MediaType STREAMING_JSON_TYPE = new MediaType(APPLICATION_JSON_TYPE.getType(),APPLICATION_JSON_TYPE.getSubtype(), MapUtil.stringMap("stream","true"));
private final String baseUri;
private final UserAgent userAgent = new UserAgent();
@@ -75,8 +65,8 @@ protected void addAuthFilter(String username, String password) {
protected Client createClient() {
Client client = Client.create();
- client.setConnectTimeout(CONNECT_TIMEOUT);
- client.setReadTimeout(READ_TIMEOUT);
+ client.setConnectTimeout(Config.getConnectTimeout());
+ client.setReadTimeout(Config.getReadTimeout());
client.setChunkedEncodingSize(8*1024);
userAgent.install(client);
return client;
@@ -103,7 +93,7 @@ public static String encode( Object value ) {
private Builder builder( String path ) {
WebResource resource = client.resource( uri( pathOrAbsolute( path ) ) );
- if (STREAM_ENABLED) return resource.accept(STREAMING_JSON_TYPE).header("X-Stream","true");
+ if (Config.streamingIsEnabled()) return resource.accept(STREAMING_JSON_TYPE).header("X-Stream","true");
return resource.accept(APPLICATION_JSON_TYPE);
}
@@ -19,10 +19,7 @@
*/
package org.neo4j.rest.graphdb;
-import org.neo4j.graphdb.Node;
-import org.neo4j.graphdb.PropertyContainer;
-import org.neo4j.graphdb.Relationship;
-import org.neo4j.graphdb.RelationshipType;
+import org.neo4j.graphdb.*;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.rest.graphdb.batch.BatchCallback;
@@ -35,7 +32,9 @@
import org.neo4j.rest.graphdb.index.RestIndex;
import org.neo4j.rest.graphdb.index.RestIndexManager;
import org.neo4j.rest.graphdb.services.RequestType;
+import org.neo4j.rest.graphdb.transaction.NullTransaction;
import org.neo4j.rest.graphdb.traversal.RestTraverser;
+import org.neo4j.rest.graphdb.util.Config;
import org.neo4j.rest.graphdb.util.QueryResult;
import org.neo4j.rest.graphdb.util.ResultConverter;
@@ -47,6 +46,7 @@
* @since 03.05.12
*/
public class RestAPIFacade implements RestAPI {
+
@Override
public RestIndexManager index() {
return new RestIndexManager(this);
@@ -108,8 +108,10 @@ public Node getReferenceNode() {
}
@Override
- public BatchTransaction beginTx() {
- return BatchTransaction.begin(this);
+ public Transaction beginTx() {
+ if (Config.useBatchTransactions())
+ return BatchTransaction.begin(this);
+ return new NullTransaction();
}
@Override
@@ -0,0 +1,48 @@
+/**
+ * Copyright (c) 2002-2012 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
+ *
+ * This file is part of Neo4j.
+ *
+ * Neo4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.neo4j.rest.graphdb.util;
+
+import java.util.concurrent.TimeUnit;
+
+public class Config {
+ public final static String CONFIG_PREFIX = "org.neo4j.rest.";
+ public static final String CONFIG_STREAM = CONFIG_PREFIX + "stream";
+ public static final String CONFIG_BATCH_TRANSACTION = CONFIG_PREFIX+"batch_transaction";
+
+ public static int getConnectTimeout() {
+ return getTimeout("connect_timeout", 30);
+ }
+
+ public static int getReadTimeout() {
+ return getTimeout("read_timeout", 30);
+ }
+
+ public static boolean streamingIsEnabled() {
+ return Boolean.parseBoolean(System.getProperty(CONFIG_STREAM,"true"));
+ }
+
+ public static boolean useBatchTransactions() {
+ return System.getProperty(CONFIG_BATCH_TRANSACTION,"true").equalsIgnoreCase("true");
+ }
+
+ private static int getTimeout(final String param, final int defaultValue) {
+ return (int) TimeUnit.SECONDS.toMillis(Integer.parseInt(System.getProperty(CONFIG_PREFIX + param, "" + defaultValue)));
+ }
+}
@@ -32,6 +32,8 @@
import org.neo4j.rest.graphdb.entity.RestNode;
import org.neo4j.rest.graphdb.entity.RestRelationship;
import org.neo4j.rest.graphdb.index.RestIndex;
+import org.neo4j.rest.graphdb.transaction.NullTransaction;
+import org.neo4j.rest.graphdb.util.Config;
import org.neo4j.rest.graphdb.util.TestHelper;
import static org.junit.Assert.*;
@@ -44,10 +46,26 @@
@Before
public void init() {
+ System.setProperty(Config.CONFIG_BATCH_TRANSACTION,"true");
this.restAPI = ((RestGraphDatabase) getRestGraphDb()).getRestAPI();
}
@Test
+ public void testDisableBatchTransactions() throws Exception {
+ System.setProperty(Config.CONFIG_BATCH_TRANSACTION,"false");
+ Transaction tx = restAPI.beginTx();
+ tx.failure();tx.finish();
+ assertTrue(tx instanceof NullTransaction);
+ }
+ @Test
+ public void testEnableBatchTransactions() throws Exception {
+ System.setProperty(Config.CONFIG_BATCH_TRANSACTION,"true");
+ Transaction tx = restAPI.beginTx();
+ tx.failure();tx.finish();
+ assertTrue(tx instanceof BatchTransaction);
+ }
+
+ @Test
public void testCreateNode() {
final Transaction tx = restAPI.beginTx();
Node n1 = restAPI.createNode(map("name", "node1"));

0 comments on commit b77fda7

Please sign in to comment.