@Test public void shouldBeAbleToRemoveNodeProperties() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "number", 15 ); long nodeId = createNode( properties ); actions.removeAllNodeProperties( nodeId ); try ( Transaction tx = database.getGraph().beginTx() ) { Node node = database.getGraph().getNodeById( nodeId ); assertFalse( node.getPropertyKeys().iterator().hasNext() ); tx.success(); } }
@Test public void testNodeGetProperties() { Node node1 = getGraphDb().getNodeById( node1Id ); assertTrue( !node1.hasProperty( null ) ); Iterator<String> keys = node1.getPropertyKeys().iterator(); keys.next(); keys.next(); assertTrue( node1.hasProperty( key1 ) ); assertTrue( node1.hasProperty( key2 ) ); }
@Test public void removingPropertyDoesNotBreakPreviouslyCreatedNodePropertyKeysIterator() { // GIVEN GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.setProperty( "name", "Horst" ); node.setProperty( "age", "72" ); Iterator<String> iterator = node.getPropertyKeys().iterator(); while ( iterator.hasNext() ) { node.removeProperty( iterator.next() ); } tx.success(); } }
for ( String key : node.getPropertyKeys() )
for ( String key : node.getPropertyKeys() )
for ( String key : node.getPropertyKeys() )
for ( Node node : db.getAllNodes() ) for ( String key : node.getPropertyKeys() )
for ( String key : node.getPropertyKeys() )
for ( String key : node.getPropertyKeys() )
private void changeRandomNode( GraphDatabaseService db, int nodeCount, RandomValues random ) { try ( Transaction tx = db.beginTx() ) { long nodeId = random.nextInt( nodeCount ); Node node = db.getNodeById( nodeId ); Object[] keys = Iterables.asCollection( node.getPropertyKeys() ).toArray(); String key = (String) random.among( keys ); if ( random.nextFloat() < 0.1 ) { // REMOVE node.removeProperty( key ); } else { // CHANGE node.setProperty( key, random.nextValue().asObject() ); } tx.success(); } catch ( NotFoundException e ) { // It's OK, it happens if some other thread deleted that property in between us reading it and // removing or setting it } }
public static String filterCaption(Node n, Set<String> captions, BiPredicate<String, String> predicate) { for (String caption : captions) { for (String key : n.getPropertyKeys()) { if (predicate.test(key, caption)) return n.getProperty(key).toString(); } } return null; } }
node1.setProperty( key2, int2 ); node1.setProperty( key3, string ); Iterator<String> keys = node1.getPropertyKeys().iterator(); keys.next(); keys.next();
@Override public String statementForNode(Node node, Map<String, String> uniqueConstraints, Set<String> indexedProperties, Set<String> indexNames) { StringBuilder result = new StringBuilder(100); result.append("CREATE ("); String labels = CypherFormatterUtils.formatAllLabels(node, uniqueConstraints, indexNames); if (!labels.isEmpty()) { result.append(labels); } if (node.getPropertyKeys().iterator().hasNext()) { result.append(" {"); result.append(CypherFormatterUtils.formatNodeProperties("", node, uniqueConstraints, indexNames, true)); result.append("}"); } result.append(");"); return result.toString(); }
protected String mergeStatementForNode(CypherFormat cypherFormat, Node node, Map<String, String> uniqueConstraints, Set<String> indexedProperties, Set<String> indexNames) { StringBuilder result = new StringBuilder(1000); result.append("MERGE "); result.append(CypherFormatterUtils.formatNodeLookup("n", node, uniqueConstraints, indexNames)); if (node.getPropertyKeys().iterator().hasNext()) { String notUniqueProperties = CypherFormatterUtils.formatNotUniqueProperties("n", node, uniqueConstraints, indexedProperties, false); String notUniqueLabels = CypherFormatterUtils.formatNotUniqueLabels("n", node, uniqueConstraints); if (!"".equals(notUniqueProperties) || !"".equals(notUniqueLabels)) { result.append(cypherFormat.equals(CypherFormat.ADD_STRUCTURE) ? " ON CREATE SET " : " SET "); result.append(notUniqueProperties); result.append(!"".equals(notUniqueProperties) && !"".equals(notUniqueLabels) ? ", " : ""); result.append(notUniqueLabels); } } result.append(";"); return result.toString(); }
private void add(Node node) { count++; int degree = node.getDegree(); sumDegree += degree; if (degree > maxDegree) maxDegree = degree; if (degree < minDegree) minDegree = degree; for (Label label : node.getLabels()) labels.add(label.name()); for (String key : node.getPropertyKeys()) properties.add(key); } Map<String,Object> toMap() {
public static String getCaption(Node n, Set<String> captions) { for (String caption : captions) { //first do one loop with the exact names if (n.hasProperty(caption)) return n.getProperty(caption).toString(); } String result = filterCaption(n, captions, (key, caption) -> key.equalsIgnoreCase(caption)); //2nd loop with lowercase if (result == null) { result = filterCaption(n, captions, (key, caption) -> key.toLowerCase().contains(caption) || key.toLowerCase().endsWith(caption)); //3rd loop with contains or endsWith if (result == null) { Iterator<String> iterator = n.getPropertyKeys().iterator(); if (iterator.hasNext()) { result = n.getProperty(iterator.next()).toString(); // get the first property } } } return result == null ? String.valueOf(n.getId()) : result; // if the node has no property return the ID }
private String caption(Node n) { for (String caption : CAPTIONS) { if (n.hasProperty(caption)) return n.getProperty(caption).toString(); } String first=null; for (String caption : CAPTIONS) { for (String key : n.getPropertyKeys()) { if (first==null) first = key; if (key.toLowerCase().contains(caption)) return n.getProperty(key).toString(); } } return first == null ? idStr(n) : n.getProperty(first).toString(); } }
@Test public void lazyLoadWithinWriteTransaction() throws Exception { // Given FileSystemAbstraction fileSystem = fs.get(); BatchInserter inserter = BatchInserters.inserter( testDirectory.databaseDir(), fileSystem ); int count = 3000; long nodeId = inserter.createNode( mapWithManyProperties( count /* larger than initial property index load threshold */ ) ); inserter.shutdown(); GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem( fileSystem ).newImpermanentDatabase( testDirectory.databaseDir() ); // When try ( Transaction tx = db.beginTx() ) { db.createNode(); Node node = db.getNodeById( nodeId ); // Then assertEquals( count, Iterables.count( node.getPropertyKeys() ) ); tx.success(); } finally { db.shutdown(); } }
private void iterateLabelChanges(Stream<LabelEntry> stream, IndexFunction<Index<Node>, Node, String, Object, Void> function) { stream.forEach(labelEntry -> { final String labelName = labelEntry.label().name(); final Map<String, Collection<Index<Node>>> propertyIndicesMap = indexesByLabelAndProperty.get(labelName); if (propertyIndicesMap != null) { final Node entity = labelEntry.node(); for (String key : entity.getPropertyKeys()) { Collection<Index<Node>> indices = propertyIndicesMap.get(key); if (indices != null) { for (Index<Node> index : indices) { Object value = entity.getProperty(key); String indexKey = labelName + "." + key; function.apply(index, entity, indexKey, value, null); } } } } }); }
private void appendNode(PrintWriter out, Node node, Reporter reporter) { artificialUniques += countArtificialUniques(node); String cypher = this.cypherFormat.statementForNode(node, uniqueConstraints, indexedProperties, indexNames); if (Util.isNotNullOrEmpty(cypher)) { out.println(cypher); reporter.update(1, 0, Iterables.count(node.getPropertyKeys())); } }