private boolean patch(Resource resource, RequestScope requestScope) { boolean isUpdated = false; // Update attributes first Map<String, Object> attributes = resource.getAttributes(); if (attributes != null) { for (Map.Entry<String, Object> entry : attributes.entrySet()) { String fieldName = entry.getKey(); Object newVal = entry.getValue(); isUpdated |= record.updateAttribute(fieldName, newVal); } } // Relations next Map<String, Relationship> relationships = resource.getRelationships(); if (relationships != null) { for (Map.Entry<String, Relationship> entry : relationships.entrySet()) { String fieldName = entry.getKey(); Relationship relationship = entry.getValue(); Set<PersistentResource> resources = (relationship == null) ? null : relationship.toPersistentResources(requestScope); isUpdated |= record.updateRelation(fieldName, resources); } } return isUpdated; } }
private boolean patch(Resource resource, RequestScope requestScope) { boolean isUpdated = false; // Update attributes first Map<String, Object> attributes = resource.getAttributes(); if (attributes != null) { for (Map.Entry<String, Object> entry : attributes.entrySet()) { String fieldName = entry.getKey(); Object newVal = entry.getValue(); isUpdated |= record.updateAttribute(fieldName, newVal); } } // Relations next Map<String, Relationship> relationships = resource.getRelationships(); if (relationships != null) { for (Map.Entry<String, Relationship> entry : relationships.entrySet()) { String fieldName = entry.getKey(); Relationship relationship = entry.getValue(); Set<PersistentResource> resources = (relationship == null) ? null : relationship.toPersistentResources(requestScope); isUpdated |= record.updateRelation(fieldName, resources); } } return isUpdated; } }
String fieldName = entry.getKey(); Object val = entry.getValue(); pResource.updateAttribute(fieldName, val);
String fieldName = entry.getKey(); Object val = entry.getValue(); pResource.updateAttribute(fieldName, val);
/** * Updates an object * @param toUpdate Entities to update * @param entity Resource entity * @param attributes Set of entity attributes * @return Persistence Resource object */ private PersistentResource updateAttributes(PersistentResource toUpdate, Entity entity, Set<Entity.Attribute> attributes) { EntityDictionary dictionary = entity.getRequestScope().getDictionary(); Class<?> entityClass = entity.getEntityClass(); String idFieldName = dictionary.getIdFieldName(entityClass); /* iterate through each attribute provided */ for (Entity.Attribute attribute : attributes) { if (dictionary.isAttribute(entityClass, attribute.getName())) { toUpdate.updateAttribute(attribute.getName(), attribute.getValue()); } else if (!Objects.equals(attribute.getName(), idFieldName)) { throw new IllegalStateException("Unrecognized attribute passed to 'data': " + attribute.getName()); } } return toUpdate; }
/** * Updates an object * @param toUpdate Entities to update * @param entity Resource entity * @param attributes Set of entity attributes * @return Persistence Resource object */ private PersistentResource updateAttributes(PersistentResource toUpdate, Entity entity, Set<Entity.Attribute> attributes) { EntityDictionary dictionary = entity.getRequestScope().getDictionary(); Class<?> entityClass = entity.getEntityClass(); String idFieldName = dictionary.getIdFieldName(entityClass); /* iterate through each attribute provided */ for (Entity.Attribute attribute : attributes) { if (dictionary.isAttribute(entityClass, attribute.getName())) { toUpdate.updateAttribute(attribute.getName(), attribute.getValue()); } else if (!Objects.equals(attribute.getName(), idFieldName)) { throw new IllegalStateException("Unrecognized attribute passed to 'data': " + attribute.getName()); } } return toUpdate; }