Skip to content

Commit

Permalink
issues/1968: Custom GraphDatabaseConfiguration implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sbespalov committed Dec 12, 2020
1 parent e08b500 commit c86ef8e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.diskstorage.configuration.ReadConfiguration;
import org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration;
import org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration;
import org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder;
import org.janusgraph.graphdb.database.StandardJanusGraph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.strongbox.db.server.janusgraph.CustomGraphDatabaseConfiguration;

/**
* @author sbespalov
Expand Down Expand Up @@ -84,16 +86,18 @@ protected JanusGraph buildJanusGraph(JanusGraphConfiguration configuration)
try
{
URL configLocationUrl = new URL(configLocation);
Configuration jgConfiguration = new PropertiesConfiguration(configLocationUrl);

return JanusGraphFactory.open(new CommonsConfiguration(jgConfiguration));
ReadConfiguration janusGraphLocalConfig = new CommonsConfiguration(new PropertiesConfiguration(configLocationUrl));
GraphDatabaseConfigurationBuilder configBuilder = new GraphDatabaseConfigurationBuilder();
GraphDatabaseConfiguration janusGraphDbConfig = configBuilder.build(janusGraphLocalConfig);

return new StandardJanusGraph(new CustomGraphDatabaseConfiguration(janusGraphDbConfig));
}
catch (MalformedURLException|ConfigurationException e)
{
throw new RuntimeException(String.format("Invalid configuration [%s].", configLocation), e);
}
}

@PreDestroy
@Override
public synchronized void stop()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.strongbox.db.server.janusgraph;

import org.janusgraph.diskstorage.Backend;
import org.janusgraph.diskstorage.configuration.ModifiableConfiguration;
import org.janusgraph.diskstorage.configuration.ReadConfiguration;
import org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration;
import org.janusgraph.graphdb.database.idassigner.VertexIDAssigner;

/**
* @author sbespalov
*/
public class CustomGraphDatabaseConfiguration extends GraphDatabaseConfiguration
{

public CustomGraphDatabaseConfiguration(GraphDatabaseConfiguration target)
{
super((ReadConfiguration) target.getConfigurationAtOpen(), (ModifiableConfiguration) target.getLocalConfiguration(),
target.getUniqueGraphId(), target.getConfiguration());
}

@Override
public VertexIDAssigner getIDAssigner(Backend backend)
{
return new TransactionalVertexIDAssigner(getConfiguration(), backend.getIDAuthority(), backend.getStoreFeatures());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.strongbox.db.server.janusgraph;

import org.janusgraph.diskstorage.IDAuthority;
import org.janusgraph.diskstorage.configuration.Configuration;
import org.janusgraph.diskstorage.keycolumnvalue.StoreFeatures;
import org.janusgraph.graphdb.database.idassigner.VertexIDAssigner;

/**
* @author sbespalov
*/
public class TransactionalVertexIDAssigner extends VertexIDAssigner
{

public TransactionalVertexIDAssigner(Configuration config,
IDAuthority idAuthority,
StoreFeatures idAuthFeatures)
{
super(config, idAuthority, idAuthFeatures);
}

}

0 comments on commit c86ef8e

Please sign in to comment.