Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enhancements to AGCatalog methods and AGServer.getCatalog

Tests added and prepush passes.  Root catalog methods also tested
with use in TBC plugins.

<release-note>
rfe9837: avoid log warning when opening an existing repo

Added method AGCatalog.hasRepository(id) which tests for existance.
Added AGCatalog.openRepository(id) which will open but not create.
Added AGCatalog.createRepository(id,strict) where the strict option
will throw an exception if the repository already exists.

rfe9980: getCatalog now works with the root catalog

Added AGCatalog.isRootId(id) to identify id's for the root catalog.
Enhanced AGServer.getCatalog(id) to accept root catalog identifiers.
Also added AGServer.getCatalog() to return the root catalog.
</release-note>

Change-Id: I9f79c18ef58e59149efa65168cde7d3c076c3a7a
Reviewed-on: https://gerrit.franz.com:9080/735
Reviewed-by: Kevin Layer <layer@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
Reviewed-by: John O'Rourke <john.orourke@franz.com>
  • Loading branch information...
commit efc3986157e2859c77f3a0fd346eda6916339b93 1 parent 563a960
Bill Millar authored dklayer committed
100 src/com/franz/agraph/repository/AGCatalog.java
View
@@ -20,7 +20,6 @@
import org.openrdf.query.TupleQueryResult;
import org.openrdf.repository.RepositoryException;
-import com.franz.agraph.http.AGErrorType;
import com.franz.agraph.http.AGHTTPClient;
import com.franz.agraph.http.AGHttpException;
import com.franz.agraph.http.AGProtocol;
@@ -124,6 +123,15 @@ public String getRepositoriesURL() {
return repositoriesURL;
}
+ // TODO this should be part of AGProtocol.
+ public String getRepositoryURL(String repositoryID) {
+ return repositoriesURL + "/" + encode(repositoryID);
+ }
+
+ public AGHTTPClient getHTTPClient() {
+ return getServer().getHTTPClient();
+ }
+
protected String getCatalogPrefixedRepositoryID(String repositoryID) {
String catalogPrefixedRepositoryID;
switch (getCatalogType()) {
@@ -139,11 +147,6 @@ protected String getCatalogPrefixedRepositoryID(String repositoryID) {
return catalogPrefixedRepositoryID;
}
- // TODO this should be part of AGProtocol.
- public String getRepositoryURL(String repositoryID) {
- return repositoriesURL + "/" + encode(repositoryID);
- }
-
/**
* Returns a List of repository ids contained in this catalog.
*
@@ -166,10 +169,17 @@ public String getRepositoryURL(String repositoryID) {
return result;
}
- public AGHTTPClient getHTTPClient() {
- return getServer().getHTTPClient();
+ /**
+ * Returns true if the repository id is contained in this catalog.
+ *
+ * @return true if the repository id is contained in this catalog.
+ * @throws OpenRDFException
+ */
+ public boolean hasRepository(String repoId) throws OpenRDFException {
+ List<String> repos = listRepositories();
+ return repos.contains(repoId);
}
-
+
/**
* Returns an uninitialized AGRepository instance for the given
* repository id.
@@ -183,25 +193,64 @@ public AGHTTPClient getHTTPClient() {
*/
public AGRepository createRepository(String repositoryID)
throws RepositoryException {
+ return createRepository(repositoryID, false);
+ }
+
+ /**
+ * Returns an uninitialized AGRepository instance for the given
+ * repository id.
+ *
+ * The repository is created if it does not exist. If the
+ * repository already exists, it is simply opened, or an exception
+ * is thrown if strict=true.
+ *
+ * @param repositoryID the id (the name) of the repository
+ * @param strict if true and the repository already exists, throw an exception
+ * @return an uninitialized AGRepository instance.
+ * @throws RepositoryException
+ */
+ public AGRepository createRepository(String repositoryID, boolean strict)
+ throws RepositoryException {
String repoURL = AGProtocol.getRepositoryLocation(getCatalogURL(),
repositoryID);
try {
- getHTTPClient().putRepository(repoURL);
+ if (strict || !hasRepository(repositoryID)) {
+ getHTTPClient().putRepository(repoURL);
+ }
} catch (IOException e) {
throw new RepositoryException(e);
+ } catch (OpenRDFException e) {
+ // TODO: consider having methods in this class all throw OpenRDFExceptions
+ throw new RepositoryException(e);
} catch (AGHttpException e) {
- if (AGErrorType.PRECONDITION_FAILED == e.getErrorInfo()
- .getErrorType()) {
- // don't error if repo already exists
- // TODO: check if repo exists first
- } else {
- throw new RepositoryException(e);
- }
+ throw new RepositoryException(e);
}
return new AGRepository(this, repositoryID);
}
/**
+ * Returns an uninitialized AGRepository instance for the given
+ * repository id.
+ *
+ * If the repository already exists, it is simply opened.
+ *
+ * @param repositoryID the id (the name) of the repository.
+ * @return an uninitialized AGRepository instance.
+ * @throws RepositoryException if the repositoryID does not exist
+ */
+ public AGRepository openRepository(String repositoryID)
+ throws RepositoryException {
+ try {
+ if (!hasRepository(repositoryID)) {
+ throw new RepositoryException("Repository not found with ID: " + repositoryID);
+ }
+ } catch (OpenRDFException e) {
+ // TODO: consider having methods in this class all throw OpenRDFExceptions
+ throw new RepositoryException(e);
+ }
+ return new AGRepository(this, repositoryID);
+ }
+ /**
* Deletes the repository with the given repository id.
*
* @param repositoryID the name of the repository to delete.
@@ -218,4 +267,21 @@ public void deleteRepository(String repositoryID)
}
}
+ /**
+ * Returns true iff the id identifies the root catalog.
+ *
+ * Currently null, the empty string, and "/" are all considered to identify
+ * the root catalog.
+ *
+ * @param catalogID
+ * @return true iff the id identifies the root catalog.
+ */
+ public static boolean isRootID(String catalogID) {
+ boolean result = false;
+ if (catalogID == null || catalogID.equals("") || catalogID.equals("/")) {
+ result = true;
+ }
+ return result;
+ }
+
}
25 src/com/franz/agraph/repository/AGServer.java
View
@@ -59,9 +59,11 @@ AGHTTPClient getHTTPClient() {
}
/**
- * Returns the root catalog for this AllegroGraph server.
+ * Returns the unnamed root catalog for this AllegroGraph server.
+ * Note: this method may be deprecated in an upcoming release.
*
- * @return the root catalog.
+ * @return the root catalog.
+ * @see #getCatalog()
*/
public AGCatalog getRootCatalog() {
return rootCatalog;
@@ -92,11 +94,28 @@ public AGCatalog getRootCatalog() {
/**
* Gets the catalog instance for a given catalog id.
*
+ * Returns the root catalog if the id is a root id.
+ *
* @param catalogID a catalog id.
* @return the corresponding catalog instance.
*/
public AGCatalog getCatalog(String catalogID) {
- return new AGCatalog(this, catalogID);
+ AGCatalog catalog;
+ if (AGCatalog.isRootID(catalogID)) {
+ catalog = getRootCatalog();
+ } else {
+ catalog = new AGCatalog(this, catalogID);
+ }
+ return catalog;
+ }
+
+ /**
+ * Returns the unnamed root catalog for this AllegroGraph server.
+ *
+ * @return the root catalog.
+ */
+ public AGCatalog getCatalog() {
+ return rootCatalog;
}
public AGVirtualRepository virtualRepository(String spec) {
36 src/test/QuickTests.java
View
@@ -31,8 +31,12 @@
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.query.QueryLanguage;
+import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.RepositoryResult;
+import com.franz.agraph.repository.AGRepository;
+import com.franz.agraph.repository.AGRepositoryConnection;
+
import test.TestSuites.NonPrepushTest;
public class QuickTests extends AGAbstractTest {
@@ -136,7 +140,7 @@ public void bulkDelete() throws Exception {
URI firstname = vf.createURI("http://example.org/ontology/firstname");
URI lastname = vf.createURI("http://example.org/ontology/lastname");
Literal alicesName = vf.createLiteral("Alice");
- List input = new ArrayList<Statement>();
+ List<Statement> input = new ArrayList<Statement>();
input.add(vf.createStatement(alice, firstname, alicesName));
input.add(vf.createStatement(alice, lastname, alicesName));
conn.add(input);
@@ -145,4 +149,32 @@ public void bulkDelete() throws Exception {
assertEquals("size", 0, conn.size());
}
-}
+ @Test
+ @Category(TestSuites.Prepush.class)
+ public void openRepo_rfe9837() throws Exception {
+ AGRepository repo2 = closeLater( cat.openRepository(repo.getRepositoryID()));
+ AGRepositoryConnection conn2 = closeLater( repo2.getConnection());
+ assertEquals("size", conn.size(), conn2.size());
+ assertEquals("id", repo.getRepositoryID(), repo2.getRepositoryID());
+ try {
+ AGRepository repo3 = closeLater( cat.createRepository(repo.getRepositoryID(), true));
+ fail("strict should cause an exception: " + repo3.getRepositoryURL());
+ } catch (RepositoryException e) {
+ if (e.getMessage().contains("There is already a repository")) {
+ // good
+ } else {
+ throw e;
+ }
+ }
+ try {
+ AGRepository repo3 = closeLater( cat.openRepository("no-such-repo"));
+ fail("should not exist: " + repo3.getRepositoryURL());
+ } catch (RepositoryException e) {
+ if (e.getMessage().contains("Repository not found with ID:")) {
+ // good
+ } else {
+ throw e;
+ }
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.