use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class RelationshipEntity method removeProperty.
@Override
public Object removeProperty(String key) {
KernelTransaction transaction = internalTransaction.kernelTransaction();
int propertyKeyId;
try {
propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName(key);
} catch (IllegalTokenNameException e) {
throw new IllegalArgumentException(format("Invalid property key '%s'.", key), e);
} catch (KernelException e) {
throw new TransactionFailureException("Unknown error trying to get property key token", e);
}
try {
return transaction.dataWrite().relationshipRemoveProperty(id, propertyKeyId).asObjectCopy();
} catch (InvalidTransactionTypeKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
} catch (EntityNotFoundException e) {
throw new NotFoundException(e);
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class TransactionImpl method allNodesWithLabel.
private ResourceIterator<Node> allNodesWithLabel(final Label myLabel) {
KernelTransaction ktx = kernelTransaction();
int labelId = ktx.tokenRead().nodeLabel(myLabel.name());
if (labelId == TokenRead.NO_TOKEN) {
return emptyResourceIterator();
}
var index = findUsableMatchingIndex(ktx, SchemaDescriptor.forAnyEntityTokens(EntityType.NODE));
if (index != IndexDescriptor.NO_INDEX) {
try {
var session = ktx.dataRead().tokenReadSession(index);
var cursor = ktx.cursors().allocateNodeLabelIndexCursor(ktx.cursorContext());
ktx.dataRead().nodeLabelScan(session, cursor, unconstrained(), new TokenPredicate(labelId));
return new CursorIterator<>(cursor, NodeIndexCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
} catch (KernelException e) {
// ignore, fallback to all node scan
}
}
return allNodesByLabelWithoutIndex(ktx, labelId);
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class IndexWriterStep method createIndex.
private IndexDescriptor createIndex(EntityType entityType, IndexConfig config, SchemaRuleAccess schemaRule, SchemaStore schemaStore, MemoryTracker memoryTracker, CursorContext cursorContext) {
try {
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("token-lookup", "1.0");
IndexPrototype prototype = forSchema(forAnyEntityTokens(entityType)).withIndexType(LOOKUP).withIndexProvider(providerDescriptor);
String name = defaultIfEmpty(config.indexName(entityType), generateName(prototype, new String[] {}, new String[] {}));
IndexDescriptor descriptor = prototype.withName(name).materialise(schemaStore.nextId(cursorContext));
schemaRule.writeSchemaRule(descriptor, cursorContext, memoryTracker);
return descriptor;
} catch (KernelException e) {
throw new RuntimeException("Error preparing indexes", e);
}
}
Aggregations