Commit 87e13f01 authored by Peter Harrison's avatar Peter Harrison

* Adding Indexes for Jcr Repository

* Different Handling of Numbers - Integer to Double.
parent ff08d726
...@@ -26,6 +26,8 @@ import java.util.Map; ...@@ -26,6 +26,8 @@ import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.jackrabbit.ocm.manager.ObjectContentManager; import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -35,6 +37,8 @@ import nz.net.orcon.kanban.tools.OcmMapperFactory; ...@@ -35,6 +37,8 @@ import nz.net.orcon.kanban.tools.OcmMapperFactory;
@Service @Service
public class RuleCache extends CacheImpl<Rule> { public class RuleCache extends CacheImpl<Rule> {
private static final Logger LOG = LoggerFactory.getLogger(RuleCache.class);
@Resource(name="ocmFactory") @Resource(name="ocmFactory")
OcmMapperFactory ocmFactory; OcmMapperFactory ocmFactory;
...@@ -44,6 +48,9 @@ public class RuleCache extends CacheImpl<Rule> { ...@@ -44,6 +48,9 @@ public class RuleCache extends CacheImpl<Rule> {
@Override @Override
protected Rule getFromStore(String... itemIds) throws Exception { protected Rule getFromStore(String... itemIds) throws Exception {
LOG.info("Get Rule Store: "+ getStringFromArray(itemIds));
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
Rule rule; Rule rule;
try{ try{
...@@ -56,6 +63,9 @@ public class RuleCache extends CacheImpl<Rule> { ...@@ -56,6 +63,9 @@ public class RuleCache extends CacheImpl<Rule> {
@Override @Override
protected Map<String, String> getListFromStore(String... prefixes) throws Exception { protected Map<String, String> getListFromStore(String... prefixes) throws Exception {
LOG.info("Get Rule List Store: "+ getStringFromArray(prefixes));
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
Map<String,String> result = null; Map<String,String> result = null;
try{ try{
...@@ -65,5 +75,16 @@ public class RuleCache extends CacheImpl<Rule> { ...@@ -65,5 +75,16 @@ public class RuleCache extends CacheImpl<Rule> {
} }
return result; return result;
} }
private String getStringFromArray( String[] stringArray){
StringBuilder builder = new StringBuilder();
for( int a=0; a<stringArray.length; a++){
builder.append("[");
builder.append(stringArray[a]);
builder.append("] ");
}
return builder.toString();
}
} }
...@@ -96,7 +96,7 @@ public class TemplateCache extends CacheImpl<Template>{ ...@@ -96,7 +96,7 @@ public class TemplateCache extends CacheImpl<Template>{
case STRING: case STRING:
return value.toString(); return value.toString();
case NUMBER: case NUMBER:
return Integer.parseInt(value.toString()); return Double.valueOf(value.toString());
case BOOLEAN: case BOOLEAN:
return Boolean.parseBoolean(value.toString()); return Boolean.parseBoolean(value.toString());
case DATE: case DATE:
......
...@@ -45,7 +45,6 @@ import org.apache.jackrabbit.ocm.mapper.Mapper; ...@@ -45,7 +45,6 @@ import org.apache.jackrabbit.ocm.mapper.Mapper;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.AnnotationMapperImpl; import org.apache.jackrabbit.ocm.mapper.impl.annotation.AnnotationMapperImpl;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
import com.mongodb.DB; import com.mongodb.DB;
import com.mongodb.MongoClient; import com.mongodb.MongoClient;
...@@ -53,7 +52,7 @@ import com.mongodb.MongoClient; ...@@ -53,7 +52,7 @@ import com.mongodb.MongoClient;
public class OcmMapperFactory { public class OcmMapperFactory {
private static final Logger logger = LoggerFactory.getLogger(OcmMapperFactory.class); private static final Logger logger = LoggerFactory.getLogger(OcmMapperFactory.class);
private Repository repository; private Repository repository;
private String domainPackage; private String domainPackage;
...@@ -86,8 +85,12 @@ public class OcmMapperFactory { ...@@ -86,8 +85,12 @@ public class OcmMapperFactory {
DB db = new MongoClient(host, 27017).getDB("gravity"); DB db = new MongoClient(host, 27017).getDB("gravity");
DocumentNodeStore ns = new DocumentMK.Builder(). DocumentNodeStore ns = new DocumentMK.Builder().
setMongoDB(db).getNodeStore(); setMongoDB(db).getNodeStore();
this.repository = new Jcr(new Oak(ns)).createRepository();
this.repository = new Jcr(new Oak(ns))
.with(new RepositoryIndexInitializer())
.withAsyncIndexing()
.createRepository();
} }
if(this.mapper==null){ if(this.mapper==null){
...@@ -134,7 +137,7 @@ public class OcmMapperFactory { ...@@ -134,7 +137,7 @@ public class OcmMapperFactory {
* *
* @param session * @param session
*/ */
private void setupListener(Session session){ private void setupListener(){
//session.getWorkspace().getObservationManager().addEventListener(arg0, arg1, arg2, arg3, arg4, arg5, arg6) //session.getWorkspace().getObservationManager().addEventListener(arg0, arg1, arg2, arg3, arg4, arg5, arg6)
......
package nz.net.orcon.kanban.tools;
import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import com.google.common.collect.ImmutableList;
public class RepositoryIndexInitializer implements RepositoryInitializer{
@Override
public void initialize(NodeBuilder builder) {
NodeBuilder root = builder.getBaseState().builder();
NodeBuilder index = IndexUtils.getOrCreateOakIndex(root);
ImmutableList fields =
ImmutableList.builder().add( "id","name" ).build();
NodeBuilder indexNodebuilder =
IndexUtils.createIndexDefinition(index, "gravityIndexes", true, false, fields, null);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment