deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johndam...@apache.org
Subject [2/2] deltaspike git commit: DELTASPIKE-1105 Added param to control appending entity name. Updated to latest apache parent.
Date Sat, 02 Apr 2016 18:04:08 GMT
DELTASPIKE-1105 Added param to control appending entity name.  Updated to latest apache parent.


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/2214758b
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/2214758b
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/2214758b

Branch: refs/heads/master
Commit: 2214758bdac1ff36c025afd26dca953b5023436f
Parents: 08efe4f
Author: John D. Ament <johndament@apache.org>
Authored: Sat Apr 2 14:03:58 2016 -0400
Committer: John D. Ament <johndament@apache.org>
Committed: Sat Apr 2 14:03:58 2016 -0400

----------------------------------------------------------------------
 .../apache/deltaspike/data/api/QueryResult.java | 121 +++++++++++++------
 .../OrderByQueryStringPostProcessor.java        |  18 ++-
 .../impl/builder/result/DefaultQueryResult.java |  36 +++++-
 .../deltaspike/data/impl/QueryResultTest.java   |  22 ++++
 pom.xml                                         |  20 +--
 5 files changed, 152 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2214758b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/QueryResult.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/QueryResult.java
b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/QueryResult.java
index fce1a87..8fe7369 100644
--- a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/QueryResult.java
+++ b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/QueryResult.java
@@ -38,49 +38,90 @@ public interface QueryResult<E>
      * This is the typesafe version, alternatively a {@link #orderAsc(String)}
      * String can be used.
      *
-     * @param attribute         Sort attribute.
-     * @return                  Fluent API: the result instance.
+     * @param attribute Sort attribute.
+     * @return Fluent API: the result instance.
      */
     <X> QueryResult<E> orderAsc(SingularAttribute<E, X> attribute);
 
     /**
+     * Sort the query result ascending by the given entity singular attribute.
+     * This is the typesafe version, alternatively a {@link #orderAsc(String)}
+     * String can be used.
+     *
+     * @param attribute        Sort attribute.
+     * @param appendEntityName whether the entity name 'e' should be appended to this attribute
+     * @return Fluent API: the result instance.
+     */
+    <X> QueryResult<E> orderAsc(SingularAttribute<E, X> attribute, boolean
appendEntityName);
+
+    /**
      * Sort the query result ascending by the given entity attribute.
      *
-     * @param attribute         Sort attribute.
-     * @return                  Fluent API: the result instance.
+     * @param attribute Sort attribute.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> orderAsc(String attribute);
 
     /**
+     * Sort the query result ascending by the given entity attribute.
+     *
+     * @param attribute        Sort attribute.
+     * @param appendEntityName whether the entity name 'e' should be appended to this attribute
+     * @return Fluent API: the result instance.
+     */
+    QueryResult<E> orderAsc(String attribute, boolean appendEntityName);
+
+    /**
      * Sort the query result descending by the given entity singular attribute.
      * This is the typesafe version, alternatively a {@link #orderDesc(String)}
      * String can be used.
      *
-     * @param attribute         Sort attribute.
-     * @return                  Fluent API: the result instance.
+     * @param attribute Sort attribute.
+     * @return Fluent API: the result instance.
      */
     <X> QueryResult<E> orderDesc(SingularAttribute<E, X> attribute);
 
     /**
+     * Sort the query result descending by the given entity singular attribute.
+     * This is the typesafe version, alternatively a {@link #orderDesc(String)}
+     * String can be used.
+     *
+     * @param attribute        Sort attribute.
+     * @param appendEntityName whether the entity name 'e' should be appended to this attribute
+     * @return Fluent API: the result instance.
+     */
+    <X> QueryResult<E> orderDesc(SingularAttribute<E, X> attribute, boolean
appendEntityName);
+
+    /**
      * Sort the query result descending by the given entity attribute.
      *
-     * @param attribute         Sort attribute.
-     * @return                  Fluent API: the result instance.
+     * @param attribute Sort attribute.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> orderDesc(String attribute);
 
     /**
+     * Sort the query result descending by the given entity attribute.
+     *
+     * @param attribute        Sort attribute.
+     * @param appendEntityName whether the entity name 'e' should be appended to this attribute
+     * @return Fluent API: the result instance.
+     */
+    QueryResult<E> orderDesc(String attribute, boolean appendEntityName);
+
+    /**
      * Revert an existing order attribute sort direction. Defaults to ascending
      * order if the sort attribute was not used before.
      *
-     * @param attribute         Sort attribute.
-     * @return                  Fluent API: the result instance.
+     * @param attribute Sort attribute.
+     * @return Fluent API: the result instance.
      */
     <X> QueryResult<E> changeOrder(SingularAttribute<E, X> attribute);
 
     /**
      * Remove any ordering from the query result object.
-     * @return                  Fluent API: the result instance.
+     *
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> clearOrder();
 
@@ -88,70 +129,70 @@ public interface QueryResult<E>
      * Revert an existing order attribute sort direction. Defaults to ascending
      * order if the sort attribute was not used before.
      *
-     * @param attribute         Sort attribute.
-     * @return                  Fluent API: the result instance.
+     * @param attribute Sort attribute.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> changeOrder(String attribute);
 
     /**
      * Limit the number of results returned by the query.
      *
-     * @param max               Max number of results.
-     * @return                  Fluent API: the result instance.
+     * @param max Max number of results.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> maxResults(int max);
 
     /**
      * Pagination: Set the result start position.
      *
-     * @param first             Result start position.
-     * @return                  Fluent API: the result instance.
+     * @param first Result start position.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> firstResult(int first);
 
     /**
      * Sets the query lock mode.
      *
-     * @param lockMode          Query lock mode to use in the query.
-     * @return                  Fluent API: the result instance.
+     * @param lockMode Query lock mode to use in the query.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> lockMode(LockModeType lockMode);
 
     /**
      * Sets the query flush mode.
      *
-     * @param flushMode         Query flush mode to use in the query.
-     * @return                  Fluent API: the result instance.
+     * @param flushMode Query flush mode to use in the query.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> flushMode(FlushModeType flushMode);
 
     /**
      * Apply a query hint to the query to execute.
      *
-     * @param hint              Hint name.
-     * @param value             Hint value.
-     * @return                  Fluent API: the result instance.
+     * @param hint  Hint name.
+     * @param value Hint value.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> hint(String hint, Object value);
 
     /**
      * Fetch the result set.
      *
-     * @return                  List of entities retrieved by the query.
+     * @return List of entities retrieved by the query.
      */
     List<E> getResultList();
 
     /**
      * Fetch a single result entity.
      *
-     * @return                  Entity retrieved by the query.
+     * @return Entity retrieved by the query.
      */
     E getSingleResult();
 
     /**
      * Fetch a single result entity. Returns {@code null} if no result is found.
      *
-     * @return                  Entity retrieved by the query, or {@code null} if no result.
+     * @return Entity retrieved by the query, or {@code null} if no result.
      */
     E getOptionalResult();
 
@@ -159,13 +200,14 @@ public interface QueryResult<E>
      * Fetch a single result entity. Returns {@code null} if no result is found. If the
      * query finds multiple results, it simply returns the first one found.
      *
-     * @return                  First Entity retrieved by the query, or {@code null} if no
result.
+     * @return First Entity retrieved by the query, or {@code null} if no result.
      */
     E getAnyResult();
 
     /**
      * Count the result set.
-     * @return                  Result count.
+     *
+     * @return Result count.
      */
     long count();
 
@@ -173,48 +215,51 @@ public interface QueryResult<E>
      * Set a page size on the query result. Defaults to 10 or takes the value of a
      * previous {@link #maxResults(int)} call.
      *
-     * @param pageSize          Page size for further queries.
-     * @return                  Fluent API: the result instance.
+     * @param pageSize Page size for further queries.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> withPageSize(int pageSize);
 
     /**
      * Move the page cursor to a specific page.
      *
-     * @param page              Page to move to for the next query.
-     * @return                  Fluent API: the result instance.
+     * @param page Page to move to for the next query.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> toPage(int page);
 
     /**
      * Move to the next page.
      *
-     * @return                  Fluent API: the result instance.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> nextPage();
 
     /**
      * Move to the previous page.
      *
-     * @return                  Fluent API: the result instance.
+     * @return Fluent API: the result instance.
      */
     QueryResult<E> previousPage();
 
     /**
      * Count the number of pages.
-     * @return                  Page count.
+     *
+     * @return Page count.
      */
     int countPages();
 
     /**
      * Return the actual page.
-     * @return                  Page position.
+     *
+     * @return Page position.
      */
     int currentPage();
 
     /**
      * Return the actual page size.
-     * @return                  Page size.
+     *
+     * @return Page size.
      */
     int pageSize();
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2214758b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/postprocessor/OrderByQueryStringPostProcessor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/postprocessor/OrderByQueryStringPostProcessor.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/postprocessor/OrderByQueryStringPostProcessor.java
index cb9f046..edc0f46 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/postprocessor/OrderByQueryStringPostProcessor.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/postprocessor/OrderByQueryStringPostProcessor.java
@@ -31,17 +31,21 @@ public class OrderByQueryStringPostProcessor implements QueryStringPostProcessor
 
     private final String attribute;
     private OrderDirection direction;
+    private boolean appendEntityName;
 
-    public OrderByQueryStringPostProcessor(SingularAttribute<?, ?> attribute, OrderDirection
direction)
+    public OrderByQueryStringPostProcessor(SingularAttribute<?, ?> attribute, OrderDirection
direction,
+                                           boolean appendEntityName)
     {
         this.attribute = attribute.getName();
         this.direction = direction;
+        this.appendEntityName = appendEntityName;
     }
 
-    public OrderByQueryStringPostProcessor(String attribute, OrderDirection direction)
+    public OrderByQueryStringPostProcessor(String attribute, OrderDirection direction, boolean
appendEntityName)
     {
         this.attribute = attribute;
         this.direction = direction;
+        this.appendEntityName = appendEntityName;
     }
 
     @Override
@@ -56,8 +60,14 @@ public class OrderByQueryStringPostProcessor implements QueryStringPostProcessor
         {
             builder.append(ORDER_BY);
         }
-        return builder.append(QueryBuilder.ENTITY_NAME)
-                .append(".").append(attribute)
+        if (appendEntityName)
+        {
+            builder.append(QueryBuilder.ENTITY_NAME)
+                .append(".");
+        }
+
+        return builder
+                .append(attribute)
                 .append(" ").append(direction)
                 .toString();
     }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2214758b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/DefaultQueryResult.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/DefaultQueryResult.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/DefaultQueryResult.java
index 557d156..2548984 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/DefaultQueryResult.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/DefaultQueryResult.java
@@ -58,28 +58,56 @@ public class DefaultQueryResult<T> implements QueryResult<T>
     @Override
     public <X> QueryResult<T> orderAsc(SingularAttribute<T, X> attribute)
     {
-        context.addQueryStringPostProcessor(new OrderByQueryStringPostProcessor(attribute,
OrderDirection.ASC));
+        return orderAsc(attribute, true);
+    }
+
+    @Override
+    public <X> QueryResult<T> orderAsc(SingularAttribute<T, X> attribute,
boolean appendEntityName)
+    {
+        context.addQueryStringPostProcessor(new OrderByQueryStringPostProcessor(attribute,
OrderDirection.ASC,
+                appendEntityName));
         return this;
     }
 
     @Override
     public QueryResult<T> orderAsc(String attribute)
     {
-        context.addQueryStringPostProcessor(new OrderByQueryStringPostProcessor(attribute,
OrderDirection.ASC));
+        return orderAsc(attribute, true);
+    }
+
+    @Override
+    public QueryResult<T> orderAsc(String attribute, boolean appendEntityName)
+    {
+        context.addQueryStringPostProcessor(new OrderByQueryStringPostProcessor(attribute,
OrderDirection.ASC,
+                appendEntityName));
         return this;
     }
 
     @Override
     public <X> QueryResult<T> orderDesc(SingularAttribute<T, X> attribute)
     {
-        context.addQueryStringPostProcessor(new OrderByQueryStringPostProcessor(attribute,
OrderDirection.DESC));
+        return orderDesc(attribute, true);
+    }
+
+    @Override
+    public <X> QueryResult<T> orderDesc(SingularAttribute<T, X> attribute,
boolean appendEntityName)
+    {
+        context.addQueryStringPostProcessor(new OrderByQueryStringPostProcessor(attribute,
OrderDirection.DESC,
+                appendEntityName));
         return this;
     }
 
     @Override
     public QueryResult<T> orderDesc(String attribute)
     {
-        context.addQueryStringPostProcessor(new OrderByQueryStringPostProcessor(attribute,
OrderDirection.DESC));
+        return orderDesc(attribute, true);
+    }
+
+    @Override
+    public QueryResult<T> orderDesc(String attribute, boolean appendEntityName)
+    {
+        context.addQueryStringPostProcessor(new OrderByQueryStringPostProcessor(attribute,
OrderDirection.DESC,
+                appendEntityName));
         return this;
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2214758b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
index c322cc4..a42025a 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
@@ -377,6 +377,28 @@ public class QueryResultTest extends TransactionalTestCase
         assertEquals("b", resultList.get(1).getId());
     }
 
+    @Test
+    public void should_sort_all_result()
+    {
+        List<Simple> result = repo.queryAll()
+                .orderDesc("s.counter",false)
+                .orderAsc("s.enabled", false)
+                .getResultList();
+        // no real check here, verifying query syntax passes.
+        assertNotNull(result);
+    }
+
+    @Test
+    public void should_sort_name_results()
+    {
+        List<Simple> result = repo.queryResultWithNamed("name")
+                .orderDesc(Simple_.counter, true)
+                .orderAsc(Simple_.id)
+                .getResultList();
+        // no real check here, verifying query syntax passes.
+        assertNotNull(result);
+    }
+
     @Before
     public void setup()
     {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2214758b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2b040fe..600b3c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,30 +19,12 @@
   -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-<!--
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
--->
     <modelVersion>4.0.0</modelVersion>
 
     <parent>
         <groupId>org.apache</groupId>
         <artifactId>apache</artifactId>
-        <version>14</version>
+        <version>17</version>
     </parent>
 
     <!-- 


Mime
View raw message