deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject deltaspike git commit: DELTASPIKE-1267 Remove second factory mechanism of QueryBuilder's
Date Wed, 07 Jun 2017 12:17:18 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 80d672bf0 -> 442366998


DELTASPIKE-1267 Remove second factory mechanism of QueryBuilder's

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

Branch: refs/heads/master
Commit: 442366998715112497f6b18391bbee33dfa31a71
Parents: 80d672b
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Wed Jun 7 14:17:03 2017 +0200
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Wed Jun 7 14:17:03 2017 +0200

----------------------------------------------------------------------
 .../impl/builder/AnnotatedQueryBuilder.java     |  3 --
 .../data/impl/builder/DelegateQueryBuilder.java |  3 --
 .../data/impl/builder/MethodQueryBuilder.java   |  5 +--
 .../data/impl/builder/QueryBuilderFactory.java  | 40 +++++++++--------
 .../data/impl/meta/QueryInvocation.java         | 46 --------------------
 .../data/impl/meta/QueryInvocationLiteral.java  | 46 --------------------
 6 files changed, 24 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/44236699/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
index c27a6c6..53cc660 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
@@ -20,8 +20,6 @@ package org.apache.deltaspike.data.impl.builder;
 
 import org.apache.deltaspike.data.api.Query;
 import org.apache.deltaspike.data.impl.handler.CdiQueryInvocationContext;
-import org.apache.deltaspike.data.impl.meta.RepositoryMethodType;
-import org.apache.deltaspike.data.impl.meta.QueryInvocation;
 import org.apache.deltaspike.data.impl.param.Parameters;
 import org.apache.deltaspike.data.impl.util.jpa.QueryStringExtractorFactory;
 
@@ -37,7 +35,6 @@ import static org.apache.deltaspike.core.util.StringUtils.isNotEmpty;
 /**
  * Create the query based on method annotations.
  */
-@QueryInvocation(RepositoryMethodType.ANNOTATED)
 @ApplicationScoped
 public class AnnotatedQueryBuilder extends QueryBuilder
 {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/44236699/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/DelegateQueryBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/DelegateQueryBuilder.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/DelegateQueryBuilder.java
index 9994f1d..b86252c 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/DelegateQueryBuilder.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/DelegateQueryBuilder.java
@@ -39,12 +39,9 @@ import org.apache.deltaspike.core.util.OptionalUtil;
 import org.apache.deltaspike.core.util.StreamUtil;
 import org.apache.deltaspike.data.api.QueryInvocationException;
 import org.apache.deltaspike.data.impl.handler.CdiQueryInvocationContext;
-import org.apache.deltaspike.data.impl.meta.RepositoryMethodType;
-import org.apache.deltaspike.data.impl.meta.QueryInvocation;
 import org.apache.deltaspike.data.impl.util.bean.BeanDestroyable;
 import org.apache.deltaspike.data.spi.DelegateQueryHandler;
 
-@QueryInvocation(RepositoryMethodType.DELEGATE)
 @ApplicationScoped
 public class DelegateQueryBuilder extends QueryBuilder
 {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/44236699/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/MethodQueryBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/MethodQueryBuilder.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/MethodQueryBuilder.java
index f9efd1e..89f3e58 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/MethodQueryBuilder.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/MethodQueryBuilder.java
@@ -23,11 +23,8 @@ import javax.persistence.Query;
 
 import org.apache.deltaspike.data.impl.builder.part.QueryRoot;
 import org.apache.deltaspike.data.impl.handler.CdiQueryInvocationContext;
-import org.apache.deltaspike.data.impl.meta.RepositoryMethodType;
-import org.apache.deltaspike.data.impl.meta.QueryInvocation;
 import org.apache.deltaspike.data.impl.param.Parameters;
 
-@QueryInvocation(RepositoryMethodType.PARSE)
 @ApplicationScoped
 public class MethodQueryBuilder extends QueryBuilder
 {
@@ -39,7 +36,7 @@ public class MethodQueryBuilder extends QueryBuilder
         return context.executeQuery(jpaQuery);
     }
 
-    private Query createJpaQuery(CdiQueryInvocationContext context)
+     private Query createJpaQuery(CdiQueryInvocationContext context)
     {
         Parameters params = context.getParams();
         QueryRoot root = context.getRepositoryMethodMetadata().getQueryRoot();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/44236699/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryBuilderFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryBuilderFactory.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryBuilderFactory.java
index 77a8653..9d512a9 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryBuilderFactory.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryBuilderFactory.java
@@ -22,36 +22,42 @@ import static org.apache.deltaspike.data.impl.meta.RepositoryMethodType.ANNOTATE
 import static org.apache.deltaspike.data.impl.meta.RepositoryMethodType.DELEGATE;
 import static org.apache.deltaspike.data.impl.meta.RepositoryMethodType.PARSE;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
 
-import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.data.api.QueryResult;
 import org.apache.deltaspike.data.impl.handler.CdiQueryInvocationContext;
 import org.apache.deltaspike.data.impl.meta.RepositoryMethodType;
-import org.apache.deltaspike.data.impl.meta.QueryInvocationLiteral;
 import org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata;
 
 @ApplicationScoped
 public class QueryBuilderFactory
 {
-    private static final Map<RepositoryMethodType, QueryInvocationLiteral> LITERALS
=
-            new HashMap<RepositoryMethodType, QueryInvocationLiteral>()
-            {
-                private static final long serialVersionUID = 1L;
-
-                {
-                    put(ANNOTATED, new QueryInvocationLiteral(ANNOTATED));
-                    put(DELEGATE, new QueryInvocationLiteral(DELEGATE));
-                    put(PARSE, new QueryInvocationLiteral(PARSE));
-                }
-            };
+    @Inject
+    private MethodQueryBuilder methodQueryBuilder;
+    @Inject
+    private DelegateQueryBuilder delegateQueryBuilder;
+    @Inject
+    private AnnotatedQueryBuilder annotatedQueryBuilder;
+            
+    protected QueryBuilder getQueryBuilder(RepositoryMethodType repositoryMethodType)
+    {
+        switch (repositoryMethodType)
+        {
+            case ANNOTATED:
+                return annotatedQueryBuilder;
+            case PARSE:
+                return methodQueryBuilder;
+            case DELEGATE:
+                return delegateQueryBuilder;
+        }
+        
+        throw new RuntimeException("No " + QueryBuilder.class.getName() + " avialable for
type: " + repositoryMethodType);
+    }
 
     public QueryBuilder build(RepositoryMethodMetadata methodMetadata, CdiQueryInvocationContext
context)
     {
-        QueryBuilder builder = BeanProvider.getContextualReference(
-                QueryBuilder.class, LITERALS.get(methodMetadata.getMethodType()));
+        QueryBuilder builder = getQueryBuilder(context.getRepositoryMethodMetadata().getMethodType());
 
         if (QueryResult.class.equals(methodMetadata.getMethod().getReturnType()))
         {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/44236699/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/QueryInvocation.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/QueryInvocation.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/QueryInvocation.java
deleted file mode 100644
index bbd900b..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/QueryInvocation.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.impl.meta;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * CDI qualifier - defines the kind of query invocation. Mainly used to resolve the correct
query builder by method
- * type.
- */
-@Qualifier
-@Target({ TYPE, METHOD, PARAMETER, FIELD })
-@Retention(RUNTIME)
-@Documented
-public @interface QueryInvocation
-{
-
-    RepositoryMethodType value();
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/44236699/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/QueryInvocationLiteral.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/QueryInvocationLiteral.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/QueryInvocationLiteral.java
deleted file mode 100644
index a21143c..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/QueryInvocationLiteral.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.impl.meta;
-
-import javax.enterprise.util.AnnotationLiteral;
-
-/**
- * Utility class to construct a qualifier and resolve a dependency programmatically.
- */
-@SuppressWarnings("all")
-public class QueryInvocationLiteral extends AnnotationLiteral<QueryInvocation>
-        implements QueryInvocation
-{
-
-    private static final long serialVersionUID = 1L;
-
-    private final RepositoryMethodType methodType;
-
-    public QueryInvocationLiteral(RepositoryMethodType methodType)
-    {
-        this.methodType = methodType;
-    }
-
-    @Override
-    public RepositoryMethodType value()
-    {
-        return methodType;
-    }
-
-}


Mime
View raw message