
org.liquigraph.trinity.neo4jv2.EmbeddedClientCreator Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.trinity.neo4jv2;
import org.liquigraph.trinity.CypherClientCreator;
import org.liquigraph.trinity.CypherTransport;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.config.Setting;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class EmbeddedClientCreator implements CypherClientCreator {
private static final Logger LOGGER = LoggerFactory.getLogger(EmbeddedClientCreator.class);
private final Map> settings;
public EmbeddedClientCreator() {
settings = populateSettings();
}
@Override
public boolean supports(CypherTransport transport) {
return CypherTransport.EMBEDDED_2 == transport;
}
@Override
public EmbeddedClient create(Properties properties) {
return new EmbeddedClient(newGraphDatabase(properties));
}
private static Map> populateSettings() {
Field[] fields = GraphDatabaseSettings.class.getFields();
Map> settings = new HashMap<>((int) Math.ceil(fields.length / 0.75));
for (Field field : fields) {
putField(field, settings);
}
return settings;
}
private GraphDatabaseService newGraphDatabase(Properties properties) {
String path = readPath(properties);
GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(path);
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy