本文整理汇总了Java中org.neo4j.unsafe.batchinsert.BatchInserter.createNode方法的典型用法代码示例。如果您正苦于以下问题:Java BatchInserter.createNode方法的具体用法?Java BatchInserter.createNode怎么用?Java BatchInserter.createNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.neo4j.unsafe.batchinsert.BatchInserter
的用法示例。
在下文中一共展示了BatchInserter.createNode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldNotIndexNodesWithWrongLabel
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的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.BatchInserter; //导入方法依赖的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.BatchInserter; //导入方法依赖的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.BatchInserter; //导入方法依赖的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: getOrCreateUserNodeID
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的package包/类
private static long getOrCreateUserNodeID(final String userid,
final Map<String, Long> usersNodesMap,
final BatchInserterIndex usersIndex,
final BatchInserter inserter,
final Label label) {
long userNodeID;
if (usersNodesMap.containsKey(userid)) {
userNodeID = usersNodesMap.get(userid);
} else {
userNodeID = inserter.createNode(MapUtil.map("node_id", userid), label);
usersNodesMap.put(userid, userNodeID);
usersIndex.add(userNodeID, MapUtil.map("node_id", userid));
}
return userNodeID;
}
示例6: getOrCreateItemNodeID
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的package包/类
private static long getOrCreateItemNodeID(final String itemid,
final Map<String, Long> itemsNodesMap,
final BatchInserterIndex itemsIndex,
final BatchInserter inserter,
final Label label) {
long itemNodeID;
if (itemsNodesMap.containsKey(itemid)) {
itemNodeID = itemsNodesMap.get(itemid);
} else {
itemNodeID = inserter.createNode(MapUtil.map("node_id", itemid), label);
itemsNodesMap.put(itemid, itemNodeID);
itemsIndex.add(itemNodeID, MapUtil.map("node_id", itemid));
}
return itemNodeID;
}
示例7: batchInsert
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的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();
}
示例8: shouldIndexNodesWithMultipleLabels
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的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();
}
}
示例9: shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的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();
}
}
示例10: createNode
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的package包/类
/**
*
* @param node
* @return
*/
public static long createNode(Node node)
{
BatchInserter batchInserter = getBatchInserterInstance();
long nodeId = batchInserter.createNode(node.getProperties(), node.getLabels());
node.setNodeId(nodeId);
return nodeId;
}
示例11: main
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的package包/类
public static void main(String[] args) {
// init neo4j db
BatchInserter inserter = BatchInserters.inserter("test_db");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("name", "holman");
inserter.createNode(1, properties);
properties.put("name", "jefferson");
inserter.createNode(2, properties);
inserter.createRelationship(1, 2, Rels.KNOWS, null);
inserter.shutdown();
}
示例12: importLabels
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的package包/类
public void importLabels(File dbPath, final File file) throws IOException {
log.info("Importing {} ({} KiB) to {} ...", file, NUMBER.format(DefaultGroovyMethods.asType(file.length() / 1024, Long.class)), dbPath);
long importeds = 0l;
final BatchInserter inserter = BatchInserters.inserter(dbPath);
try {
final Label resourceLabel = DynamicLabel.label("Resource");
final Label labelLabel = DynamicLabel.label("Label");
inserter.createDeferredConstraint(resourceLabel).assertPropertyIsUnique("href").create();
// PLEASE create the label indexes on last step, not now! to speed up imports on later stages
// inserter.createDeferredSchemaIndex(resourceLabel).on('prefLabel').create()
// inserter.createDeferredSchemaIndex(resourceLabel).on('isPreferredMeaningOf').create()
// inserter.createDeferredSchemaIndex(labelLabel).on('v').create()
final DynamicRelationshipType rdfsLabel = DynamicRelationshipType.withName("rdfs_label");
try (final Scanner scanner = new Scanner(file, StandardCharsets.UTF_8.name())) {
scanner.useDelimiter("\u0001");// Ctrl+A (SOH)
while (true) {
final Object line;
try {
line = scanner.next();
} catch (NoSuchElementException ex) {
break;
}
final IndexedResource res = mapper.readValue((String) line, IndexedResource.class);
if (res.getPrefLabel() == null && res.getLabels() != null && !res.getLabels().isEmpty()) {
res.setPrefLabel(res.getLabels().get(0).getValue());
res.getLabels().remove(0);
}
final Map<String, Object> props = new HashMap<>();
if (res.getPrefLabel() != null) {
props.put("prefLabel", res.getPrefLabel());
}
if (res.getIsPreferredMeaningOf() != null) {
props.put("isPreferredMeaningOf", res.getIsPreferredMeaningOf());
}
final long resNode = inserter.createNode(props, resourceLabel);
for (IndexedResource.LocalizedLabel it : res.getLabels()) {
final Map<String, Object> labelProps = new HashMap<>();
if (it.getLanguage() != null) {
labelProps.put("l", it.getLanguage());
}
final long labelNode = inserter.createNode(labelProps, labelLabel);
inserter.createRelationship(resNode, labelNode, rdfsLabel, new LinkedHashMap());
}
importeds++;
if (importeds % 10000 == 0) {
log.info("Imported {} resource nodes +prefLabel +isPreferredMeaningOf +label relationships from {}", NUMBER.format(importeds), file);
}
}
}
} catch (Exception e) {
throw new RuntimeException("Cannot process", e);
} finally {
log.info("Shutting down batchInserter after importing {} resource nodes from {} ...", NUMBER.format(importeds), file);
inserter.shutdown();
}
log.info("Completed importing {} resource nodes +prefLabel +isPreferredMeaningOf +label relationships from {}", NUMBER.format(importeds), file);
}
示例13: uploadGraph
import org.neo4j.unsafe.batchinsert.BatchInserter; //导入方法依赖的package包/类
@Override
public void uploadGraph(Graph graph) throws Exception {
LOG.info("Importing graph \"{}\" into a Neo4j database", graph.getName());
String databasePath = Paths.get(dbPath, graph.getName()).toString();
InputStream propertiesStream = getClass().getResourceAsStream(PROPERTIES_PATH);
Map<String, String> properties = MapUtil.load(propertiesStream);
BatchInserter inserter = BatchInserters.inserter(databasePath, properties);
LOG.debug("- Inserting vertices");
Long2LongMap vertexIdMap = new Long2LongOpenHashMap((int)graph.getNumberOfVertices());
try (BufferedReader vertexData = new BufferedReader(new FileReader(graph.getVertexFilePath()))) {
Map<String, Object> propertiesCache = new HashMap<>(1, 1.0f);
for (String vertexLine = vertexData.readLine(); vertexLine != null; vertexLine = vertexData.readLine()) {
if (vertexLine.isEmpty()) {
continue;
}
long vertexId = Long.parseLong(vertexLine);
propertiesCache.put(ID_PROPERTY, vertexId);
long internalVertexId = inserter.createNode(propertiesCache, (Label)Vertex);
vertexIdMap.put(vertexId, internalVertexId);
}
}
LOG.debug("- Inserting edges");
try (BufferedReader edgeData = new BufferedReader(new FileReader(graph.getEdgeFilePath()))) {
for (String edgeLine = edgeData.readLine(); edgeLine != null; edgeLine = edgeData.readLine()) {
if (edgeLine.isEmpty()) {
continue;
}
String[] edgeLineChunks = edgeLine.split(" ");
if (edgeLineChunks.length != 2) {
throw new IOException("Invalid data found in edge list: \"" + edgeLine + "\"");
}
inserter.createRelationship(vertexIdMap.get(Long.parseLong(edgeLineChunks[0])),
vertexIdMap.get(Long.parseLong(edgeLineChunks[1])), EDGE, null);
}
}
inserter.createDeferredSchemaIndex(Vertex).on(ID_PROPERTY).create();
inserter.shutdown();
LOG.debug("- Graph \"{}\" imported successfully", graph.getName());
}