Skip to content

Commit

Permalink
Committing quite a bit of Sesame API code for the HTTPD server
Browse files Browse the repository at this point in the history
  • Loading branch information
bmacgregor committed Oct 21, 2008
1 parent 8a7c468 commit ce69613
Show file tree
Hide file tree
Showing 15 changed files with 1,359 additions and 40 deletions.
1 change: 1 addition & 0 deletions httpdsail/.classpath
Expand Up @@ -9,5 +9,6 @@
<classpathentry kind="lib" path="commons-httpclient-3.0.1.jar"/>
<classpathentry kind="lib" path="commons-logging-1.0.4.jar"/>
<classpathentry kind="lib" path="commons-codec-1.3.jar"/>
<classpathentry kind="lib" path="log4j-1.2.11.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion httpdsail/src/miniclient/Catalog.java
Expand Up @@ -14,7 +14,7 @@ public class Catalog {
private Object curl = null;

public Catalog(String url, String username, String password) {
this.url = url;
this.url = Server.toFullURL(url);
this.username = username;
this.password = password;
}
Expand Down
8 changes: 4 additions & 4 deletions httpdsail/src/miniclient/Repository.java
Expand Up @@ -37,8 +37,8 @@ public void nullRequest(String method, String url, JSONObject options,
/**
* Return the number of triples/quads in the repository.
*/
public int getSize() {
return (int)new Integer((String)this.jsonRequest("GET", this.url + "/size"));
public long getSize() {
return (long)new Long((String)this.jsonRequest("GET", this.url + "/size"));
}

/**
Expand Down Expand Up @@ -93,7 +93,7 @@ public void definePrologFunctor(String definition) {
* Context can be None or a list of contexts, as in
* evalSparqlQuery.
*/
public List getStatements(String subj, String pred, String obj, Object context, boolean infer, Object callback) {
public List<List<String>> getStatements(String subj, String pred, String obj, Object context, boolean infer, Object callback) {
try {
JSONObject options = new JSONObject().put("subj", subj).put("pred", pred).put("obj", obj).
put("context", context).put("infer", infer);
Expand All @@ -117,7 +117,7 @@ public void addStatement(String subj, String pred, String obj, Object context) {
* Delete all statements matching the constraints from the
* repository. Context can be None or a single graph name.
*/
public void deleteMatchingStatements(String subj, String pred, String obj, String context) {
public void deleteMatchingStatements(String subj, String pred, String obj, Object context) {
try {
JSONObject options = new JSONObject().put("subj", subj).put("pred", pred).put("obj",obj).
put("context", context);
Expand Down
15 changes: 12 additions & 3 deletions httpdsail/src/miniclient/Server.java
Expand Up @@ -8,8 +8,17 @@

public class Server {

/**
* Make sure that 'url' has an HTTP protocol prepended.
*/
protected static String toFullURL(String url) {
if (!url.toLowerCase().startsWith("http"))
url = "http://" + url;
return url;
}

public static List<String> listCatalogs(String serverURL) {
return (List)Request.jsonRequest("GET", serverURL + "/catalogs", null, null, null);
return (List)Request.jsonRequest("GET", toFullURL(serverURL) + "/catalogs", null, null, null);
}

public static Catalog openCatalog(String serverURL, String catalogName, String username, String password) {
Expand Down Expand Up @@ -72,7 +81,7 @@ private static void test0() {
System.out.println( "Now is 'test' there??:" + reps + (reps.contains("test")));
} catch (Exception ex) {}
Repository rep = cat.getRepository("test");
int size = rep.getSize();
long size = rep.getSize();
System.out.println( "Size of 'test' repository " + size);
if (size == 0) {
rep.addStatement("<http://www.franz.com/example#ted>", "<http://www.franz.com/example#age>",
Expand Down Expand Up @@ -101,7 +110,7 @@ private static Repository openRep () {
System.out.println( "Now is 'test' there??:" + reps + (reps.contains("test")));
} catch (Exception ex) {}
Repository rep = cat.getRepository("test");
int size = rep.getSize();
long size = rep.getSize();
System.out.println("Repository size = " + rep.getSize());
return rep;
}
Expand Down
83 changes: 56 additions & 27 deletions httpdsail/src/org/openrdf/repository/sail/AllegroRepository.java
Expand Up @@ -6,14 +6,14 @@
package org.openrdf.repository.sail;

import java.io.File;

import miniclient.Catalog;
import java.util.HashMap;
import java.util.Map;

import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailException;

import franz.exceptions.ServerException;
import franz.exceptions.UnimplementedMethodException;
Expand Down Expand Up @@ -44,34 +44,51 @@
* repository.initialize();
* </pre>
*
* @author Arjohn Kampman
*/
public class AllegroRepository {
public class AllegroRepository implements Repository {

private String accessVerb = null;
private Catalog miniCatalog = null;
private miniclient.Catalog miniCatalog = null;
private miniclient.Repository miniRepository;
private String repositoryName = null;
private SailRepository sailRepository = null;
private SailRepositoryConnection repositoryConnection = null;
private AllegroRepositoryConnection repositoryConnection = null;
private Map<String, String> inlinedPredicates = new HashMap<String, String>();
private Map<String, String> inlinedDatatypes = new HashMap<String, String>();

/*--------------*
* Constructors *
*--------------*/
private static AllegroValueFactory VALUE_FACTORY = null;

public static String RENEW = "RENEW";
public static String CREATE = "CREATE";
public static String OPEN = "OPEN";
public static String ACCESS = "ACCESS";

/**
* Create a new Sail that operates on the triple store that 'miniRepository'
* Constructor. Create a new Sail that operates on the triple store that 'miniRepository'
* connects to.
*/
public AllegroRepository(Catalog catalog, String repositoryName, String accessVerb) {
this.miniCatalog = catalog;
protected AllegroRepository(Catalog catalog, String repositoryName, String accessVerb) {
this.miniCatalog = catalog.getMiniCatalog();
this.repositoryName = repositoryName;
this.accessVerb = accessVerb;
}

protected miniclient.Repository getMiniRepository() {
this.verify();
return this.miniRepository;
}

public String getName () {return this.repositoryName;}

public Map<String, String> getInlinedPredicates () {
return this.inlinedPredicates;
}

public Map<String, String> getInlinedDatatypes () {
return this.inlinedDatatypes;
}



/*---------*
* Methods *
*---------*/

public File getDataDir() {
throw new UnimplementedMethodException("getDataDir");
Expand All @@ -81,30 +98,30 @@ public void setDataDir(File dataDir) {
throw new UnimplementedMethodException("setDataDir");
}

public void initialize() throws RepositoryException {
public void initialize() {
System.out.println("ATTACH" + this.accessVerb + " " + this.miniCatalog.listTripleStores());
boolean clearIt = false;
String repName = this.repositoryName;
Catalog conn = this.miniCatalog;
if (this.accessVerb == SailRepository.RENEW) {
miniclient.Catalog conn = this.miniCatalog;
if (this.accessVerb == RENEW) {
if (conn.listTripleStores().contains(repName)) {
// not nice, since someone else probably has it open:
clearIt = true;
} else {
conn.createTripleStore(repName);
}
} else if (this.accessVerb == SailRepository.CREATE) {
} else if (this.accessVerb == CREATE) {
if (conn.listTripleStores().contains(repName)) {
throw new ServerException(
"Can't create triple store named '" + repName + "' because a store with that name already exists.");
}
conn.createTripleStore(repName);
} else if (this.accessVerb == SailRepository.OPEN) {
} else if (this.accessVerb == OPEN) {
if (!conn.listTripleStores().contains(repName)) {
throw new ServerException(
"Can't open a triple store named '" + repName + "' because there is none.");
}
} else if(this.accessVerb == SailRepository.ACCESS) {
} else if(this.accessVerb == ACCESS) {
if (!conn.listTripleStores().contains(repName)) {
conn.createTripleStore(repName) ;
}
Expand All @@ -115,6 +132,14 @@ public void initialize() throws RepositoryException {
this.miniRepository.deleteMatchingStatements(null, null, null, null);
}
}

private void verify () {
if (this.miniCatalog != null && this.miniRepository != null) return;
else if (this.miniCatalog == null)
throw new ServerException("Attempt to use the repository after it has been closed.");
else
throw new ServerException("Attempt to use the repository before it has been initialized.");
}

public void shutDown() {
this.miniCatalog = null;
Expand All @@ -123,17 +148,21 @@ public void shutDown() {


public boolean isWritable() {
this.verify();
return this.miniRepository.isWriteable();
}

public ValueFactory getValueFactory() {
return sail.getValueFactory();
if (VALUE_FACTORY == null) {
VALUE_FACTORY = new AllegroValueFactory(this);
}
return VALUE_FACTORY;
}

public SailRepositoryConnection getConnection() {
public RepositoryConnection getConnection() {
this.verify();
if (this.repositoryConnection == null) {
this.repositoryConnection = new SailRepositoryConnection(this.sailRepository);
this.repositoryConnection = new AllegroRepositoryConnection(this);
}
return this.repositoryConnection;
}
Expand Down

0 comments on commit ce69613

Please sign in to comment.