奇怪的码头行为

时间:2013-07-10 01:19:55

标签: rest jersey jetty neo4j tinkerpop

我真的试图找到问题的根源,但我找不到导致它的原因。基本上我在码头上运行泽西岛maven项目。我有一个数据库类,在静态初始化器中,我使用目录创建了一个tinkerpop蓝图Neo4jGraph数据库。一旦创建,Jetty将在接下来的10-15秒内重新启动。这意味着初始化程序将再次运行,数据库将被覆盖。谢谢

package org.isatools.database;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.commons.io.FileDeleteStrategy;
import org.isatools.bii.loader.impl.BIILoaderAdaptor;
import org.openrdf.sail.NotifyingSailConnection;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailException;
import org.openrdf.sail.inferencer.fc.ForwardChainingRDFSInferencer;

import com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph;
import com.tinkerpop.blueprints.impls.sail.SailGraph;
import com.tinkerpop.blueprints.oupls.sail.GraphSail;

public class GraphDatabase {

private static Neo4jGraph graph;
private static BIILoaderAdaptor loader;
private static GraphSail<Neo4jGraph> sail;
private static ForwardChainingRDFSInferencer reasoner;
private static SailGraph sailGraph;

static {
    String dbPath = GraphDatabase.class.getResource("/database/").getFile();
    String name = "neo4j-" + System.currentTimeMillis();
    File file = new File(dbPath + name);

    if (file.exists()) {
        try {
            FileDeleteStrategy.FORCE.delete(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    graph = new Neo4jGraph(dbPath + "/neo4j-" + System.currentTimeMillis());
    sail = new GraphSail<Neo4jGraph>(graph);

    sailGraph = new SailGraph(sail);

    // Sail reasoner = new ForwardChainingRDFSInferencer(
    // new GraphSail<Neo4jGraph>(graph));
    //
    // try {
    // reasoner.initialize();
    // NotifyingSailConnection sailConnection = sail.getConnection();
    // } catch (SailException e) {
    // e.printStackTrace();
    // }

    // graph = new Neo4jGraph(dbPath + name);
    // graph.setCheckElementsInTransaction(true);
    // sail = new GraphSail<Neo4jGraph>(graph);
    // sailGraph = new SailGraph(sail);
    // reasoner = new ForwardChainingRDFSInferencer(sail);
    // try {
    // reasoner.initialize();
    // } catch (SailException e) {
    // e.printStackTrace();
    // }

    addSampleStudies();
}

public static void addSampleStudies() {
    String file = GraphDatabase.class.getResource("/database/init/")
            .getFile();
    File folder = new File(file);
    for (File f : folder.listFiles()) {
        FileInputStream is = null;
        try {
            is = new FileInputStream(f);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        sailGraph.loadRDF(is, "http://isa-tools.org/isa/", "rdf-xml",     null);
    }
}

public static SailGraph getSailGraph() {
    return sailGraph;
}

public static Neo4jGraph getGraph() {
    return graph;
}

public static BIILoaderAdaptor getLoader() {
    return loader;
}

public static GraphSail<Neo4jGraph> getSail() {
    return sail;
}

public static ForwardChainingRDFSInferencer getReasoner() {
    return reasoner;
}

}

0 个答案:

没有答案