Search in sources :

Example 71 with ClassInfo

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();
}
Also used : WrongPropertyCompositeIndexEntity(org.neo4j.ogm.domain.autoindex.invalid.WrongPropertyCompositeIndexEntity) MetaData(org.neo4j.ogm.metadata.MetaData) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 72 with ClassInfo

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();
}
Also used : MetaData(org.neo4j.ogm.metadata.MetaData) NoPropertyCompositeIndexEntity(org.neo4j.ogm.domain.autoindex.NoPropertyCompositeIndexEntity) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 73 with ClassInfo

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;
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 74 with ClassInfo

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);
        }
    }
}
Also used : MappedRelationship(org.neo4j.ogm.context.MappedRelationship) RelationshipEntity(org.neo4j.ogm.annotation.RelationshipEntity) AbstractTransaction(org.neo4j.ogm.transaction.AbstractTransaction) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Response(org.neo4j.ogm.response.Response) HashMap(java.util.HashMap) CompileContext(org.neo4j.ogm.cypher.compiler.CompileContext) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) MappingContext(org.neo4j.ogm.context.MappingContext) Statement(org.neo4j.ogm.request.Statement) ArrayList(java.util.ArrayList) List(java.util.List) RowModel(org.neo4j.ogm.model.RowModel) Map(java.util.Map) Compiler(org.neo4j.ogm.cypher.compiler.Compiler) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Transaction(org.neo4j.ogm.transaction.Transaction) EntityUtils(org.neo4j.ogm.utils.EntityUtils) TransientRelationship(org.neo4j.ogm.context.TransientRelationship) TransientRelationship(org.neo4j.ogm.context.TransientRelationship) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 75 with ClassInfo

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);
            }
        }
    }
}
Also used : ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Aggregations

ClassInfo (org.neo4j.ogm.metadata.ClassInfo)145 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)100 Test (org.junit.Test)76 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)8 MetaData (org.neo4j.ogm.metadata.MetaData)8 CompileContext (org.neo4j.ogm.cypher.compiler.CompileContext)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 NodeBuilder (org.neo4j.ogm.cypher.compiler.NodeBuilder)5 MappingException (org.neo4j.ogm.exception.core.MappingException)5 RowModel (org.neo4j.ogm.model.RowModel)5 Collection (java.util.Collection)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 Optional (java.util.Optional)4 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)4 Member (org.neo4j.ogm.domain.forum.Member)4 Satellite (org.neo4j.ogm.domain.satellites.Satellite)4 Collections (java.util.Collections)3