use of org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.
the class RelationshipProxy method setProperty.
@Override
public void setProperty(String key, Object value) {
try (Statement statement = actions.statement()) {
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(key);
statement.dataWriteOperations().relationshipSetProperty(getId(), Property.property(propertyKeyId, value));
} catch (IllegalArgumentException e) {
// Trying to set an illegal value is a critical error - fail this transaction
actions.failTransaction();
throw e;
} catch (EntityNotFoundException e) {
throw new NotFoundException(e);
} catch (IllegalTokenNameException e) {
// TODO: Maybe throw more context-specific error than just IllegalArgument
throw new IllegalArgumentException(e);
} catch (InvalidTransactionTypeKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
} catch (AutoIndexingKernelException e) {
throw new IllegalStateException("Auto indexing encountered a failure while setting property: " + e.getMessage(), e);
}
}
use of org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.
the class LegacyIndexProxy method putIfAbsent.
@Override
public T putIfAbsent(T entity, String key, Object value) {
try (Statement statement = statementContextBridge.get()) {
// Does it already exist?
long existing = single(internalGet(key, value, statement), -1L);
if (existing != -1) {
return entityOf(existing);
}
// No, OK so Grab lock
statement.readOperations().acquireExclusive(LEGACY_INDEX, legacyIndexResourceId(name, key));
// and check again -- now holding an exclusive lock
existing = single(internalGet(key, value, statement), -1L);
if (existing != -1) {
// Someone else created this entry before us just before we got the lock,
// release the lock as we won't be needing it
statement.readOperations().releaseExclusive(LEGACY_INDEX, legacyIndexResourceId(name, key));
return entityOf(existing);
}
internalAdd(entity, key, value, statement);
return null;
} catch (EntityNotFoundException e) {
throw new NotFoundException(format("%s %d not found", type, type.id(entity)), e);
} catch (InvalidTransactionTypeKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
} catch (LegacyIndexNotFoundKernelException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.
the class KernelTest method shouldNotAllowCreationOfConstraintsWhenInHA.
@Test
public void shouldNotAllowCreationOfConstraintsWhenInHA() throws Exception {
//noinspection deprecation
GraphDatabaseAPI db = new FakeHaDatabase();
ThreadToStatementContextBridge stmtBridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
try (Transaction ignored = db.beginTx()) {
Statement statement = stmtBridge.get();
try {
statement.schemaWriteOperations().uniquePropertyConstraintCreate(forLabel(1, 1));
fail("expected exception here");
} catch (InvalidTransactionTypeKernelException e) {
assertThat(e.getMessage(), containsString("HA"));
}
}
db.shutdown();
}
use of org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.
the class NodeProxy method createRelationshipTo.
@Override
public Relationship createRelationshipTo(Node otherNode, RelationshipType type) {
if (otherNode == null) {
throw new IllegalArgumentException("Other node is null.");
}
//}
try (Statement statement = actions.statement()) {
int relationshipTypeId = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName(type.name());
long relationshipId = statement.dataWriteOperations().relationshipCreate(relationshipTypeId, nodeId, otherNode.getId());
return actions.newRelationshipProxy(relationshipId, nodeId, relationshipTypeId, otherNode.getId());
} catch (IllegalTokenNameException | RelationshipTypeIdNotFoundKernelException e) {
throw new IllegalArgumentException(e);
} 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);
}
}
Aggregations