Skip to content

Commit

Permalink
[ issue #14 ] SOLR client configuration within SLFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
agazzarini committed Aug 27, 2014
1 parent c55f983 commit 3defee6
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
.project
.classpath
.settings
target
target

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
Expand Down
2 changes: 1 addition & 1 deletion jena-nosql-binding/jena-nosql-binding-cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<relativePath>..</relativePath>
</parent>
<artifactId>jena-nosql-binding-cassandra</artifactId>
<name>Jena Cassandra binding implementation.</name>
<name>Jena NoSQL Apache Cassandra binding module</name>
<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public <K, V> MapDAO<K, V> getMapDAO(
}

@Override
public TripleIndexDAO getTripleIndexDAO() {
public TripleIndexDAO<byte[][], byte[][]> getTripleIndexDAO() {
return new CassandraTripleIndexDAO(session, dictionary);
}

Expand Down Expand Up @@ -162,7 +162,7 @@ public ClientShutdownHook getClientShutdownHook() {

@Override
public String getInfo() {
return "Cassandra binding v1.0";
return "Jena-nosql Apache Cassandra binding";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion jena-nosql-binding/jena-nosql-binding-hbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<relativePath>..</relativePath>
</parent>
<artifactId>jena-nosql-binding-hbase</artifactId>
<name>Jena HBase binding implementation.</name>
<name>Jena NoSQL Apache HBase binding module</name>
</project>
2 changes: 1 addition & 1 deletion jena-nosql-binding/jena-nosql-binding-solr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<relativePath>..</relativePath>
</parent>
<artifactId>jena-nosql-binding-solr</artifactId>
<name>Apache SOLR binding module</name>
<name>Jena NoSQL Apache SOLR binding module</name>
<description>https://github.com/agazzarini/jena-nosql/issues/14</description>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.gazzax.labs.jena.nosql.solr;

import org.apache.solr.client.solrj.SolrServer;
import org.gazzax.labs.jena.nosql.fwk.factory.ClientShutdownHook;
import org.gazzax.labs.jena.nosql.fwk.log.Log;
import org.gazzax.labs.jena.nosql.fwk.log.MessageCatalog;
import org.slf4j.LoggerFactory;

/**
* A {@link ClientShutdownHook} for SOLR clients.
*
* @author Andrea Gazzarini
* @since 1.0
*/
public class SolrClientShutdownHook implements ClientShutdownHook {
private final static Log LOGGER = new Log(LoggerFactory.getLogger(ClientShutdownHook.class));
private final SolrServer connection;

/**
* Builds a new SOLR Client shutdown hook.
*
* @param connection the connection to SOLR.
*/
public SolrClientShutdownHook(final SolrServer connection) {
this.connection = connection;
}

@Override
public void close() {
try {
connection.shutdown();
} catch (final Exception exception) {
LOGGER.error(MessageCatalog._00099_CLIENT_SHUTDOWN_FAILURE, exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import java.util.Map;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
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;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.TripleMatch;

/**
* Concrete factory for creating SOLR-based domain and data access objects.
Expand All @@ -27,7 +29,14 @@ public class SolrStorageLayerFactory extends StorageLayerFactory {

@Override
public void accept(final Configuration<Map<String, Object>> configuration) {
// TODO Auto-generated method stub
final String address = configuration.getParameter("solr-address", "http://127.0.0.1:8080/solr/store");
try {
solr = (SolrServer) Class.forName(configuration.getParameter("solr-server-class", HttpSolrServer.class.getName()))
.getConstructor(String.class)
.newInstance(address);
} catch (final Exception exception) {
throw new IllegalArgumentException(exception);
}
}

@Override
Expand All @@ -36,7 +45,7 @@ public <K, V> MapDAO<K, V> getMapDAO(
final Class<V> valueClass,
final boolean isBidirectional,
final String name) {
return null;
throw new UnsupportedOperationException();
}

@Override
Expand All @@ -50,22 +59,22 @@ public Graph getGraph(Node graphNode) {
}

@Override
public TripleIndexDAO getTripleIndexDAO() {
public TripleIndexDAO<Triple, TripleMatch> getTripleIndexDAO() {
return new SolrTripleIndexDAO(solr);
}

@Override
public TopLevelDictionary getDictionary() {
return null;
throw new UnsupportedOperationException();
}

@Override
public ClientShutdownHook getClientShutdownHook() {
return null;
return new SolrClientShutdownHook(solr);
}

@Override
public String getInfo() {
return null;
return "Jena-nosql Apache SOLR binding";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gazzax.labs.jena.nosql.solr.SolrStorageLayerFactory
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
##########################################
## JENA-NOSQL default configuration ##
##########################################

# SorlServer implementation
solr-server-class: "org.apache.solr.client.solrj.impl.HttpSolrServer"
solr-address: "http://127.0.0.1:8080/solr/store"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="s" type="string" indexed="true" stored="true" required="true" />
<field name="p" type="string" indexed="true" stored="true" required="true" />
<field name="o" type="string" indexed="true" stored="true" required="true" />
<field name="c" type="string" indexed="true" stored="true" required="true" />
<field name="c" type="string" indexed="true" stored="true" />
<field name="_version_" type="long" indexed="true" stored="true" />
</fields>
<uniqueKey>id</uniqueKey>
Expand Down
1 change: 1 addition & 0 deletions jena-nosql-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@
<version>1.0</version>
</dependency>
</dependencies>
<name>Jena NoSQL Integration Tests</name>
</project>
Binary file modified src/site/dev/modeling/modeling.zargo
Binary file not shown.

0 comments on commit 3defee6

Please sign in to comment.