use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class StoreUpgrader method migrateToIsolatedDirectory.
private void migrateToIsolatedDirectory(DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, String versionToMigrateFrom) {
try {
for (Map.Entry<String, StoreMigrationParticipant> participantEntry : participants.entrySet()) {
ProgressReporter progressReporter = progressMonitor.startSection(participantEntry.getKey());
String versionToMigrateTo = storeVersionCheck.configuredVersion();
IndexImporterFactory indexImporterFactory = new IndexImporterFactoryImpl(config);
participantEntry.getValue().migrate(directoryLayout, migrationLayout, progressReporter, versionToMigrateFrom, versionToMigrateTo, indexImporterFactory);
progressReporter.completed();
}
} catch (IOException | UncheckedIOException | KernelException e) {
throw new UnableToUpgradeException("Failure doing migration", e);
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class SchemaStatementProcedure method createStatement.
public static String createStatement(TokenRead tokenRead, IndexDescriptor indexDescriptor) throws ProcedureException {
try {
final String name = indexDescriptor.getName();
final String labelsOrRelTypes = labelsOrRelTypesAsStringArray(tokenRead, indexDescriptor.schema());
final String properties = propertiesAsStringArray(tokenRead, indexDescriptor.schema());
switch(indexDescriptor.getIndexType()) {
case BTREE:
String btreeConfig = btreeConfigAsString(indexDescriptor);
final String providerName = indexDescriptor.getIndexProvider().name();
return format(CREATE_BTREE_INDEX, name, labelsOrRelTypes, properties, providerName, btreeConfig);
case FULLTEXT:
String fulltextConfig = fulltextConfigAsString(indexDescriptor);
switch(indexDescriptor.schema().entityType()) {
case NODE:
return format(CREATE_NODE_FULLTEXT_INDEX, name, labelsOrRelTypes, properties, fulltextConfig);
case RELATIONSHIP:
return format(CREATE_RELATIONSHIP_FULLTEXT_INDEX, name, labelsOrRelTypes, properties, fulltextConfig);
default:
throw new IllegalArgumentException("Did not recognize entity type " + indexDescriptor.schema().entityType());
}
default:
throw new IllegalArgumentException("Did not recognize index type " + indexDescriptor.getIndexType());
}
} catch (KernelException e) {
throw new ProcedureException(Status.General.UnknownError, e, "Failed to re-create create statement.");
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class NodeEntity method createRelationshipTo.
@Override
public Relationship createRelationshipTo(Node otherNode, RelationshipType type) {
if (otherNode == null) {
throw new IllegalArgumentException("Other node is null.");
}
KernelTransaction transaction = internalTransaction.kernelTransaction();
int relationshipTypeId;
try {
relationshipTypeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName(type.name());
} catch (IllegalTokenNameException e) {
throw new IllegalArgumentException(e);
} catch (TokenCapacityExceededKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
} catch (KernelException e) {
throw new TransactionFailureException("Unknown error trying to create relationship type token", e);
}
try {
long relationshipId = transaction.dataWrite().relationshipCreate(nodeId, relationshipTypeId, otherNode.getId());
return internalTransaction.newRelationshipEntity(relationshipId, nodeId, relationshipTypeId, otherNode.getId());
} catch (EntityNotFoundException e) {
throw new NotFoundException("Node[" + e.entityId() + "] is deleted and cannot be used to create a relationship");
} catch (InvalidTransactionTypeKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class NodeEntity method addLabel.
@Override
public void addLabel(Label label) {
KernelTransaction transaction = internalTransaction.kernelTransaction();
int labelId;
try {
labelId = transaction.tokenWrite().labelGetOrCreateForName(label.name());
} catch (IllegalTokenNameException e) {
throw new ConstraintViolationException(format("Invalid label name '%s'.", label.name()), e);
} catch (TokenCapacityExceededKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
} catch (KernelException e) {
throw new TransactionFailureException("Unknown error trying to create label token", e);
}
try {
transaction.dataWrite().nodeAddLabel(getId(), labelId);
} catch (ConstraintValidationException e) {
throw new ConstraintViolationException(e.getUserMessage(transaction.tokenRead()), e);
} catch (EntityNotFoundException e) {
throw new NotFoundException("No node with id " + getId() + " found.", e);
} catch (KernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class NodeEntity method setProperty.
@Override
public void setProperty(String key, Object value) {
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 (TokenCapacityExceededKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
} catch (KernelException e) {
throw new TransactionFailureException("Unknown error trying to create property key token", e);
}
try {
transaction.dataWrite().nodeSetProperty(nodeId, propertyKeyId, Values.of(value, false));
} catch (ConstraintValidationException e) {
throw new ConstraintViolationException(e.getUserMessage(transaction.tokenRead()), e);
} catch (IllegalArgumentException e) {
try {
transaction.rollback();
} catch (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException ex) {
ex.addSuppressed(e);
throw new TransactionFailureException("Fail to rollback transaction.", ex);
}
throw e;
} catch (EntityNotFoundException e) {
throw new NotFoundException(e);
} catch (KernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
}
Aggregations