/** * 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(); }
/** * Get the calculated {@link UpdatePermission} value for the field. * * @param clazz the entity class * @param fieldName the field * @return the update permissions for a field */ protected String getUpdatePermission(Class<?> clazz, String fieldName) { UpdatePermission classPermission = dictionary.getAnnotation(clazz, UpdatePermission.class); UpdatePermission fieldPermission = dictionary.getAttributeOrRelationAnnotation(clazz, UpdatePermission.class, fieldName); if (fieldPermission != null) { return fieldPermission.expression(); } if (classPermission != null) { return classPermission.expression(); } return null; }
/** * Get the calculated {@link ReadPermission} value for the field. * * @param clazz the entity class * @param fieldName the field * @return the read permissions for a field */ protected String getReadPermission(Class<?> clazz, String fieldName) { ReadPermission classPermission = dictionary.getAnnotation(clazz, ReadPermission.class); ReadPermission fieldPermission = dictionary.getAttributeOrRelationAnnotation(clazz, ReadPermission.class, fieldName); if (fieldPermission != null) { return fieldPermission.expression(); } if (classPermission != null) { return classPermission.expression(); } return null; }