use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class DomainInfoSchemaBuilder method buildRelationships.
private void buildRelationships() {
for (ClassInfo classInfo : classInfoMap.values()) {
if (!classInfo.isRelationshipEntity()) {
String label = classInfo.neo4jName();
NodeImpl node = (NodeImpl) schema.findNode(label);
collectRelationshipsInHierarchy(node, classInfo);
} else {
String type = classInfo.neo4jName();
if (schema.getRelationship(type) == null) {
if (classInfo.getStartNodeReader() == null || classInfo.getEndNodeReader() == null) {
logger.warn("Start or end node not found for classInfo={}, is the metadata correct?", classInfo);
continue;
}
NodeImpl start = getNodeByFieldAndContainingClass(classInfo, classInfo.getStartNodeReader());
NodeImpl end = getNodeByFieldAndContainingClass(classInfo, classInfo.getEndNodeReader());
schema.addRelationship(new RelationshipImpl(type, Direction.OUTGOING, start, end));
}
}
}
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class ExecuteQueriesDelegate method count.
public long count(Class<?> clazz, Iterable<Filter> filters) {
ClassInfo classInfo = session.metaData().classInfo(clazz.getSimpleName());
if (classInfo != null) {
resolvePropertyAnnotations(clazz, filters);
CypherQuery query;
if (classInfo.isRelationshipEntity()) {
query = new CountStatements().countEdges(classInfo.neo4jName(), filters);
} else {
query = new CountStatements().countNodes(classInfo.neo4jName(), filters);
}
return count(query, classInfo.isRelationshipEntity());
}
throw new RuntimeException(clazz.getName() + " is not a persistable class");
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class LoadByIdsDelegate method includeMappedEntity.
private <T, ID extends Serializable> boolean includeMappedEntity(Collection<ID> ids, T mapped) {
final ClassInfo classInfo = session.metaData().classInfo(mapped);
if (classInfo.hasPrimaryIndexField()) {
final Object primaryIndexValue = classInfo.readPrimaryIndexValueOf(mapped);
if (ids.contains(primaryIndexValue)) {
return true;
}
}
Object id = EntityUtils.identity(mapped, session.metaData());
return ids.contains(id);
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class LoadByIdsDelegate method sortResultsByIds.
private <T, ID extends Serializable> Set<T> sortResultsByIds(Class<T> type, Collection<ID> ids, Iterable<T> mapped) {
Map<ID, T> items = new HashMap<>();
ClassInfo classInfo = session.metaData().classInfo(type.getName());
Function<Object, Optional<Object>> primaryIndexOrIdReader = classInfo.getPrimaryIndexOrIdReader();
for (T t : mapped) {
primaryIndexOrIdReader.apply(t).ifPresent(id -> items.put((ID) id, t));
}
Set<T> results = new LinkedHashSet<>();
for (ID id : ids) {
T item = items.get(id);
if (item != null) {
results.add(item);
}
}
return results;
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class LoadByInstancesDelegate method loadAll.
public <T> Collection<T> loadAll(Collection<T> objects, SortOrder sortOrder, Pagination pagination, int depth) {
if (objects == null || objects.isEmpty()) {
return objects;
}
ClassInfo commonClassInfo = findCommonClassInfo(objects);
Function<Object, Optional<Object>> primaryIndexOrIdReader = commonClassInfo.getPrimaryIndexOrIdReader();
Set<Serializable> ids = objects.stream().map(primaryIndexOrIdReader::apply).filter(Optional::isPresent).map(Optional::get).map(Serializable.class::cast).collect(toCollection(LinkedHashSet::new));
return session.loadAll((Class<T>) commonClassInfo.getUnderlyingClass(), ids, sortOrder, pagination, depth);
}
Aggregations