use of org.neo4j.kernel.api.exceptions.EntityNotFoundException 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.EntityNotFoundException in project neo4j by neo4j.
the class RelationshipProxy method getProperty.
@Override
public Object getProperty(String key) {
if (null == key) {
throw new IllegalArgumentException("(null) property key is not allowed");
}
try (Statement statement = actions.statement()) {
try {
int propertyId = statement.readOperations().propertyKeyGetForName(key);
if (propertyId == KeyReadOperations.NO_SUCH_PROPERTY_KEY) {
throw new NotFoundException(String.format("No such property, '%s'.", key));
}
Object value = statement.readOperations().relationshipGetProperty(getId(), propertyId);
if (value == null) {
throw new PropertyNotFoundException(propertyId, EntityType.RELATIONSHIP, getId());
}
return value;
} catch (EntityNotFoundException | PropertyNotFoundException e) {
throw new NotFoundException(e.getUserMessage(new StatementTokenNameLookup(statement.readOperations())), e);
}
}
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException 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.EntityNotFoundException in project neo4j by neo4j.
the class TxStateTransactionDataSnapshot method relationship.
private Relationship relationship(long relId) {
RelationshipProxy relationship = new RelationshipProxy(relationshipActions, relId);
if (!state.relationshipVisit(relId, relationship)) {
// This relationship has been created or changed in this transaction
RelationshipProxy cached = relationshipsReadFromStore.get(relId);
if (cached != null) {
return cached;
}
try {
// Get this relationship data from the store
store.relationshipVisit(relId, relationship);
relationshipsReadFromStore.put(relId, relationship);
} catch (EntityNotFoundException e) {
throw new IllegalStateException("Getting deleted relationship data should have been covered by the tx state");
}
}
return relationship;
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class InternalAutoIndexOperations method propertyAdded.
@Override
public void propertyAdded(DataWriteOperations ops, long entityId, Property property) throws AutoIndexingKernelException {
if (enabled) {
try {
String name = propertyKeyLookup.getTokenById(property.propertyKeyId()).name();
if (propertyKeysToInclude.get().contains(name)) {
ensureIndexExists(ops);
type.add(ops, entityId, name, property.value());
}
} catch (LegacyIndexNotFoundKernelException | EntityNotFoundException | PropertyNotFoundException e) {
throw new AutoIndexingKernelException(e);
} catch (TokenNotFoundException e) {
// KernelException now
throw new AutoIndexingKernelException(new PropertyKeyIdNotFoundKernelException(property.propertyKeyId(), e));
}
}
}
Aggregations