persistence.xml
.
- * @param entityManager The involved entity manager.
- * @return The currently configured bean validation mode.
- */
- public static ValidationMode getValidationMode(EntityManager entityManager) {
- Object validationMode = entityManager.getEntityManagerFactory().getProperties().get(PROPERTY_VALIDATION_MODE);
- return validationMode != null ? ValidationMode.valueOf(validationMode.toString().toUpperCase()) : ValidationMode.AUTO;
- }
-
-
- // Query utils ------------------------------------------------------------------------------------------------------------------------
-
- /**
- * Returns single result of given typed query as {@link Optional}.
- * @param T
is of wrong type.
- */
- public static null
if there is none.
- * @param null
if there is none.
- * @throws NonUniqueResultException When there is no unique result.
- */
- public static null
if there is none.
- * @param null
if there is none.
- * @throws NonUniqueResultException When there is no unique result.
- * @throws ClassCastException When T
is of wrong type.
- */
- @SuppressWarnings("unchecked")
- public static T
is of wrong type.
- */
- @SuppressWarnings("unchecked")
- public static null
if there is none.
- * The difference with {@link #getSingleResultOrNull(TypedQuery)} is that it doesn't throw {@link NonUniqueResultException} when there are multiple matches.
- * @param null
if there is none.
- */
- public static null
if there is none.
- * The difference with {@link #getSingleResultOrNull(Query)} is that it doesn't throw {@link NonUniqueResultException} when there are multiple matches.
- * @param null
if there is none.
- * @throws ClassCastException When T
is of wrong type.
- */
- @SuppressWarnings("unchecked")
- public static persistence.xml
.
+ * @param entityManager The involved entity manager.
+ * @return The currently configured bean validation mode.
+ */
+ public static ValidationMode getValidationMode(EntityManager entityManager) {
+ Object validationMode = entityManager.getEntityManagerFactory().getProperties().get(PROPERTY_VALIDATION_MODE);
+ return validationMode != null ? ValidationMode.valueOf(validationMode.toString().toUpperCase()) : ValidationMode.AUTO;
+ }
+
+
+ // Query utils ------------------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Returns single result of given typed query as {@link Optional}.
+ * @param T
is of wrong type.
+ */
+ public static null
if there is none.
+ * @param null
if there is none.
+ * @throws NonUniqueResultException When there is no unique result.
+ */
+ public static null
if there is none.
+ * @param null
if there is none.
+ * @throws NonUniqueResultException When there is no unique result.
+ * @throws ClassCastException When T
is of wrong type.
+ */
+ @SuppressWarnings("unchecked")
+ public static T
is of wrong type.
+ */
+ @SuppressWarnings("unchecked")
+ public static null
if there is none.
+ * The difference with {@link #getSingleResultOrNull(TypedQuery)} is that it doesn't throw {@link NonUniqueResultException} when there are multiple matches.
+ * @param null
if there is none.
+ */
+ public static null
if there is none.
+ * The difference with {@link #getSingleResultOrNull(Query)} is that it doesn't throw {@link NonUniqueResultException} when there are multiple matches.
+ * @param null
if there is none.
+ * @throws ClassCastException When T
is of wrong type.
+ */
+ @SuppressWarnings("unchecked")
+ public static - * Example implementation: - *
- * YourAuditedChange yourAuditedChange = new YourAuditedChange(); - * yourAuditedChange.setTimestamp(Instant.now()); - * yourAuditedChange.setUser(activeUser); - * yourAuditedChange.setEntityName(entityManager.getMetamodel().entity(entity.getClass()).getName()); - * yourAuditedChange.setEntityId(entity.getId()); - * yourAuditedChange.setPropertyName(property.getName()); - * yourAuditedChange.setOldValue(oldValue != null ? oldValue.toString() : null); - * yourAuditedChange.setNewValue(newValue != null ? newValue.toString() : null); - * inject(YourAuditedChangeService.class).persist(yourAuditedChange); - *- * - * @param entity The parent entity. - * @param property The audited property. - * @param oldValue The old value. - * @param newValue The new value. - */ - protected abstract void saveAuditedChange(BaseEntity entity, PropertyDescriptor property, Object oldValue, Object newValue); + /** + *
+ * Example implementation: + *
+ * YourAuditedChange yourAuditedChange = new YourAuditedChange(); + * yourAuditedChange.setTimestamp(Instant.now()); + * yourAuditedChange.setUser(activeUser); + * yourAuditedChange.setEntityName(entityManager.getMetamodel().entity(entity.getClass()).getName()); + * yourAuditedChange.setEntityId(entity.getId()); + * yourAuditedChange.setPropertyName(property.getName()); + * yourAuditedChange.setOldValue(oldValue != null ? oldValue.toString() : null); + * yourAuditedChange.setNewValue(newValue != null ? newValue.toString() : null); + * inject(YourAuditedChangeService.class).persist(yourAuditedChange); + *+ * + * @param entity The parent entity. + * @param property The audited property. + * @param oldValue The old value. + * @param newValue The new value. + */ + protected abstract void saveAuditedChange(BaseEntity entity, PropertyDescriptor property, Object oldValue, Object newValue); - /** - *
- * Work around for CDI inject not working in JPA EntityListener. Usage: - *
- * YourAuditedChangeService service = inject(YourAuditedChangeService.class); - *- * - * @param
+ * Work around for CDI inject not working in JPA EntityListener. Usage: + *
+ * YourAuditedChangeService service = inject(YourAuditedChangeService.class); + *+ * + * @param
- * return criteriaBuilder.equal(path, parameterBuilder.create(getValue())); - *- * @param path Entity property path. You can use this to inspect the target entity property. - * @param criteriaBuilder So you can build a predicate with a {@link ParameterExpression}. - * @param parameterBuilder You must use this to create a {@link ParameterExpression} for the criteria value. - * @return A predicate for the criteria value. - */ - public abstract Predicate build(Expression> path, CriteriaBuilder criteriaBuilder, ParameterBuilder parameterBuilder); - - /** - * Returns whether this criteria value would apply to the given model value. This must basically represent the "plain Java" - * equivalent of the SQL behavior as achieved by {@link #build(Expression, CriteriaBuilder, ParameterBuilder)}. - * @param modelValue The model value to test this criteria on. - * @return Whether this criteria value would apply to the given model value. - * @throws IllegalArgumentException When given model value cannot be reasonably parsed. - * @throws UnsupportedOperationException When this method is not implemented yet. - */ - public boolean applies(Object modelValue) { - throw new UnsupportedOperationException("This method is not implemented yet."); - } - - /** - * Returns the criteria value. - * @return The criteria value. - */ - public T getValue() { - return value; - } - - /** - * Unwraps the criteria value from given object which could possibly represent a {@link Criteria}. - * @param possibleCriteria Any object which could possibly represent a {@link Criteria}. - * @return The unwrapped criteria value when given object actually represents a {@link Criteria}, else the original value unmodified. - */ - public static Object unwrap(Object possibleCriteria) { - Object value = possibleCriteria; - - while (value instanceof Criteria) { - value = ((Criteria>) possibleCriteria).getValue(); - } - - return value; - } - - @Override - public int hashCode() { - return Objects.hash(getClass(), value); - } - - @Override - public boolean equals(Object object) { - return getClass().isInstance(object) && (object == this || (Objects.equals(value, ((Criteria>) object).value))); - } - - @Override - public String toString() { - return getClass().getSimpleName().toUpperCase() + "(" + getValue() + ")"; - } - - /** - * This is used in {@link Criteria#build(Expression, CriteriaBuilder, ParameterBuilder)}. - */ - @FunctionalInterface - public interface ParameterBuilder { -
+ * return criteriaBuilder.equal(path, parameterBuilder.create(getValue())); + *+ * @param path Entity property path. You can use this to inspect the target entity property. + * @param criteriaBuilder So you can build a predicate with a {@link ParameterExpression}. + * @param parameterBuilder You must use this to create a {@link ParameterExpression} for the criteria value. + * @return A predicate for the criteria value. + */ + public abstract Predicate build(Expression> path, CriteriaBuilder criteriaBuilder, ParameterBuilder parameterBuilder); + + /** + * Returns whether this criteria value would apply to the given model value. This must basically represent the "plain Java" + * equivalent of the SQL behavior as achieved by {@link #build(Expression, CriteriaBuilder, ParameterBuilder)}. + * @param modelValue The model value to test this criteria on. + * @return Whether this criteria value would apply to the given model value. + * @throws IllegalArgumentException When given model value cannot be reasonably parsed. + * @throws UnsupportedOperationException When this method is not implemented yet. + */ + public boolean applies(Object modelValue) { + throw new UnsupportedOperationException("This method is not implemented yet."); + } + + /** + * Returns the criteria value. + * @return The criteria value. + */ + public T getValue() { + return value; + } + + /** + * Unwraps the criteria value from given object which could possibly represent a {@link Criteria}. + * @param possibleCriteria Any object which could possibly represent a {@link Criteria}. + * @return The unwrapped criteria value when given object actually represents a {@link Criteria}, else the original value unmodified. + */ + public static Object unwrap(Object possibleCriteria) { + Object value = possibleCriteria; + + while (value instanceof Criteria) { + value = ((Criteria>) possibleCriteria).getValue(); + } + + return value; + } + + @Override + public int hashCode() { + return Objects.hash(getClass(), value); + } + + @Override + public boolean equals(Object object) { + return getClass().isInstance(object) && (object == this || (Objects.equals(value, ((Criteria>) object).value))); + } + + @Override + public String toString() { + return getClass().getSimpleName().toUpperCase() + "(" + getValue() + ")"; + } + + /** + * This is used in {@link Criteria#build(Expression, CriteriaBuilder, ParameterBuilder)}. + */ + @FunctionalInterface + public interface ParameterBuilder { +