Search in sources :

Example 6 with MalformedSchemaRuleException

use of org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException in project neo4j by neo4j.

the class SchemaRuleSerialization35 method readMultiTokenSchema.

private static SchemaDescriptor readMultiTokenSchema(ByteBuffer source) throws MalformedSchemaRuleException {
    byte schemaDescriptorType = source.get();
    EntityType type;
    switch(schemaDescriptorType) {
        case SIMPLE_LABEL:
            type = EntityType.NODE;
            break;
        case SIMPLE_REL_TYPE:
            type = EntityType.RELATIONSHIP;
            break;
        default:
            throw new MalformedSchemaRuleException(format("Got unknown schema descriptor type '%d'.", schemaDescriptorType));
    }
    int[] entityTokenIds = readTokenIdList(source);
    int[] propertyIds = readTokenIdList(source);
    return SchemaDescriptor.fulltext(type, entityTokenIds, propertyIds);
}
Also used : EntityType(org.neo4j.common.EntityType) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)

Example 7 with MalformedSchemaRuleException

use of org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException in project neo4j by neo4j.

the class SchemaRuleSerialization35 method readIndexRule.

// PRIVATE
// READ INDEX
private static IndexDescriptor readIndexRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
    String providerKey = getDecodedStringFrom(source);
    String providerVersion = getDecodedStringFrom(source);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(providerKey, providerVersion);
    byte indexRuleType = source.get();
    Optional<String> name;
    switch(indexRuleType) {
        case GENERAL_INDEX:
            {
                SchemaDescriptor schema = readSchema(source);
                name = readRuleName(source);
                IndexPrototype prototype = IndexPrototype.forSchema(schema, providerDescriptor);
                if (schema.isFulltextSchemaDescriptor()) {
                    prototype = prototype.withIndexType(IndexType.FULLTEXT);
                }
                if (name.isPresent()) {
                    prototype = prototype.withName(name.get());
                } else {
                    prototype = prototype.withName(defaultIndexName(id));
                }
                return prototype.materialise(id);
            }
        case UNIQUE_INDEX:
            {
                long readOwningConstraint = source.getLong();
                SchemaDescriptor schema = readSchema(source);
                name = readRuleName(source);
                IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema, providerDescriptor);
                if (name.isPresent()) {
                    prototype = prototype.withName(name.get());
                } else {
                    prototype = prototype.withName(defaultIndexName(id));
                }
                IndexDescriptor index = prototype.materialise(id);
                if (readOwningConstraint != NO_OWNING_CONSTRAINT_YET) {
                    index = index.withOwningConstraintId(readOwningConstraint);
                }
                return index;
            }
        default:
            throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType));
    }
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 8 with MalformedSchemaRuleException

use of org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException in project neo4j by neo4j.

the class SchemaStore method schemaRecordToMap.

private static Map<String, Value> schemaRecordToMap(SchemaRecord record, PropertyStore propertyStore, TokenHolders tokenHolders, CursorContext cursorContext) throws MalformedSchemaRuleException {
    Map<String, Value> props = new HashMap<>();
    PropertyRecord propRecord = propertyStore.newRecord();
    long nextProp = record.getNextProp();
    while (nextProp != NO_NEXT_PROPERTY.longValue()) {
        try {
            propertyStore.getRecord(nextProp, propRecord, RecordLoad.NORMAL, cursorContext);
        } catch (InvalidRecordException e) {
            throw new MalformedSchemaRuleException("Cannot read schema rule because it is referencing a property record (id " + nextProp + ") that is invalid: " + propRecord, e);
        }
        for (PropertyBlock propertyBlock : propRecord) {
            PropertyKeyValue propertyKeyValue = propertyBlock.newPropertyKeyValue(propertyStore, cursorContext);
            insertPropertyIntoMap(propertyKeyValue, props, tokenHolders);
        }
        nextProp = propRecord.getNextProp();
    }
    if (props.isEmpty()) {
        IndexDescriptor descriptor = IndexDescriptor.NLI_PROTOTYPE.materialise(record.getId());
        props.putAll(mapifySchemaRule(descriptor));
    }
    return props;
}
Also used : PropertyKeyValue(org.neo4j.storageengine.api.PropertyKeyValue) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) IntObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap) HashMap(java.util.HashMap) Value(org.neo4j.values.storable.Value) PropertyKeyValue(org.neo4j.storageengine.api.PropertyKeyValue) TextValue(org.neo4j.values.storable.TextValue) LongValue(org.neo4j.values.storable.LongValue) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 9 with MalformedSchemaRuleException

use of org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException in project neo4j by neo4j.

the class SchemaStore method insertPropertyIntoMap.

private static void insertPropertyIntoMap(PropertyKeyValue propertyKeyValue, Map<String, Value> props, TokenHolders tokenHolders) throws MalformedSchemaRuleException {
    try {
        NamedToken propertyKeyTokenName = tokenHolders.propertyKeyTokens().getInternalTokenById(propertyKeyValue.propertyKeyId());
        props.put(propertyKeyTokenName.name(), propertyKeyValue.value());
    } catch (TokenNotFoundException | InvalidRecordException e) {
        int id = propertyKeyValue.propertyKeyId();
        throw new MalformedSchemaRuleException("Cannot read schema rule because it is referring to a property key token (id " + id + ") that does not exist.", e);
    }
}
Also used : MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) NamedToken(org.neo4j.token.api.NamedToken) TokenNotFoundException(org.neo4j.token.api.TokenNotFoundException)

Example 10 with MalformedSchemaRuleException

use of org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException in project neo4j by neo4j.

the class SchemaChecker method buildObligationsMap.

private void buildObligationsMap(long highId, RecordReader<SchemaRecord> reader, SchemaStorage schemaStorage, Map<Long, SchemaRecord> indexObligations, Map<Long, SchemaRecord> constraintObligations, Map<SchemaRuleKey, SchemaRecord> verifiedRulesWithRecords, CursorContext cursorContext) {
    for (long id = schemaStore.getNumberOfReservedLowIds(); id < highId && !context.isCancelled(); id++) {
        try {
            SchemaRecord record = reader.read(id);
            if (!record.inUse()) {
                continue;
            }
            SchemaRule schemaRule = schemaStorage.loadSingleSchemaRule(id, cursorContext);
            SchemaRecord previousContentRecord = verifiedRulesWithRecords.put(new SchemaRuleKey(schemaRule), record.copy());
            if (previousContentRecord != null) {
                reporter.forSchema(record).duplicateRuleContent(previousContentRecord);
            }
            if (schemaRule instanceof IndexDescriptor) {
                IndexDescriptor rule = (IndexDescriptor) schemaRule;
                if (rule.isUnique() && rule.getOwningConstraintId().isPresent()) {
                    SchemaRecord previousObligation = constraintObligations.put(rule.getOwningConstraintId().getAsLong(), record.copy());
                    if (previousObligation != null) {
                        reporter.forSchema(record).duplicateObligation(previousObligation);
                    }
                }
            } else if (schemaRule instanceof ConstraintDescriptor) {
                ConstraintDescriptor rule = (ConstraintDescriptor) schemaRule;
                if (rule.enforcesUniqueness()) {
                    SchemaRecord previousObligation = indexObligations.put(rule.asIndexBackedConstraint().ownedIndexId(), record.copy());
                    if (previousObligation != null) {
                        reporter.forSchema(record).duplicateObligation(previousObligation);
                    }
                }
            }
        } catch (MalformedSchemaRuleException e) {
        // This is OK, we'll report it below
        }
    }
}
Also used : MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaRule(org.neo4j.internal.schema.SchemaRule) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaRuleKey(org.neo4j.consistency.checking.SchemaRuleKey)

Aggregations

MalformedSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)10 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)4 SchemaRule (org.neo4j.internal.schema.SchemaRule)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)3 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)3 OptionalLong (java.util.OptionalLong)2 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)2 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 IntObjectHashMap (org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap)1 EntityType (org.neo4j.common.EntityType)1 SchemaRuleKey (org.neo4j.consistency.checking.SchemaRuleKey)1 PrefetchingIterator (org.neo4j.internal.helpers.collection.PrefetchingIterator)1 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)1 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)1 SchemaProcessor (org.neo4j.internal.schema.SchemaProcessor)1 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)1 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)1