/** * Get the list of relationship names for an entity. * * @param entity entity instance * @return List of relationship names for entity */ public List<String> getRelationships(Object entity) { return getRelationships(entity.getClass()); }
/** * Get the list of relationship names for an entity. * * @param entity entity instance * @return List of relationship names for entity */ public List<String> getRelationships(Object entity) { return getRelationships(entity.getClass()); }
/** * Get a list of elide-bound relationships. * * @param entityClass Entity class to find relationships for * @return List of elide-bound relationship names. */ public List<String> getElideBoundRelationships(Class<?> entityClass) { return getRelationships(entityClass).stream() .filter(relationName -> getBindings().contains(getParameterizedType(entityClass, relationName))) .collect(Collectors.toList()); }
/** * Get a list of elide-bound relationships. * * @param entityClass Entity class to find relationships for * @return List of elide-bound relationship names. */ public List<String> getElideBoundRelationships(Class<?> entityClass) { return getRelationships(entityClass).stream() .filter(relationName -> getBindings().contains(getParameterizedType(entityClass, relationName))) .collect(Collectors.toList()); }
/** * Get a list of all fields including both relationships and attributes. * * @param entityClass entity name * @return List of all fields. */ public List<String> getAllFields(Class<?> entityClass) { List<String> fields = new ArrayList<>(); List<String> attrs = getAttributes(entityClass); List<String> rels = getRelationships(entityClass); if (attrs != null) { fields.addAll(attrs); } if (rels != null) { fields.addAll(rels); } return fields; }
/** * Get a list of all fields including both relationships and attributes. * * @param entityClass entity name * @return List of all fields. */ public List<String> getAllFields(Class<?> entityClass) { List<String> fields = new ArrayList<>(); List<String> attrs = getAttributes(entityClass); List<String> rels = getRelationships(entityClass); if (attrs != null) { fields.addAll(attrs); } if (rels != null) { fields.addAll(rels); } return fields; }
/** * Builds a JOIN clause that eagerly fetches to-one relationships that Hibernate needs to hydrate. * @param entityClass The entity class that is being queried in the HQL query. * @param alias The HQL alias for the entity class. * @return The JOIN clause that can be added to the FROM clause. */ protected String extractToOneMergeJoins(Class<?> entityClass, String alias) { List<String> relationshipNames = dictionary.getRelationships(entityClass); StringBuilder joinString = new StringBuilder(""); for (String relationshipName : relationshipNames) { RelationshipType type = dictionary.getRelationshipType(entityClass, relationshipName); if (type.isToOne() && !type.isComputed()) { // fetch only OneToOne with mappedBy OneToOne oneToOne = dictionary.getAttributeOrRelationAnnotation( entityClass, OneToOne.class, relationshipName); if (oneToOne == null || oneToOne.mappedBy().isEmpty()) { continue; } joinString.append(" LEFT JOIN FETCH "); joinString.append(alias); joinString.append(PERIOD); joinString.append(relationshipName); joinString.append(SPACE); } } return joinString.toString(); }
relationshipNames = dictionary.getRelationships(current.getType());
/** * Get relationship mappings. * * @param relationshipFunction a function to load the value of a relationship. Takes a string of the relationship * name and returns the relationship's value. * @return Relationship mapping */ protected Map<String, Relationship> getRelationshipsWithRelationshipFunction( final Function<String, Set<PersistentResource>> relationshipFunction) { final Map<String, Relationship> relationshipMap = new LinkedHashMap<>(); final Set<String> relationshipFields = filterFields(dictionary.getRelationships(obj)); for (String field : relationshipFields) { TreeMap<String, Resource> orderedById = new TreeMap<>(lengthFirstComparator); for (PersistentResource relationship : relationshipFunction.apply(field)) { orderedById.put(relationship.getId(), new ResourceIdentifier(relationship.getType(), relationship.getId()).castToResource()); } Collection<Resource> resources = orderedById.values(); Data<Resource> data; RelationshipType relationshipType = getRelationshipType(field); if (relationshipType.isToOne()) { data = resources.isEmpty() ? new Data<>((Resource) null) : new Data<>(resources.iterator().next()); } else { data = new Data<>(resources); } // TODO - links relationshipMap.put(field, new Relationship(null, data)); } return relationshipMap; }
/** * Check the permissions of the relationship, and return true or false. * @param relationName The relationship to the entity * @return True if the relationship to the entity has valid permissions for the user */ protected boolean checkRelation(String relationName) { List<String> relations = dictionary.getRelationships(obj); String realName = dictionary.getNameFromAlias(obj, relationName); relationName = (realName == null) ? relationName : realName; if (relationName == null || relations == null || !relations.contains(relationName)) { throw new InvalidAttributeException(relationName, type); } checkFieldAwareDeferPermissions(ReadPermission.class, relationName, null, null); return !shouldSkipCollection( dictionary.getParameterizedType(obj, relationName), ReadPermission.class, requestScope); }
/** * Check the permissions of the relationship, and return true or false. * @param relationName The relationship to the entity * @return True if the relationship to the entity has valid permissions for the user */ protected boolean checkRelation(String relationName) { List<String> relations = dictionary.getRelationships(obj); String realName = dictionary.getNameFromAlias(obj, relationName); relationName = (realName == null) ? relationName : realName; if (relationName == null || relations == null || !relations.contains(relationName)) { throw new InvalidAttributeException(relationName, type); } checkFieldAwareDeferPermissions(ReadPermission.class, relationName, null, null); return !shouldSkipCollection( dictionary.getParameterizedType(obj, relationName), ReadPermission.class, requestScope); }
/** * Get relationship mappings. * * @param relationshipFunction a function to load the value of a relationship. Takes a string of the relationship * name and returns the relationship's value. * @return Relationship mapping */ protected Map<String, Relationship> getRelationshipsWithRelationshipFunction( final Function<String, Set<PersistentResource>> relationshipFunction) { final Map<String, Relationship> relationshipMap = new LinkedHashMap<>(); final Set<String> relationshipFields = filterFields(dictionary.getRelationships(obj)); for (String field : relationshipFields) { TreeMap<String, Resource> orderedById = new TreeMap<>(lengthFirstComparator); for (PersistentResource relationship : relationshipFunction.apply(field)) { orderedById.put(relationship.getId(), new ResourceIdentifier(relationship.getType(), relationship.getId()).castToResource()); } Collection<Resource> resources = orderedById.values(); Data<Resource> data; RelationshipType relationshipType = getRelationshipType(field); if (relationshipType.isToOne()) { data = resources.isEmpty() ? new Data<>((Resource) null) : new Data<>(resources.iterator().next()); } else { data = new Data<>(resources); } // TODO - links relationshipMap.put(field, new Relationship(null, data)); } return relationshipMap; }
/** * @return the JSON-API 'include' query parameter for some GET operations. */ private Parameter getIncludeParameter() { List<String> relationshipNames = dictionary.getRelationships(type); return new QueryParameter() .type("array") .name("include") .description("Selects the set of relationships that should be expanded as a compound document in " + "the result.") .items(new StringProperty()._enum(relationshipNames)) .collectionFormat("csv"); }
requestScope.getDictionary().getRelationships(entityClass).stream() .filter(relationName -> newResource.getRelationshipType(relationName).isToMany() && newResource.getValueUnchecked(relationName) == null)
requestScope.getDictionary().getRelationships(entityClass).stream() .filter(relationName -> newResource.getRelationshipType(relationName).isToMany() && newResource.getValueUnchecked(relationName) == null)
List<String> relationshipNames = dictionary.getRelationships(clazz); for (String relationshipName : relationshipNames) {