From cfdf84629dec75a7d230df1b46216b5fb70e2d77 Mon Sep 17 00:00:00 2001 From: agazzarini Date: Mon, 25 Aug 2014 22:20:21 +0200 Subject: [PATCH] [ issue #14 ] first draft SOLR binding module --- .../jena-nosql-binding-cassandra/pom.xml | 5 - .../CassandraStorageLayerFactory.java | 7 - .../dao/CassandraTripleIndexDAO.java | 2 +- .../jena-nosql-binding-solr/pom.xml | 24 +++ .../src/collection/solr.xml | 0 .../gazzax/labs/jena/nosql/solr/Field.java | 8 + .../nosql/solr/SolrStorageLayerFactory.java | 71 +++++++ .../nosql/solr/dao/SolrTripleIndexDAO.java | 199 ++++++++++++++++++ .../labs/jena/nosql/solr/graph/SolrGraph.java | 112 ++++++++++ .../labs/jena/nosql/solr/package-info.java | 7 + jena-nosql-binding/pom.xml | 41 ++-- .../jena/nosql/fwk/ds/TripleIndexDAO.java | 17 +- .../fwk/factory/StorageLayerFactory.java | 14 +- .../nosql/fwk/graph/NoSqlDatasetGraph.java | 4 +- .../labs/jena/nosql/fwk/graph/NoSqlGraph.java | 2 +- jena-nosql-integration-tests/pom.xml | 4 + 16 files changed, 475 insertions(+), 42 deletions(-) create mode 100644 jena-nosql-binding/jena-nosql-binding-solr/pom.xml create mode 100644 jena-nosql-binding/jena-nosql-binding-solr/src/collection/solr.xml create mode 100644 jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/Field.java create mode 100644 jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/SolrStorageLayerFactory.java create mode 100644 jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/dao/SolrTripleIndexDAO.java create mode 100644 jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/graph/SolrGraph.java create mode 100644 jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/package-info.java diff --git a/jena-nosql-binding/jena-nosql-binding-cassandra/pom.xml b/jena-nosql-binding/jena-nosql-binding-cassandra/pom.xml index 622d88e..af802f7 100644 --- a/jena-nosql-binding/jena-nosql-binding-cassandra/pom.xml +++ b/jena-nosql-binding/jena-nosql-binding-cassandra/pom.xml @@ -10,11 +10,6 @@ jena-nosql-binding-cassandra Jena Cassandra binding implementation. - - org.gazzax.labs - jena-nosql-framework - 1.0 - com.datastax.cassandra cassandra-driver-core diff --git a/jena-nosql-binding/jena-nosql-binding-cassandra/src/main/java/org/gazzax/labs/jena/nosql/cassandra/CassandraStorageLayerFactory.java b/jena-nosql-binding/jena-nosql-binding-cassandra/src/main/java/org/gazzax/labs/jena/nosql/cassandra/CassandraStorageLayerFactory.java index 1094d48..20732b8 100644 --- a/jena-nosql-binding/jena-nosql-binding-cassandra/src/main/java/org/gazzax/labs/jena/nosql/cassandra/CassandraStorageLayerFactory.java +++ b/jena-nosql-binding/jena-nosql-binding-cassandra/src/main/java/org/gazzax/labs/jena/nosql/cassandra/CassandraStorageLayerFactory.java @@ -18,14 +18,7 @@ import org.gazzax.labs.jena.nosql.fwk.InitialisationException; import org.gazzax.labs.jena.nosql.fwk.configuration.Configuration; import org.gazzax.labs.jena.nosql.fwk.dictionary.TopLevelDictionary; -import org.gazzax.labs.jena.nosql.fwk.dictionary.node.CacheNodectionary; -import org.gazzax.labs.jena.nosql.fwk.dictionary.node.KnownURIsDictionary; -import org.gazzax.labs.jena.nosql.fwk.dictionary.node.PersistentNodeDictionary; -import org.gazzax.labs.jena.nosql.fwk.dictionary.node.ThreeTieredNodeDictionary; import org.gazzax.labs.jena.nosql.fwk.dictionary.node.TransientNodeDictionary; -import org.gazzax.labs.jena.nosql.fwk.dictionary.string.CacheStringDictionary; -import org.gazzax.labs.jena.nosql.fwk.dictionary.string.PersistentStringDictionary; -import org.gazzax.labs.jena.nosql.fwk.dictionary.string.TransientStringDictionary; import org.gazzax.labs.jena.nosql.fwk.ds.MapDAO; import org.gazzax.labs.jena.nosql.fwk.ds.TripleIndexDAO; import org.gazzax.labs.jena.nosql.fwk.factory.ClientShutdownHook; diff --git a/jena-nosql-binding/jena-nosql-binding-cassandra/src/main/java/org/gazzax/labs/jena/nosql/cassandra/dao/CassandraTripleIndexDAO.java b/jena-nosql-binding/jena-nosql-binding-cassandra/src/main/java/org/gazzax/labs/jena/nosql/cassandra/dao/CassandraTripleIndexDAO.java index b2e5057..46f47c5 100644 --- a/jena-nosql-binding/jena-nosql-binding-cassandra/src/main/java/org/gazzax/labs/jena/nosql/cassandra/dao/CassandraTripleIndexDAO.java +++ b/jena-nosql-binding/jena-nosql-binding-cassandra/src/main/java/org/gazzax/labs/jena/nosql/cassandra/dao/CassandraTripleIndexDAO.java @@ -30,7 +30,7 @@ * @author Andrea Gazzarini * @since 1.0 */ -public class CassandraTripleIndexDAO implements TripleIndexDAO { +public class CassandraTripleIndexDAO implements TripleIndexDAO { protected static final byte[] EMPTY_VAL = new byte[0]; protected static final String SELECT_SPOC_FROM = "SELECT s, p, o, c FROM "; diff --git a/jena-nosql-binding/jena-nosql-binding-solr/pom.xml b/jena-nosql-binding/jena-nosql-binding-solr/pom.xml new file mode 100644 index 0000000..58fbf8f --- /dev/null +++ b/jena-nosql-binding/jena-nosql-binding-solr/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + jena-nosql-binding + org.gazzax.labs + 1.0 + .. + + jena-nosql-binding-solr + Apache SOLR binding module + https://github.com/agazzarini/jena-nosql/issues/14 + + 4.8.0 + + + + org.apache.solr + solr-solrj + ${solr.version} + provided + + + \ No newline at end of file diff --git a/jena-nosql-binding/jena-nosql-binding-solr/src/collection/solr.xml b/jena-nosql-binding/jena-nosql-binding-solr/src/collection/solr.xml new file mode 100644 index 0000000..e69de29 diff --git a/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/Field.java b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/Field.java new file mode 100644 index 0000000..f15eb35 --- /dev/null +++ b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/Field.java @@ -0,0 +1,8 @@ +package org.gazzax.labs.jena.nosql.solr; + +public interface Field { + String S = "s"; + String P = "p"; + String O = "o"; + String C = "c"; +} diff --git a/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/SolrStorageLayerFactory.java b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/SolrStorageLayerFactory.java new file mode 100644 index 0000000..52d3e75 --- /dev/null +++ b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/SolrStorageLayerFactory.java @@ -0,0 +1,71 @@ +package org.gazzax.labs.jena.nosql.solr; + +import java.util.Map; + +import org.apache.solr.client.solrj.SolrServer; +import org.gazzax.labs.jena.nosql.fwk.configuration.Configuration; +import org.gazzax.labs.jena.nosql.fwk.dictionary.TopLevelDictionary; +import org.gazzax.labs.jena.nosql.fwk.ds.MapDAO; +import org.gazzax.labs.jena.nosql.fwk.ds.TripleIndexDAO; +import org.gazzax.labs.jena.nosql.fwk.factory.ClientShutdownHook; +import org.gazzax.labs.jena.nosql.fwk.factory.StorageLayerFactory; +import org.gazzax.labs.jena.nosql.fwk.graph.NoSqlGraph; +import org.gazzax.labs.jena.nosql.solr.dao.SolrTripleIndexDAO; +import org.gazzax.labs.jena.nosql.solr.graph.SolrGraph; + +import com.hp.hpl.jena.graph.Graph; +import com.hp.hpl.jena.graph.Node; + +/** + * Concrete factory for creating SOLR-based domain and data access objects. + * + * @author Andrea Gazzarini + * @since 1.0 + */ +public class SolrStorageLayerFactory extends StorageLayerFactory { + private SolrServer solr; + + @Override + public void accept(final Configuration> configuration) { + // TODO Auto-generated method stub + } + + @Override + public MapDAO getMapDAO( + final Class keyClass, + final Class valueClass, + final boolean isBidirectional, + final String name) { + return null; + } + + @Override + public Graph getGraph() { + return new SolrGraph(this); + } + + @Override + public Graph getGraph(Node graphNode) { + return new SolrGraph(graphNode, this); + } + + @Override + public TripleIndexDAO getTripleIndexDAO() { + return new SolrTripleIndexDAO(solr); + } + + @Override + public TopLevelDictionary getDictionary() { + return null; + } + + @Override + public ClientShutdownHook getClientShutdownHook() { + return null; + } + + @Override + public String getInfo() { + return null; + } +} diff --git a/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/dao/SolrTripleIndexDAO.java b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/dao/SolrTripleIndexDAO.java new file mode 100644 index 0000000..71bddb0 --- /dev/null +++ b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/dao/SolrTripleIndexDAO.java @@ -0,0 +1,199 @@ +package org.gazzax.labs.jena.nosql.solr.dao; + +import static org.gazzax.labs.jena.nosql.fwk.util.NTriples.asNt; +import static org.gazzax.labs.jena.nosql.fwk.util.NTriples.asNtURI; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.client.solrj.response.UpdateResponse; +import org.apache.solr.common.SolrDocument; +import org.apache.solr.common.SolrDocumentList; +import org.apache.solr.common.SolrInputDocument; +import org.gazzax.labs.jena.nosql.fwk.StorageLayerException; +import org.gazzax.labs.jena.nosql.fwk.ds.TripleIndexDAO; +import org.gazzax.labs.jena.nosql.fwk.util.NTriples; +import org.gazzax.labs.jena.nosql.solr.Field; + +import com.google.common.collect.AbstractIterator; +import com.hp.hpl.jena.graph.Node; +import com.hp.hpl.jena.graph.Triple; +import com.hp.hpl.jena.graph.TripleMatch; + +public class SolrTripleIndexDAO implements TripleIndexDAO { + + private final static Iterator EMPTY_TRIPLES_ITERATOR = new ArrayList(0).iterator(); + + private final SolrServer solr; + + /** + * Builds a new {@link TripleIndexDAO} with the given SOLR client. + * + * @param solr the SOLR client. + */ + public SolrTripleIndexDAO(final SolrServer solr) { + this.solr = solr; + } + + @Override + public void insertTriple(final Triple triple) throws StorageLayerException { + final SolrInputDocument document = new SolrInputDocument(); + document.setField(Field.S, asNt(triple.getSubject())); + document.setField(Field.P, asNtURI(triple.getPredicate())); + document.setField(Field.O, asNt(triple.getSubject())); + + try { + solr.add(document); + } catch (final Exception exception) { + throw new StorageLayerException(exception); + } + } + + @Override + public void deleteTriple(final Triple triple) throws StorageLayerException { + try { + solr.deleteByQuery(deleteQuery(triple)); + } catch (final Exception exception) { + throw new StorageLayerException(exception); + } + } + + /** + * Builds a delete query starting from a given triple. + * + * @param triple the triple. + * @return a delete query starting from a given triple. + */ + private String deleteQuery(final Triple triple) { + return new StringBuilder() + .append(Field.S).append(":\"").append(asNt(triple.getSubject())).append("\" AND ") + .append(Field.P).append(":\"").append(asNt(triple.getPredicate())).append("\" AND ") + .append(Field.O).append(":\"").append(asNt(triple.getObject())).append("\"") + .toString(); + } + + // TODO: To be optimized...with this implementation wildcard queries are not supported + // so if I need to delete 5 triples then 5 commands should be issued. + @Override + public List deleteTriples( + final Iterator triples, + final int batchSize) throws StorageLayerException { + final List result = new ArrayList(); + while (triples.hasNext()) { + final Triple triple = triples.next(); + try { + final UpdateResponse response = solr.deleteByQuery(deleteQuery(triple)); + if (response.getStatus() == 0) { + result.add(triple); + } + } catch (final Exception exception) { + throw new StorageLayerException(exception); + } + } + + return null; + } + + @Override + public void executePendingMutations() throws StorageLayerException { + try { + solr.commit(); + } catch (final Exception exception) { + throw new StorageLayerException(exception); + } + } + + @Override + public void clear() { + try { + solr.deleteByQuery("*;*"); + } catch (final Exception exception) { + // TODO: log + exception.printStackTrace(); + } + } + + @Override + public Iterator query(final TripleMatch query) throws StorageLayerException { + final SolrQuery q = new SolrQuery("*:*"); + q.setStart(0); + final Node s = query.getMatchSubject(); + final Node p = query.getMatchPredicate(); + final Node o = query.getMatchObject(); + + if (s != null) { + q.addFilterQuery( + new StringBuilder() + .append(Field.S) + .append(":\"") + .append(asNt(s)) + .append("\"") + .toString()); + } + + if (p != null) { + q.addFilterQuery( + new StringBuilder() + .append(Field.P) + .append(":\"") + .append(asNtURI(p)) + .append("\"") + .toString()); + } + + if (o != null) { + q.addFilterQuery( + new StringBuilder() + .append(Field.O) + .append(":\"") + .append(asNt(o)) + .append("\"") + .toString()); + } + + try { + final QueryResponse response = solr.query(q); + + if (response.getResults().getNumFound() == 0) { + return EMPTY_TRIPLES_ITERATOR; + } + + return new AbstractIterator() { + + int rowId; + SolrDocumentList page = response.getResults(); + + @Override + protected Triple computeNext() { + + if (page.getStart() + page.size() == page.getNumFound()) { + return endOfData(); + } + + if (rowId == page.size() - 1) { + rowId = 0; + q.setStart(q.getStart() + page.size()); + try { + page = solr.query(q).getResults(); + } catch (final SolrServerException exception) { + throw new RuntimeException(exception); + } + } + + final SolrDocument document = page.get(rowId); + return Triple.create( + NTriples.asURIorBlankNode((String) document.getFieldValue(Field.S)), + NTriples.asURI((String) document.getFieldValue(Field.P)), + NTriples.asNode((String) document.getFieldValue(Field.P))); + } + }; + } catch (final Exception exception) { + throw new StorageLayerException(exception); + } + } +} \ No newline at end of file diff --git a/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/graph/SolrGraph.java b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/graph/SolrGraph.java new file mode 100644 index 0000000..56c67fc --- /dev/null +++ b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/graph/SolrGraph.java @@ -0,0 +1,112 @@ +package org.gazzax.labs.jena.nosql.solr.graph; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.gazzax.labs.jena.nosql.fwk.StorageLayerException; +import org.gazzax.labs.jena.nosql.fwk.ds.TripleIndexDAO; +import org.gazzax.labs.jena.nosql.fwk.factory.StorageLayerFactory; +import org.gazzax.labs.jena.nosql.fwk.log.Log; +import org.gazzax.labs.jena.nosql.fwk.log.MessageCatalog; +import org.gazzax.labs.jena.nosql.fwk.log.MessageFactory; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.graph.GraphEvents; +import com.hp.hpl.jena.graph.Node; +import com.hp.hpl.jena.graph.Triple; +import com.hp.hpl.jena.graph.TripleMatch; +import com.hp.hpl.jena.graph.impl.GraphBase; +import com.hp.hpl.jena.shared.AddDeniedException; +import com.hp.hpl.jena.shared.DeleteDeniedException; +import com.hp.hpl.jena.util.iterator.ExtendedIterator; +import com.hp.hpl.jena.util.iterator.WrappedIterator; + +/** + * SOLR Graph implementation. + * + * @author Andrea Gazzarini + * @since 1.0 + */ +public class SolrGraph extends GraphBase { + private final static Log LOGGER = new Log(LoggerFactory.getLogger(SolrGraph.class)); + + private final static ExtendedIterator EMPTY_TRIPLES_ITERATOR = WrappedIterator.createNoRemove(new ArrayList(0).iterator()); + + private final TripleIndexDAO dao; + private final Node name; + + /** + * Builds a new unnamed graph with the given factory. + * + * @param factory the storage layer factory. + */ + public SolrGraph(final StorageLayerFactory factory) { + this(null, factory); + } + + /** + * Builds a new named graph with the given data. + * + * @param name the graph name. + * @param factory the storage layer factory. + */ + @SuppressWarnings("unchecked") + public SolrGraph(final Node name, final StorageLayerFactory factory) { + this.name = name; + this.dao = factory.getTripleIndexDAO(); + } + + @Override + public void performAdd(final Triple triple) { + try { + dao.insertTriple(triple); + dao.executePendingMutations(); + } catch (final StorageLayerException exception) { + final String message = MessageFactory.createMessage(MessageCatalog._00101_UNABLE_TO_ADD_TRIPLE, triple); + LOGGER.error(message, exception); + throw new AddDeniedException(message, triple); + } + } + + @Override + public void performDelete(final Triple triple) { + try { + if (triple.isConcrete()) { + dao.deleteTriple(triple); + } else if (triple.getSubject().isConcrete() && + triple.getPredicate().isConcrete() && + triple.getObject().isConcrete()){ + clear(); + } else { + // TODO: batch size must be configurable + dao.deleteTriples(query(triple), 1000); + } + } catch (final StorageLayerException exception) { + final String message = MessageFactory.createMessage(MessageCatalog._00100_UNABLE_TO_DELETE_TRIPLE, triple); + LOGGER.error(message, exception); + throw new DeleteDeniedException(message, triple); + } + } + + @Override + public void clear() + { + dao.clear(); + getEventManager().notifyEvent(this, GraphEvents.removeAll ) ; + } + + @Override + protected ExtendedIterator graphBaseFind(final TripleMatch pattern) { + try + { + return WrappedIterator.createNoRemove(query(pattern)); + } catch (StorageLayerException exception) { + LOGGER.error(MessageCatalog._00010_DATA_ACCESS_LAYER_FAILURE, exception); + return EMPTY_TRIPLES_ITERATOR; + } + } + + Iterator query(final TripleMatch query) throws StorageLayerException { + return dao.query(query); + } +} \ No newline at end of file diff --git a/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/package-info.java b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/package-info.java new file mode 100644 index 0000000..3192652 --- /dev/null +++ b/jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/package-info.java @@ -0,0 +1,7 @@ +/** + * Top level package of SOLR binding module. + * + * @author Andrea Gazzarini + * @since 1.0 + */ +package org.gazzax.labs.jena.nosql.solr; diff --git a/jena-nosql-binding/pom.xml b/jena-nosql-binding/pom.xml index 35a6ef3..c7e6ae8 100644 --- a/jena-nosql-binding/pom.xml +++ b/jena-nosql-binding/pom.xml @@ -1,17 +1,26 @@ - - 4.0.0 - - jena-nosql - org.gazzax.labs - 1.0 - .. - - jena-nosql-binding - pom - Jena NoSQL bindings container project. - Includes all implemented NoSQL bindings. - - jena-nosql-binding-hbase - jena-nosql-binding-cassandra - + + 4.0.0 + + jena-nosql + org.gazzax.labs + 1.0 + .. + + jena-nosql-binding + pom + Jena NoSQL bindings container project. + Includes all implemented NoSQL bindings. + + + org.gazzax.labs + jena-nosql-framework + ${project.version} + + + + jena-nosql-binding-hbase + jena-nosql-binding-cassandra + jena-nosql-binding-solr + \ No newline at end of file diff --git a/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/ds/TripleIndexDAO.java b/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/ds/TripleIndexDAO.java index 7cbaf5e..42c4454 100644 --- a/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/ds/TripleIndexDAO.java +++ b/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/ds/TripleIndexDAO.java @@ -12,34 +12,35 @@ * @author Andrea Gazzarini * @since 1.0 * @param how this DAO represents a triple. + * @param

how this DAO represents a triple pattern. */ -public interface TripleIndexDAO { +public interface TripleIndexDAO { /** * Inserts a triple. * - * @param identifiers the incoming triple. + * @param triple the incoming triple. * @throws StorageLayerException in case of storage layer access failure. */ - void insertTriple(final T identifiers) throws StorageLayerException; + void insertTriple(final T triple) throws StorageLayerException; /** * Removes a triple from the storage. * - * @param identifiers the incoming triple. + * @param triple the incoming triple. * @throws StorageLayerException in case of storage layer access failure. */ - void deleteTriple(final T identifiers) throws StorageLayerException; + void deleteTriple(final T triple) throws StorageLayerException; /** * Removes the given triples from the storage. * - * @param identifiers the incoming triples. + * @param triples the incoming triples. * @param batchSize how many delete will be grouped in a single chunks in order to optimize the command execution. * @return the triples that have been removed. * @throws StorageLayerException in case of storage layer access failure. */ List deleteTriples( - final Iterator identifiers, + final Iterator triples, final int batchSize) throws StorageLayerException; /** @@ -62,5 +63,5 @@ List deleteTriples( * @return an iterator over query results. * @throws StorageLayerException in case of storage access failure. */ - Iterator query(T query) throws StorageLayerException; + Iterator query(P query) throws StorageLayerException; } \ No newline at end of file diff --git a/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/factory/StorageLayerFactory.java b/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/factory/StorageLayerFactory.java index 0ffe7b1..dd9231c 100644 --- a/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/factory/StorageLayerFactory.java +++ b/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/factory/StorageLayerFactory.java @@ -14,6 +14,7 @@ import org.gazzax.labs.jena.nosql.fwk.graph.NoSqlGraph; import com.hp.hpl.jena.graph.Graph; +import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.sparql.core.DatasetGraph; /** @@ -67,14 +68,23 @@ public abstract MapDAO getMapDAO( public abstract TripleIndexDAO getTripleIndexDAO(); /** - * Returns the {@link Graph} specific implementation associated with the underlying kind of storage. + * Returns an unnamed {@link Graph} specific implementation associated with the underlying kind of storage. * - * @return the {@link Graph} specific implementation associated with the underlying kind of storage. + * @return an unnamed {@link Graph} specific implementation associated with the underlying kind of storage. */ public Graph getGraph() { return new NoSqlGraph(this); } + /** + * Returns a named {@link Graph} specific implementation associated with the underlying kind of storage. + * + * @return a named {@link Graph} specific implementation associated with the underlying kind of storage. + */ + public Graph getGraph(Node graphNode) { + return new NoSqlGraph(graphNode, this); + } + /** * Returns the {@link DatasetGraph} associated with the underlying kind of storage. * diff --git a/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/graph/NoSqlDatasetGraph.java b/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/graph/NoSqlDatasetGraph.java index 21070d1..718b97a 100644 --- a/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/graph/NoSqlDatasetGraph.java +++ b/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/graph/NoSqlDatasetGraph.java @@ -41,12 +41,12 @@ protected void _close() { @Override protected Graph _createNamedGraph(final Node graphNode) { - return new NoSqlGraph(graphNode, factory); + return factory.getGraph(graphNode); } @Override protected Graph _createDefaultGraph() { - return new NoSqlGraph(factory); + return factory.getGraph(); } @Override diff --git a/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/graph/NoSqlGraph.java b/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/graph/NoSqlGraph.java index 366397e..bc13a60 100644 --- a/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/graph/NoSqlGraph.java +++ b/jena-nosql-framework/src/main/java/org/gazzax/labs/jena/nosql/fwk/graph/NoSqlGraph.java @@ -34,7 +34,7 @@ public class NoSqlGraph extends GraphBase { private final static Iterator EMPTY_IDS_ITERATOR = new ArrayList(0).iterator(); private final static ExtendedIterator EMPTY_TRIPLES_ITERATOR = WrappedIterator.createNoRemove(new ArrayList(0).iterator()); - private final TripleIndexDAO dao; + private final TripleIndexDAO dao; private final TopLevelDictionary dictionary; private final Node name; diff --git a/jena-nosql-integration-tests/pom.xml b/jena-nosql-integration-tests/pom.xml index 45633c8..a847854 100644 --- a/jena-nosql-integration-tests/pom.xml +++ b/jena-nosql-integration-tests/pom.xml @@ -25,6 +25,10 @@ + + solr-4x + + cassandra-2x