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-923 Add #entityName() to AbstractEntityRepository
Date Thu, 11 Jun 2015 16:52:21 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 66dfd4f36 -> 13b3f97be


DELTASPIKE-923 Add #entityName() to AbstractEntityRepository


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

Branch: refs/heads/master
Commit: 13b3f97bebeae2a041c8bd9f0da56f1f4e5fd7ae
Parents: 66dfd4f
Author: Daniel Cunha (soro) <danielsoro@apache.org>
Authored: Thu Jun 11 11:45:14 2015 -0300
Committer: Daniel Cunha (soro) <danielsoro@apache.org>
Committed: Thu Jun 11 13:45:10 2015 -0300

----------------------------------------------------------------------
 .../data/api/AbstractEntityRepository.java      |  6 +++
 .../impl/handler/EntityRepositoryHandler.java   | 11 +++--
 .../handler/EntityRepositoryHandlerTest.java    | 15 ++++++
 .../deltaspike/data/test/domain/Simple4.java    | 50 ++++++++++++++++++++
 .../service/ExtendedRepositoryAbstract.java     |  5 ++
 .../service/ExtendedRepositoryAbstract2.java    |  5 ++
 .../service/ExtendedRepositoryAbstract4.java    | 33 +++++++++++++
 7 files changed, 122 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/13b3f97b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
index 5f459f8..933c136 100755
--- a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
+++ b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
@@ -68,4 +68,10 @@ public abstract class AbstractEntityRepository<E, PK extends Serializable>
      */
     protected abstract String tableName();
 
+    /**
+     * Get the entity name this Repository is related to.
+     * @return          Repository entity name.
+     */
+    protected abstract String entityName();
+
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/13b3f97b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
index f7e06b5..aa7fa66 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
@@ -26,6 +26,7 @@ import org.apache.deltaspike.data.impl.meta.unit.PersistenceUnits;
 import org.apache.deltaspike.data.impl.property.Property;
 import org.apache.deltaspike.data.impl.property.query.NamedPropertyCriteria;
 import org.apache.deltaspike.data.impl.property.query.PropertyQueries;
+import org.apache.deltaspike.data.impl.util.EntityUtils;
 import org.apache.deltaspike.data.spi.DelegateQueryHandler;
 import org.apache.deltaspike.data.spi.QueryInvocationContext;
 
@@ -43,7 +44,6 @@ import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import static org.apache.deltaspike.data.impl.util.EntityUtils.entityName;
 import static org.apache.deltaspike.data.impl.util.QueryUtils.isEmpty;
 import static org.apache.deltaspike.data.impl.util.QueryUtils.isString;
 
@@ -237,18 +237,23 @@ public class EntityRepositoryHandler<E, PK extends Serializable>
         return tableName;
     }
 
+    public String entityName()
+    {
+        return EntityUtils.entityName(entityClass());
+    }
+
     // ----------------------------------------------------------------------------
     // PRIVATE
     // ----------------------------------------------------------------------------
 
     private String allQuery()
     {
-        return QueryBuilder.selectQuery(entityName(entityClass()));
+        return QueryBuilder.selectQuery(entityName());
     }
 
     private String countQuery()
     {
-        return QueryBuilder.countQuery(entityName(entityClass()));
+        return QueryBuilder.countQuery(entityName());
     }
 
     private String exampleQuery(String queryBase, List<Property<Object>> properties,
boolean useLikeOperator)

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/13b3f97b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
index ae6dd5f..c885a4d 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
@@ -38,6 +38,7 @@ import org.apache.deltaspike.data.test.domain.Simple2;
 import org.apache.deltaspike.data.test.domain.Simple_;
 import org.apache.deltaspike.data.test.service.ExtendedRepositoryAbstract;
 import org.apache.deltaspike.data.test.service.ExtendedRepositoryAbstract2;
+import org.apache.deltaspike.data.test.service.ExtendedRepositoryAbstract4;
 import org.apache.deltaspike.data.test.service.ExtendedRepositoryInterface;
 import org.apache.deltaspike.test.category.WebProfileCategory;
 import org.jboss.arquillian.container.test.api.Deployment;
@@ -56,6 +57,7 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
                 .addClasses(ExtendedRepositoryInterface.class)
                 .addClasses(ExtendedRepositoryAbstract.class)
                 .addClasses(ExtendedRepositoryAbstract2.class)
+                .addClasses(ExtendedRepositoryAbstract4.class)
                 .addPackage(Simple.class.getPackage());
     }
 
@@ -68,6 +70,9 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
     @Inject
     private ExtendedRepositoryAbstract2 repoAbstract2;
 
+    @Inject
+    private ExtendedRepositoryAbstract4 repoAbstract4;
+
     @Produces
     @PersistenceContext
     private EntityManager entityManager;
@@ -388,6 +393,16 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
         assertEquals(Simple2.class.getSimpleName(), tableName2);
     }
 
+    @Test
+    public void should_return_entity_name()
+    {
+        final String entityName = repoAbstract.getEntityName();
+        final String entityName2 = repoAbstract4.getEntityName();
+
+        assertEquals("Simple", entityName);
+        assertEquals("EntitySimple4", entityName2);
+    }
+
     @Override
     protected EntityManager getEntityManager()
     {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/13b3f97b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/Simple4.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/Simple4.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/Simple4.java
new file mode 100644
index 0000000..af3a2bd
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/Simple4.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+package org.apache.deltaspike.data.test.domain;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity(name = "EntitySimple4")
+public class Simple4
+{
+
+    @GeneratedValue
+    @Id
+    private long id;
+
+    private String name;
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public long getId()
+    {
+        return id;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/13b3f97b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract.java
index f60b012..88cb6a4 100755
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract.java
@@ -31,4 +31,9 @@ public abstract class ExtendedRepositoryAbstract
     {
         return tableName();
     }
+
+    public String getEntityName()
+    {
+        return entityName();
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/13b3f97b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract2.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract2.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract2.java
index ecbbe97..8b1c62e 100755
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract2.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract2.java
@@ -30,4 +30,9 @@ public abstract class ExtendedRepositoryAbstract2
     {
         return tableName();
     }
+
+    public String getEntityName()
+    {
+        return entityName();
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/13b3f97b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract4.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract4.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract4.java
new file mode 100755
index 0000000..645dca8
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryAbstract4.java
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+package org.apache.deltaspike.data.test.service;
+
+import org.apache.deltaspike.data.api.AbstractEntityRepository;
+import org.apache.deltaspike.data.api.Repository;
+import org.apache.deltaspike.data.test.domain.Simple4;
+
+@Repository
+public abstract class ExtendedRepositoryAbstract4
+        extends AbstractEntityRepository<Simple4, Long>
+{
+    public String getEntityName()
+    {
+        return entityName();
+    }
+}


Mime
View raw message