//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void newSlaveJoiningClusterShouldNotAcceptOperationsUntilConstraintIsOnline() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void NewSlaveJoiningClusterShouldNotAcceptOperationsUntilConstraintIsOnline() { // Given ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); string type = type(4); string key = key(4); HighlyAvailableGraphDatabase master = cluster.Master; HighlyAvailableGraphDatabase slave = cluster.AnySlave; File slaveStoreDirectory = cluster.GetDatabaseDir(slave); // Crash the slave ClusterManager.RepairKit shutdownSlave = cluster.Shutdown(slave); deleteRecursively(slaveStoreDirectory); using (Transaction tx = master.BeginTx()) { CreateConstraint(master, type, key); tx.Success(); } // When slave = shutdownSlave.Repair(); // Then using (Transaction ignored = slave.BeginTx()) { ConstraintDefinition definition = GetConstraint(slave, type, key); assertThat(definition, instanceOf(ConstraintDefinitionClass())); assertThat(single(definition.PropertyKeys), equalTo(key)); ValidateLabelOrRelationshipType(definition, type); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void concurrentCreatingUniquenessConstraint() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ConcurrentCreatingUniquenessConstraint() { // given Race race = (new Race()).withMaxDuration(10, SECONDS); Label label = label(0); race.AddContestants(10, () => { try { using (Transaction tx = Db.beginTx()) { Db.schema().constraintFor(label).assertPropertyIsUnique(KEY).create(); tx.Success(); } } catch (Exception e) when(e is TransientFailureException || e is ConstraintViolationException) { // It's OK } }, 300); // when race.Go(); using (Transaction tx = Db.beginTx()) { // then ConstraintDefinition constraint = single(Db.schema().getConstraints(label)); assertNotNull(constraint); IndexDefinition index = single(Db.schema().getIndexes(label)); assertNotNull(index); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCreateConstraintOnMaster() public virtual void ShouldCreateConstraintOnMaster() { // given ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); HighlyAvailableGraphDatabase master = cluster.Master; string type = type(0); string key = key(0); // when using (Transaction tx = master.BeginTx()) { CreateConstraint(master, type, key); tx.Success(); } cluster.Sync(); // then foreach (HighlyAvailableGraphDatabase clusterMember in cluster.AllMembers) { using (Transaction tx = clusterMember.BeginTx()) { ConstraintDefinition constraint = GetConstraint(clusterMember, type, key); ValidateLabelOrRelationshipType(constraint, type); assertEquals(key, single(constraint.PropertyKeys)); tx.Success(); } } }
protected internal virtual void Serialize(ConstraintDefinition constraintDefinition, MappingSerializer serializer) { System.Func <string, Representation> converter = ValueRepresentation.@string; IEnumerable <Representation> propertyKeyRepresentations = map(converter, constraintDefinition.PropertyKeys); serializer.PutList("property_keys", new ListRepresentation(RepresentationType.String, propertyKeyRepresentations)); }
private void VerifyConstraints(GraphDatabaseAPI db, ConstraintType expectedConstraintType) { using (Transaction tx = Db.beginTx()) { // only one index IEnumerator <ConstraintDefinition> constraints = Db.schema().Constraints.GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("has one index", constraints.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: ConstraintDefinition constraint = constraints.next(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse("not more than one index", constraints.hasNext()); Label label = constraint.Label; string property = constraint.PropertyKeys.GetEnumerator().next(); ConstraintType constraintType = constraint.ConstraintType; // with correct pattern and provider assertEquals("correct label", "Person", label.Name()); assertEquals("correct property", "name", property); assertEquals("correct constraint type", expectedConstraintType, constraintType); tx.Success(); } }
public ConstraintDefinition EmitDefinition(EmitMode mode) { if (mode == EmitMode.ForStorage) { SaveObjectID(); } else { RemoveObjectID(); } try { ConstraintDefinition statement = new ConstraintDefinition(); statement.ConstraintName = Name; statement.MetaData = MetaData == null ? null : MetaData.Copy(); statement.Expression = (Expression)Node.EmitStatement(mode); return(statement); } finally { if (mode == EmitMode.ForStorage) { RemoveObjectID(); } } }
public SqliteConstraintWriterTests() { _sb = new StringBuilder(); _key = new UniqueKeyConstraint() { Columns = "id, user name", Name = "PK_Id" }; }
public override Statement EmitDefinition(EmitMode mode) { ConstraintDefinition statement = new ConstraintDefinition(); statement.ConstraintName = Name; statement.MetaData = MetaData == null ? null : MetaData.Copy(); statement.Expression = (Expression)Node.EmitStatement(mode); return(statement); }
private ConstraintDefinition Recreate(ConstraintDefinition constraint, int times) { for (int i = 0; i < times; i++) { constraint.Drop(); constraint = _graphDb.schema().constraintFor(constraint.Label).assertPropertyIsUnique(single(constraint.PropertyKeys)).create(); } return(constraint); }
private ConstraintDefinition CreateLabelUniquenessPropertyConstraint(string labelName, string propertyKey) { using (Transaction tx = Graphdb().beginTx()) { ConstraintDefinition constraintDefinition = Graphdb().schema().constraintFor(label(labelName)).assertPropertyIsUnique(propertyKey).create(); tx.Success(); return(constraintDefinition); } }
private bool AreSameConstraint(ConstraintDefinition fromConstraint, ConstraintDefinition toConstraint) { return(fromConstraint.ConstraintName == toConstraint.ConstraintName && fromConstraint.IsPrimaryKeyConstraint == toConstraint.IsPrimaryKeyConstraint && fromConstraint.IsUniqueConstraint == toConstraint.IsUniqueConstraint && fromConstraint.TableName == toConstraint.TableName && fromConstraint.SchemaName == toConstraint.SchemaName && MatchStrings(fromConstraint.Columns, toConstraint.Columns)); }
public override void Visit(ConstraintDefinition node) { if (NamedConstraintExists) { return; } NamedConstraintExists = node.ConstraintIdentifier != null; }
public override void Visit(ConstraintDefinition a) { if (a.ConstraintIdentifier == null) sw.WriteLine("<Constraint>"); else sw.WriteLine("<Constraint id='" + a.ConstraintIdentifier.Value + "'>"); a.AcceptChildren(this); sw.WriteLine("</Constraint>"); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void recoverFromHalfConstraintAppliedBeforeCrash(System.Action<org.neo4j.kernel.internal.GraphDatabaseAPI,java.util.List<org.neo4j.kernel.impl.transaction.TransactionRepresentation>> applier, System.Action<org.neo4j.kernel.internal.GraphDatabaseAPI> constraintCreator, boolean composite) throws Exception private void RecoverFromHalfConstraintAppliedBeforeCrash(System.Action <GraphDatabaseAPI, IList <TransactionRepresentation> > applier, System.Action <GraphDatabaseAPI> constraintCreator, bool composite) { // GIVEN IList <TransactionRepresentation> transactions = CreateTransactionsForCreatingConstraint(constraintCreator); GraphDatabaseAPI db = NewDb(); EphemeralFileSystemAbstraction crashSnapshot; try { Apply(db, transactions.subList(0, transactions.Count - 1)); FlushStores(db); crashSnapshot = Fs.snapshot(); } finally { Db.shutdown(); } // WHEN db = ( GraphDatabaseAPI )(new TestEnterpriseGraphDatabaseFactory()).setFileSystem(crashSnapshot).newImpermanentDatabase(); try { applier(db, transactions); // THEN using (Transaction tx = Db.beginTx()) { ConstraintDefinition constraint = single(Db.schema().getConstraints(LABEL)); assertEquals(LABEL.Name(), constraint.Label.name()); if (composite) { assertEquals(Arrays.asList(KEY, KEY2), Iterables.asList(constraint.PropertyKeys)); } else { assertEquals(KEY, single(constraint.PropertyKeys)); } IndexDefinition index = single(Db.schema().getIndexes(LABEL)); assertEquals(LABEL.Name(), single(index.Labels).name()); if (composite) { assertEquals(Arrays.asList(KEY, KEY2), Iterables.asList(index.PropertyKeys)); } else { assertEquals(KEY, single(index.PropertyKeys)); } tx.Success(); } } finally { Db.shutdown(); } }
public void WhenDefaultSchemaConventionIsAppliedAndSchemaIsSetThenSchemaShouldNotBeChanged() { var constraintDefinition = new ConstraintDefinition(ConstraintType.PrimaryKey) { ConstraintName = "Test", SchemaName = "testschema" }; constraintDefinition.ApplyConventions(new MigrationConventions()); Assert.That(constraintDefinition.SchemaName, Is.EqualTo("testschema")); }
internal static void ValidateLabelOrRelationshipType(ConstraintDefinition constraint, string type) { if (constraint.IsConstraintType(ConstraintType.RELATIONSHIP_PROPERTY_EXISTENCE)) { assertEquals(type, constraint.RelationshipType.name()); } else { assertEquals(type, constraint.Label.name()); } }
public void WhenDefaultSchemaConventionIsAppliedAndSchemaIsNotSetThenSchemaShouldBeNull() { var constraintDefinition = new ConstraintDefinition(ConstraintType.PrimaryKey) { ConstraintName = "Test" }; constraintDefinition.ApplyConventions(new MigrationConventions()); Assert.That(constraintDefinition.SchemaName, Is.Null); }
private static string GetConstraintName(ConstraintDefinition expression) { var sb = new StringBuilder(); sb.Append(expression.IsPrimaryKeyConstraint ? "PK_" : "UC_"); sb.Append(expression.TableName); foreach (var column in expression.Columns) { sb.Append('_').Append(column); } return(sb.ToString()); }
public virtual void DropConstraint() { Data.get(); string labelName = _labels.newInstance(); string propertyKey = _properties.newInstance(); ConstraintDefinition constraintDefinition = CreateLabelUniquenessPropertyConstraint(labelName, propertyKey); assertThat(getConstraints(Graphdb(), label(labelName)), containsOnly(constraintDefinition)); GenConflict.get().expectedStatus(204).delete(GetSchemaConstraintLabelUniquenessPropertyUri(labelName, propertyKey)).entity(); assertThat(getConstraints(Graphdb(), label(labelName)), Empty); }
public void WhenDefaultSchemaConventionIsChangedAndSchemaIsNotSetThenSetSchema() { var constraintDefinition = new ConstraintDefinition(ConstraintType.PrimaryKey) { ConstraintName = "Test" }; var migrationConventions = new MigrationConventions { GetDefaultSchema = () => "testdefault" }; constraintDefinition.ApplyConventions(migrationConventions); Assert.That(constraintDefinition.SchemaName, Is.EqualTo("testdefault")); }
public virtual ConstraintDefinition CreatePropertyUniquenessConstraint(string labelName, IList <string> propertyKeys) { using (Transaction tx = _database.Graph.beginTransaction(@implicit, AUTH_DISABLED)) { ConstraintCreator creator = _database.Graph.schema().constraintFor(label(labelName)); foreach (string propertyKey in propertyKeys) { creator = creator.AssertPropertyIsUnique(propertyKey); } ConstraintDefinition result = creator.Create(); tx.Success(); return(result); } }
private static string GetNameOrInfer(string table, ConstraintDefinition constraint) { if (!constraint.Identifier.IsEmpty) { return(constraint.Identifier.Get()); } switch (constraint.ColumnConstraint) { case PrimaryKeyConstraint p: return($"{table}_{string.Join("_", p.Columns)}_pkey"); } return("undefined"); }
private ConstraintDefinition GetConstraint(Label label, string propertyKey) { using (Transaction tx = _graphDb.beginTx()) { ConstraintDefinition found = null; foreach (ConstraintDefinition constraint in _graphDb.schema().getConstraints(label)) { if (propertyKey.Equals(single(constraint.PropertyKeys))) { assertNull("Found multiple constraints.", found); found = constraint; } } tx.Success(); return(found); } }
private static void SetupConstraints <T>(ConstraintDefinition c, IValueSchema <object> schema) { if (c == null) { return; } if (!string.IsNullOrEmpty(c.DefaultValue)) { schema.DefaultValue = JsonConvert.DeserializeObject <T>(c.DefaultValue); } if (c.PossibleValues != null) { schema.PossibleValues = c.PossibleValues.Select(JsonConvert.DeserializeObject <T>).Cast <object>().ToArray(); } schema.DisplayHint = c.DisplayHint.ToString(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void convertConstraintToIndex() public virtual void ConvertConstraintToIndex() { using (Transaction tx = _graphDb.beginTx()) { _graphDb.schema().constraintFor(_label).assertPropertyIsUnique(PROPERTY_KEY).create(); tx.Success(); } using (Transaction tx = _graphDb.beginTx()) { ConstraintDefinition constraint = firstOrNull(_graphDb.schema().getConstraints(_label)); constraint.Drop(); _graphDb.schema().indexFor(_label).on(PROPERTY_KEY).create(); tx.Success(); } // assert no exception is thrown }
public static string GetConstraintName(ConstraintDefinition expression) { StringBuilder sb = new StringBuilder(); if (expression.IsPrimaryKeyConstraint) { sb.Append("PK_"); } else { sb.Append("UC_"); } sb.Append(expression.TableName); foreach (var column in expression.Columns) { sb.Append("_" + column); } return sb.ToString(); }
protected virtual void Write(ConstraintDefinition constraint) { _definition = constraint; constraint.Options.Use(Engine); if (constraint.IsRedefined(Engine)) { Builder.Append(constraint.GetDefinition(Engine)); return; } Builder.Append(" CONSTRAINT"); var name = ConstraintName(constraint.Name); if (!name.IsNullOrEmpty()) { Builder.AppendFormat(" {0} ", name); } WriteConstraintType(); Builder.Append(" ("); WriteConstraintFeature(); Builder.Append(")"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleCheckExistenceOfConstraints() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleCheckExistenceOfConstraints() { // GIVEN using (Org.Neo4j.Graphdb.Transaction tx = graphDb.beginTx()) { graphDb.schema().constraintFor(label("FOO")).assertPropertyIsUnique("prop1").create(); ConstraintDefinition dropped = graphDb.schema().constraintFor(label("FOO")).assertPropertyIsUnique("prop2").create(); dropped.Drop(); tx.Success(); } using (Transaction tx = beginTransaction()) { int label = tx.tokenWrite().labelGetOrCreateForName("FOO"); int prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop1"); int prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop2"); // THEN assertTrue(tx.schemaRead().constraintExists(UniqueConstraintDescriptor(label, prop1))); assertFalse(tx.schemaRead().constraintExists(UniqueConstraintDescriptor(label, prop2))); } }
public static string GetConstraintName(this ConstraintDefinition constraint) { string ret = null; if (constraint == null) { return(null); } switch (constraint) { case DefaultConstraintDefinition defaultConstraint: ret = defaultConstraint.ConstraintIdentifier?.Value; break; case UniqueConstraintDefinition uniqueConstraint: ret = uniqueConstraint.ConstraintIdentifier?.Value; break; case ForeignKeyConstraintDefinition foreignKeyConstraint: ret = foreignKeyConstraint.ConstraintIdentifier?.Value; break; case CheckConstraintDefinition checkConstraint: ret = checkConstraint.ConstraintIdentifier?.Value; break; case NullableConstraintDefinition nullableConstraint: ret = null; break; default: throw new ApplicationException("Unable to determine constraint name"); } return(ret); }
private WConstraintDefinition ParseConstraintDefinition(ConstraintDefinition consDef) { if (consDef == null) return null; WConstraintDefinition wConsDef = null; switch (consDef.GetType().Name) { case "CheckConstraintDefinition": { var checkConsDef = consDef as CheckConstraintDefinition; wConsDef = new WCheckConstraintDefinition { ConstraintIdentifier = checkConsDef.ConstraintIdentifier, CheckCondition = ParseBooleanExpression(checkConsDef.CheckCondition), NotForReplication = checkConsDef.NotForReplication }; break; } case "DefaultConstraintDefinition": { var defaultConsDef = consDef as DefaultConstraintDefinition; wConsDef = new WDefaultConstraintDefinition { ConstraintIdentifier = defaultConsDef.ConstraintIdentifier, Expression = ParseScalarExpression(defaultConsDef.Expression), Column = defaultConsDef.Column, WithValues = defaultConsDef.WithValues, }; break; } case "ForeignKeyConstraintDefinition": { var foreignConsDef = consDef as ForeignKeyConstraintDefinition; var wForeignConsDef = new WForeignKeyConstraintDefinition { ConstraintIdentifier = foreignConsDef.ConstraintIdentifier, ReferenceTableName = ParseSchemaObjectName(foreignConsDef.ReferenceTableName), DeleteAction = foreignConsDef.DeleteAction, UpdateAction = foreignConsDef.UpdateAction, NotForReplication = foreignConsDef.NotForReplication, }; if (foreignConsDef.Columns != null) { wForeignConsDef.Columns = new List<Identifier>(foreignConsDef.Columns.Count); foreach (var col in foreignConsDef.Columns) wForeignConsDef.Columns.Add(col); } if (foreignConsDef.ReferencedTableColumns != null) { wForeignConsDef.ReferencedTableColumns = new List<Identifier>(foreignConsDef.ReferencedTableColumns.Count); foreach (var col in foreignConsDef.ReferencedTableColumns) wForeignConsDef.ReferencedTableColumns.Add(col); } wConsDef = wForeignConsDef; break; } case "NullableConstraintDefinition": { var nullConsDef = consDef as NullableConstraintDefinition; wConsDef = new WNullableConstraintDefinition { ConstraintIdentifier = nullConsDef.ConstraintIdentifier, Nullable = nullConsDef.Nullable, }; break; } case "UniqueConstraintDefinition": { var uniqConsDef = consDef as UniqueConstraintDefinition; var wUniqConsDef = new WUniqueConstraintDefinition { ConstraintIdentifier = uniqConsDef.ConstraintIdentifier, Clustered = uniqConsDef.Clustered, IsPrimaryKey = uniqConsDef.IsPrimaryKey, }; if (uniqConsDef.Columns != null) { wUniqConsDef.Columns = new List<Tuple<WColumnReferenceExpression, SortOrder>>(); foreach (var col in uniqConsDef.Columns) { wUniqConsDef.Columns.Add(new Tuple<WColumnReferenceExpression, SortOrder>( new WColumnReferenceExpression { ColumnType = col.Column.ColumnType, MultiPartIdentifier = ParseMultiPartIdentifier(col.Column.MultiPartIdentifier), FirstTokenIndex = col.Column.FirstTokenIndex, LastTokenIndex = col.Column.LastTokenIndex, }, col.SortOrder)); } } wConsDef = wUniqConsDef; break; } } return wConsDef; }
public void AddConstraint(ConstraintDefinition constraintDefinition) { Constraints.Add(constraintDefinition); }
public override void ExplicitVisit(ConstraintDefinition node) { this.action(node); }
/// <summary> /// Initializes a new instance of the <see cref="DeleteConstraintExpression" /> class. /// </summary> public DeleteConstraintExpression(ConstraintType type) { Constraint = new ConstraintDefinition(type); }
public override void ExplicitVisit(ConstraintDefinition fragment) { _fragments.Add(fragment); }