use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class InvalidMetadataAutoIndexManagerTest method shouldCheckPropertiesMatchFieldNames.
@Test(expected = MetadataException.class)
public void shouldCheckPropertiesMatchFieldNames() {
MetaData metadata = new MetaData(WrongPropertyCompositeIndexEntity.class.getName());
ClassInfo classInfo = metadata.classInfo(WrongPropertyCompositeIndexEntity.class.getName());
classInfo.getCompositeIndexes();
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class InvalidMetadataAutoIndexManagerTest method shouldCheckPropertiesExistsForCompositeIndex.
@Test(expected = MetadataException.class)
public void shouldCheckPropertiesExistsForCompositeIndex() {
MetaData metadata = new MetaData(NoPropertyCompositeIndexEntity.class.getName());
ClassInfo classInfo = metadata.classInfo(NoPropertyCompositeIndexEntity.class.getName());
classInfo.getCompositeIndexes();
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class EntityUtils method identity.
/**
* Return native id of given node or relationship entity.
* If the id field is null the field is set to unique negative refId, which is then returned.
* You most likely want to use {@link org.neo4j.ogm.context.MappingContext#nativeId(Object)}
*
* @param entity entity
* @param metaData metadata
* @return native id or refId
*/
public static Long identity(Object entity, MetaData metaData) {
ClassInfo classInfo = metaData.classInfo(entity);
FieldInfo identityField = classInfo.identityField();
Object id = identityField.readProperty(entity);
if (id == null) {
Long generated = idSequence.decrementAndGet();
identityField.write(entity, generated);
return generated;
} else {
return (Long) id;
}
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class RequestExecutor method updateNodeEntities.
/**
* Update the mapping context with entity ids for new/existing nodes created or updated in the request.
*
* @param context the compile context
* @param entityRefMappings mapping of entity reference used in the compile context and the entity id from the database
*/
private void updateNodeEntities(CompileContext context, List<ReferenceMapping> entityRefMappings) {
// Ensures the last saved version of existing nodes is current in the cache
for (Object obj : context.registry()) {
if (!(obj instanceof TransientRelationship)) {
ClassInfo classInfo = session.metaData().classInfo(obj);
if (!classInfo.isRelationshipEntity()) {
session.context().optionalNativeId(obj).filter(id -> id >= 0).ifPresent(id -> {
LOGGER.debug("updating existing node id: {}, {}", id, obj);
registerEntity(session.context(), classInfo, id, obj);
});
}
}
}
// Ensures newly created nodes are current in the cache and also assigns their new graph ids
for (ReferenceMapping referenceMapping : entityRefMappings) {
// by a reference mapping will always have identical 'ref' and 'id' values.
if (!(referenceMapping.ref.equals(referenceMapping.id))) {
Object newEntity = context.getNewObject(referenceMapping.ref);
LOGGER.debug("creating new node id: {}, {}, {}", referenceMapping.ref, referenceMapping.id, newEntity);
initialiseNewEntity(referenceMapping.id, newEntity);
}
}
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class RequestExecutor method updateRelationshipEntities.
/**
* Update the mapping context with entity ids for new/existing relationship entities created in a request.
*
* @param context the compile context
* @param relationshipEntityRefMappings mapping of relationship entity reference used in the compile context and the entity id from the database
*/
private void updateRelationshipEntities(CompileContext context, List<ReferenceMapping> relationshipEntityRefMappings) {
for (ReferenceMapping referenceMapping : relationshipEntityRefMappings) {
if (referenceMapping.ref.equals(referenceMapping.id)) {
Object existingRelationshipEntity = session.context().getRelationshipEntity(referenceMapping.id);
// not all relationship ids represent relationship entities
if (existingRelationshipEntity != null) {
LOGGER.debug("updating existing relationship entity id: {}", referenceMapping.id);
ClassInfo classInfo = session.metaData().classInfo(existingRelationshipEntity);
registerEntity(session.context(), classInfo, referenceMapping.id, existingRelationshipEntity);
}
} else {
Object newRelationshipEntity = context.getNewObject(referenceMapping.ref);
// not all relationship ids represent relationship entities
if (newRelationshipEntity != null) {
LOGGER.debug("creating new relationship entity id: {}", referenceMapping.id);
initialiseNewEntity(referenceMapping.id, newRelationshipEntity);
}
}
}
}
Aggregations