internal virtual void AddSchemaRule(SchemaRule rule) { if (rule is ConstraintRule) { ConstraintRule constraintRule = ( ConstraintRule )rule; ConstraintRuleById.put(constraintRule.Id, constraintRule); ConstraintsConflict.Add(ConstraintSemantics.readConstraint(constraintRule)); } else if (rule is StoreIndexDescriptor) { CapableIndexDescriptor index = IndexProviderMap.withCapabilities(( StoreIndexDescriptor )rule); IndexDescriptorById.put(index.Id, index); SchemaDescriptor schemaDescriptor = index.Schema(); IndexDescriptorsConflict[schemaDescriptor] = index; IndexDescriptorsByName[rule.Name] = index; foreach (int entityTokenId in schemaDescriptor.EntityTokenIds) { //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: ISet <CapableIndexDescriptor> forLabel = IndexDescriptorsByLabel.getIfAbsentPut(entityTokenId, HashSet <object>::new); forLabel.Add(index); } foreach (int propertyId in index.Schema().PropertyIds) { //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: IList <CapableIndexDescriptor> indexesForProperty = IndexByProperty.getIfAbsentPut(propertyId, List <object>::new); indexesForProperty.Add(index); } } }
public override void IndexDoUpdateEntry(SchemaDescriptor descriptor, long nodeId, ValueTuple propertiesBefore, ValueTuple propertiesAfter) { NodeStateImpl nodeState = GetOrCreateNodeState(nodeId); IDictionary <ValueTuple, MutableLongDiffSets> updates = GetOrCreateIndexUpdatesByDescriptor(descriptor); if (propertiesBefore != null) { MutableLongDiffSets before = GetOrCreateIndexUpdatesForSeek(updates, propertiesBefore); //noinspection ConstantConditions before.Remove(nodeId); if (before.Removed.contains(nodeId)) { nodeState.AddIndexDiff(before); } else { nodeState.RemoveIndexDiff(before); } } if (propertiesAfter != null) { MutableLongDiffSets after = GetOrCreateIndexUpdatesForSeek(updates, propertiesAfter); //noinspection ConstantConditions after.Add(nodeId); if (after.Added.contains(nodeId)) { nodeState.AddIndexDiff(after); } else { nodeState.RemoveIndexDiff(after); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void raceContestantsAndVerifyResults(org.neo4j.internal.kernel.api.schema.SchemaDescriptor newDescriptor, Runnable aliceWork, Runnable changeConfig, Runnable bobWork) throws Throwable private void RaceContestantsAndVerifyResults(SchemaDescriptor newDescriptor, ThreadStart aliceWork, ThreadStart changeConfig, ThreadStart bobWork) { _race.addContestants(_aliceThreads, aliceWork); _race.addContestant(changeConfig); _race.addContestants(_bobThreads, bobWork); _race.go(); Await(IndexDescriptorFactory.forSchema(newDescriptor, "nodes", FulltextIndexProviderFactory.Descriptor)); using (Transaction tx = Db.beginTx()) { KernelTransaction ktx = KernelTransaction(tx); ScoreEntityIterator bob = FulltextAdapter.query(ktx, "nodes", "bob"); IList <ScoreEntityIterator.ScoreEntry> list = bob.ToList(); try { assertEquals(_bobThreads * _nodesCreatedPerThread, list.Count); } catch (Exception e) { StringBuilder sb = (new StringBuilder(e.Message)).Append(Environment.NewLine).Append("Nodes found in query for bob:"); foreach (ScoreEntityIterator.ScoreEntry entry in list) { sb.Append(Environment.NewLine).Append("\t").Append(Db.getNodeById(entry.EntityId())); } throw e; } ScoreEntityIterator alice = FulltextAdapter.query(ktx, "nodes", "alice"); assertEquals(0, alice.Count()); } }
public override SchemaDescriptor SchemaFor(EntityType type, string[] entityTokens, Properties indexConfiguration, params string[] properties) { if (entityTokens.Length == 0) { throw new BadSchemaException("At least one " + (type == EntityType.NODE ? "label" : "relationship type") + " must be specified when creating a fulltext index."); } if (properties.Length == 0) { throw new BadSchemaException("At least one property name must be specified when creating a fulltext index."); } if (Arrays.asList(properties).contains(LuceneFulltextDocumentStructure.FIELD_ENTITY_ID)) { throw new BadSchemaException("Unable to index the property, the name is reserved for internal use " + LuceneFulltextDocumentStructure.FIELD_ENTITY_ID); } int[] entityTokenIds = new int[entityTokens.Length]; if (type == EntityType.NODE) { _tokenHolders.labelTokens().getOrCreateIds(entityTokens, entityTokenIds); } else { _tokenHolders.relationshipTypeTokens().getOrCreateIds(entityTokens, entityTokenIds); } int[] propertyIds = java.util.properties.Select(_tokenHolders.propertyKeyTokens().getOrCreateId).ToArray(); SchemaDescriptor schema = SchemaDescriptorFactory.multiToken(entityTokenIds, type, propertyIds); indexConfiguration.putIfAbsent(FulltextIndexSettings.INDEX_CONFIG_ANALYZER, _defaultAnalyzerName); indexConfiguration.putIfAbsent(FulltextIndexSettings.INDEX_CONFIG_EVENTUALLY_CONSISTENT, _defaultEventuallyConsistentSetting); return(new FulltextSchemaDescriptor(schema, indexConfiguration)); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private org.neo4j.graphdb.schema.IndexDefinition descriptorToDefinition(final org.neo4j.internal.kernel.api.TokenRead tokenRead, org.neo4j.internal.kernel.api.IndexReference index) private IndexDefinition DescriptorToDefinition(TokenRead tokenRead, IndexReference index) { try { SchemaDescriptor schema = index.Schema(); int[] entityTokenIds = Schema.EntityTokenIds; bool constraintIndex = index.Unique; string[] propertyNames = PropertyNameUtils.GetPropertyKeys(tokenRead, index.Properties()); switch (Schema.entityType()) { case NODE: Label[] labels = new Label[entityTokenIds.Length]; for (int i = 0; i < labels.Length; i++) { labels[i] = label(tokenRead.NodeLabelName(entityTokenIds[i])); } return(new IndexDefinitionImpl(_actions, index, labels, propertyNames, constraintIndex)); case RELATIONSHIP: RelationshipType[] relTypes = new RelationshipType[entityTokenIds.Length]; for (int i = 0; i < relTypes.Length; i++) { relTypes[i] = withName(tokenRead.RelationshipTypeName(entityTokenIds[i])); } return(new IndexDefinitionImpl(_actions, index, relTypes, propertyNames, constraintIndex)); default: throw new System.ArgumentException("Cannot create IndexDefinition for " + Schema.entityType() + " entity-typed schema."); } } catch (KernelException e) { throw new Exception(e); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("ConstantConditions") private <INDEX_KEY extends org.neo4j.internal.kernel.api.schema.SchemaDescriptorSupplier> Iterable<org.neo4j.kernel.api.index.IndexEntryUpdate<INDEX_KEY>> gatherUpdatesForPotentials(Iterable<INDEX_KEY> potentiallyRelevant) private IEnumerable <IndexEntryUpdate <INDEX_KEY> > GatherUpdatesForPotentials <INDEX_KEY>(IEnumerable <INDEX_KEY> potentiallyRelevant) where INDEX_KEY : [email protected] { IList <IndexEntryUpdate <INDEX_KEY> > indexUpdates = new List <IndexEntryUpdate <INDEX_KEY> >(); foreach (INDEX_KEY indexKey in potentiallyRelevant) { SchemaDescriptor schema = indexKey.schema(); bool relevantBefore = relevantBefore(schema); bool relevantAfter = relevantAfter(schema); int[] propertyIds = Schema.PropertyIds; if (relevantBefore && !relevantAfter) { indexUpdates.Add(IndexEntryUpdate.remove(_entityId, indexKey, ValuesBefore(propertyIds))); } else if (!relevantBefore && relevantAfter) { indexUpdates.Add(IndexEntryUpdate.add(_entityId, indexKey, ValuesAfter(propertyIds))); } else if (relevantBefore && relevantAfter) { if (ValuesChanged(propertyIds, Schema.propertySchemaType())) { indexUpdates.Add(IndexEntryUpdate.change(_entityId, indexKey, ValuesBefore(propertyIds), ValuesAfter(propertyIds))); } } } return(indexUpdates); }
public override void Check(RelationshipRecord record, CheckerEngine <RelationshipRecord, Org.Neo4j.Consistency.report.ConsistencyReport_RelationshipConsistencyReport> engine, RecordAccess records) { try { IntObjectMap <PropertyBlock> propertyMap = null; foreach (StoreIndexDescriptor index in _relationshipIndexes) { SchemaDescriptor schema = index.Schema(); if (ArrayUtils.contains(Schema.EntityTokenIds, record.Type)) { if (propertyMap == null) { ICollection <PropertyRecord> propertyRecs = _propertyReader.getPropertyRecordChain(record.NextProp); propertyMap = properties(_propertyReader.propertyBlocks(propertyRecs)); } if (entityIntersectsSchema(propertyMap, schema)) { Value[] values = getPropertyValues(_propertyReader, propertyMap, Schema.PropertyIds); using (IndexReader reader = _indexes.accessorFor(index).newReader()) { long entityId = record.Id; long count = reader.CountIndexedNodes(entityId, Schema.PropertyIds, values); ReportIncorrectIndexCount(values, engine, index, count); } } } } } catch (PropertyReader.CircularPropertyRecordChainException) { // The property chain contains a circular reference and is therefore not sane. // Skip it, since this inconsistency has been reported by PropertyChain checker already. } }
/// <summary> /// Generates the code for each entity map. /// </summary> /// <param name="templateFile">The templateFile.</param> /// <param name="workingFolder">The working folder.</param> /// <param name="config">The config.</param> /// <param name="fileNameFunction">The file name function.</param> /// <param name="excludedTables">The excluded tables.</param> /// <param name="properties"></param> public void GenerateCodeForEachEntityMap(string templateFile, string workingFolder, MapConfig config, Func <string, int?, string> fileNameFunction = null, IDictionary <string, string> properties = null, params string[] excludedTables) { var counter = 0; foreach (var table in config.EntityConfigs) { if ((table.IsLinkTable || SchemaDescriptor.IsExcludedEntity(excludedTables, table.Name)) && !config.Settings.GenerateLinkTable) { continue; } try { var name = table.Name + ".txt"; counter++; if (fileNameFunction != null) { name = fileNameFunction(table.Name, counter); } var fname = Path.Combine(workingFolder, name); logger.Log(LogLevel.Debug, $"Running Code gen for entity {table}"); interpreter.Generate(templateFile, fname, table, properties); logger.Log(LogLevel.Info, $"File {fname} generate from template {templateFile} for entity {table}"); } catch (Exception ex) { logger.Error("Couldn't generate code file for " + table.Name, ex); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setUp() public virtual void SetUp() { File folder = _testDir.directory("folder"); _indexStorage = new PartitionedIndexStorage(_directoryFactory, _fileSystemRule.get(), folder); _index = LuceneSchemaIndexBuilder.create(_descriptor, Config.defaults()).withIndexStorage(_indexStorage).build(); _schemaDescriptor = _descriptor.schema(); }
public double indexUniqueValueSelectivity(int labelId, params int[] propertyKeyIds) { SchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyIds); IndexStatistics result1 = _outerInstance.regularIndices.getIndex(descriptor); IndexStatistics result2 = result1 == null?_outerInstance.uniqueIndices.getIndex(descriptor) : result1; return(result2 == null ? Double.NaN : result2.UniqueValuesPercentage); }
public static System.Predicate <T> HasLabel <T>(int labelId) where T : SchemaDescriptorSupplier { return(supplier => { SchemaDescriptor schema = supplier.schema(); return Schema.entityType() == EntityType.NODE && ArrayUtils.contains(Schema.EntityTokenIds, labelId); }); }
public static System.Predicate <T> HasRelType <T>(int relTypeId) where T : SchemaDescriptorSupplier { return(supplier => { SchemaDescriptor schema = supplier.schema(); return Schema.entityType() == EntityType.RELATIONSHIP && ArrayUtils.contains(Schema.EntityTokenIds, relTypeId); }); }
public virtual void CreateNodeFulltextIndex(string name, IList <string> labels, IList <string> properties, IDictionary <string, string> indexConfigurationMap) { Properties indexConfiguration = new Properties(); indexConfiguration.putAll(indexConfigurationMap); SchemaDescriptor schemaDescriptor = Accessor.schemaFor(EntityType.NODE, StringArray(labels), indexConfiguration, StringArray(properties)); Tx.schemaWrite().indexCreate(schemaDescriptor, DESCRIPTOR.name(), name); }
public virtual void CreateRelationshipFulltextIndex(string name, IList <string> relTypes, IList <string> properties, IDictionary <string, string> config) { Properties settings = new Properties(); settings.putAll(config); SchemaDescriptor schemaDescriptor = Accessor.schemaFor(EntityType.RELATIONSHIP, StringArray(relTypes), settings, StringArray(properties)); Tx.schemaWrite().indexCreate(schemaDescriptor, DESCRIPTOR.name(), name); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void validate() throws org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException public override void Validate() { if (_failures.Count > 0) { SchemaDescriptor descriptor = Descriptor.schema(); throw new UniquePropertyValueValidationException(ConstraintDescriptorFactory.uniqueForSchema(descriptor), ConstraintValidationException.Phase.VERIFICATION, new HashSet <>(_failures) ); } }
public virtual void PutIndex(SchemaDescriptor descriptor, string userDescription, double uniqueValuesPercentage, long size) { if (IndexMap.ContainsKey(descriptor)) { throw new System.ArgumentException(format("Duplicate index descriptor %s for %s index %s", descriptor, IndexType, userDescription)); } IndexMap[descriptor] = new IndexStatistics(uniqueValuesPercentage, size); }
private void GatherPropsToLoad(SchemaDescriptor schema, MutableIntSet target) { foreach (int propertyId in Schema.PropertyIds) { if (_knownProperties.get(propertyId) == null) { target.add(propertyId); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public long getIndexId(org.neo4j.internal.kernel.api.schema.SchemaDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException public virtual long GetIndexId(SchemaDescriptor descriptor) { IndexProxy proxy = _indexMap.getIndexProxy(descriptor); if (proxy == null) { throw new IndexNotFoundKernelException("No index for " + descriptor + " exists."); } return(_indexMap.getIndexId(descriptor)); }
public void PutIndexProxy(IndexProxy indexProxy) { StoreIndexDescriptor descriptor = indexProxy.Descriptor; SchemaDescriptor schema = descriptor.Schema(); _indexesById.put(descriptor.Id, indexProxy); _indexesByDescriptor[schema] = indexProxy; _indexIdsByDescriptor.put(schema, descriptor.Id); AddDescriptorToLookups(schema); }
public double indexPropertyExistsSelectivity(int labelId, params int[] propertyKeyIds) { SchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyIds); IndexStatistics result1 = _outerInstance.regularIndices.getIndex(descriptor); IndexStatistics result2 = result1 == null?_outerInstance.uniqueIndices.getIndex(descriptor) : result1; double indexSize = result2 == null ? Double.NaN : result2.Size; return(indexSize / nodesWithLabelCardinality(labelId)); }
public virtual void ValidateBeforeCommit(SchemaDescriptor index, Value[] tuple) { IndexProxy proxy = _indexMap.getIndexProxy(index); if (proxy != null) { // Do this null-check since from the outside there's a best-effort matching going on between updates and actual indexes backing those. proxy.ValidateBeforeCommit(tuple); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void verifyVerifyUniqueness(org.neo4j.kernel.api.impl.schema.SchemaIndex index, org.neo4j.internal.kernel.api.schema.SchemaDescriptor descriptor, Object... values) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException private void VerifyVerifyUniqueness(SchemaIndex index, SchemaDescriptor descriptor, params object[] values) { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") org.mockito.ArgumentCaptor<java.util.List<org.neo4j.values.storable.Value[]>> captor = org.mockito.ArgumentCaptor.forClass(java.util.List.class); ArgumentCaptor <IList <Value[]> > captor = ArgumentCaptor.forClass(typeof(System.Collections.IList)); verify(index).verifyUniqueness(any(), eq(descriptor.PropertyIds), captor.capture()); assertThat(captor.Value, containsInAnyOrder(valueTupleList(values).toArray())); }
private static int[] SortedPropertyKeyIds(SchemaDescriptor schemaDescriptor) { int[] tokenIds = schemaDescriptor.PropertyIds; if (tokenIds.Length > 1) { // Clone it because we don't know if the array was an internal array that the descriptor handed out tokenIds = tokenIds.Clone(); Arrays.sort(tokenIds); } return(tokenIds); }
public virtual void AddNode(long nodeId, SchemaDescriptor schema, params Value[] values) { IDictionary <int, Value> propertyMap = new Dictionary <int, Value>(); int[] propertyIds = Schema.PropertyIds; for (int i = 0; i < propertyIds.Length; i++) { propertyMap[propertyIds[i]] = values[i]; } _nodePropertyMap[nodeId] = propertyMap; }
private IndexQuery[] Seek(SchemaDescriptor schema, Value[] propertyValues) { int[] propertyIds = Schema.PropertyIds; Debug.Assert(propertyIds.Length == propertyValues.Length); IndexQuery[] query = new IndexQuery[propertyValues.Length]; for (int i = 0; i < query.Length; i++) { query[i] = IndexQuery.exact(propertyIds[i], propertyValues[i]); } return(query); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.storageengine.api.schema.IndexDescriptor indexDescriptor(org.neo4j.graphdb.Label label, String propertyKey, boolean constraint) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException, org.neo4j.internal.kernel.api.exceptions.schema.TooManyLabelsException private IndexDescriptor IndexDescriptor(Label label, string propertyKey, bool constraint) { using (Transaction tx = _kernel.beginTransaction(@implicit, AUTH_DISABLED)) { int labelId = tx.TokenWrite().labelGetOrCreateForName(label.Name()); int propertyKeyId = tx.TokenWrite().propertyKeyGetOrCreateForName(propertyKey); SchemaDescriptor schema = SchemaDescriptorFactory.forLabel(labelId, propertyKeyId); IndexDescriptor descriptor = constraint ? IndexDescriptorFactory.uniqueForSchema(schema, PROVIDER_DESCRIPTOR) : IndexDescriptorFactory.forSchema(schema, PROVIDER_DESCRIPTOR); tx.Success(); return(descriptor); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.internal.kernel.api.IndexReference createInitialIndex(org.neo4j.internal.kernel.api.schema.SchemaDescriptor descriptor) throws Exception private IndexReference CreateInitialIndex(SchemaDescriptor descriptor) { IndexReference index; using (KernelTransactionImplementation transaction = KernelTransaction) { SchemaWrite schemaWrite = transaction.SchemaWrite(); index = schemaWrite.IndexCreate(descriptor, FulltextIndexProviderFactory.Descriptor.name(), "nodes"); transaction.Success(); } Await(index); return(index); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public long getOnlineIndexId(org.neo4j.internal.kernel.api.schema.SchemaDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException public virtual long GetOnlineIndexId(SchemaDescriptor descriptor) { IndexProxy proxy = GetIndexProxy(descriptor); switch (proxy.State) { case ONLINE: return(_indexMap.getIndexId(descriptor)); default: throw new IndexNotFoundKernelException("Expected index on " + descriptor + " to be online."); } }
/// <summary> /// Iterate over some schema suppliers, and invoke a callback for every supplier that matches the node. To match the /// node N the supplier must supply a LabelSchemaDescriptor D, such that N has values for all the properties of D. /// The supplied schemas are all assumed to match N on label. /// <para> /// To avoid unnecessary store lookups, this implementation only gets propertyKeyIds for the node if some /// descriptor has a valid label. /// /// </para> /// </summary> /// @param <SUPPLIER> the type to match. Must implement SchemaDescriptorSupplier </param> /// @param <EXCEPTION> The type of exception that can be thrown when taking the action </param> /// <param name="schemaSuppliers"> The suppliers to match </param> /// <param name="specialPropertyId"> This property id will always count as a match for the descriptor, regardless of /// whether the node has this property or not </param> /// <param name="existingPropertyIds"> sorted array of property ids for the entity to match schema for. </param> /// <param name="callback"> The action to take on match </param> /// <exception cref="EXCEPTION"> This exception is propagated from the action </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: static <SUPPLIER extends org.neo4j.internal.kernel.api.schema.SchemaDescriptorSupplier, EXCEPTION extends Exception> void onMatchingSchema(java.util.Iterator<SUPPLIER> schemaSuppliers, int specialPropertyId, int[] existingPropertyIds, org.neo4j.function.ThrowingConsumer<SUPPLIER,EXCEPTION> callback) throws EXCEPTION internal static void OnMatchingSchema <SUPPLIER, EXCEPTION>(IEnumerator <SUPPLIER> schemaSuppliers, int specialPropertyId, int[] existingPropertyIds, ThrowingConsumer <SUPPLIER, EXCEPTION> callback) where SUPPLIER : [email protected] where EXCEPTION : Exception { Debug.Assert(isSortedSet(existingPropertyIds)); while (schemaSuppliers.MoveNext()) { SUPPLIER schemaSupplier = schemaSuppliers.Current; SchemaDescriptor schema = schemaSupplier.schema(); if (NodeHasSchemaProperties(existingPropertyIds, Schema.PropertyIds, specialPropertyId)) { callback.Accept(schemaSupplier); } } }
internal FulltextIndexTransactionState(FulltextIndexProvider provider, Log log, IndexReference indexReference) { FulltextIndexAccessor accessor = provider.GetOpenOnlineAccessor(( StoreIndexDescriptor )indexReference); log.Debug("Acquired online fulltext schema index accessor, as base accessor for transaction state: %s", accessor); _descriptor = accessor.Descriptor; SchemaDescriptor schema = _descriptor.schema(); _toCloseLater = new List <AutoCloseable>(); _writer = accessor.TransactionStateIndexWriter; _modifiedEntityIdsInThisTransaction = new LongHashSet(); _visitingNodes = Schema.entityType() == EntityType.NODE; _txStateVisitor = new FulltextIndexTransactionStateVisitor(_descriptor, _modifiedEntityIdsInThisTransaction, _writer); }