Skip to content

Commit

Permalink
Enable creation of Mandatory Property Constraints
Browse files Browse the repository at this point in the history
The constraints are not yet validated or enforced. This only supports
creating and dropping the constraints, as well as the storage of the
constraint metadata.
  • Loading branch information
thobe authored and pontusmelke committed Jul 2, 2015
1 parent 3c9410d commit 8d9bedb
Show file tree
Hide file tree
Showing 89 changed files with 1,368 additions and 545 deletions.
Expand Up @@ -27,7 +27,7 @@
import org.neo4j.consistency.store.RecordAccess; import org.neo4j.consistency.store.RecordAccess;
import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException; import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException;
import org.neo4j.kernel.impl.store.SchemaRuleAccess; import org.neo4j.kernel.impl.store.SchemaRuleAccess;
import org.neo4j.kernel.impl.store.UniquenessConstraintRule; import org.neo4j.kernel.impl.store.UniquePropertyConstraintRule;
import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.store.record.IndexRule;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
Expand Down Expand Up @@ -131,15 +131,15 @@ public void check( DynamicRecord record,
checkIndexRule( (IndexRule) rule, engine, record, records ); checkIndexRule( (IndexRule) rule, engine, record, records );
break; break;
case UNIQUENESS_CONSTRAINT: case UNIQUENESS_CONSTRAINT:
checkUniquenessConstraintRule( (UniquenessConstraintRule) rule, engine, record, records ); checkUniquenessConstraintRule( (UniquePropertyConstraintRule) rule, engine, record, records );
break; break;
default: default:
engine.report().unsupportedSchemaRuleKind( kind ); engine.report().unsupportedSchemaRuleKind( kind );
} }
} }
} }


private void checkUniquenessConstraintRule( UniquenessConstraintRule rule, private void checkUniquenessConstraintRule( UniquePropertyConstraintRule rule,
CheckerEngine<DynamicRecord, ConsistencyReport.SchemaConsistencyReport> engine, CheckerEngine<DynamicRecord, ConsistencyReport.SchemaConsistencyReport> engine,
DynamicRecord record, RecordAccess records ) DynamicRecord record, RecordAccess records )
{ {
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/ */
package org.neo4j.consistency.checking; package org.neo4j.consistency.checking;


import org.neo4j.kernel.impl.store.UniquenessConstraintRule; import org.neo4j.kernel.impl.store.UniquePropertyConstraintRule;
import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.store.record.IndexRule;
import org.neo4j.kernel.impl.store.record.SchemaRule; import org.neo4j.kernel.impl.store.record.SchemaRule;


Expand Down Expand Up @@ -63,8 +63,8 @@ public boolean equals( Object obj )
return indexRulesEquals( (IndexRule) this.schemaRule, (IndexRule) that.schemaRule ); return indexRulesEquals( (IndexRule) this.schemaRule, (IndexRule) that.schemaRule );
case UNIQUENESS_CONSTRAINT: case UNIQUENESS_CONSTRAINT:
return this.schemaRule.getKind() == that.schemaRule.getKind() && uniquenessConstraintEquals( return this.schemaRule.getKind() == that.schemaRule.getKind() && uniquenessConstraintEquals(
(UniquenessConstraintRule) this.schemaRule, (UniquePropertyConstraintRule) this.schemaRule,
(UniquenessConstraintRule) that.schemaRule ); (UniquePropertyConstraintRule) that.schemaRule );
default: default:
throw new IllegalArgumentException( "Invalid SchemaRule kind: " + schemaRule.getKind() ); throw new IllegalArgumentException( "Invalid SchemaRule kind: " + schemaRule.getKind() );
} }
Expand All @@ -77,7 +77,7 @@ private static boolean indexRulesEquals( IndexRule lhs, IndexRule rhs )
return lhs.getPropertyKey() == rhs.getPropertyKey(); return lhs.getPropertyKey() == rhs.getPropertyKey();
} }


private static boolean uniquenessConstraintEquals( UniquenessConstraintRule lhs, UniquenessConstraintRule rhs ) private static boolean uniquenessConstraintEquals( UniquePropertyConstraintRule lhs, UniquePropertyConstraintRule rhs )
{ {
return lhs.getPropertyKey() == rhs.getPropertyKey(); return lhs.getPropertyKey() == rhs.getPropertyKey();
} }
Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException; import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException;
import org.neo4j.kernel.api.index.SchemaIndexProvider; import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.impl.store.SchemaStorage; import org.neo4j.kernel.impl.store.SchemaStorage;
import org.neo4j.kernel.impl.store.UniquenessConstraintRule; import org.neo4j.kernel.impl.store.UniquePropertyConstraintRule;
import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.store.record.IndexRule;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
Expand Down Expand Up @@ -126,7 +126,8 @@ public void shouldReportInvalidPropertyReferenceFromUniquenessConstraintRule() t


DynamicRecord record = inUse( dynamicRecord( schemaRuleId ) ); DynamicRecord record = inUse( dynamicRecord( schemaRuleId ) );


UniquenessConstraintRule rule = UniquenessConstraintRule.uniquenessConstraintRule( schemaRuleId, labelId, propertyKeyId, indexRuleId ); UniquePropertyConstraintRule rule = UniquePropertyConstraintRule
.uniquenessConstraintRule( schemaRuleId, labelId, propertyKeyId, indexRuleId );


when( checker().ruleAccess.loadSingleSchemaRule( schemaRuleId ) ).thenReturn( rule ); when( checker().ruleAccess.loadSingleSchemaRule( schemaRuleId ) ).thenReturn( rule );


Expand Down Expand Up @@ -155,7 +156,8 @@ public void shouldReportUniquenessConstraintNotReferencingBack() throws Exceptio
SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor( "in-memory", "1.0" ); SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor( "in-memory", "1.0" );


IndexRule rule1 = IndexRule.constraintIndexRule( ruleId1, labelId, propertyKeyId, providerDescriptor, (long) ruleId2 ); IndexRule rule1 = IndexRule.constraintIndexRule( ruleId1, labelId, propertyKeyId, providerDescriptor, (long) ruleId2 );
UniquenessConstraintRule rule2 = UniquenessConstraintRule.uniquenessConstraintRule( ruleId2, labelId, propertyKeyId, ruleId2 ); UniquePropertyConstraintRule rule2 = UniquePropertyConstraintRule
.uniquenessConstraintRule( ruleId2, labelId, propertyKeyId, ruleId2 );


when( checker().ruleAccess.loadSingleSchemaRule( ruleId1 ) ).thenReturn( rule1 ); when( checker().ruleAccess.loadSingleSchemaRule( ruleId1 ) ).thenReturn( rule1 );
when( checker().ruleAccess.loadSingleSchemaRule( ruleId2 ) ).thenReturn( rule2 ); when( checker().ruleAccess.loadSingleSchemaRule( ruleId2 ) ).thenReturn( rule2 );
Expand Down Expand Up @@ -214,8 +216,10 @@ public void shouldReportTwoUniquenessConstraintsReferencingSameIndex() throws Ex
DynamicRecord record1 = inUse( dynamicRecord( ruleId1 ) ); DynamicRecord record1 = inUse( dynamicRecord( ruleId1 ) );
DynamicRecord record2 = inUse( dynamicRecord( ruleId2 ) ); DynamicRecord record2 = inUse( dynamicRecord( ruleId2 ) );


UniquenessConstraintRule rule1 = UniquenessConstraintRule.uniquenessConstraintRule( ruleId1, labelId, propertyKeyId, ruleId2 ); UniquePropertyConstraintRule rule1 = UniquePropertyConstraintRule
UniquenessConstraintRule rule2 = UniquenessConstraintRule.uniquenessConstraintRule( ruleId2, labelId, propertyKeyId, ruleId2 ); .uniquenessConstraintRule( ruleId1, labelId, propertyKeyId, ruleId2 );
UniquePropertyConstraintRule rule2 = UniquePropertyConstraintRule
.uniquenessConstraintRule( ruleId2, labelId, propertyKeyId, ruleId2 );


when( checker().ruleAccess.loadSingleSchemaRule( ruleId1 ) ).thenReturn( rule1 ); when( checker().ruleAccess.loadSingleSchemaRule( ruleId1 ) ).thenReturn( rule1 );
when( checker().ruleAccess.loadSingleSchemaRule( ruleId2 ) ).thenReturn( rule2 ); when( checker().ruleAccess.loadSingleSchemaRule( ruleId2 ) ).thenReturn( rule2 );
Expand All @@ -241,7 +245,8 @@ public void shouldReportUnreferencedUniquenessConstraint() throws Exception


DynamicRecord record = inUse( dynamicRecord( ruleId ) ); DynamicRecord record = inUse( dynamicRecord( ruleId ) );


UniquenessConstraintRule rule = UniquenessConstraintRule.uniquenessConstraintRule( ruleId, labelId, propertyKeyId, ruleId ); UniquePropertyConstraintRule rule = UniquePropertyConstraintRule
.uniquenessConstraintRule( ruleId, labelId, propertyKeyId, ruleId );


when( checker().ruleAccess.loadSingleSchemaRule( ruleId ) ).thenReturn( rule ); when( checker().ruleAccess.loadSingleSchemaRule( ruleId ) ).thenReturn( rule );


Expand Down Expand Up @@ -271,8 +276,10 @@ public void shouldReportConstraintIndexNotReferencingBack() throws Exception


SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor( "in-memory", "1.0" ); SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor( "in-memory", "1.0" );


IndexRule rule1 = IndexRule.constraintIndexRule( ruleId1, labelId, propertyKeyId, providerDescriptor, (long) ruleId1 ); IndexRule rule1 = IndexRule.constraintIndexRule( ruleId1, labelId, propertyKeyId, providerDescriptor, (long)
UniquenessConstraintRule rule2 = UniquenessConstraintRule.uniquenessConstraintRule( ruleId2, labelId, propertyKeyId, ruleId1 ); ruleId1 );
UniquePropertyConstraintRule rule2 = UniquePropertyConstraintRule
.uniquenessConstraintRule( ruleId2, labelId, propertyKeyId, ruleId1 );


when( checker().ruleAccess.loadSingleSchemaRule( ruleId1 ) ).thenReturn( rule1 ); when( checker().ruleAccess.loadSingleSchemaRule( ruleId1 ) ).thenReturn( rule1 );
when( checker().ruleAccess.loadSingleSchemaRule( ruleId2 ) ).thenReturn( rule2 ); when( checker().ruleAccess.loadSingleSchemaRule( ruleId2 ) ).thenReturn( rule2 );
Expand Down
Expand Up @@ -26,7 +26,7 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;


import static org.neo4j.kernel.impl.store.UniquenessConstraintRule.uniquenessConstraintRule; import static org.neo4j.kernel.impl.store.UniquePropertyConstraintRule.uniquenessConstraintRule;
import static org.neo4j.kernel.impl.store.record.IndexRule.constraintIndexRule; import static org.neo4j.kernel.impl.store.record.IndexRule.constraintIndexRule;
import static org.neo4j.kernel.impl.store.record.IndexRule.indexRule; import static org.neo4j.kernel.impl.store.record.IndexRule.indexRule;


Expand Down
Expand Up @@ -75,7 +75,7 @@
import org.neo4j.kernel.impl.store.RecordStore; import org.neo4j.kernel.impl.store.RecordStore;
import org.neo4j.kernel.impl.store.SchemaStorage; import org.neo4j.kernel.impl.store.SchemaStorage;
import org.neo4j.kernel.impl.store.StoreAccess; import org.neo4j.kernel.impl.store.StoreAccess;
import org.neo4j.kernel.impl.store.UniquenessConstraintRule; import org.neo4j.kernel.impl.store.UniquePropertyConstraintRule;
import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.store.record.IndexRule;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
Expand Down Expand Up @@ -856,7 +856,8 @@ protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx,
SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor( "lucene", "1.0" ); SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor( "lucene", "1.0" );


IndexRule rule1 = IndexRule.constraintIndexRule( ruleId1, labelId, propertyKeyId, providerDescriptor, (long) ruleId2 ); IndexRule rule1 = IndexRule.constraintIndexRule( ruleId1, labelId, propertyKeyId, providerDescriptor, (long) ruleId2 );
UniquenessConstraintRule rule2 = UniquenessConstraintRule.uniquenessConstraintRule( ruleId2, labelId, propertyKeyId, ruleId2 ); UniquePropertyConstraintRule rule2 = UniquePropertyConstraintRule
.uniquenessConstraintRule( ruleId2, labelId, propertyKeyId, ruleId2 );




Collection<DynamicRecord> records1 = serializeRule( rule1, record1 ); Collection<DynamicRecord> records1 = serializeRule( rule1, record1 );
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/ */
package org.neo4j.cypher.internal.compiler.v2_3.spi package org.neo4j.cypher.internal.compiler.v2_3.spi


import org.neo4j.kernel.api.constraints.UniquenessConstraint import org.neo4j.kernel.api.constraints.PropertyConstraint
import org.neo4j.kernel.api.index.IndexDescriptor import org.neo4j.kernel.api.index.IndexDescriptor


/** /**
Expand All @@ -35,7 +35,7 @@ trait PlanContext extends TokenContext {


def getUniqueIndexRule(labelName: String, propertyKey: String): Option[IndexDescriptor] def getUniqueIndexRule(labelName: String, propertyKey: String): Option[IndexDescriptor]


def getUniquenessConstraint(labelName: String, propertyKey: String): Option[UniquenessConstraint] def getUniquenessConstraint(labelName: String, propertyKey: String): Option[PropertyConstraint]


def checkNodeIndex(idxName: String) def checkNodeIndex(idxName: String)


Expand Down
Expand Up @@ -21,7 +21,7 @@ package org.neo4j.cypher.internal.compiler.v2_3.spi


import org.neo4j.cypher.internal.compiler.v2_3.InternalQueryStatistics import org.neo4j.cypher.internal.compiler.v2_3.InternalQueryStatistics
import org.neo4j.graphdb._ import org.neo4j.graphdb._
import org.neo4j.kernel.api.constraints.UniquenessConstraint import org.neo4j.kernel.api.constraints.{MandatoryPropertyConstraint, UniquenessConstraint}
import org.neo4j.kernel.api.index.IndexDescriptor import org.neo4j.kernel.api.index.IndexDescriptor


/* /*
Expand Down Expand Up @@ -95,7 +95,7 @@ trait QueryContext extends TokenContext {


def dropUniqueConstraint(labelId: Int, propertyKeyId: Int) def dropUniqueConstraint(labelId: Int, propertyKeyId: Int)


def createMandatoryConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint]//TODO add MandatoryConstraint when doing kernel work def createMandatoryConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[MandatoryPropertyConstraint]


def dropMandatoryConstraint(labelId: Int, propertyKeyId: Int) def dropMandatoryConstraint(labelId: Int, propertyKeyId: Int)


Expand Down
Expand Up @@ -33,7 +33,7 @@ import org.neo4j.cypher.internal.compiler.v2_3.pipes.FakePipe
import org.neo4j.cypher.internal.compiler.v2_3.spi.PlanContext import org.neo4j.cypher.internal.compiler.v2_3.spi.PlanContext
import org.neo4j.cypher.internal.compiler.v2_3.symbols._ import org.neo4j.cypher.internal.compiler.v2_3.symbols._
import org.neo4j.graphdb.Direction import org.neo4j.graphdb.Direction
import org.neo4j.kernel.api.constraints.UniquenessConstraint import org.neo4j.kernel.api.constraints.{UniquenessConstraint, PropertyConstraint}
import org.neo4j.kernel.api.index.IndexDescriptor import org.neo4j.kernel.api.index.IndexDescriptor


class StartPointChoosingBuilderTest extends BuilderTest { class StartPointChoosingBuilderTest extends BuilderTest {
Expand Down
Expand Up @@ -36,7 +36,7 @@ import org.neo4j.cypher.internal.compiler.v2_3.spi.{GraphStatistics, PlanContext
import org.neo4j.cypher.internal.compiler.v2_3.test_helpers.{CypherFunSuite, CypherTestSupport} import org.neo4j.cypher.internal.compiler.v2_3.test_helpers.{CypherFunSuite, CypherTestSupport}
import org.neo4j.cypher.internal.compiler.v2_3.tracing.rewriters.RewriterStepSequencer import org.neo4j.cypher.internal.compiler.v2_3.tracing.rewriters.RewriterStepSequencer
import org.neo4j.helpers.collection.Visitable import org.neo4j.helpers.collection.Visitable
import org.neo4j.kernel.api.constraints.UniquenessConstraint import org.neo4j.kernel.api.constraints.{UniquenessConstraint, PropertyConstraint}
import org.neo4j.kernel.api.index.IndexDescriptor import org.neo4j.kernel.api.index.IndexDescriptor
import org.neo4j.kernel.impl.util.dbstructure.DbStructureVisitor import org.neo4j.kernel.impl.util.dbstructure.DbStructureVisitor


Expand Down Expand Up @@ -95,7 +95,7 @@ trait LogicalPlanningTestSupport2 extends CypherTestSupport with AstConstruction
else else
None None


def getUniquenessConstraint(labelName: String, propertyKey: String): Option[UniquenessConstraint] = { def getUniquenessConstraint(labelName: String, propertyKey: String): Option[PropertyConstraint] = {
if (config.uniqueIndexes((labelName, propertyKey))) if (config.uniqueIndexes((labelName, propertyKey)))
Some(new UniquenessConstraint( Some(new UniquenessConstraint(
semanticTable.resolvedLabelIds(labelName).id, semanticTable.resolvedLabelIds(labelName).id,
Expand Down
Expand Up @@ -26,7 +26,7 @@ import org.mockito.stubbing.Answer
import org.neo4j.cypher.internal.compiler.v2_3.InternalQueryStatistics import org.neo4j.cypher.internal.compiler.v2_3.InternalQueryStatistics
import org.neo4j.cypher.internal.compiler.v2_3.test_helpers.CypherFunSuite import org.neo4j.cypher.internal.compiler.v2_3.test_helpers.CypherFunSuite
import org.neo4j.graphdb.{Node, Relationship} import org.neo4j.graphdb.{Node, Relationship}
import org.neo4j.kernel.api.constraints.UniquenessConstraint import org.neo4j.kernel.api.constraints.{MandatoryPropertyConstraint, UniquenessConstraint}
import org.neo4j.kernel.api.index.IndexDescriptor import org.neo4j.kernel.api.index.IndexDescriptor


class UpdateCountingQueryContextTest extends CypherFunSuite { class UpdateCountingQueryContextTest extends CypherFunSuite {
Expand Down Expand Up @@ -61,7 +61,7 @@ class UpdateCountingQueryContextTest extends CypherFunSuite {
.thenReturn(IdempotentResult(mock[UniquenessConstraint])) .thenReturn(IdempotentResult(mock[UniquenessConstraint]))


when( inner.createMandatoryConstraint(anyInt(), anyInt()) ) when( inner.createMandatoryConstraint(anyInt(), anyInt()) )
.thenReturn(IdempotentResult(mock[UniquenessConstraint])) .thenReturn(IdempotentResult(mock[MandatoryPropertyConstraint]))


when( inner.addIndexRule(anyInt(), anyInt()) ) when( inner.addIndexRule(anyInt(), anyInt()) )
.thenReturn(IdempotentResult(mock[IndexDescriptor])) .thenReturn(IdempotentResult(mock[IndexDescriptor]))
Expand Down
Expand Up @@ -61,8 +61,10 @@ class TransactionBoundPlanContext(someStatement: Statement, val gdb: GraphDataba
val labelId = statement.readOperations().labelGetForName(labelName) val labelId = statement.readOperations().labelGetForName(labelName)
val propertyKeyId = statement.readOperations().propertyKeyGetForName(propertyKey) val propertyKeyId = statement.readOperations().propertyKeyGetForName(propertyKey)


val matchingConstraints = statement.readOperations().constraintsGetForLabelAndPropertyKey(labelId, propertyKeyId) import scala.collection.JavaConverters._
if ( matchingConstraints.hasNext ) Some(matchingConstraints.next()) else None statement.readOperations().constraintsGetForLabelAndPropertyKey(labelId, propertyKeyId).asScala.collectFirst {
case unique: UniquenessConstraint => unique
}
} catch { } catch {
case _: KernelException => None case _: KernelException => None
} }
Expand Down
Expand Up @@ -27,7 +27,6 @@ import org.neo4j.cypher.internal.compiler.v2_3.helpers.JavaConversionSupport._
import org.neo4j.graphdb.DynamicRelationshipType._ import org.neo4j.graphdb.DynamicRelationshipType._
import org.neo4j.graphdb._ import org.neo4j.graphdb._
import org.neo4j.graphdb.factory.GraphDatabaseSettings import org.neo4j.graphdb.factory.GraphDatabaseSettings
import org.neo4j.helpers.collection.IteratorUtil
import org.neo4j.kernel.GraphDatabaseAPI import org.neo4j.kernel.GraphDatabaseAPI
import org.neo4j.kernel.api._ import org.neo4j.kernel.api._
import org.neo4j.kernel.api.constraints.UniquenessConstraint import org.neo4j.kernel.api.constraints.UniquenessConstraint
Expand Down Expand Up @@ -281,12 +280,10 @@ final class TransactionBoundQueryContext(graph: GraphDatabaseAPI,
statement.schemaWriteOperations().indexDrop(new IndexDescriptor(labelId, propertyKeyId)) statement.schemaWriteOperations().indexDrop(new IndexDescriptor(labelId, propertyKeyId))


def createUniqueConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint] = try { def createUniqueConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint] = try {
IdempotentResult(statement.schemaWriteOperations().uniquenessConstraintCreate(labelId, propertyKeyId)) IdempotentResult(statement.schemaWriteOperations().uniquePropertyConstraintCreate(labelId, propertyKeyId))
} catch { } catch {
case _: AlreadyConstrainedException => case existing: AlreadyConstrainedException =>
val readOperations: ReadOperations = statement.readOperations() IdempotentResult(existing.constraint().asInstanceOf[UniquenessConstraint], wasCreated = false)
val uniquenessConstraints = readOperations.constraintsGetForLabelAndPropertyKey(labelId, propertyKeyId)
IdempotentResult(IteratorUtil.single(uniquenessConstraints), wasCreated = false)
} }


def dropUniqueConstraint(labelId: Int, propertyKeyId: Int) = def dropUniqueConstraint(labelId: Int, propertyKeyId: Int) =
Expand Down
Expand Up @@ -24,7 +24,7 @@ import org.neo4j.cypher.internal.compiler.v2_3.spi._
import org.neo4j.graphdb.GraphDatabaseService import org.neo4j.graphdb.GraphDatabaseService
import org.neo4j.kernel.GraphDatabaseAPI import org.neo4j.kernel.GraphDatabaseAPI
import org.neo4j.kernel.api.Statement import org.neo4j.kernel.api.Statement
import org.neo4j.kernel.api.constraints.UniquenessConstraint import org.neo4j.kernel.api.constraints.PropertyConstraint
import org.neo4j.kernel.api.exceptions.KernelException import org.neo4j.kernel.api.exceptions.KernelException
import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException
import org.neo4j.kernel.api.index.{IndexDescriptor, InternalIndexState} import org.neo4j.kernel.api.index.{IndexDescriptor, InternalIndexState}
Expand Down Expand Up @@ -57,7 +57,7 @@ class TransactionBoundPlanContext(initialStatement: Statement, val gdb: GraphDat
case _ => None case _ => None
} }


def getUniquenessConstraint(labelName: String, propertyKey: String): Option[UniquenessConstraint] = try { def getUniquenessConstraint(labelName: String, propertyKey: String): Option[PropertyConstraint] = try {
val labelId = statement.readOperations().labelGetForName(labelName) val labelId = statement.readOperations().labelGetForName(labelName)
val propertyKeyId = statement.readOperations().propertyKeyGetForName(propertyKey) val propertyKeyId = statement.readOperations().propertyKeyGetForName(propertyKey)


Expand Down
Expand Up @@ -30,10 +30,9 @@ import org.neo4j.cypher.internal.compiler.v2_3.{EntityNotFoundException, FailedI
import org.neo4j.graphdb.DynamicRelationshipType._ import org.neo4j.graphdb.DynamicRelationshipType._
import org.neo4j.graphdb._ import org.neo4j.graphdb._
import org.neo4j.graphdb.factory.GraphDatabaseSettings import org.neo4j.graphdb.factory.GraphDatabaseSettings
import org.neo4j.helpers.collection.IteratorUtil
import org.neo4j.kernel.GraphDatabaseAPI import org.neo4j.kernel.GraphDatabaseAPI
import org.neo4j.kernel.api._ import org.neo4j.kernel.api._
import org.neo4j.kernel.api.constraints.UniquenessConstraint import org.neo4j.kernel.api.constraints.{MandatoryPropertyConstraint, UniquenessConstraint}
import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException} import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException}
import org.neo4j.kernel.api.index.{IndexDescriptor, InternalIndexState} import org.neo4j.kernel.api.index.{IndexDescriptor, InternalIndexState}
import org.neo4j.kernel.configuration.Config import org.neo4j.kernel.configuration.Config
Expand Down Expand Up @@ -297,22 +296,24 @@ final class TransactionBoundQueryContext(graph: GraphDatabaseAPI,
statement.schemaWriteOperations().indexDrop(new IndexDescriptor(labelId, propertyKeyId)) statement.schemaWriteOperations().indexDrop(new IndexDescriptor(labelId, propertyKeyId))


def createUniqueConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint] = try { def createUniqueConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint] = try {
IdempotentResult(statement.schemaWriteOperations().uniquenessConstraintCreate(labelId, propertyKeyId)) IdempotentResult(statement.schemaWriteOperations().uniquePropertyConstraintCreate(labelId, propertyKeyId))
} catch { } catch {
case _: AlreadyConstrainedException => case existing: AlreadyConstrainedException =>
val readOperations: ReadOperations = statement.readOperations() IdempotentResult(existing.constraint().asInstanceOf[UniquenessConstraint], wasCreated = false)
val uniquenessConstraints = readOperations.constraintsGetForLabelAndPropertyKey(labelId, propertyKeyId)
IdempotentResult(IteratorUtil.single(uniquenessConstraints), wasCreated = false)
} }


def dropUniqueConstraint(labelId: Int, propertyKeyId: Int) = def dropUniqueConstraint(labelId: Int, propertyKeyId: Int) =
statement.schemaWriteOperations().constraintDrop(new UniquenessConstraint(labelId, propertyKeyId)) statement.schemaWriteOperations().constraintDrop(new UniquenessConstraint(labelId, propertyKeyId))


//TODO implement def createMandatoryConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[MandatoryPropertyConstraint] = try {
def createMandatoryConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint] = ??? IdempotentResult(statement.schemaWriteOperations().mandatoryPropertyConstraintCreate(labelId, propertyKeyId))
} catch {
case existing: AlreadyConstrainedException =>
IdempotentResult(existing.constraint().asInstanceOf[MandatoryPropertyConstraint], wasCreated = false)
}


//TODO implement def dropMandatoryConstraint(labelId: Int, propertyKeyId: Int) =
def dropMandatoryConstraint(labelId: Int, propertyKeyId: Int) = ??? statement.schemaWriteOperations().constraintDrop(new MandatoryPropertyConstraint(labelId, propertyKeyId))


override def hasLocalFileAccess: Boolean = graph match { override def hasLocalFileAccess: Boolean = graph match {
case db: GraphDatabaseAPI => db.getDependencyResolver.resolveDependency(classOf[Config]).get(GraphDatabaseSettings.allow_file_urls) case db: GraphDatabaseAPI => db.getDependencyResolver.resolveDependency(classOf[Config]).get(GraphDatabaseSettings.allow_file_urls)
Expand Down

0 comments on commit 8d9bedb

Please sign in to comment.