r2805 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: . framework
Author: athimel Date: 2013-09-27 20:27:15 +0200 (Fri, 27 Sep 2013) New Revision: 2805 Url: http://nuiton.org/projects/topia/repository/revisions/2805 Log: refs #552 Improve TopiaJpaSupport : add find methods using Map instead of Object... Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-09-17 16:55:51 UTC (rev 2804) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-09-27 18:27:15 UTC (rev 2805) @@ -25,6 +25,7 @@ */ import java.util.List; +import java.util.Map; /** * This API provides methods to use persistence using JPA queries @@ -41,11 +42,26 @@ * WARNING : Depending on the registered service, this method may not * support something else than queries on TopiaEntity * + * @param jpaql the JPA-QL query + * @param parameters a map which keys are the attribute names and values are the attributes expected values + * @return The result list + */ + <T> List<T> findAll(String jpaql, + Map<String, Object> parameters); + + /** + * Allow to do some JPA-QL query + * <p/> + * WARNING : Depending on the registered service, this method may not + * support something else than queries on TopiaEntity + * * @param jpaql the JPA-QL query * @param propertyNamesAndValues the query parameters. Arguments are key-value paired : * [propertyName;value;propertyName;value;...] * @return The result list + * @deprecated prefer using {@link #findAll(String, java.util.Map)} */ + @Deprecated <T> List<T> findAll(String jpaql, Object... propertyNamesAndValues); @@ -61,10 +77,32 @@ * @param jpaql the JPA-QL query * @param startIndex first index of entity to return * @param endIndex last index of entity to return + * @param parameters a map which keys are the attribute names and values are the attributes expected values + * @return The result list + */ + <T> List<T> find(String jpaql, + int startIndex, + int endIndex, + Map<String, Object> parameters); + + /** + * Allow to do some JPA-QL query using the given bounds. + * <p/> + * No lower bound : <code>startIndex</code> = 0.<br/> + * No upper bound : <code>endIndex</code> = -1. + * <p/> + * WARNING : Depending on the registered service, this method may not + * support something else than queries on TopiaEntity + * + * @param jpaql the JPA-QL query + * @param startIndex first index of entity to return + * @param endIndex last index of entity to return * @param propertyNamesAndValues the query parameters. Arguments are key-value paired : * [propertyName;value;propertyName;value;...] * @return The result list + * @deprecated prefer using {@link #find(String, int, int, java.util.Map)} */ + @Deprecated <T> List<T> find(String jpaql, int startIndex, int endIndex, @@ -79,11 +117,27 @@ * support something else than queries on TopiaEntity * * @param jpaql the JPA-QL query + * @param parameters a map which keys are the attribute names and values are the attributes expected values + * @return The result instance or null + */ + <T> T findUnique(String jpaql, + Map<String, Object> parameters); + + /** + * Allow to do some JPA-QL query and return an unique result. If nothing if + * found by the query, will return null. If more than one result is found, + * will throw an exception. + * <p/> + * WARNING : Depending on the registered service, this method may not + * support something else than queries on TopiaEntity + * + * @param jpaql the JPA-QL query * @param propertyNamesAndValues the query parameters. Arguments are key-value paired : * [propertyName;value;propertyName;value;...] * @return The result instance or null + * @deprecated prefer using {@link #findUnique(String, java.util.Map)} */ - // TODO AThimel 02/08/13 Throw another exception if more than 1 result is found + @Deprecated <T> T findUnique(String jpaql, Object... propertyNamesAndValues); @@ -91,11 +145,34 @@ * Execute JPA-QL operation on data (Update, Delete). * * @param jpaql the JPA-QL query + * @param parameters a map which keys are the attribute names and values are the attributes expected values + * @return The number of entities updated or deleted. + */ + int execute(String jpaql, + Map<String, Object> parameters); + + /** + * Execute JPA-QL operation on data (Update, Delete). + * + * @param jpaql the JPA-QL query * @param propertyNamesAndValues the query parameters. Arguments are key-value paired : * [propertyName;value;propertyName;value;...] * @return The number of entities updated or deleted. + * @deprecated prefer using {@link #execute(String, java.util.Map)} */ + @Deprecated int execute(String jpaql, Object... propertyNamesAndValues); + /** + * Tells to the context if it has to use a flush mode before each query. + * <p/> + * By default, we use a flush mode, but in some case it costs to much doing + * this, that's why you can disable it setting the value to {@code false}. + * + * @param useFlushMode the new value to set + * @since 2.5 + */ + void setUseFlushMode(boolean useFlushMode); // XXX AThimel 27/09/13 Maybe this method has to be renamed + } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-09-17 16:55:51 UTC (rev 2804) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-09-27 18:27:15 UTC (rev 2805) @@ -1087,7 +1087,28 @@ } } + @Override + public <T> List<T> findAll(String jpaql, Map<String, Object> parameters) { + throw new UnsupportedOperationException("This method is not available on TopiaContext, please use TopiaJpaSupport"); + } + + @Override + public <T> List<T> find(String jpaql, int startIndex, int endIndex, Map<String, Object> parameters) { + throw new UnsupportedOperationException("This method is not available on TopiaContext, please use TopiaJpaSupport"); + } + + @Override + public <T> T findUnique(String jpaql, Map<String, Object> parameters) { + throw new UnsupportedOperationException("This method is not available on TopiaContext, please use TopiaJpaSupport"); + } + + @Override + public int execute(String jpaql, Map<String, Object> parameters) { + throw new UnsupportedOperationException("This method is not available on TopiaContext, please use TopiaJpaSupport"); + } + + @Override public void add(TopiaEntity e) throws TopiaException { update(e); }
participants (1)
-
athimelï¼ users.nuiton.org