private LabelResult( Label label ) { this.label = label.name(); } }
@Override public boolean equals( Object other ) { return other instanceof Label && ((Label) other).name().equals( name ); }
@Override public ConstraintDefinition createPropertyExistenceConstraint( Label label, String... propertyKeys ) { int labelId = getOrCreateLabelId( label.name() ); int[] propertyKeyIds = getOrCreatePropertyKeyIds( propertyKeys ); validateNodePropertyExistenceConstraintCanBeCreated( labelId, propertyKeyIds ); createNodePropertyExistenceConstraintRule( labelId, propertyKeyIds ); return new NodePropertyExistenceConstraintDefinition( this, label, propertyKeys ); }
public static TypeSafeDiagnosingMatcher<Node> hasLabels( Label... expectedLabels ) { Set<String> labelNames = new HashSet<>( expectedLabels.length ); for ( Label l : expectedLabels ) { labelNames.add( l.name() ); } return hasLabels( labelNames ); }
private static String labelsOf( Node node ) { StringBuilder builder = new StringBuilder(); for ( Label label : node.getLabels() ) { builder.append( label.name() + " " ); } return builder.toString(); }
void assignedLabel( Node node, Label label ) { if ( removeLabel( expectedRemovedLabels, node, label ) ) { expectedAssignedLabels.get( node ).add( label.name() ); } }
private void rightSide( KernelTransaction ktx, DbStructureVisitor visitor, Label label, int labelId, RelationshipType relType, int relTypeId ) { String userDescription = format( "MATCH ()-[%s]->(%s) RETURN count(*)", colon( relType.name() ), colon( label.name() ) ); long amount = ktx.dataRead().countsForRelationship( ANY_LABEL, relTypeId, labelId ); visitor.visitRelCount( ANY_LABEL, relTypeId, labelId, userDescription, amount ); }
@Override public ConstraintDefinition createPropertyUniquenessConstraint( IndexDefinition indexDefinition ) { int labelId = getOrCreateLabelId( indexDefinition.getLabel().name() ); int[] propertyKeyIds = getOrCreatePropertyKeyIds( indexDefinition.getPropertyKeys() ); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ); validateUniquenessConstraintCanBeCreated( labelId, propertyKeyIds ); createUniquenessConstraintRule( descriptor ); return new UniquenessConstraintDefinition( this, indexDefinition ); }
@Override public ConstraintDefinition createNodeKeyConstraint( IndexDefinition indexDefinition ) { int labelId = getOrCreateLabelId( indexDefinition.getLabel().name() ); int[] propertyKeyIds = getOrCreatePropertyKeyIds( indexDefinition.getPropertyKeys() ); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ); validateNodeKeyConstraintCanBeCreated( labelId, propertyKeyIds ); createNodeKeyConstraintRule( descriptor ); return new NodeKeyConstraintDefinition( this, indexDefinition ); }
public ListRepresentation getAllLabels( boolean inUse ) { ResourceIterable<Label> labels = inUse ? graphDb.getAllLabelsInUse() : graphDb.getAllLabels(); Collection<ValueRepresentation> labelNames = Iterables.asSet( map( label -> ValueRepresentation.string( label.name() ), labels ) ); return new ListRepresentation( RepresentationType.STRING, labelNames ); }
@Override public ResourceIterator<Node> findNodes( final Label myLabel, final String key, final Object value ) { KernelTransaction transaction = statementContext.getKernelTransactionBoundToThisThread( true ); TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( myLabel.name() ); int propertyId = tokenRead.propertyKey( key ); return nodesByLabelAndProperty( transaction, labelId, IndexQuery.exact( propertyId, Values.of( value ) ) ); }
private void createSimpleNodesIndex() { db.execute( format( NODE_CREATE, "nodes", array( LABEL.name() ), array( PROP ) ) ).close(); } }
private void assertNodeEquals( InputEntity input, Node node ) { // properties assertPropertiesEquals( input, node ); // labels Set<String> expectedLabels = asSet( input.labels() ); for ( Label label : node.getLabels() ) { assertTrue( expectedLabels.remove( label.name() ) ); } assertTrue( expectedLabels.isEmpty() ); }
private int labelId( Label alien ) { try ( Transaction ignore = db.beginTx() ) { return ktx().tokenRead().nodeLabel( alien.name() ); } }
@Override public ResourceIterator<Node> findNodes( Label label, String key1, Object value1, String key2, Object value2 ) { KernelTransaction transaction = statementContext.getKernelTransactionBoundToThisThread( true ); TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( label.name() ); return nodesByLabelAndProperties( transaction, labelId, IndexQuery.exact( tokenRead.propertyKey( key1 ), Values.of( value1 ) ), IndexQuery.exact( tokenRead.propertyKey( key2 ), Values.of( value2 ) ) ); }
private IndexReference indexId( org.neo4j.internal.kernel.api.Transaction tx ) { int labelId = tx.tokenRead().nodeLabel( label.name() ); int propertyKeyId = tx.tokenRead().propertyKey( property ); return tx.schemaRead().index( labelId, propertyKeyId ); }
private static void shouldHaveUniquenessConstraintForNamePropertyOnPersonLabel( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { ConstraintDefinition constraint = Iterables.single( db.schema().getConstraints() ); assertEquals( ConstraintType.UNIQUENESS, constraint.getConstraintType() ); assertEquals( "Person", constraint.getLabel().name() ); assertEquals( "name", Iterables.single( constraint.getPropertyKeys() ) ); tx.success(); } }
@Test public void shouldCreateDeferredSchemaIndexesInEmptyDatabase() throws Exception { // GIVEN BatchInserter inserter = newBatchInserter(); // WHEN IndexDefinition definition = inserter.createDeferredSchemaIndex( label( "Hacker" ) ).on( "handle" ).create(); // THEN assertEquals( "Hacker", single( definition.getLabels() ).name() ); assertEquals( asCollection( iterator( "handle" ) ), Iterables.asCollection( definition.getPropertyKeys() ) ); inserter.shutdown(); }