protected NodeConstraintDefinition( InternalSchemaActions actions, IndexDefinition indexDefinition ) { super( actions, indexDefinition ); if ( indexDefinition.isMultiTokenIndex() ) { throw new IllegalArgumentException( "Node constraints do not support multi-token definitions. That is, they cannot apply to more than one label, " + "but an attempt was made to create a node constraint on the following labels: " + labelNameList( indexDefinition.getLabels(), "", "." ) ); } this.label = single( indexDefinition.getLabels() ); }
private PropertyCommand singlePropertyCommand( Collection<StorageCommand> commands ) { return (PropertyCommand) Iterables.single( filter( t -> t instanceof PropertyCommand, commands ) ); }
private RelationshipGroupCommand singleRelationshipGroupCommand( Collection<StorageCommand> commands ) { return (RelationshipGroupCommand) Iterables.single( filter( t -> t instanceof RelationshipGroupCommand, commands ) ); }
private static String onlyTimezone( MapValue map ) { if ( map.size() == 1 ) { String key = single( map.keySet() ); if ( "timezone".equalsIgnoreCase( key ) ) { AnyValue timezone = map.get( key ); if ( timezone instanceof TextValue ) { return ((TextValue) timezone).stringValue(); } } } return null; }
public boolean dropSchemaIndex( String labelName, String propertyKey ) { boolean found = false; for ( IndexDefinition index : graphDb.schema().getIndexes( label( labelName ) ) ) { // TODO Assumption about single property key if ( propertyKey.equals( Iterables.single( index.getPropertyKeys() ) ) ) { index.drop(); found = true; break; } } return found; }
@Test public void shouldServiceLoaderFindCypherEngineProvider() { // WHEN ServiceLoader<QueryEngineProvider> services = ServiceLoader.load(QueryEngineProvider.class); // THEN assertTrue(Iterables.single(services) instanceof CommunityCypherEngineProvider ); } }
@Test public void shouldListAddedLabels() throws Exception { // Given int labelId = 2; when( tokenRead.nodeLabelName( labelId ) ).thenReturn( "theLabel" ); state.nodeDoAddLabel( labelId, 1L ); // When Iterable<LabelEntry> labelEntries = snapshot().assignedLabels(); // Then LabelEntry entry = single( labelEntries ); assertThat( entry.label().name(), equalTo( "theLabel" ) ); assertThat( entry.node().getId(), equalTo( 1L ) ); }
@Test public void shouldListRemovedLabels() throws Exception { // Given int labelId = 2; when( tokenRead.nodeLabelName( labelId ) ).thenReturn( "theLabel" ); state.nodeDoRemoveLabel( labelId, 1L ); // When Iterable<LabelEntry> labelEntries = snapshot().removedLabels(); // Then LabelEntry entry = single( labelEntries ); assertThat( entry.label().name(), equalTo( "theLabel" ) ); assertThat( entry.node().getId(), equalTo( 1L ) ); }
@Test public void showsDeletedNodes() throws Exception { // Given state.nodeDoDelete( 1L ); state.nodeDoDelete( 2L ); int labelId = 15; when( tokenRead.nodeLabelName( labelId ) ).thenReturn( "label" ); ops.withNode( 1, new long[]{labelId}, genericMap( "key", Values.of( "p" ) ) ); ops.withNode( 2, NO_LABELS ); // When & Then TxStateTransactionDataSnapshot snapshot = snapshot(); assertThat( idList( snapshot.deletedNodes() ), equalTo( asList( 1L, 2L ) ) ); assertThat( single( snapshot.removedLabels() ).label().name(), equalTo( "label" ) ); assertThat( single( snapshot.removedNodeProperties() ).key(), equalTo( "key" ) ); }
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 showsRemovedRelationships() throws Exception { // Given state.relationshipDoDelete( 1L, 1, 1L, 2L ); state.relationshipDoDelete( 2L, 1, 1L, 1L ); ops.withRelationship( 1, 1, 1, 2 ); ops.withRelationship( 2, 1, 1, 1, genericMap( "key", Values.of( "p") ) ); // When & Then TxStateTransactionDataSnapshot snapshot = snapshot(); assertThat( idList( snapshot.deletedRelationships() ), equalTo( asList( 1L, 2L ) ) ); assertThat( single( snapshot.removedRelationshipProperties() ).key(), equalTo( "key" ) ); }
private ConstraintDefinition recreate( ConstraintDefinition constraint, int times ) { for ( int i = 0; i < times; i++ ) { constraint.drop(); constraint = graphDb.schema() .constraintFor( constraint.getLabel() ) .assertPropertyIsUnique( single( constraint.getPropertyKeys() ) ) .create(); } return constraint; }
@Test public void shouldCreatePropertyUniquenessConstraint() { // GIVEN String labelName = "person"; String propertyKey = "name"; // WHEN actions.createPropertyUniquenessConstraint( labelName, asList( propertyKey ) ); // THEN try ( Transaction tx = graph.beginTx() ) { Iterable<ConstraintDefinition> defs = graphdbHelper.getPropertyUniquenessConstraints( labelName, propertyKey ); assertEquals( asSet( propertyKey ), Iterables.asSet( single( defs ).getPropertyKeys() ) ); tx.success(); } }
@Test public void shouldListRemovedNodeProperties() throws Exception { // Given int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); Value prevValue = Values.of( "prevValue" ); state.nodeDoRemoveProperty( 1L, propertyKeyId ); ops.withNode( 1, NO_LABELS, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Node>> propertyEntries = snapshot().removedNodeProperties(); // Then PropertyEntry<Node> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
@Test public void shouldListRemovedRelationshipProperties() throws Exception { // Given int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); Value prevValue = Values.of( "prevValue" ); state.relationshipDoRemoveProperty( 1L, propertyKeyId ); ops.withRelationship( 1, 0, 0, 0, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Relationship>> propertyEntries = snapshot().removedRelationshipProperties(); // Then PropertyEntry<Relationship> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
@Test public void shouldListAddedNodePropertiesProperties() throws Exception { // Given int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); Value prevValue = Values.of( "prevValue" ); state.nodeDoChangeProperty( 1L, propertyKeyId, Values.of( "newValue" ) ); ops.withNode( 1, NO_LABELS, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Node>> propertyEntries = snapshot().assignedNodeProperties(); // Then PropertyEntry<Node> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.value(), equalTo( "newValue" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
@Test public void shouldListAddedRelationshipProperties() throws Exception { // Given Value prevValue = Values.of( "prevValue" ); int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); state.relationshipDoReplaceProperty( 1L, propertyKeyId, prevValue, Values.of( "newValue" ) ); ops.withRelationship( 1, 0, 0, 0, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Relationship>> propertyEntries = snapshot().assignedRelationshipProperties(); // Then PropertyEntry<Relationship> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.value(), equalTo( "newValue" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
@Test public void oneDynamicRecordShouldShrinkIntoInlinedWhenRemoving() { // GIVEN NodeRecord node = nodeRecordWithDynamicLabels( nodeStore, oneByteLongs( 5 ) ); Collection<DynamicRecord> initialRecords = node.getDynamicLabelRecords(); NodeLabels nodeLabels = NodeLabelsField.parseLabelsField( node ); // WHEN Collection<DynamicRecord> changedDynamicRecords = Iterables.asCollection( nodeLabels.remove( 255, nodeStore ) ); // THEN assertEquals( initialRecords, changedDynamicRecords ); assertFalse( Iterables.single( changedDynamicRecords ).inUse() ); assertEquals( inlinedLabelsLongRepresentation( 251, 252, 253, 254 ), node.getLabelField() ); }
@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(); }