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);
}
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));
}
}
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;
}
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);
}
}
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
}
}
}
Aggregations