use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class Set method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException {
boolean forProperty = parser.options().containsKey("p");
boolean forLabel = parser.options().containsKey("l");
if (forProperty || !forLabel) {
// Property
if (parser.arguments().size() < 2) {
throw new ShellException("Must supply key and value, " + "like: set title \"This is a my title\"");
}
String key = parser.arguments().get(0);
ValueType valueType = getValueType(parser);
Object value = parseValue(parser.arguments().get(1), valueType);
NodeOrRelationship thing = getCurrent(session);
thing.setProperty(key, value);
} else {
// Label
Node node = getCurrent(session).asNode();
for (Label label : parseLabels(parser)) {
node.addLabel(label);
}
}
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class ClusterLocksIT method aPendingMemberShouldBeAbleToServeReads.
@Test
public void aPendingMemberShouldBeAbleToServeReads() throws Throwable {
// given
createNodeOnMaster(testLabel, cluster.getMaster());
cluster.sync();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
cluster.fail(slave, ClusterManager.NetworkFlag.values());
cluster.await(instanceEvicted(slave));
assertEquals(PENDING, slave.getInstanceState());
// when
for (int i = 0; i < 10; i++) {
try (Transaction tx = slave.beginTx()) {
Node single = Iterables.single(slave.getAllNodes());
Label label = Iterables.single(single.getLabels());
assertEquals(testLabel, label);
tx.success();
break;
} catch (TransactionTerminatedException e) {
// Race between going to pending and reading, try again in a little while
Thread.sleep(1_000);
}
}
// then no exceptions thrown
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class StoreUpgradeIntegrationTest method checkLabelCounts.
private static void checkLabelCounts(GraphDatabaseAPI db) {
try (Transaction ignored = db.beginTx()) {
HashMap<Label, Long> counts = new HashMap<>();
for (Node node : db.getAllNodes()) {
for (Label label : node.getLabels()) {
Long count = counts.get(label);
if (count != null) {
counts.put(label, count + 1);
} else {
counts.put(label, 1L);
}
}
}
ThreadToStatementContextBridge bridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
Statement statement = bridge.get();
for (Map.Entry<Label, Long> entry : counts.entrySet()) {
assertEquals(entry.getValue().longValue(), statement.readOperations().countsForNode(statement.readOperations().labelGetForName(entry.getKey().name())));
}
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class SchemaProcedure method buildSchemaGraph.
public GraphResult buildSchemaGraph() {
final Map<String, NodeImpl> nodes = new HashMap<>();
final Map<String, Set<RelationshipImpl>> relationships = new HashMap<>();
try (Statement statement = kernelTransaction.acquireStatement()) {
ReadOperations readOperations = statement.readOperations();
StatementTokenNameLookup statementTokenNameLookup = new StatementTokenNameLookup(readOperations);
try (Transaction transaction = graphDatabaseAPI.beginTx()) {
// add all labelsInDatabase
ResourceIterator<Label> labelsInDatabase = graphDatabaseAPI.getAllLabelsInUse().iterator();
while (labelsInDatabase.hasNext()) {
Label label = labelsInDatabase.next();
Map<String, Object> properties = new HashMap<>();
Iterator<NewIndexDescriptor> indexDescriptorIterator = readOperations.indexesGetForLabel(readOperations.labelGetForName(label.name()));
ArrayList<String> indexes = new ArrayList<>();
while (indexDescriptorIterator.hasNext()) {
NewIndexDescriptor index = indexDescriptorIterator.next();
String[] propertyNames = PropertyNameUtils.getPropertyKeys(statementTokenNameLookup, index.schema().getPropertyIds());
indexes.add(String.join(",", propertyNames));
}
properties.put("indexes", indexes);
Iterator<ConstraintDescriptor> nodePropertyConstraintIterator = readOperations.constraintsGetForLabel(readOperations.labelGetForName(label.name()));
ArrayList<String> constraints = new ArrayList<>();
while (nodePropertyConstraintIterator.hasNext()) {
PropertyConstraint constraint = ConstraintBoundary.map(nodePropertyConstraintIterator.next());
constraints.add(constraint.userDescription(statementTokenNameLookup));
}
properties.put("constraints", constraints);
getOrCreateLabel(label.name(), properties, nodes);
}
//add all relationships
Iterator<RelationshipType> relationshipTypeIterator = graphDatabaseAPI.getAllRelationshipTypesInUse().iterator();
while (relationshipTypeIterator.hasNext()) {
RelationshipType relationshipType = relationshipTypeIterator.next();
String relationshipTypeGetName = relationshipType.name();
int relId = readOperations.relationshipTypeGetForName(relationshipTypeGetName);
ResourceIterator<Label> labelsInUse = graphDatabaseAPI.getAllLabelsInUse().iterator();
List<NodeImpl> startNodes = new LinkedList<>();
List<NodeImpl> endNodes = new LinkedList<>();
while (labelsInUse.hasNext()) {
Label labelToken = labelsInUse.next();
String labelName = labelToken.name();
Map<String, Object> properties = new HashMap<>();
NodeImpl node = getOrCreateLabel(labelName, properties, nodes);
int labelId = readOperations.labelGetForName(labelName);
if (readOperations.countsForRelationship(labelId, relId, ReadOperations.ANY_LABEL) > 0) {
startNodes.add(node);
}
if (readOperations.countsForRelationship(ReadOperations.ANY_LABEL, relId, labelId) > 0) {
endNodes.add(node);
}
}
for (NodeImpl startNode : startNodes) {
for (NodeImpl endNode : endNodes) {
RelationshipImpl relationship = addRelationship(startNode, endNode, relationshipTypeGetName, relationships);
}
}
}
transaction.success();
return getGraphResult(nodes, relationships);
}
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class GraphDatabaseFacade method allNodesWithLabel.
private ResourceIterator<Node> allNodesWithLabel(final Label myLabel) {
Statement statement = spi.currentStatement();
int labelId = statement.readOperations().labelGetForName(myLabel.name());
if (labelId == KeyReadOperations.NO_SUCH_LABEL) {
statement.close();
return emptyIterator();
}
final PrimitiveLongIterator nodeIds = statement.readOperations().nodesGetForLabel(labelId);
return ResourceClosingIterator.newResourceIterator(statement, map(nodeId -> new NodeProxy(nodeActions, nodeId), nodeIds));
}
Aggregations