本文整理汇总了Java中org.neo4j.unsafe.batchinsert.BatchInserters.inserter方法的典型用法代码示例。如果您正苦于以下问题:Java BatchInserters.inserter方法的具体用法?Java BatchInserters.inserter怎么用?Java BatchInserters.inserter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.neo4j.unsafe.batchinsert.BatchInserters
的用法示例。
在下文中一共展示了BatchInserters.inserter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldNotIndexNodesWithWrongLabel
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
@Test
public void shouldNotIndexNodesWithWrongLabel() throws Exception
{
// Given
BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );
inserter.createNode( map("name", "Bob"), label( "User" ), label("Admin"));
inserter.createDeferredSchemaIndex( label( "Banana" ) ).on( "name" ).create();
// When
inserter.shutdown();
// Then
GraphDatabaseService db = dbRule.getGraphDatabaseService();
try(Transaction tx = db.beginTx())
{
assertThat( count( db.findNodes( label( "Banana" ), "name", "Bob" ) ), equalTo(0) );
}
finally
{
db.shutdown();
}
}
示例2: shouldBeAbleToMakeRepeatedCallsToSetNodeProperty
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception
{
BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );
long nodeId = inserter.createNode( Collections.<String, Object>emptyMap() );
final Object finalValue = 87;
inserter.setNodeProperty( nodeId, "a", "some property value" );
inserter.setNodeProperty( nodeId, "a", 42 );
inserter.setNodeProperty( nodeId, "a", 3.14 );
inserter.setNodeProperty( nodeId, "a", true );
inserter.setNodeProperty( nodeId, "a", finalValue );
inserter.shutdown();
GraphDatabaseService db = dbRule.getGraphDatabaseService();
try(Transaction ignored = db.beginTx())
{
assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue ) );
}
finally
{
db.shutdown();
}
}
示例3: testInsertionSpeed
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
@Ignore
@Test
public void testInsertionSpeed() throws Exception
{
BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider( inserter );
BatchInserterIndex index = provider.nodeIndex( "yeah", EXACT_CONFIG );
index.setCacheCapacity( "key", 1000000 );
long t = currentTimeMillis();
for ( int i = 0; i < 1000000; i++ )
{
Map<String, Object> properties = map( "key", "value" + i );
long id = inserter.createNode( properties );
index.add( id, properties );
}
System.out.println( "insert:" + ( currentTimeMillis() - t ) );
index.flush();
t = currentTimeMillis();
for ( int i = 0; i < 1000000; i++ )
{
count( (Iterator<Long>) index.get( "key", "value" + i ) );
}
System.out.println( "get:" + ( currentTimeMillis() - t ) );
}
示例4: testBatchIndexToAutoIndex
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
@Test
public void testBatchIndexToAutoIndex() throws IOException {
BatchInserter inserter = BatchInserters.inserter(new File(path));
BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);
BatchInserterIndex index =
indexProvider.nodeIndex("node_auto_index", MapUtil.stringMap("type", "exact"));
long node = inserter.createNode(MapUtil.map("foo", "bar"));
index.add(node, MapUtil.map("foo", "bar"));
index.flush();
assertThat("Batch indexed node can be retrieved", index.get("foo", "bar").next(), is(node));
indexProvider.shutdown();
inserter.shutdown();
graphDb = getGraphDb();
try (Transaction tx = graphDb.beginTx()) {
assertThat("AutoIndex is not enabled after reopening the graph", graphDb.index()
.getNodeAutoIndexer().isEnabled(), is(false));
assertThat("AutoIndexed properties are not maintained after closing the graph", graphDb
.index().getNodeAutoIndexer().getAutoIndexedProperties(), is(empty()));
assertThat("Batch index properties are in the index", graphDb.index().getNodeAutoIndexer()
.getAutoIndex().query("foo", "bar").size(), is(1));
tx.success();
}
}
示例5: Neo4jBatchBuilder
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
/**
* Create a new {@link Neo4jBatchBuilder}, which batch inserts to
* the specified database path.
* @param storeDir the path where the database is stored.
* @param annotations the {@link AnnotationCollection} to connect the nodes with.
* @param phylogeny the phylogenetic tree, for linking the source nodes together.
*/
public Neo4jBatchBuilder(String storeDir, AnnotationCollection annotations,
TreeNode phylogeny) {
this.annotations = annotations;
this.storeDir = storeDir;
this.phylogeny = phylogeny;
batchInserter = BatchInserters.inserter(storeDir);
annotationIDToNodeID = new HashMap<>();
sequenceIDToNodeID = new HashMap<>();
sourceToNodeID = new HashMap<>();
annotationProperties = new HashMap<>();
nodeProperties = new HashMap<>();
annotations.getAll().forEach(e ->
annotationIDToNodeID.put(e.getGeneName(), createAnnotation(e)));
}
示例6: NeoDb
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
public NeoDb(String dbPath, long flushInterval, int cacheCapacity) throws IOException {
this.flushInterval = flushInterval;
this.cacheCapacity = cacheCapacity;
File tempStoreDir = new File(dbPath);
FileUtils.deleteRecursively(tempStoreDir);
this.inserter = BatchInserters.inserter(tempStoreDir);
this.indexProvider = new LuceneBatchInserterIndexProvider(this.inserter);
}
示例7: Neo4jBatchDatabase
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
/**
* Constructor that create an embedded database.
*
* @param path Path of the graph database folder
* @param configuration Configuration map of database
*/
public Neo4jBatchDatabase(String path, Map<String, String> configuration) {
try {
// Initialize batch inserter
this.inserter = BatchInserters.inserter(new File(path), configuration);
// Init
this.indexProvider = new LuceneBatchInserterIndexProvider(inserter);
this.batchInserterIndexes = new HashMap<>();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例8: batchInsert
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
@Test
public void batchInsert() throws Exception
{
Neo4jTestCase.deleteFileOrDirectory( new File(
"target/neo4jdb-batchinsert" ) );
// START SNIPPET: batchInsert
BatchInserter inserter = BatchInserters.inserter( "target/neo4jdb-batchinsert" );
BatchInserterIndexProvider indexProvider =
new LuceneBatchInserterIndexProvider( inserter );
BatchInserterIndex actors =
indexProvider.nodeIndex( "actors", MapUtil.stringMap( "type", "exact" ) );
actors.setCacheCapacity( "name", 100000 );
Map<String, Object> properties = MapUtil.map( "name", "Keanu Reeves" );
long node = inserter.createNode( properties );
actors.add( node, properties );
//make the changes visible for reading, use this sparsely, requires IO!
actors.flush();
// Make sure to shut down the index provider as well
indexProvider.shutdown();
inserter.shutdown();
// END SNIPPET: batchInsert
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( "target/neo4jdb-batchinsert" );
try ( Transaction tx = db.beginTx() )
{
Index<Node> index = db.index().forNodes( "actors" );
Node reeves = index.get( "name", "Keanu Reeves" ).next();
assertEquals( node, reeves.getId() );
}
db.shutdown();
}
示例9: shouldIndexNodesWithMultipleLabels
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
@Test
public void shouldIndexNodesWithMultipleLabels() throws Exception
{
// Given
String path = dbRule.getStoreDirAbsolutePath();
BatchInserter inserter = BatchInserters.inserter( path );
inserter.createNode( map( "name", "Bob" ), label( "User" ), label( "Admin" ) );
inserter.createDeferredSchemaIndex( label( "User" ) ).on( "name" ).create();
inserter.createDeferredSchemaIndex( label( "Admin" ) ).on( "name" ).create();
// When
inserter.shutdown();
// Then
GraphDatabaseService db = dbRule.getGraphDatabaseService();
try ( Transaction tx = db.beginTx() )
{
assertThat( count( db.findNodes( label( "User" ), "name", "Bob" ) ), equalTo(1) );
assertThat( count( db.findNodes( label( "Admin" ), "name", "Bob" ) ), equalTo(1) );
}
finally
{
db.shutdown();
}
}
示例10: shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock() throws Exception
{
BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );
long nodeId = inserter.createNode( Collections.<String, Object>emptyMap() );
final Object finalValue1 = 87;
final Object finalValue2 = 3.14;
inserter.setNodeProperty( nodeId, "a", "some property value" );
inserter.setNodeProperty( nodeId, "a", 42 );
inserter.setNodeProperty( nodeId, "b", finalValue2 );
inserter.setNodeProperty( nodeId, "a", finalValue2 );
inserter.setNodeProperty( nodeId, "a", true );
inserter.setNodeProperty( nodeId, "a", finalValue1 );
inserter.shutdown();
GraphDatabaseService db = dbRule.getGraphDatabaseService();
try(Transaction ignored = db.beginTx())
{
assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue1 ) );
assertThat( db.getNodeById( nodeId ).getProperty( "b" ), equalTo( finalValue2 ) );
}
finally
{
db.shutdown();
}
}
示例11: getBatchInserterInstance
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
/**
*
* @return
* @return
*/
private static BatchInserter getBatchInserterInstance(Map<String, String> config)
{
if (batchInserter == null)
{
try {
batchInserter = BatchInserters.inserter(new File(NEO4J_STORE_DIR), config);
}
catch (Exception e) {
}
}
return batchInserter;
}
示例12: newBatchInserterInstance
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
private void newBatchInserterInstance(File storeDir, Map<String, String> config) {
if (batchInserter == null) {
try {
batchInserter = BatchInserters.inserter(storeDir, config);
logger.info("Batch inserter instance created. Neo4j store directory = " + storeDir);
}
catch (Exception e) {
logger.error("Error creating batch inserter in store dir " + storeDir);
}
}
}
示例13: getGraph
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
public static BatchInserter getGraph(String st) {
File f = new File(st);
Map<String, String> config = new HashMap<String, String>();
long x = Runtime.getRuntime().maxMemory() / 1000000 / 60;
config.put("neostore.nodestore.db.mapped_memory", 3 * x + "M");
config.put("neostore.relationshipstore.db.mapped_memory", 14 * x + "M");
config.put("neostore.propertystore.db.mapped_memory", x + "M");
config.put("neostore.propertystore.db.strings.mapped_memory", 2 * x
+ "M");
config.put("neostore.propertystore.db.arrays.mapped_memory", x + "M");
config.put("neostore.propertystore.db.index.keys.mapped_memory", x
+ "M");
config.put("neostore.propertystore.db.index.mapped_memory", x + "M");
config.put("keep_logical_logs", "false");
System.out.println("Opening: " + f.getPath() + "\nWITH: "
+ Runtime.getRuntime().maxMemory() / 1000000000 + "."
+ Runtime.getRuntime().maxMemory() % 1000000000
+ " GB of HEAP and: " + getTotalVM(config) / 1000 + "."
+ getTotalVM(config) % 1000
+ " GB of Database VM (embedded in heap)");
BatchInserter i = BatchInserters.inserter(f.getPath(), config);
registerShutdownHook(i);
return i;
}
示例14: main
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
public static void main(String[] args) {
//GraphDatabaseService njgraph = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(NEO_STORE).loadPropertiesFromFile("neo4j.properties").newGraphDatabase();
BatchInserter db = BatchInserters.inserter(NEO_STORE);
Course_Test.write(db);
//Course_Test.getJob(njgraph);
//Course_Test.search(njgraph);
//Course_Test.insertData(njgraph);
//njgraph.shutdown();
db.shutdown();
log.info("Connection closed");
}
示例15: getInserter
import org.neo4j.unsafe.batchinsert.BatchInserters; //导入方法依赖的package包/类
@Provides
@Singleton
BatchInserter getInserter() throws IOException {
File location = new File(config.getGraphConfiguration().getLocation());
logger.info("Getting BatchInserter for " + location);
return BatchInserters.inserter(new File(location.toString()), config.getGraphConfiguration()
.getNeo4jConfig());
}