r2634 - in branches/topia-2.6.x/topia-persistence/src: main/java/org/nuiton/topia main/java/org/nuiton/topia/framework main/java/org/nuiton/topia/persistence test/java/org/nuiton/topia/test/ano1991
Author: tchemit Date: 2012-08-19 13:11:48 +0200 (Sun, 19 Aug 2012) New Revision: 2634 Url: http://nuiton.org/repositories/revision/topia/2634 Log: fixes #2271: Deprecate TopiaQuery refs #2274: Improve TopiaDAO javadoc refs #2272: Add new methods to TopiaDAO to do search without using TopiaQuery Added: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java branches/topia-2.6.x/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2012-08-19 11:11:32 UTC (rev 2633) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2012-08-19 11:11:48 UTC (rev 2634) @@ -182,7 +182,9 @@ * @param query TopiaQuery to execute * @return a List of results as hibernate give us * @throws TopiaException + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 */ + @Deprecated List findByQuery(TopiaQuery query) throws TopiaException; /** @@ -192,7 +194,9 @@ * @param alias alias of the entity in the Query * @return a new TopiaQuery * @see TopiaQuery + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 */ + @Deprecated TopiaQuery createQuery(Class<?> entityClass, String alias); /** Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-08-19 11:11:32 UTC (rev 2633) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-08-19 11:11:48 UTC (rev 2634) @@ -62,39 +62,39 @@ * addGroup, ... * - execution of the query, using executeToEntityList, executeToEntity, * executeToInteger, ... - * <p/> + * * Construction * ============ - * <p/> + * * This class make easier the way to construct a HQL query. - * <p/> + * * Example 1 : * ----------- - * <p/> + * * SQL : * "SELECT * FROM PersonImpl WHERE firstName LIKE 'M%' AND year > 1980" - * <p/> + * * HQL using {@link TopiaContext#findAll(String, Object...) } : * TopiaContext context = rootContext.beginTransaction(); * context.find("FROM " + Person.class.getName() + " WHERE firstName LIKE * :firstName AND year > :year", * "firstName", "M%", year, 1980); - * <p/> + * * TopiaQuery : * TopiaQuery query = TopiaQuery.createQuery(Person.class).add( * Person.FIRST_NAME, Op.LIKE, "M%").add(Person.YEAR, Op.GT, 1980); - * <p/> + * * But the real advantage is when you have some parameters to test before * adding * them to the query. With the older method, it was tidious to construct * and add parameters to finally use the find method from TopiaContext. - * <p/> + * * Example 2 : * ----------- - * <p/> + * * HQL using {@link TopiaContext#findAll(String, Object...) } : * TopiaContext context = rootContext.beginTransaction(); - * <p/> + * * String query = "FROM " + Person.class.getName(); * List<Object> params = new ArrayList<Object>(); * String separator = " WHERE "; @@ -105,7 +105,7 @@ * params.add(company); * separator = " AND "; * } - * <p/> + * * // contact paramater can be null * if (contact != null) { * query += separator + "contact = :contact"; @@ -113,33 +113,33 @@ * params.add(contact); * separator = " AND "; * } - * <p/> + * * context.findAll(query, params.toArray()); - * <p/> + * * Here we have only two non obligatory params, but imagine if we must have * almost 6 or 7 parameters like this ! - * <p/> + * * TopiaQuery : * TopiaQuery query = TopiaQuery.createQuery(Person.class); - * <p/> + * * if (company != null) { * query.add(Person.COMPANY, company); * } - * <p/> + * * if (contact != null) { * query.add(Person.CONTACT, contact); * } - * <p/> + * * Many ways to create the same query : * ------------------------------------ - * <p/> + * * You can use multiple different manners to create a query, it depends on the * complexicity. More complex is the query, more easier is to construct it. - * <p/> + * * HQL : "FROM PersonImpl AS P WHERE (P.company IS NULL OR P.company = * :company) * AND P.firstName LIKE :firstName" - * <p/> + * * Using TopiaQuery and an Alias (these different queries are equivalent) : * query = TopiaQuery.createQuery(Person.class, "P"); * 1- query.add("(P.company IS NULL OR P.company = :company") AND P.firstName @@ -153,72 +153,72 @@ * .addParam("company", company); * 4- query.addNullOr("P.company", Op.EQ, company). * add("P.firstName", Op.LIKE, firstName + "%"); - * <p/> + * * You can use TopiaQuery to create a subquery in an other TopiaQuery, you have * to use the method {@link #fullQuery() } to get the full query in HQL and * give * it as a string in the other TopiaQuery. - * <p/> + * * Execution * ========= - * <p/> + * * After construction, you can execute the query in different ways. - * <p/> + * * Default method : * ---------------- - * <p/> + * * - execute : as the same result as * {@link TopiaContext#findAll(String, Object...) } - * <p/> + * * Depends on entity type ; * ------------------------ - * <p/> + * * - executeToEntity : only one result, the first one * - executeToEntityList : all results returned in a List * - executeToEntityMap : all results returned in a Map with key defined by * user * or topiaId by default - * <p/> + * * For aggregate : * --------------- - * <p/> + * * These methods have in argument the SELECT to execute the query. The previous * SELECT (if defined) will not be deleted, but temporarly not used. - * <p/> + * * - executeToInteger : for example for "SUM", "COUNT" * - executeToString : for example for "MAX" * - executeCount : directly a "count(*)" * - executeToObject : for other type of possible result (Long, Boolean, * Double, * ...) - * <p/> + * * Property loading * ================ - * <p/> + * * When using Hibernate, some times, Entities linked to the main one will be * lazy initialized, but you want them directly when the query will be executed * to avoid problems when closing context. You can use the method * {@link #addLoad(String...) } to tell the TopiaQuery to load some * properties when executing the query. After that, you don't need to call them * for loading them in Hibernate. - * <p/> + * * The syntax is the same as a property in HQL query using delegation : * "person.company" where person and company are entities. - * <p/> + * * Note : loading only available on collection or entities but not property * on a collection of entities which must be made manually. - * <p/> + * * For a Contact which is linked to a person (entity) and the person linked to * company (entity) you can add to a TopiaQuery<Contact> : * query.addLoad("person.company") - * <p/> + * * For a list of addresses (entity) in the contact you can do : * query.addLoad("addresses") - * <p/> + * * But it's not possible to do for example with meeting (entity) linked to the * contact and responsible (entity) linked to a meeting : * query.addLoad("meetings.responsible") - * <p/> + * * </pre> * <p/> * Created: 21 déc. 2009 @@ -227,9 +227,6 @@ * @version $Revision$ * @since 2.3.0 * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 - * <p/> - * Mise a jour: $Date$ par - * : $Author$ */ @Deprecated public class TopiaQuery { @@ -250,7 +247,7 @@ /** * To keep SELECT part of the query filled by user. - * + * * @since 2.6.7 */ protected List<String> userSelects; @@ -279,6 +276,7 @@ protected boolean distinct; //TODO tchemit-2012-02-01 Remove this (see Evol #1931) + /** From part of the query. */ protected StringBuilder from; @@ -411,7 +409,7 @@ * @param str the element to add * @return the TopiaQuery * @see #addFrom(Class, String) - * @see #addJoin(String, String, boolean) + * @see #addJoin(String, String, boolean) * @see #addLeftJoin(String, String, boolean) * @deprecated since 2.3.4 use correct addFrom or addJoin or addLeftJoin */ @@ -425,7 +423,7 @@ * the query or for join as specific {@code separator}. * * @param property the property to add - * @param alias alias of the property to add in form part of the query + * @param alias alias of the property to add in form part of the query * @param separator The separator to use before adding the element (if null * the {@link #FROM_SEPARATOR_DEFAULT} will be used). * @return the TopiaQuery @@ -545,7 +543,7 @@ // result.append(selectStatement).append(mainAlias); // } result.append(from); - + if (CollectionUtils.isNotEmpty(wheres)) { result.append(" WHERE "); boolean first = true; @@ -673,7 +671,7 @@ boolean needAlias = false; if (StringUtils.isEmpty(mainAlias)) { mainAlias = RandomStringUtils.randomAlphabetic(4); - from.append(' ').append(mainAlias); + from.append(' ').append(mainAlias); needAlias = true; } @@ -687,8 +685,8 @@ for (String current : properties) { // Add missing alias if needed - String property = needAlias ? - getProperty(mainAlias, current) : current; + String property = needAlias ? + getProperty(mainAlias, current) : current; // Split property on . String[] parts = property.split("\\."); @@ -709,7 +707,7 @@ } // Add the property in left join with fetch to true - addLeftJoin(propertyToJoin, alias, true); + addLeftJoin(propertyToJoin, alias, true); } } return this; @@ -767,7 +765,7 @@ } /** - * @param paramName name of the parameter to add + * @param paramName name of the parameter to add * @param constraint constraint to use * @param paramValue value of this parameter * @return TopiaQuery @@ -804,7 +802,7 @@ result.append(Op.NULL); } else { String valueName = getValueName(paramName); - if (Op.IN ==operator || Op.NOT_IN == operator) { + if (Op.IN == operator || Op.NOT_IN == operator) { result.append(operator).append(" (:").append(valueName).append(')'); } else { @@ -830,13 +828,13 @@ if (getParams().contains(valueName)) { valueName = valueName + "_" + - RandomStringUtils.randomAlphanumeric(4); + RandomStringUtils.randomAlphanumeric(4); } return valueName; } /** - * @param paramName name of the parameter to add + * @param paramName name of the parameter to add * @param paramValue value of this parameter * @return TopiaQuery * @since 2.3.1 @@ -1025,7 +1023,7 @@ * Add link constraint between two properties. {@code elementProperty} is in * elements of {@code containerProperty} which is a collection with same type * than {@code elementProperty}. (HQL : elementProperty IN elements - * (containerProperty)) + * (containerProperty)) * * @param elementProperty contains in containerProperty collection * @param containerProperty collection which contains elementProperty @@ -1090,7 +1088,7 @@ // Replace old paramName in subquery subqueryString = subqueryString.replace(":" + paramName, - ":" + newParamName); + ":" + newParamName); // Add the param to the current query addParam(newParamName, paramValue); @@ -1137,9 +1135,9 @@ userSelects.add(mainAlias); } } - + userSelects.addAll(Arrays.asList(select)); - + // // if select is not null, add the new element to the select // if (this.select != null) { // this.select.append(", "); @@ -1185,7 +1183,7 @@ * @return the TopiaQuery */ public TopiaQuery addOrder(String... order) { - if (orderBys==null) { + if (orderBys == null) { orderBys = new ArrayList<String>(); } Collections.addAll(orderBys, order); @@ -1210,7 +1208,7 @@ * @return the TopiaQuery */ public TopiaQuery addGroup(String... group) { - if (groupBys==null) { + if (groupBys == null) { groupBys = new ArrayList<String>(); } Collections.addAll(groupBys, group); @@ -1287,10 +1285,10 @@ * recent in first) * * @param filter Filter to apply on the query - * @see #addFilter(EntityFilter, String) * @return the TopiaQuery * @throws IllegalArgumentException if referenceId is defined but no * referenceProperty was set + * @see #addFilter(EntityFilter, String) */ public TopiaQuery addFilter(EntityFilter filter) throws IllegalArgumentException { @@ -1360,8 +1358,8 @@ if (filter.hasReference()) { if (referenceProperty == null) { throw new IllegalArgumentException("Reference property need" + - " to be defined in filter to use referenceId = " + - referenceId); + " to be defined in filter to use referenceId = " + + referenceId); } addEquals(getPropertyId(referenceProperty), referenceId); } @@ -1386,7 +1384,7 @@ List result; if (startIndex != null && endIndex != null) { result = transaction.find(query, startIndex, endIndex, - getParams().toArray()); + getParams().toArray()); } else { result = transaction.findAll(query, getParams().toArray()); } @@ -1425,8 +1423,8 @@ } if (!entityClass.isAssignableFrom(o.getClass())) { throw new ClassCastException(o.getClass().getName() + - " can't be cast to " + entityClass.getName() + - " o : " + o); + " can't be cast to " + entityClass.getName() + + " o : " + o); } E entity = (E) o; // Check distinct constraint for complex query where o is firstly an @@ -1469,7 +1467,7 @@ Object value = loadProperty(elmt, keyName); if (value != null && !keyClass.isAssignableFrom(value.getClass())) { throw new ClassCastException(value.getClass().getName() + - " can't be cast to " + keyClass.getName()); + " can't be cast to " + keyClass.getName()); } results.put((K) value, elmt); } @@ -1492,7 +1490,7 @@ TopiaContext transaction, Class<E> entityClass) throws TopiaException, ClassCastException { return executeToEntityMap(transaction, entityClass, - TopiaEntity.TOPIA_ID, String.class); + TopiaEntity.TOPIA_ID, String.class); } /** @@ -1589,7 +1587,7 @@ */ public int executeCount(TopiaContext transaction) throws TopiaException { List<String> oldOrderBys = orderBys; - orderBys=null; + orderBys = null; // StringBuilder oldOrder = orderBy; // orderBy = null; StringBuilder count = new StringBuilder("COUNT("); @@ -1639,10 +1637,10 @@ // orderBy = oldOrder; return result; } - + protected boolean isUserSelectEqualsMainAlias() { boolean result = !CollectionUtils.isEmpty(userSelects) && - userSelects.size()==1 && + userSelects.size() == 1 && userSelects.get(0).equals(mainAlias); return result; } @@ -1672,7 +1670,7 @@ } if (log.isTraceEnabled()) { log.trace("Current entity : " + - currEntity.getClass().getSimpleName()); + currEntity.getClass().getSimpleName()); log.trace("Current loading : " + s); } if (it.hasNext()) { @@ -1717,7 +1715,7 @@ Object res = PropertyUtils.getProperty(entity, property); if (log.isDebugEnabled()) { log.debug("load property '" + property + "' for '" + - entity.getClass().getSimpleName() + "'"); + entity.getClass().getSimpleName() + "'"); } if (res != null && Collection.class.isAssignableFrom(res.getClass())) { Collection<?> list = (Collection<?>) res; @@ -1726,16 +1724,16 @@ return res; } catch (IllegalAccessException eee) { throw new TopiaException("Illegal access on property " + - property + " from entity " + - entity.getClass().getName(), eee); + property + " from entity " + + entity.getClass().getName(), eee); } catch (InvocationTargetException eee) { throw new TopiaException("Invocation error on entity " + - entity.getClass().getName() + " for property " + - property, eee); + entity.getClass().getName() + " for property " + + property, eee); } catch (NoSuchMethodException eee) { throw new TopiaException("Getter method does not exist for" + - " property " + property + " from entity " + - entity.getClass().getName(), eee); + " property " + property + " from entity " + + entity.getClass().getName(), eee); } } Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2012-08-19 11:11:32 UTC (rev 2633) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2012-08-19 11:11:48 UTC (rev 2634) @@ -36,12 +36,10 @@ */ package org.nuiton.topia.persistence; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.event.TopiaEntityListener; import org.nuiton.topia.event.TopiaEntityVetoable; import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.generator.EntityDAOTransformer; import java.security.Permission; @@ -50,37 +48,27 @@ /** * TopiaDAO is used to manipulate entities corresponding to {@code E} type : - * create, delete, update or find entities using properties of {@link - * TopiaQuery}. + * create, delete, update or find entities. * <p/> * This interface is implemented by {@link TopiaDAOImpl} overridden by generation * from {@link EntityDAOTransformer}. * <p/> * - * @param <E> the entity type linked with the dao + * @param <E> the entity type managed by the dao * @author bpoussin <poussin@codelutin.com> * @author fdesbois <fdesbois@codelutin.com> * @author tchemit <chemit@codelutin.com> * @version $Id$ */ -public interface TopiaDAO<E extends TopiaEntity> { +public interface TopiaDAO<E extends TopiaEntity> extends TopiaDAODeprecated<E> { - TopiaEntityEnum getTopiaEntityEnum(); + //------------------------------------------------------------------------// + //-- Create - update - delete methods ------------------------------------// + //------------------------------------------------------------------------// /** - * When TopiaContextImpl create the TopiaDAOHibernate, it must call this - * method just after. + * Create a new instance of managed entity <strong>not persisted</strong>. * - * @param context context - * @param entityClass entity class - * @throws TopiaException if any pb while init - */ - void init(TopiaContextImplementor context, Class<E> entityClass) - throws TopiaException; - - /** - * Create a new instance of managed entity. - * * @return new entity instance * @throws TopiaException if any pb while creating the entity * @since 2.3.1 @@ -88,73 +76,6 @@ E newInstance() throws TopiaException; /** - * Return class of entity managed by this DAO. - * - * @return entity managed by this DAO - */ - Class<E> getEntityClass(); - - /** - * Return context used by this DAO. - * - * @return Returns the context. - */ - TopiaContextImplementor getContext(); - - /** - * Find usages of the given {@code entity} in the entities of the given - * {@code type}. - * - * @param type the type of entity to search - * @param entity the entity - * @param <U> tthe type of entity to search - * @return the list of entities of the given type which uses the given - * entity - * @throws TopiaException if any problem while getting data - * @since 2.3.0 - */ - <U extends TopiaEntity> List<U> findUsages(Class<U> type, E entity) - throws TopiaException; - - /** - * Find all usages of the given {@code entity}. - * - * @param entity the entity - * @return the dictionnary of usages of the given entities (keys are entity - * usage container, values are the list of this type of entity to - * use the given entity). - * @throws TopiaException if any pb while getting data - * @since 2.3.0 - */ - - Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity) - throws TopiaException; - - /** - * Retourne les permissions a verifier pour l'acces a l'entite pour le - * service Taas. - * - * @param topiaId topiaId d'une entite - * @param actions encoded actions - * @return la liste des permissions - * @throws TopiaException if any pb while getting datas - */ - List<Permission> getRequestPermission(String topiaId, int actions) - throws TopiaException; - - /* Adders */ - - void addTopiaEntityListener(TopiaEntityListener listener); - - void addTopiaEntityVetoable(TopiaEntityVetoable vetoable); - - /* Removers */ - - void removeTopiaEntityListener(TopiaEntityListener listener); - - void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable); - - /** * Construit une nouvelle instance de l'objet géré par ce DAO * * @param properties la liste des propriétés que doit avoir l'objet créé les @@ -212,36 +133,13 @@ */ void delete(E e) throws TopiaException; - /** - * Crée une requete basé sur l'entité lié au DAO. Résultat attendu : "FROM - * E" - * - * @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le - * type d'entité) - * @since 2.3 - * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 - */ - @Deprecated - TopiaQuery createQuery(); + //------------------------------------------------------------------------// + //-- findByXXX methods ---------------------------------------------------// + //------------------------------------------------------------------------// /** - * Crée une requête basé sur l'entité lié au DAO et lui assigne un alias - * valable dans la requête.. - * <p/> - * Résultat attendu : "FROM E AS entityAlias" - * - * @param entityAlias alias permettant de manipuler l'entité dans la - * requête - * @return une nouvelle TopiaQuery - * @since 2.3 - * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 - */ - @Deprecated - TopiaQuery createQuery(String entityAlias); - - /** * Find an entity corresponding to the {@code id}. If the {@code id} is - * null, nothing will be search. + * null, nothing will be searched. * * @param id topiaId of the entity to found * @return the entity found or null if not @@ -249,8 +147,15 @@ */ E findByTopiaId(String id) throws TopiaException; - E findByProperty(String propertyName, Object value) - throws TopiaException; + /** + * Find an entity matching {@code value} for the given {@code propertyName}. + * + * @param propertyName property name to filter + * @param value value of the property to math + * @return the first entity matching the request + * @throws TopiaException + */ + E findByProperty(String propertyName, Object value) throws TopiaException; /** * @param propertyName le nom de la propriété @@ -260,26 +165,88 @@ * @return l'entité trouvé * @throws TopiaException if any pb while getting datas */ - E findByProperties(String propertyName, Object value, - Object... others) throws TopiaException; + E findByProperties(String propertyName, Object value, Object... others) throws TopiaException; + /** + * Find an entity matching {@code properties}. + * + * @param properties les propriétés à matcher + * @return l'entité trouvé + * @throws TopiaException if any pb while getting datas + */ E findByProperties(Map<String, Object> properties) throws TopiaException; /** * Execute une requête basé sur l'entité du DAO. Permet de récupérer une * entité correspondant à la requête. * - * @param query la requête + * @param hql la requête hql à executer + * @param params les paramètres de la requète * @return l'entité correspondant à la recherche ou null si aucune entité * n'a été trouvée * @throws TopiaException if any pb while getting datas - * @see TopiaQuery#executeToEntity(TopiaContext, Class) - * @since 2.3 - * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + * @since 2.6.12 */ - @Deprecated - E findByQuery(TopiaQuery query) throws TopiaException; + E findByQuery(String hql, Object... params) throws TopiaException; + /** + * Execute une requête basé sur le {@code type} donné. + * <p/> + * Permet de récupérer une entité correspondant à la requête. + * + * @param hql la requête hql à executer + * @param params les paramètres de la requète + * @return l'entité correspondant à la recherche ou null si aucune entité + * n'a été trouvée + * @throws TopiaException if any pb while getting datas + * @since 2.6.12 + */ + <R> R findByQuery(Class<R> type, String hql, Object... params) throws TopiaException; + + /** + * Recherche la classe en utilisant la cle naturelle, chaque champs de la + * cle naturelle est une entre de la map passe en argument. + * + * @param keys la liste des champs de la cle naturelle avec leur valeur + * @return l'entite trouvé + * @throws TopiaException if any pb while getting datas + */ + E findByPrimaryKey(Map<String, Object> keys) throws TopiaException; + + /** + * Recherche la classe en utilisant la cle naturelle, si la cle naturelle + * est composé de plusieurs champs alors les arguments passés doivent être + * dans l'ordre de declaration dans le fichier de mapping + * + * @param k l'objet cle naturelle de la classe + * @return l'entité trouvé + * @throws TopiaException if any pb while getting datas + */ + E findByPrimaryKey(Object... k) throws TopiaException; + + /** + * Récupère la première entité (du type géré par ce dao) dont la + * collection nommée {@code propertyName} contient la {@code property} + * donnée. + * + * @param propertyName le nom de la propriété + * @param property la propriété recherchée + * @return la première entité recherchée + * @throws TopiaException pour tout erreur lors de la recherche + * @since 2.5.4 + */ + E findContains(String propertyName, Object property) throws TopiaException; + + //------------------------------------------------------------------------// + //-- findAllXXX methods --------------------------------------------------// + //------------------------------------------------------------------------// + + /** + * Gets all entitys of the dao type in db. + * + * @return all entities of the dao type in db + * @throws TopiaException + */ List<E> findAll() throws TopiaException; /** @@ -290,71 +257,112 @@ */ List<String> findAllIds() throws TopiaException; + /** + * Gets all entities of the dao type matching the {@code value} for the + * given {@code propertyName}. + * + * @param propertyName property name to filter + * @param value value to match + * @return matching entities + * @throws TopiaException if any pb while getting datas + */ List<E> findAllByProperty(String propertyName, Object value) throws TopiaException; /** + * Gets all entities of the dao type matching the {@code value} for the + * given {@code propertyName} and {@code others}. + * * @param propertyName le nom de la propriété * @param value la valeur à tester * @param others les autres proprietes doivent aller par 2 * propertyName, value - * @return l'entité trouvé + * @return matching entities * @throws TopiaException if any pb while getting datas */ List<E> findAllByProperties(String propertyName, Object value, Object... others) throws TopiaException; + /** + * Gets all entities of the dao type matching all the {@code properties}. + * + * @param properties properties to match + * @return matching entities + * @throws TopiaException if any pb while getting datas + */ List<E> findAllByProperties(Map<String, Object> properties) throws TopiaException; /** - * Execute une requête basé sur l'entité du DAO. Permet de récupérer une - * liste d'entités correspondant à la requête. + * Gets all entities when executing the given select query for the dao + * entity type. * - * @param query la requête - * @return la liste d'entités correspondant à la recherche + * @param hql hql query + * @param params query params + * @return entites of the query result * @throws TopiaException if any pb while getting datas - * @see TopiaQuery#executeToEntityList(TopiaContext, Class) - * @since 2.3 - * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + * @since 2.6.12 */ - @Deprecated - List<E> findAllByQuery(TopiaQuery query) throws TopiaException; + List<E> findAllByQuery(String hql, Object... params) throws TopiaException; /** - * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map - * d'entités correspondant à la requête. La clé de la map étant le topiaId - * de l'entité. + * Gets all entities when executing the given select query for the given + * {@code type} which may not be a entity type (int, long, map,...). * - * @param query la requête - * @return la map d'entités correspondant à la recherche + * @param hql hql query + * @param params query params + * @return entites of the query result * @throws TopiaException if any pb while getting datas - * @see TopiaQuery#executeToEntityMap(TopiaContext, Class) - * @since 2.3 - * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + * @since 2.6.12 */ - @Deprecated - Map<String, E> findAllMappedByQuery(TopiaQuery query) throws TopiaException; + <R> List<R> findAllByQuery(Class<R> type, + String hql, + Object... params) throws TopiaException; /** - * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map - * d'entités correspondant à la requête. Le type et le nom de la propriété - * utilisé comme clé de la map doit être passé en argument. + * Gets a page of entities when executing the given select query for the dao + * entity type (will only return the window of {@code startIndex - + * endIndex} entities). * - * @param <K> type de la clé de la map - * @param query la requête - * @param keyName nom de la propriété de l'entité utilisée comme clé - * @param keyClass type de la propriété de l'entité utilisée comme clé - * @return la map d'entités correspondant à la recherche + * @param hql hql query to execute + * @param startIndex first index of entity to return + * @param endIndex last index of entity to return + * @param params query params + * @return entites of the paginated query result * @throws TopiaException if any pb while getting datas - * @see TopiaQuery#executeToEntityMap(TopiaContext, Class) - * @since 2.3 - * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + * @since 2.6.12 */ - @Deprecated - <K> Map<K, E> findAllMappedByQuery(TopiaQuery query, - String keyName, Class<K> keyClass) throws TopiaException; + List<E> findAllByQueryWithBound(String hql, + int startIndex, + int endIndex, + Object... params) throws TopiaException; + /** + * Gets a page of entities of the given select {@code hql} query using the + * {@code pager} to obtain the window of entities to return. + * + * @param hql hql query to execute + * @param pager pager to obtan the correct window of data + * @param params params of the query + * @return entities of the paginated query result + * @throws TopiaException if any pb while getting datas + * @see TopiaFilterPagerUtil.FilterPagerBean + * @since 2.6.12 + */ + List<E> findAllByQueryAndPager(String hql, + TopiaFilterPagerUtil.FilterPagerBean pager, + Object... params) throws TopiaException; + + /** + * Gets all entites for the dao entity type order by given {@code propertyNames}. + * <p/> + * You can add on each {@code property} {@code ASC} ou {@code DESC} to + * fix order way (by default is {@code ASC}). + * + * @param propertyNames property names of order to apply + * @return all entities of the dao entity type with given order + * @throws TopiaException if any pb while getting datas + */ List<E> findAllWithOrder(String... propertyNames) throws TopiaException; @@ -372,19 +380,9 @@ List<E> findAllContains(String propertyName, Object property) throws TopiaException; - /** - * Récupère la première entité (du type géré par ce dao) dont la - * collection nommée {@code propertyName} contient la {@code property} - * donnée. - * - * @param propertyName le nom de la propriété - * @param property la propriété recherchée - * @return la première entité recherchée - * @throws TopiaException pour tout erreur lors de la recherche - * @since 2.5.4 - */ - E findContains(String propertyName, - Object property) throws TopiaException; + //------------------------------------------------------------------------// + //-- existsByXXX methods -------------------------------------------------// + //------------------------------------------------------------------------// /** * Check the existence of an entity with technical {@code id}. @@ -411,19 +409,21 @@ boolean existByProperties(String propertyName, Object propertyValue, Object... others) throws TopiaException; - /** - * Check the existence of an entity using a {@code query}. + * Check the existence of an entity using a {@code hql} query. * - * @param query query used to test existence + * @param hql query used to test existence + * @param params params used by the query * @return true if entity exists, false otherwise * @throws TopiaException - * @since 2.3.4 - * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + * @since 2.6.12 */ - @Deprecated - boolean existByQuery(TopiaQuery query) throws TopiaException; + boolean existsByQuery(String hql, Object... params) throws TopiaException; + //------------------------------------------------------------------------// + //-- countXXX methods ----------------------------------------------------// + //------------------------------------------------------------------------// + /** * Count the number of existing entities. * @@ -434,70 +434,124 @@ long count() throws TopiaException; /** - * Count the number of entities based on {@code query}. + * Count the number of entities based on a {@code hql}. * - * @param query query + * @param hql hql query to use * @return number of entities filtered by the query * @throws TopiaException if any pb while getting datas - * @since 2.3.4 - * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + * @since 2.6.12 */ - @Deprecated - int countByQuery(TopiaQuery query) throws TopiaException; + long countByQuery(String hql, Object... params) throws TopiaException; + //------------------------------------------------------------------------// + //-- other request methods -----------------------------------------------// + //------------------------------------------------------------------------// + /** - * Recherche la classe en utilisant la cle naturelle, chaque champs de la - * cle naturelle est une entre de la map passe en argument. + * Find usages of the given {@code entity} in the entities of the given + * {@code type}. * - * @param keys la liste des champs de la cle naturelle avec leur valeur - * @return l'entite trouvé - * @throws TopiaException if any pb while getting datas + * @param type the type of entity to search + * @param entity the entity on which search is done + * @param <R> type of entity to search + * @return the list of entities of the given type which uses the given + * entity + * @throws TopiaException if any problem while getting data + * @since 2.3.0 */ - E findByPrimaryKey(Map<String, Object> keys) throws TopiaException; + <R extends TopiaEntity> List<R> findUsages(Class<R> type, E entity) + throws TopiaException; /** - * Recherche la classe en utilisant la cle naturelle, si la cle naturelle - * est composé de plusieurs champs alors les arguments passés doivent être - * dans l'ordre de declaration dans le fichier de mapping + * Find all usages of the given {@code entity}. * - * @param k l'objet cle naturelle de la classe - * @return l'entité trouvé + * @param entity the entity + * @return the dictionnary of usages of the given entities (keys are entity + * usage container, values are the list of this type of entity to + * use the given entity). + * @throws TopiaException if any pb while getting data + * @since 2.3.0 + */ + + Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity) + throws TopiaException; + + /** + * Execute the count {@code hql} query and then synch the pager to this + * result (says fill the + * {@link TopiaFilterPagerUtil.FilterPagerBean#records} field and then adapt + * the number of pages available and the current number page). + * + * @param hql the count hql to execute + * @param pager the page to synch + * @param params params of the count query * @throws TopiaException if any pb while getting datas + * @see TopiaFilterPagerUtil.FilterPagerBean + * @since 2.6.12 */ - E findByPrimaryKey(Object... k) throws TopiaException; + void computeAndAddRecordsToPager(String hql, + TopiaFilterPagerUtil.FilterPagerBean pager, + Object... params) throws TopiaException; - boolean existsByQuery(String hql, - Object... params) throws TopiaException; + //------------------------------------------------------------------------// + //-- Misc methods --------------------------------------------------------// + //------------------------------------------------------------------------// - long countByQuery(String hql, - Object... params) throws TopiaException; + /** + * Get the entityEnum of the type of entity managed by this DAO. + * + * @return entity type enum managed by this DAO + */ + TopiaEntityEnum getTopiaEntityEnum(); - E findUniqueByQuery(String hql, - Object... params) throws TopiaException; + /** + * Get the type of entity managed by this DAO. + * + * @return entity type managed by this DAO + */ + Class<E> getEntityClass(); - <R> R findUniqueByQuery(Class<R> type, - String hql, - Object... params) throws TopiaException; + /** + * When TopiaContextImpl create the TopiaDAOHibernate, it must call this + * method just after. + * + * @param context context + * @param entityClass entity class + * @throws TopiaException if any pb while init + */ + void init(TopiaContextImplementor context, Class<E> entityClass) + throws TopiaException; - List<E> findAllByQuery(String hql, - Object... params) throws TopiaException; + /** + * Return context used by this DAO. + * + * @return the context. + */ + TopiaContextImplementor getContext(); - <R> List<R> findAllByQuery(Class<R> type, - String hql, - Object... params) throws TopiaException; + /** + * Retourne les permissions a verifier pour l'acces a l'entite pour le + * service Taas. + * + * @param topiaId topiaId d'une entite + * @param actions encoded actions + * @return la liste des permissions + * @throws TopiaException if any pb while getting datas + */ + List<Permission> getRequestPermission(String topiaId, int actions) + throws TopiaException; - List<E> findAllByQueryWithBound(String hql, - int startIndex, - int endIndex, - Object... params) throws TopiaException; + //------------------------------------------------------------------------// + //-- Listener methods ----------------------------------------------------// + //------------------------------------------------------------------------// - List<E> findByQueryAndPager(String hql, - TopiaFilterPagerUtil.FilterPagerBean pager, - Object... params) throws TopiaException; + void addTopiaEntityListener(TopiaEntityListener listener); - void computeAndAddRecordsToPager(String hql, - TopiaFilterPagerUtil.FilterPagerBean pager, - Object... params) throws TopiaException; + void addTopiaEntityVetoable(TopiaEntityVetoable vetoable); + void removeTopiaEntityListener(TopiaEntityListener listener); + + void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable); + } //TopiaDAO Added: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java (rev 0) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java 2012-08-19 11:11:48 UTC (rev 2634) @@ -0,0 +1,155 @@ +package org.nuiton.topia.persistence; +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; + +import java.util.List; +import java.util.Map; + +/** + * Contains all method that are deprecated from {@link TopiaDAO} in version + * {@code 2.6.12} and then will be removed in next major version ({@code 3.0}). + * + * @author tchemit <chemit@codelutin.com> + * @since 2.6.12 + */ +public interface TopiaDAODeprecated<E extends TopiaEntity> { + + /** + * Crée une requete basé sur l'entité lié au DAO. Résultat attendu : "FROM + * E" + * + * @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le + * type d'entité) + * @since 2.3 + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + */ + @Deprecated + TopiaQuery createQuery(); + + /** + * Crée une requête basé sur l'entité lié au DAO et lui assigne un alias + * valable dans la requête.. + * <p/> + * Résultat attendu : "FROM E AS entityAlias" + * + * @param entityAlias alias permettant de manipuler l'entité dans la + * requête + * @return une nouvelle TopiaQuery + * @since 2.3 + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + */ + @Deprecated + TopiaQuery createQuery(String entityAlias); + + /** + * Execute une requête basé sur l'entité du DAO. Permet de récupérer une + * entité correspondant à la requête. + * + * @param query la requête + * @return l'entité correspondant à la recherche ou null si aucune entité + * n'a été trouvée + * @throws TopiaException if any pb while getting datas + * @see TopiaQuery#executeToEntity(TopiaContext, Class) + * @since 2.3 + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + */ + @Deprecated + E findByQuery(TopiaQuery query) throws TopiaException; + + /** + * Execute une requête basé sur l'entité du DAO. Permet de récupérer une + * liste d'entités correspondant à la requête. + * + * @param query la requête + * @return la liste d'entités correspondant à la recherche + * @throws TopiaException if any pb while getting datas + * @see TopiaQuery#executeToEntityList(TopiaContext, Class) + * @since 2.3 + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + */ + @Deprecated + List<E> findAllByQuery(TopiaQuery query) throws TopiaException; + + /** + * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map + * d'entités correspondant à la requête. La clé de la map étant le topiaId + * de l'entité. + * + * @param query la requête + * @return la map d'entités correspondant à la recherche + * @throws TopiaException if any pb while getting datas + * @see TopiaQuery#executeToEntityMap(TopiaContext, Class) + * @since 2.3 + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + */ + @Deprecated + Map<String, E> findAllMappedByQuery(TopiaQuery query) throws TopiaException; + + /** + * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map + * d'entités correspondant à la requête. Le type et le nom de la propriété + * utilisé comme clé de la map doit être passé en argument. + * + * @param <K> type de la clé de la map + * @param query la requête + * @param keyName nom de la propriété de l'entité utilisée comme clé + * @param keyClass type de la propriété de l'entité utilisée comme clé + * @return la map d'entités correspondant à la recherche + * @throws TopiaException if any pb while getting datas + * @see TopiaQuery#executeToEntityMap(TopiaContext, Class) + * @since 2.3 + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + */ + @Deprecated + <K> Map<K, E> findAllMappedByQuery(TopiaQuery query, + String keyName, Class<K> keyClass) throws TopiaException; + + /** + * Check the existence of an entity using a {@code query}. + * + * @param query query used to test existence + * @return true if entity exists, false otherwise + * @throws TopiaException + * @since 2.3.4 + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + */ + @Deprecated + boolean existByQuery(TopiaQuery query) throws TopiaException; + + /** + * Count the number of entities based on {@code query}. + * + * @param query query + * @return number of entities filtered by the query + * @throws TopiaException if any pb while getting datas + * @since 2.3.4 + * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0 + */ + @Deprecated + int countByQuery(TopiaQuery query) throws TopiaException; +} Property changes on: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-08-19 11:11:32 UTC (rev 2633) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-08-19 11:11:48 UTC (rev 2634) @@ -594,20 +594,20 @@ public long countByQuery(String hql, Object... params) throws TopiaException { - Preconditions.checkNotNull(hql); - Preconditions.checkArgument(hql.startsWith("SELECT COUNT(")); + Preconditions.checkNotNull(StringUtils.isNotBlank(hql)); + Preconditions.checkArgument(hql.toUpperCase().trim().startsWith("SELECT COUNT(")); - return findUniqueByQuery(Long.class, hql, params); + return findByQuery(Long.class, hql, params); } - public E findUniqueByQuery(String hql, - Object... params) throws TopiaException { - return findUniqueByQuery(getEntityClass(), hql, params); + public E findByQuery(String hql, + Object... params) throws TopiaException { + return findByQuery(getEntityClass(), hql, params); } - public <R> R findUniqueByQuery(Class<R> type, - String hql, - Object... params) throws TopiaException { + public <R> R findByQuery(Class<R> type, + String hql, + Object... params) throws TopiaException { Preconditions.checkNotNull(type); Preconditions.checkNotNull(hql); @@ -646,9 +646,9 @@ return result; } - public List<E> findByQueryAndPager(String hql, - TopiaFilterPagerUtil.FilterPagerBean pager, - Object... params) throws TopiaException { + public List<E> findAllByQueryAndPager(String hql, + TopiaFilterPagerUtil.FilterPagerBean pager, + Object... params) throws TopiaException { Preconditions.checkNotNull(pager); Preconditions.checkNotNull(hql); Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java 2012-08-19 11:11:32 UTC (rev 2633) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java 2012-08-19 11:11:48 UTC (rev 2634) @@ -63,14 +63,15 @@ /** * Surcharge du {@link TopiaDAOImpl} pour utiliser l'api criteria au lieu du hql * pour tout ce qui est requétage. - * + * <p/> * Created: 31 déc. 2005 13:10:34 * * @param <E> le type de l'entite * @author bpoussin <poussin@codelutin.com> * @author tchemit <chemit@codelutin.com> + * @deprecated since 2.6.12 Using the hibernate Criteria api is not a good idea as we wants to use in ToPIA next generation (version 3.0) jpa api. */ - +@Deprecated public class TopiaDAOLegacy<E extends TopiaEntity> extends TopiaDAOImpl<E> { // TopiaDAOLegacy /** Logger. */ @@ -88,20 +89,20 @@ Object propertyName = null; Object value = null; try { - for (int i = 0; i < properties.length;) { + for (int i = 0; i < properties.length; ) { propertyName = properties[i++]; value = properties[i++]; map.put((String) propertyName, value); } } catch (ArrayIndexOutOfBoundsException eee) { throw new IllegalArgumentException("Wrong number of argument " - + properties.length - + ", you must have even number. Last property name read: " - + propertyName); + + properties.length + + ", you must have even number. Last property name read: " + + propertyName); } catch (ClassCastException eee) { throw new IllegalArgumentException( "Wrong argument type, wait property name as String and have " - + propertyName.getClass().getName()); + + propertyName.getClass().getName()); } E result = create(map); @@ -123,7 +124,7 @@ throw new TopiaException(eee); } throw new TopiaException("La classe " + entityClass.getName() - + " n'a pas de cle primaire naturelle"); + + " n'a pas de cle primaire naturelle"); } @@ -150,17 +151,17 @@ throw new TopiaException(eee); } throw new TopiaException("La classe " + entityClass.getName() - + " n'a pas de cle primaire naturelle"); + + " n'a pas de cle primaire naturelle"); } @Override public E findByProperties(String propertyName, Object value, - Object... others) throws TopiaException { + Object... others) throws TopiaException { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(propertyName, value); Object name = null; - for (int i = 0; i < others.length;) { + for (int i = 0; i < others.length; ) { try { name = others[i++]; value = others[i++]; @@ -168,12 +169,12 @@ } catch (ClassCastException eee) { throw new IllegalArgumentException( "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); + + propertyName.getClass().getName(), eee); } catch (ArrayIndexOutOfBoundsException eee) { throw new IllegalArgumentException( "Le nombre d'argument n'est pas un nombre pair: " - + (others.length + 2) - + " La dernière propriété était: " + name, eee); + + (others.length + 2) + + " La dernière propriété était: " + name, eee); } } E result = findByProperties(properties); @@ -182,11 +183,11 @@ @Override public List<E> findAllByProperties(String propertyName, Object value, - Object... others) throws TopiaException { + Object... others) throws TopiaException { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(propertyName, value); Object name = null; - for (int i = 0; i < others.length;) { + for (int i = 0; i < others.length; ) { try { name = others[i++]; value = others[i++]; @@ -194,12 +195,12 @@ } catch (ClassCastException eee) { throw new IllegalArgumentException( "Les noms des propriétés doivent être des chaines et non pas " - + propertyName.getClass().getName(), eee); + + propertyName.getClass().getName(), eee); } catch (ArrayIndexOutOfBoundsException eee) { throw new IllegalArgumentException( "Le nombre d'argument n'est pas un nombre pair: " - + (others.length + 2) - + " La dernière propriété était: " + name, eee); + + (others.length + 2) + + " La dernière propriété était: " + name, eee); } } List<E> result = findAllByProperties(properties); @@ -384,7 +385,7 @@ String[] numFields = fields.numFields(); for (String propName : numFields) { criterion = or(criterion, Restrictions.sqlRestriction(propName - + " like '" + textValue + "'")); + + " like '" + textValue + "'")); } } //boolFields @@ -403,14 +404,14 @@ String[] boolFields = fields.numFields(); for (String propName : boolFields) { criterion = or(criterion, Restrictions.eq(propName, - booleanValue)); + booleanValue)); } } //timeFields String[] timeFields = fields.dateFields(); for (String propName : timeFields) { criterion = or(criterion, Restrictions.sqlRestriction(propName - + " like '" + textValue + "'")); + + " like '" + textValue + "'")); } return criterion; } @@ -480,7 +481,7 @@ Criteria criteria = createCriteria(FlushMode.AUTO); List<E> result = (List<E>) criteria.list(); result = getContext().getFiresSupport().fireEntitiesLoad(context, - result); + result); return result; } catch (HibernateException eee) { throw new TopiaException(eee); @@ -495,7 +496,6 @@ } - @Override public List<E> findAllWithOrder(String... propertyNames) throws TopiaException { @@ -506,7 +506,7 @@ } List<E> result = (List<E>) criteria.list(); result = getContext().getFiresSupport().fireEntitiesLoad(context, - result); + result); return result; } catch (HibernateException eee) { throw new TopiaException(eee); @@ -531,7 +531,7 @@ criteria.add(criterion); List<E> result = (List<E>) criteria.list(); result = getContext().getFiresSupport().fireEntitiesLoad(context, - result); + result); return result; } catch (HibernateException eee) { throw new TopiaException(eee); @@ -546,14 +546,14 @@ List<E> result = (List<E>) criteria.list(); int sizeBefore = result != null ? result.size() : 0; result = getContext().getFiresSupport().fireEntitiesLoad(context, - result); + result); int sizeAfter = result != null ? result.size() : 0; if (sizeAfter < sizeBefore) { if (log.isDebugEnabled()) { log.debug((sizeBefore - sizeAfter) - + " element(s) removed. Filter entity: " - + entityClass.getName() + " - criterion: " - + criterion); + + " element(s) removed. Filter entity: " + + entityClass.getName() + " - criterion: " + + criterion); } } if (result != null && result.size() > 0) { @@ -612,6 +612,7 @@ /** * Renvoie un Criteria créé avec l'entityClass + * * @param mode le FlushMode du Criteria * @return le Criteria nouvellement créé * @throws TopiaException if any pb Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java 2012-08-19 11:11:32 UTC (rev 2633) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java 2012-08-19 11:11:48 UTC (rev 2634) @@ -48,6 +48,13 @@ protected TopiaFilterPagerUtil() { } + /** + * @param query + * @param pager + * @return + * @deprecated since 2.6.12 TopiaQuery will be removed in version 3.0 of ToPIA + */ + @Deprecated public static TopiaQuery addPagerToQuery(TopiaQuery query, FilterPagerBean pager) { PagerUtil.computeRecordIndexesAndPagesNumber(pager); Modified: branches/topia-2.6.x/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java 2012-08-19 11:11:32 UTC (rev 2633) +++ branches/topia-2.6.x/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java 2012-08-19 11:11:48 UTC (rev 2634) @@ -46,6 +46,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.6.8 */ +@Deprecated public class TopiaQueryTest { @Rule
participants (1)
-
tchemit@users.nuiton.org