public static void main(String []args) { dbFact = new GraphDatabaseFactory(); db= dbFact.newEmbeddedDatabase("gestionAvionsBD2"); /*AjouterDepart ad = new AjouterDepart(); ad.setLocationRelativeTo(null); ad.loadTableBD(); ad.setVisible(true);*/ MainWindow mainFen = new MainWindow(); mainFen.setLocationRelativeTo(null); mainFen.setVisible(true); /*Node jNode = db.createNode(Tutorials.JAVAtest); Node jNode2 = db.createNode(Tutorials.Test2); jNode.setProperty("Id", "5"); jNode2.setProperty("Id2", "10");11 Relationship relat = jNode.createRelationshipTo(jNode2, Relations.Relation); relat.setProperty("Id", "15"); tx.success();*/ }
@Test public void insert_node_should_succeed_with_populated_index() throws Exception { Neo4jBatchInserterNode nodeInserter = getNeo4jBatchInserterNode(false); // populate the db List<String> columns = DummyTalendPojo.getColumnList(); for (int i = 0; i < 100; i++) { DummyTalendPojo pojo = DummyTalendPojo.getDummyTalendPojo(); nodeInserter.create(pojo, columns); } nodeInserter.finish(); // check if index size Assert.assertEquals(100, batchDb.batchInserterIndexes.get(INDEX_NAME).query("*:*").size()); // check the database data batchDb.shutdown(); // Testing it with real graphdb GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath); try (Transaction tx = graphDb.beginTx()) { String result = graphDb.execute("MATCH (n:" + LABEL_NAME + ") RETURN count(n) AS count").resultAsString(); Assert.assertEquals("+-------+\n| count |\n+-------+\n| 100 |\n+-------+\n1 row\n", result); } graphDb.shutdown(); }
@Test public void update_node_should_succeed() throws Exception { // populate the db Neo4jBatchInserterNode nodeInserter = getNeo4jBatchInserterNode(false); List<String> columns = DummyTalendPojo.getColumnList(); DummyTalendPojo pojo = DummyTalendPojo.getDummyTalendPojo(); nodeInserter.create(pojo, columns); nodeInserter.finish(); // By indexing the import id, I update the last node pojo.propString = "A new String"; nodeInserter = getNeo4jBatchInserterNode(true); nodeInserter.create(pojo, columns); nodeInserter.finish(); // check the result into the database batchDb.shutdown(); GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath); try (Transaction tx = graphDb.beginTx()) { String result = graphDb.execute("MATCH (n:" + LABEL_NAME + ") WHERE exists(n.id) RETURN n.propString AS string").resultAsString(); Assert.assertEquals("+----------------+\n| string |\n+----------------+\n| \"A new String\" |\n+----------------+\n1 row\n", result); } graphDb.shutdown(); }
@Test public void create_node_uniqueness_constraint_should_work() { // Test const. String label = "Test"; String property = "myProp"; // crete the schema batchDb.createSchema("NODE_PROPERTY_UNIQUE", label, property); batchDb.shutdown(); // Testing it with real graphdb GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath); try (Transaction tx = graphDb.beginTx()) { Assert.assertTrue(graphDb.schema().getConstraints(DynamicLabel.label(label)).iterator().hasNext()); } graphDb.shutdown(); }
@Test public void create_node_index_should_work() { // Test const. String label = "Test"; String property = "myProp"; // crete the schema batchDb.createSchema("NODE_PROPERTY_INDEX", label, property); batchDb.shutdown(); // Testing it with real graphdb GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath); try (Transaction tx = graphDb.beginTx()) { Assert.assertTrue(graphDb.schema().getIndexes(DynamicLabel.label(label)).iterator().hasNext()); } graphDb.shutdown(); }
@Test public void shouldTransformCypherAlbumsToJSONDoc() throws SQLException { // GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase(); GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(new File("/Applications/Development/Neo4j-2.3.2/neo4j-community-2.3.2/data/graph.db")); database.registerTransactionEventHandler(new Neo4jEventListener(database)); String cypher = "MATCH (n) " + "WHERE n.name = \"Volcano\" " + "WITH n " + "SET n.explicit = true " + "RETURN n"; try (Transaction tx = database.beginTx()) { database.execute(cypher); tx.success(); } }
@SuppressWarnings("deprecation") public KnowledgeGraph(String db_path) { this.db_path = new String(db_path); // delete data from previous runs try { FileUtils.deleteRecursively(new File(this.db_path)); } catch (IOException e) { e.printStackTrace(); } // create a neo4j database this.graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(this.db_path); registerShutdownHook(graphDb); }
@Test public void testRelReader() throws IOException{ RelReader reader = new RelReader(neo4jLocation); reader.batchBuildGraph(new File("my_test_umls/"), "CtakesAllTuis.txt", "SNOMEDCT_US"); GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(new File(neo4jLocation)); try ( Transaction tx = db.beginTx() ){ TraversalDescription td = db.traversalDescription() .breadthFirst() .relationships(RelReader.RelTypes.ISA, Direction.INCOMING) .evaluator(Evaluators.excludeStartPosition()); Node cuiNode = db.findNode(RelReader.DictLabels.Concept, RelReader.CUI_PROPERTY, "C0007102"); Assert.assertNotNull(cuiNode); Traverser traverser = td.traverse(cuiNode); for(Path path : traverser){ System.out.println("At depth " + path.length() + " => " + path.endNode().getProperty("cui")); } } db.shutdown(); }
public GraphDatabaseService connect() { if (null == graph) { graph = new GraphDatabaseFactory().newEmbeddedDatabase(path); try (Transaction tx = graph.beginTx()) { graph.schema().indexFor(LABEL).on(ID).create(); tx.success(); } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { graph.shutdown(); } }); } return graph; }
private void createDb() { graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); try (Transaction tx = graphDb.beginTx()) { // Database operations go here firstNode = graphDb.createNode(); firstNode.setProperty("message", "Hello, "); secondNode = graphDb.createNode(); secondNode.setProperty("message", "World!"); relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS); relationship.setProperty("message", "brave Neo4j "); System.out.print(firstNode.getProperty("message")); System.out.print(relationship.getProperty("message")); System.out.print(secondNode.getProperty("message")); greeting = ((String) firstNode.getProperty("message")) + ((String) relationship.getProperty("message")) + ((String) secondNode.getProperty("message")); tx.success(); } }
@Override protected GraphTransactionalImpl createInstance() throws Exception { GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(path)); Neo4jConfiguration config = new Neo4jConfiguration(); config.getExactNodeProperties().addAll(newHashSet( NodeProperties.LABEL, Concept.SYNONYM, Concept.ABREVIATION, Concept.ACRONYM)); config.getIndexedNodeProperties().addAll(newHashSet( NodeProperties.LABEL, Concept.CATEGORY, Concept.SYNONYM, Concept.ABREVIATION, Concept.ACRONYM)); Neo4jModule.setupAutoIndexing(graphDb, config); IdMap idMap = new IdMap(); RelationshipMap relationahipMap = new RelationshipMap(); return new GraphTransactionalImpl(graphDb, idMap, relationahipMap); }
@Test public void test() throws Exception { OwlLoadConfiguration config = new OwlLoadConfiguration(); Neo4jConfiguration neo4jConfig = new Neo4jConfiguration(); neo4jConfig.setLocation(folder.getRoot().getAbsolutePath()); config.setGraphConfiguration(neo4jConfig); OntologySetup ontSetup = new OntologySetup(); ontSetup.setUrl("http://127.0.0.1:10000/main.owl"); config.getOntologies().add(ontSetup); BatchOwlLoader.load(config); GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(folder.getRoot()); graphDb.beginTx(); GraphvizWriter writer = new GraphvizWriter(); Walker walker = Walker.fullGraph(graphDb); writer.emit(new File("/tmp/test.dot"), walker); }
private WikiNerGraphConnector(String dbDir) { graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbDir); IndexDefinition indexDefinition; Schema schema; Transaction tx = graphDb.beginTx(); schema = graphDb.schema(); IndexManager index = graphDb.index(); entities = index.forNodes(entityLabel.name()); cities = index.forNodes(cityLabel.name()); try{ indexDefinition = schema.indexFor( entityLabel ).on( "nameType" ).create(); }catch(Exception e){ } tx.success(); tx.close(); }
private void DBInit() { graph_db = new GraphDatabaseFactory() .newEmbeddedDatabaseBuilder(db_name) .setConfig(GraphDatabaseSettings.keep_logical_logs, "false") .setConfig(GraphDatabaseSettings.use_memory_mapped_buffers, "true") .setConfig(ShellSettings.remote_shell_enabled, "true") .setConfig(ShellSettings.remote_shell_port, "1337") .setConfig(ShellSettings.remote_shell_read_only, "true") .newGraphDatabase(); if(bootstrap) DoBootstrap(); transaction = new NinjaTransaction(graph_db, Neo4jGraph.COUNT_THRESHOLD); }
@SuppressWarnings("unchecked") private Block dbFactory(final Path dbdir, final String dbkey) { return unit -> { GraphDatabaseService dbservice = unit.registerMock(GraphDatabaseService.class); // unit.mockStatic(RuntimeRegistry.class); // expect(RuntimeRegistry.getStartedRuntime(dbservice)).andReturn(null); LinkedBindingBuilder<GraphDatabaseService> lbb = unit.mock(LinkedBindingBuilder.class); lbb.toInstance(dbservice); Binder binder = unit.get(Binder.class); expect(binder.bind(Key.get(GraphDatabaseService.class))).andReturn(lbb); ServiceKey keys = unit.get(ServiceKey.class); keys.generate(eq(GraphDatabaseService.class), eq(dbkey), unit.capture(Consumer.class)); GraphDatabaseBuilder dbbuilder = unit.registerMock(GraphDatabaseBuilder.class); expect(dbbuilder.newGraphDatabase()).andReturn(dbservice); GraphDatabaseFactory factory = unit.constructor(GraphDatabaseFactory.class) .build(); expect(factory.setUserLogProvider(isA(Slf4jLogProvider.class))).andReturn(factory); expect(factory.newEmbeddedDatabaseBuilder(dbdir.toFile())).andReturn(dbbuilder); }; }
/** * Creates a new embedded db in the neoRepository folder. * * @param eraseExisting if true deletes previously existing db */ public GraphDatabaseBuilder newEmbeddedDb(File storeDir, boolean eraseExisting) { if (eraseExisting && storeDir.exists()) { // erase previous db LOG.debug("Removing previous neo4j database from {}", storeDir.getAbsolutePath()); FileUtils.deleteQuietly(storeDir); } GraphDatabaseBuilder builder = new GraphDatabaseFactory() .setUserLogProvider(new Slf4jLogProvider()) .newEmbeddedDatabaseBuilder(storeDir) .setConfig(GraphDatabaseSettings.keep_logical_logs, "false") .setConfig(GraphDatabaseSettings.pagecache_memory, mappedMemory + "m"); if (shell) { LOG.info("Enable neo4j shell on port " + port); builder.setConfig(ShellSettings.remote_shell_enabled, "true") .setConfig(ShellSettings.remote_shell_port, String.valueOf(port)) // listen to all IPs, not localhost only .setConfig(ShellSettings.remote_shell_host, "0.0.0.0"); } return builder; }
@Override public EmbeddedNeo4jDatastore createGraphDatabaseService(URI uri, Properties properties) throws MalformedURLException { String path; try { path = URLDecoder.decode(uri.toURL().getPath(), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new MalformedURLException(e.getMessage()); } GraphDatabaseBuilder databaseBuilder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File(path)); Properties neo4jProperties = Neo4jPropertyHelper.getNeo4jProperties(properties); for (String name : neo4jProperties.stringPropertyNames()) { databaseBuilder.setConfig(name, neo4jProperties.getProperty(name)); } GraphDatabaseService graphDatabaseService = databaseBuilder.newGraphDatabase(); return new EmbeddedNeo4jDatastore(graphDatabaseService); }
public Neo4jManager(String dbFolder, boolean createServices, boolean readOnly, Map<String, String> config) { if (createServices) { if(!readOnly){ if(config != null){ graphService = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbFolder).setConfig(config).newGraphDatabase(); }else{ graphService = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbFolder).newGraphDatabase(); } }else{ if(config != null){ config.put( "read_only", "true" ); graphService = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbFolder).setConfig(config).newGraphDatabase(); }else{ config = new HashMap<>(); config.put( "read_only", "true" ); graphService = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbFolder).setConfig(config).newGraphDatabase(); } } } }
@Override public void open() { neo4jGraph = new GraphDatabaseFactory().newEmbeddedDatabase(dbStorageDirectory.getAbsolutePath()); try (final Transaction tx = beginUnforcedTransaction()) { try { neo4jGraph.schema().awaitIndexesOnline(10l, TimeUnit.MINUTES); tx.success(); } catch (Exception e) { tx.failure(); throw new BenchmarkingException("unknown error", e); } } }
@Override public void createGraphForSingleLoad() { neo4jGraph = new GraphDatabaseFactory().newEmbeddedDatabase(dbStorageDirectory.getAbsolutePath()); try (final Transaction tx = beginUnforcedTransaction()) { try { schema = neo4jGraph.schema(); schema.indexFor(NODE_LABEL).on(NODE_ID).create(); schema.indexFor(NODE_LABEL).on(COMMUNITY).create(); schema.indexFor(NODE_LABEL).on(NODE_COMMUNITY).create(); tx.success(); } catch (Exception e) { tx.failure(); throw new BenchmarkingException("unknown error", e); } } }
/** * Clears all data in the DB and reconnects to it afterwards. */ public void ClearDatabase(){ // Shutdown database before erasing it log.debug("Shutting down the database"); mGraphDb.shutdown(); try { log.debug("Erasing the database files"); FileUtils.deleteRecursively( new File( mDbPath ) ); } catch ( IOException e ) { throw new RuntimeException( e ); } // Restart database log.debug("Reconnecting to database"); mGraphDb = new GraphDatabaseFactory(). newEmbeddedDatabaseBuilder(mDbPath). setConfig( GraphDatabaseSettings.node_keys_indexable, KEY_HASH ). setConfig( GraphDatabaseSettings.node_auto_indexing, "true" ). newGraphDatabase(); registerShutdownHook(mGraphDb); }
@Bean(destroyMethod = "shutdown") public GraphDatabaseService graphDatabaseService() { if(Arrays.asList(environment.getActiveProfiles()).contains("cloud")) { // Connect to external Neo4j server setGraphDatabaseService(new SpringCypherRestGraphDatabase(url, username, password)); } else { // Connect to local ephemeral database return new GraphDatabaseFactory().newEmbeddedDatabase("user3.db"); } return getGraphDatabaseService(); }
@Bean(destroyMethod = "shutdown") public GraphDatabaseService graphDatabaseService() { if(Arrays.asList(environment.getActiveProfiles()).contains("cloud")) { // Connect to external Neo4j server setGraphDatabaseService(new SpringCypherRestGraphDatabase(url, username, password)); } else { // Connect to local ephemeral database return new GraphDatabaseFactory().newEmbeddedDatabase("user2.db"); } return getGraphDatabaseService(); }
public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd = Utils.parseCommandLine(getOptions(), args); String graphDbPath = cmd.getOptionValue("d", Owl2Neo4jLoader.GRAPH_DB_PATH); GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(graphDbPath)); String query = "MATCH (n) RETURN n ORDER BY ID(n) DESC LIMIT 30;"; Transaction tx = graphDb.beginTx(); try { Result result = graphDb.execute(query); while (result.hasNext()) { Map<String, Object> row = result.next(); for (String key : result.columns()) { Node node = (Node) row.get(key); Object name = node.getProperty("name"); System.out.printf("%s = %s; name = %s%n", key, row.get(key), name); } } tx.success(); } catch (Exception e) { System.err.println("Exception caught: " + e.getMessage()); e.printStackTrace(); System.exit(ERR_STATUS); } finally { tx.close(); } System.out.println("Exiting with success..."); System.exit(OK_STATUS); }
@Before public void setUp() throws Exception { graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(TEST_GRAPH_DB_PATH)); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.loadOntologyFromOntologyDocument(file.getFile()); OWLDataFactory factory = manager.getOWLDataFactory(); loader = new Owl2Neo4jLoader(graphDb, ontology, factory); }
@Test public void execute_import_should_succeed() throws IOException { this.importTool.execute(); // Testing it with real graphdb GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath); try (Transaction tx = graphDb.beginTx()) { String result = graphDb.execute("MATCH ()-[r]->() RETURN count(r) AS count").resultAsString(); Assert.assertEquals("+-------+\n| count |\n+-------+\n| 9 |\n+-------+\n1 row\n", result); } graphDb.shutdown(); }
@Test public void insert_edge_should_succeed() throws Exception { Neo4jBatchInserterNode nodeInserter = getNeo4jBatchInserterNode(false); // populate the db with nodes List<String> columns = DummyTalendPojo.getColumnList(); for (int i = 0; i < 100; i++) { DummyTalendPojo pojo = DummyTalendPojo.getDummyTalendPojo(i); nodeInserter.create(pojo, columns); } nodeInserter.finish(); // create relationship Neo4jBatchInserterRelationship batchInserterRelationship = getNeo4jBatchInserterRelationship(true); for (int i = 0; i < 100; i++) { batchInserterRelationship.create(DummyTalendPojo.getDummyTalendPojo(i), DummyTalendPojo.getColumnList()); } batchInserterRelationship.finish(); // check the database data batchDb.shutdown(); // Testing it with real graphdb GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath); try (Transaction tx = graphDb.beginTx()) { String result = graphDb.execute("MATCH ()-[r:" + REL_TYPE + "]->() RETURN count(r) AS count").resultAsString(); Assert.assertEquals("+-------+\n| count |\n+-------+\n| 100 |\n+-------+\n1 row\n", result); } graphDb.shutdown(); }
private void run(){ GraphDatabaseService graph=new GraphDatabaseFactory().newEmbeddedDatabase( new File(config.getGraphPath()) ); for (int i=0;i<extractors.size();i++) { System.out.println(extractors.get(i).getClass().getName()+" started."); extractors.get(i).run(graph); extractors.set(i, new DefaultExtractor()); System.gc(); } }
private boolean initDB() { File db = new File(this.networkFileName); graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(db); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { shutdown(); } }); //graphDb.beginTx(); return true; }
public GraphDatabaseService connect() { if (null == graph) { graph = new GraphDatabaseFactory().newEmbeddedDatabase(path); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { graph.shutdown(); } }); } return graph; }
public Problem(String path) { if (null == path || (path = path.trim()).isEmpty()) throw new IllegalArgumentException("Illegal 'path' argument in Problem(String): " + path); this.graph = new GraphDatabaseFactory().newEmbeddedDatabase(path); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { graph.shutdown(); } }); this.path = path; }
public Kimmig() { Utils.delete(DB_PATH); this.graph = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); this.nodes = new HashMap<>(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { graph.shutdown(); } }); }
public BDD(Set<Set<Relationship>> expression, Set<Relationship> relationships) { if (null == relationships) throw new IllegalArgumentException("Illegal 'relationships' argument in BDD(Set<Set<Relationship>>, Set<Relationship>): " + relationships); if (null == expression) throw new IllegalArgumentException("Illegal 'paths' argument in BDD(Set<Set<Relationship>>, Set<Relationship>): " + expression); try { File db = Files.createTempDirectory("neo4j_bdd").toFile(); db.deleteOnExit(); this.graph = new GraphDatabaseFactory().newEmbeddedDatabase(db.toString()); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { graph.shutdown(); } }); try (Transaction tx = graph.beginTx()) { for (Relationship relationship : GlobalGraphOperations.at(graph).getAllRelationships()) relationship.delete(); for (Node node : GlobalGraphOperations.at(graph).getAllNodes()) node.delete(); this.zero = graph.createNode(); this.zero.setProperty(REFERENCE, "0"); this.one = graph.createNode(); this.one.setProperty(REFERENCE, "1"); this.root = build(expression, relationships); this.max = 1 + relationships.size(); tx.success(); } } catch (IOException e) { throw new IllegalArgumentException("Cannot create a temporary Neo4j db for BDDs..."); } }
@Override public void connect() throws Exception { if (graphDb == null) { graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(getConfiguration().get("neo4j.path")) .newGraphDatabase(); } }
public void init() throws IOException { // recursively delete directory contents System.out.println("Deleting directory <" + getOutputDir() + "> ..."); FileUtils.deleteDirectory(new File(getOutputDir())); System.out.println("Output directory cleaned"); setDbFactory(new GraphDatabaseFactory()); setDbService(dbFactory.newEmbeddedDatabase(new File(getOutputDir()))); }
/** * Constructs a Neo4j database on the specified path. * @param path specified path */ public Neo4jGraph(String path) { // Create our database and register a shutdown hook service = new GraphDatabaseFactory().newEmbeddedDatabase(path); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { service.shutdown(); } }); this.is = new SummingScoresStrategy(); }
@Bean(destroyMethod = "shutdown") public GraphDatabaseService graphDatabaseService() { if(Arrays.asList(environment.getActiveProfiles()).contains("cloud")) { // Connect to external Neo4j server setGraphDatabaseService(new SpringCypherRestGraphDatabase(url, username, password)); } else { // Connect to local ephemeral database return new GraphDatabaseFactory().newEmbeddedDatabase("user.db"); } return getGraphDatabaseService(); }
public static void main(String[] args) throws IOException { if (args.length != 3) { printUsage(); System.exit(1); } File jar = new File(args[0]); if (!jar.exists()) { System.err.println(jar + " does not exist"); System.exit(1); } GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(args[1]); Runtime.getRuntime().addShutdownHook(new Thread(db::shutdown)); Graph.prepareSchema(db); ProgressSink sink = new ProgressSink(new Neo4jSink(db, s -> s.startsWith(args[2]))) { @Override protected void typesProcessed(int typeCounter) { if (typeCounter % 100 == 0) { System.out.printf("%d classes processed...\n", typeCounter); } } }; System.out.println("Processing "+jar); long start = System.currentTimeMillis(); new JarCollector(sink).walk(jar); System.out.println("Processed " + sink.getNumTypesProcessed() + " classes in " + secondsSince(start) + "s."); start = System.currentTimeMillis(); System.out.print("Inferring additional information... "); Graph.finalizeSchema(db); System.out.println("Done in "+secondsSince(start)+ "s."); }
@Test public void shouldLoadAndUseLuceneProvider() throws Exception { // GIVEN File storeDir = testDirectory.graphDbDir(); BatchInserter inserter = BatchInserters.inserter( storeDir ); inserter.createDeferredSchemaIndex( LABEL ).on( "name" ).create(); // WHEN inserter.createNode( map( "name", "Mattias" ), LABEL ); inserter.shutdown(); // THEN GraphDatabaseFactory graphDatabaseFactory = new TestGraphDatabaseFactory(); GraphDatabaseAPI db = (GraphDatabaseAPI) graphDatabaseFactory.newEmbeddedDatabase( storeDir ); DependencyResolver dependencyResolver = db.getDependencyResolver(); SchemaIndexProvider schemaIndexProvider = dependencyResolver.resolveDependency( SchemaIndexProvider.class, SchemaIndexProvider.HIGHEST_PRIORITIZED_OR_NONE ); // assert the indexProvider is a Lucene one try ( Transaction ignore = db.beginTx() ) { IndexDefinition indexDefinition = single( db.schema().getIndexes( LABEL ) ); assertThat( db.schema().getIndexState( indexDefinition ), is( Schema.IndexState.ONLINE ) ); assertThat( schemaIndexProvider, instanceOf( LuceneSchemaIndexProvider.class ) ); } // CLEANUP db.shutdown(); }
public static void main( String[] args ) throws IOException { String path = args[0]; final GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(path ); final Index<Node> index = getIndex( db ); final String[] keys = new String[] { "apoc", "zion", "morpheus" }; final String[] values = new String[] { "hej", "yo", "something", "just a value", "anything" }; for ( int i = 0; i < 5; i++ ) { new Thread() { @Override public void run() { while ( true ) { try ( Transaction tx = db.beginTx() ) { for ( int i = 0; i < 100; i++ ) { String key = keys[i%keys.length]; String value = values[i%values.length]+i; Node node = db.createNode(); node.setProperty( key, value ); index.add( node, key, value ); } tx.success(); } } } }.start(); } new File( path, "started" ).createNewFile(); }