public static <V, E> Neo4jTopology loadTopology(Neo4jWorkspaceSettings settings) throws Exception { String db = DatabaseConfiguration.readDatabase(settings); Logger.getLogger(Neo4jWorkspace.class).info("using db " + db); // Get neo4j stuffs GraphDatabaseFactory factory = new GraphDatabaseFactory(); GraphDatabaseService database = factory.newEmbeddedDatabase(db); GlobalGraphOperations operation = GlobalGraphOperations.at(database); ViewsManager views = new ViewsManager(); views.load(settings); // Setup graph model Neo4jGraphModelIO gio = new Neo4jGraphModelIO(); gio.read(SimpleFile.read(settings.getModelPath())); Neo4jGraphModel typeModel = gio.getGraphModel(); // Build graph INeo4jGraphReader r = views.getFirst().getFilter(); Graph<IPropertyNode, IPropertyEdge> graph = r.read(operation, typeModel); Logger.getLogger(Neo4jWorkspace.class) .info("filtered graph has " + graph.getVertexCount() + " nodes using db " + db); // Build topology using graph typing model String topologyName = views.getFirst().getTopologyName(); Neo4jTopologyFactory tfact = new Neo4jTopologyFactory(); Neo4jTopology topology = tfact.newTopology(topologyName, graph, typeModel); return topology; }
/** * Build full Neo4jWorkspace involving reading files given by settings: * * <ul> * <li>neo4j database * <li>view * <li>graph model * <li>projection * </ul> * * and build topology & geometrical model according to Neo4j factories * * @param settings * @throws Exception */ public Neo4jWorkspace(Neo4jWorkspaceSettings settings) throws Exception { String db = DatabaseConfiguration.readDatabase(settings); Logger.getLogger(Neo4jWorkspace.class).info("using db " + db); // Get neo4j stuffs GraphDatabaseFactory factory = new GraphDatabaseFactory(); database = factory.newEmbeddedDatabase(db); operation = GlobalGraphOperations.at(database); views = new ViewsManager(); views.load(settings); layoutML = views.getFirst().getLayout(); // Setup graph model Neo4jGraphModelIO gio = new Neo4jGraphModelIO(); gio.read(SimpleFile.read(settings.getModelPath())); Neo4jGraphModel typeModel = gio.getGraphModel(); // Build graph INeo4jGraphReader r = views.getFirst().getFilter(); Graph<IPropertyNode, IPropertyEdge> graph = r.read(operation, typeModel); Logger.getLogger(Neo4jWorkspace.class) .info("filtered graph has " + graph.getVertexCount() + " nodes using db " + db); // Build topology using graph typing model String topologyName = views.getFirst().getTopologyName(); Neo4jTopologyFactory tfact = new Neo4jTopologyFactory(); topology = tfact.newTopology(topologyName, graph, typeModel); // Edit topology according to dataprism Dataprism dp = loadDataprism(settings); if (dp != null) ((Neo4jTopology) topology).edit().apply(dp); // Build layout model modelFactory = new Neo4jModelFactory(gio.getGraphModel()); model = (IHierarchicalNodeModel) modelFactory.getLayoutModel(topology); edgeModel = model.getEdgeModel(); applyLayoutMLConfiguration(model, layoutML); // Build layout layoutFactory = new Neo4jLayoutFactory(typeModel); if (layoutML != null) { Map<String, String> mapping = extractModelLayoutMapping(layoutML); layoutFactory.setModelLayoutMapping(mapping); } layout = layoutFactory.getLayout(model); layout.getEdgeLayout().setEdgePostProcess(null); // finalize workspace annotationModel = new AnnotationModel(); metadata = null; setName(settings.getName()); loadMapIfExist(); this.configuration = new ConfigurationFacade(this); }
public static void main(String[] args) { GraphDatabaseFactory neodb = new GraphDatabaseFactory(); // Direccion de la Base de datos Neo4j GraphDatabaseService graphDb = neodb.newEmbeddedDatabase("C:\\Users\\Administrador\\Documents\\Neo4j\\default.graphdb"); try (Transaction tx = graphDb.beginTx()) { // Creacion de nodos con sus propiedades Node bobNode = graphDb.createNode(NodeType.Person); // Tipo del nodo Person bobNode.setProperty("Pid", 5001); bobNode.setProperty("Name", "Bob"); bobNode.setProperty("Age", 23); Node aliceNode = graphDb.createNode(NodeType.Person); aliceNode.setProperty("Pid", 5002); aliceNode.setProperty("Name", "Eve"); Node eveNode = graphDb.createNode(NodeType.Person); eveNode.setProperty("Name", "Eve"); Node itNode = graphDb.createNode(NodeType.Course); // TIpo del nodo Course itNode.setProperty("Id", 1); itNode.setProperty("Name", "IT Beginners"); itNode.setProperty("Location", "Room 153"); Node electronicNode = graphDb.createNode(NodeType.Course); electronicNode.setProperty("Name", "Electronics Advanced"); // Creacion de relaciones entre los nodos bobNode.createRelationshipTo(aliceNode, RelationType.Knows); // Tipo de relacion Knows Relationship bobRelIt = bobNode.createRelationshipTo( itNode, RelationType.BelongsTo); // Tipo de relacion BelongsTo bobRelIt.setProperty("Function", "Student"); Relationship bobRelElectronics = bobNode.createRelationshipTo(electronicNode, RelationType.BelongsTo); bobRelElectronics.setProperty("Function", "Supply Teacher"); Relationship aliceRelIt = aliceNode.createRelationshipTo(itNode, RelationType.BelongsTo); aliceRelIt.setProperty("Function", "Teacher"); tx.success(); // Proceso termino de forma exitosa } graphDb.shutdown(); // Cerrar base }
private void attemptRecoveryOrCheckStateOfLogicalLogs(Args arguments, String storeDir) { if (arguments.getBoolean(RECOVERY, false, true)) { dbFactory.newEmbeddedDatabase(storeDir).shutdown(); } else { try { if (recoveryChecker.recoveryNeededAt(new File(storeDir))) { systemError.print( lines( "Active logical log detected, this might be a source of inconsistencies.", "Consider allowing the database to recover before running the consistency check.", "Consistency checking will continue, abort if you wish to perform recovery first.", "To perform recovery before checking consistency, use the '--recovery' flag.")); exitHandle.pull(); } } catch (IOException e) { systemError.printf( "Failure when checking for recovery state: '%s', continuing as normal.%n", e); } } }