Skip to content

Commit

Permalink
rfe10303: support revised bulk-load mode interface
Browse files Browse the repository at this point in the history
<release-note>
rfe10303: support revised bulk-load mode interface

With this change, the Java client now supports the revised
bulk-load mode interface.  Bulk mode is now persistent (sticks
even after closing and reopening the store), and is controlled
with the AGRepository#setBulkMode and AGRepository#isBulkMode
methods, rather than per session.
</release-note>

Updated prepush test BulkModeTests
make prepush passes

Change-Id: I0bd4abc89e107523ab0228f15b9ade5f3ece045a
Reviewed-on: https://gerrit.franz.com:9080/1062
Reviewed-by: John O'Rourke <john.orourke@franz.com>
Reviewed-by: Ahmon Dancy <dancy@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information
Bill Millar authored and dklayer committed Dec 17, 2010
1 parent 5d661e0 commit e7c4e56
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 45 deletions.
12 changes: 0 additions & 12 deletions src/com/franz/agraph/http/AGHttpRepoClient.java
Expand Up @@ -74,7 +74,6 @@ public class AGHttpRepoClient implements Closeable {
// delay using a dedicated session until necessary
private boolean usingDedicatedSession = false;
private boolean autoCommit = true;
private boolean bulkMode = false;
private String sessionRoot, repoRoot;

// TODO: choose proper defaults
Expand Down Expand Up @@ -487,9 +486,6 @@ public void upload(String url, RequestEntity reqEntity, String baseURI,
params.add(new NameValuePair(AGProtocol.URL_PARAM_NAME,
serverSideURL.stringValue()));
}
if (bulkMode) {
params.add(new NameValuePair("bulkMode","true"));
}
if (!overwrite) {
getHTTPClient().post(url,
headers.toArray(new Header[headers.size()]),
Expand Down Expand Up @@ -1453,14 +1449,6 @@ public void dropIndex(String index) throws RepositoryException {
}
}

public void setBulkMode(boolean bulkMode) throws RepositoryException {
this.bulkMode = bulkMode;
}

public boolean isBulkMode() throws RepositoryException {
return bulkMode;
}

public void registerEncodableNamespace(String namespace, String format)
throws RepositoryException {
String url = getRoot() + "/encodedIds/prefixes";
Expand Down
46 changes: 46 additions & 0 deletions src/com/franz/agraph/repository/AGRepository.java
Expand Up @@ -12,14 +12,18 @@
package com.franz.agraph.repository;

import java.io.File;
import java.io.IOException;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.NameValuePair;
import org.openrdf.model.Value;
import org.openrdf.query.BindingSet;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.query.TupleQueryResult;
import org.openrdf.repository.RepositoryException;

import com.franz.agraph.http.AGHTTPClient;
import com.franz.agraph.http.AGHttpException;
import com.franz.agraph.http.AGHttpRepoClient;
import com.franz.util.Closeable;

Expand Down Expand Up @@ -161,4 +165,46 @@ public void close() throws RepositoryException {
shutDown();
}

/**
* Sets the repository's bulkMode (defaults to false).
*
* When in bulkMode, data can be added/loaded more quickly, but
* there is no guarantee of durability in the event of a crash.
* The bulkMode setting persists when the repository is closed.
*
* @param bulkMode a boolean indicating the bulkMode.
* @throws RepositoryException
* @see #isBulkMode()
*/
public void setBulkMode(boolean bulkMode) throws RepositoryException {
String url = repositoryURL + "/bulkMode";
Header[] headers = new Header[0];
NameValuePair[] data = {};
try {
if (bulkMode) {
getHTTPClient().put(url,headers,data,null);
} else {
getHTTPClient().delete(url,headers,data);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (AGHttpException e) {
throw new RepositoryException(e);
}
}

/**
* Returns the repository's bulkMode setting.
*
* @return a boolean indicating the bulkMode setting.
* @throws RepositoryException
* @see #setBulkMode(boolean)
*/
public boolean isBulkMode() throws RepositoryException {
try {
return Boolean.parseBoolean(getHTTPClient().getString(repositoryURL+"/bulkMode"));
} catch (AGHttpException e) {
throw new RepositoryException(e);
}
}
}
25 changes: 0 additions & 25 deletions src/com/franz/agraph/repository/AGRepositoryConnection.java
Expand Up @@ -886,31 +886,6 @@ public void sendRDFTransaction(InputStream rdftransaction) throws RepositoryExce
getHttpRepoClient().sendRDFTransaction(rdftransaction);
}

/**
* Sets the connection's bulkMode (defaults to false).
*
* When in bulkMode, data can be added/loaded more quickly, but
* there is no guarantee of durability in the event of a crash.
*
* @param bulkMode a boolean indicating the bulkMode.
* @throws RepositoryException
* @see #isBulkMode()
*/
public void setBulkMode(boolean bulkMode) throws RepositoryException {
getHttpRepoClient().setBulkMode(bulkMode);
}

/**
* Returns the connection's bulkMode setting.
*
* @return a boolean indicating the bulkMode setting.
* @throws RepositoryException
* @see #setBulkMode(boolean)
*/
public boolean isBulkMode() throws RepositoryException {
return getHttpRepoClient().isBulkMode();
}

/**
* Registers an encodable namespace having the specified format.
*
Expand Down
2 changes: 1 addition & 1 deletion src/test/AGUpload.java
Expand Up @@ -41,7 +41,7 @@ public static void main(String[] args) throws Exception {
try {
System.out.println("Loading: " + SOURCE_FILE);
long start = System.nanoTime();
conn.setBulkMode(true);
//repo.setBulkMode(true);
conn.add(new FileInputStream(SOURCE_FILE), null, RDFFormat.NTRIPLES);
System.out.println("Loaded: " + conn.size() + " triples in " + (System.nanoTime()-start)/1.0e9 + " seconds.");
} finally {
Expand Down
10 changes: 5 additions & 5 deletions src/test/BulkModeTests.java
Expand Up @@ -24,19 +24,19 @@ public class BulkModeTests extends AGAbstractTest {

@Test
@Category(TestSuites.Prepush.class)
public void bulkMode_rfe10143() throws Exception {
public void bulkMode_rfe10303() throws Exception {
Assert.assertFalse("expected bulkMode false", repo.isBulkMode());
Assert.assertTrue("expected autoCommit true", conn.isAutoCommit());
Assert.assertFalse("expected bulkMode false", conn.isBulkMode());
conn.setBulkMode(true);
repo.setBulkMode(true);
Assert.assertTrue("expected autoCommit true", conn.isAutoCommit());
Assert.assertTrue("expected bulkMode true", conn.isBulkMode());
Assert.assertTrue("expected bulkMode true", repo.isBulkMode());
String path1 = "src/tutorial/java-vcards.rdf";
URI context = vf.createURI("http://example.org#vcards");
conn.add(new File(path1), null, RDFFormat.RDFXML, context);
assertEquals("expected 16 vcard triples", 16, conn.size(context));
conn.setAutoCommit(false);
Assert.assertFalse("expected autoCommit false", conn.isAutoCommit());
Assert.assertTrue("expected bulkMode true", conn.isBulkMode());
Assert.assertTrue("expected bulkMode true", repo.isBulkMode());
String path2 = "src/tutorial/java-kennedy.ntriples";
conn.add(new File(path2), null, RDFFormat.NTRIPLES);
assertEquals("expected 1214 kennedy triples", 1214, conn.size((Resource)null));
Expand Down
3 changes: 1 addition & 2 deletions src/test/TestSuites.java
Expand Up @@ -55,8 +55,7 @@ public static class Temp {}
JenaTests.class,
BulkModeTests.class,
IndexManagementTests.class,
EncodableNamespaceTests.class,
FederationTests.class
EncodableNamespaceTests.class
})
public static class Prepush {}

Expand Down

0 comments on commit e7c4e56

Please sign in to comment.