deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From daniels...@apache.org
Subject deltaspike git commit: DELTASPIKE-1100 Support remove expressions [Forced Update!]
Date Sat, 26 Mar 2016 13:59:02 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 7e19fcb51 -> 6522fcb9e (forced update)


DELTASPIKE-1100 Support remove expressions


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

Branch: refs/heads/master
Commit: 6522fcb9e3cda9301b44430843ff2d9aa89473c2
Parents: 2b63081
Author: Daniel Cunha <danielsoro@apache.org>
Authored: Fri Mar 25 18:45:38 2016 -0700
Committer: Daniel Cunha <danielsoro@gmail.com>
Committed: Sat Mar 26 10:58:32 2016 -0300

----------------------------------------------------------------------
 .../deltaspike/data/impl/meta/MethodPrefix.java | 12 +++++++-
 .../data/impl/handler/QueryHandlerTest.java     | 32 ++++++++++++++++++++
 .../data/test/service/SimpleRepository.java     |  4 +++
 documentation/src/main/asciidoc/data.adoc       |  3 ++
 4 files changed, 50 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6522fcb9/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodPrefix.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodPrefix.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodPrefix.java
index 4bfb914..e421087 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodPrefix.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodPrefix.java
@@ -26,6 +26,7 @@ public class MethodPrefix
     public static final String DEFAULT_OPT_PREFIX = "findOptionalBy";
     public static final String DEFAULT_ANY_PREFIX = "findAnyBy";
     public static final String DEFAULT_DELETE_PREFIX = "deleteBy";
+    public static final String DEFAULT_REMOVE_PREFIX = "removeBy";
 
     private final String customPrefix;
     private final String methodName;
@@ -86,7 +87,8 @@ public class MethodPrefix
 
     public boolean isDelete()
     {
-        return this.getPrefix().equalsIgnoreCase(DEFAULT_DELETE_PREFIX);
+        return this.getPrefix().equalsIgnoreCase(DEFAULT_DELETE_PREFIX) ||
+                this.getPrefix().equalsIgnoreCase(DEFAULT_REMOVE_PREFIX);
     }
 
     private static enum KnownQueryPrefix
@@ -122,6 +124,14 @@ public class MethodPrefix
             {
                 return SingleResultType.ANY;
             }
+        },
+        REMOVE_DEFAULT(DEFAULT_REMOVE_PREFIX)
+        {
+            @Override
+            public SingleResultType getStyle()
+            {
+                return SingleResultType.ANY;
+            }
         };
 
         private final String prefix;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6522fcb9/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
index 934f892..89b9397 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
@@ -160,6 +160,38 @@ public class QueryHandlerTest extends TransactionalTestCase
     }
 
     @Test
+    public void should_create_query_remove_by_method_name()
+    {
+        // given
+        final String name = "testCreateQueryByMethodName";
+        builder.createSimple(name);
+
+        // when
+        repo.removeByName(name);
+        repo.flush();
+        Simple result = repo.findAnyByName(name);
+
+        // then
+        assertNull(result);
+    }
+
+    @Test
+    public void should_create_query_remove_by_method_name_with_multiply_params()
+    {
+        // given
+        final String name = "testCreateQueryByMethodName";
+        builder.createSimple(name);
+
+        // when
+        repo.removeByNameAndEnabled(name, Boolean.TRUE);
+        repo.flush();
+        Simple result = repo.findAnyByName(name);
+
+        // then
+        assertNull(result);
+    }
+
+    @Test
     public void should_create_query_delete_by_method_name_with_multiply_params()
     {
         // given

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6522fcb9/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
index 2b1a8d5..ebadd20 100755
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
@@ -107,8 +107,12 @@ public abstract class SimpleRepository extends AbstractEntityRepository<Simple,
 
     public abstract void deleteByName(String name);
 
+    public abstract void removeByName(String name);
+
     public abstract void deleteByNameAndEnabled(String name, boolean enable);
 
+    public abstract void removeByNameAndEnabled(String name, Boolean aTrue);
+
     @Override
     protected abstract EntityManager entityManager();
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6522fcb9/documentation/src/main/asciidoc/data.adoc
----------------------------------------------------------------------
diff --git a/documentation/src/main/asciidoc/data.adoc b/documentation/src/main/asciidoc/data.adoc
index 1c14bbb..e716fd1 100644
--- a/documentation/src/main/asciidoc/data.adoc
+++ b/documentation/src/main/asciidoc/data.adoc
@@ -390,6 +390,9 @@ Or in more concrete words:
 * Followed by a property of the Repository entity and an optional comparator (we'll define
this later). The property will be used in the query together with the comparator. Note that
the number of arguments passed to the method depend on the comparator.
 * You can add more blocks of property-comparator which have to be concatenated by a boolean
operator. This is either an `And` or `Or`.
 
+You can use the same way for delete an entity:
+* It must start with the `removeBy` keyword (or related `deleteBy`).
+
 Other assumptions taken by the expression evaluator:
 
 * The property name starts lower cased while the property in the expression has an upper
cases first character.


Mime
View raw message