You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by ta...@apache.org on 2017/06/04 00:00:39 UTC

[1/2] deltaspike git commit: DELTASPIKE-1070 Refactor RepositoryComponent/s

Repository: deltaspike
Updated Branches:
  refs/heads/master fbf62e3bb -> 46a3b6759


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryEntity.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryEntity.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryEntity.java
deleted file mode 100644
index b45fbff..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryEntity.java
+++ /dev/null
@@ -1,101 +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 java.io.Serializable;
-import org.apache.deltaspike.data.impl.property.Property;
-import org.apache.deltaspike.data.impl.util.EntityUtils;
-
-/**
- * Data structure to store information about an entity.
- */
-public class RepositoryEntity
-{
-
-    private Class<?> entityClass;
-    private Class<? extends Serializable> primaryKeyClass;
-    private Property<Serializable> primaryKeyProperty;
-    private Property<Serializable> versionProperty;
-    private String entityName;
-
-    public RepositoryEntity(Class<?> entityClass)
-    {
-        this(entityClass, null);
-    }
-
-    public RepositoryEntity(Class<?> entityClass, Class<? extends Serializable> primaryClass)
-    {
-        this.entityClass = entityClass;
-        this.primaryKeyClass = primaryClass;
-        
-        this.primaryKeyProperty = EntityUtils.primaryKeyProperty(entityClass);
-        this.versionProperty = EntityUtils.getVersionProperty(entityClass);
-        this.entityName = EntityUtils.entityName(entityClass);
-    }
-
-    public Class<?> getEntityClass()
-    {
-        return entityClass;
-    }
-
-    public void setEntityClass(Class<?> entityClass)
-    {
-        this.entityClass = entityClass;
-    }
-
-    public Class<? extends Serializable> getPrimaryKeyClass()
-    {
-        return primaryKeyClass;
-    }
-
-    public void setPrimaryKeyClass(Class<? extends Serializable> primaryKeyClass)
-    {
-        this.primaryKeyClass = primaryKeyClass;
-    }
-
-    public Property<Serializable> getVersionProperty()
-    {
-        return versionProperty;
-    }
-
-    public void setVersionProperty(Property<Serializable> versionProperty)
-    {
-        this.versionProperty = versionProperty;
-    }
-
-    public String getEntityName()
-    {
-        return entityName;
-    }
-
-    public void setEntityName(String entityName)
-    {
-        this.entityName = entityName;
-    }
-
-    public Property<Serializable> getPrimaryKeyProperty()
-    {
-        return primaryKeyProperty;
-    }
-
-    public void setPrimaryKeyProperty(Property<Serializable> primaryKeyProperty)
-    {
-        this.primaryKeyProperty = primaryKeyProperty;
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadata.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadata.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadata.java
new file mode 100644
index 0000000..e690128
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadata.java
@@ -0,0 +1,107 @@
+/*
+ * 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 java.lang.reflect.Method;
+import java.util.Map;
+import javax.persistence.FlushModeType;
+import org.apache.deltaspike.data.api.EntityManagerResolver;
+
+public class RepositoryMetadata
+{
+    private Class<?> repositoryClass;
+
+    private EntityMetadata entityMetadata;
+    private Map<Method, RepositoryMethodMetadata> methodsMetadata;
+
+    private Class<? extends EntityManagerResolver> entityManagerResolverClass;
+    private boolean entityManagerResolverIsNormalScope;
+    private FlushModeType entityManagerFlushMode;
+    
+    public RepositoryMetadata(Class<?> repositoryClass)
+    {
+        this.repositoryClass = repositoryClass;
+    }
+    
+    public RepositoryMetadata(Class<?> repositoryClass, EntityMetadata entityMetadata)
+    {
+        this.repositoryClass = repositoryClass;
+        this.entityMetadata = entityMetadata;
+    }
+    
+    public Class<?> getRepositoryClass()
+    {
+        return repositoryClass;
+    }
+
+    public void setRepositoryClass(Class<?> repositoryClass)
+    {
+        this.repositoryClass = repositoryClass;
+    }
+
+    public EntityMetadata getEntityMetadata()
+    {
+        return entityMetadata;
+    }
+
+    public void setEntityMetadata(EntityMetadata entityMetadata)
+    {
+        this.entityMetadata = entityMetadata;
+    }
+
+    public Class<? extends EntityManagerResolver> getEntityManagerResolverClass()
+    {
+        return entityManagerResolverClass;
+    }
+
+    public void setEntityManagerResolverClass(Class<? extends EntityManagerResolver> entityManagerResolverClass)
+    {
+        this.entityManagerResolverClass = entityManagerResolverClass;
+    }
+
+    public FlushModeType getEntityManagerFlushMode()
+    {
+        return entityManagerFlushMode;
+    }
+
+    public void setEntityManagerFlushMode(FlushModeType entityManagerFlushMode)
+    {
+        this.entityManagerFlushMode = entityManagerFlushMode;
+    }
+
+    public boolean isEntityManagerResolverIsNormalScope()
+    {
+        return entityManagerResolverIsNormalScope;
+    }
+
+    public void setEntityManagerResolverIsNormalScope(boolean entityManagerResolverIsNormalScope)
+    {
+        this.entityManagerResolverIsNormalScope = entityManagerResolverIsNormalScope;
+    }
+
+    public Map<Method, RepositoryMethodMetadata> getMethodsMetadata()
+    {
+        return methodsMetadata;
+    }
+
+    public void setMethodsMetadata(Map<Method, RepositoryMethodMetadata> methodsMetadata)
+    {
+        this.methodsMetadata = methodsMetadata;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataHandler.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataHandler.java
new file mode 100644
index 0000000..fbbe8e5
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataHandler.java
@@ -0,0 +1,111 @@
+/*
+ * 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 java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import org.apache.deltaspike.data.impl.RepositoryExtension;
+
+@ApplicationScoped
+public class RepositoryMetadataHandler
+{
+    private final Map<Class<?>, RepositoryMetadata> repositoriesMetadata =
+            new ConcurrentHashMap<Class<?>, RepositoryMetadata>();
+
+    @Inject
+    private BeanManager beanManager;
+    @Inject
+    private RepositoryExtension extension;
+    
+    @Inject
+    private RepositoryMetadataInitializer metadataInitializer;
+
+    @PostConstruct
+    public void init()
+    {
+        for (Class<?> repositoryClass : extension.getRepositoryClasses())
+        {
+            RepositoryMetadata metadata = metadataInitializer.init(repositoryClass, beanManager);
+            repositoriesMetadata.put(repositoryClass, metadata);
+        }
+    }
+
+    /**
+     * Repository access - lookup the Repository component meta data from a list of candidate classes.
+     * Depending on the implementation, proxy objects might have been modified so the actual class
+     * does not match the original Repository class.
+     *
+     * @param candidateClasses  List of candidates to check.
+     * @return A {@link RepositoryMetadataInitializer} corresponding to the repoClass parameter.
+     */
+    public RepositoryMetadata lookupComponent(List<Class<?>> candidateClasses)
+    {
+        for (Class<?> repoClass : candidateClasses)
+        {
+            if (repositoriesMetadata.containsKey(repoClass))
+            {
+                return repositoriesMetadata.get(repoClass);
+            }
+        }
+        throw new RuntimeException("Unknown Repository classes " + candidateClasses);
+    }
+
+    /**
+     * Repository access - lookup the Repository component meta data for a specific Repository class.
+     *
+     * @param repoClass  The Repository class to lookup the method for
+     * @return A {@link RepositoryMetadataInitializer} corresponding to the repoClass parameter.
+     */
+    public RepositoryMetadata lookupComponent(Class<?> repoClass)
+    {
+        if (repositoriesMetadata.containsKey(repoClass))
+        {
+            return repositoriesMetadata.get(repoClass);
+        }
+        throw new RuntimeException("Unknown Repository class " + repoClass.getName());
+    }
+
+    /**
+     * Repository access - lookup method information for a specific Repository class.
+     *
+     * @param repoClass The Repository class to lookup the method for
+     * @param method    The Method object to get Repository meta data for.
+     * @return A {@link RepositoryMethodMetadataInitializer} corresponding to the method parameter.
+     */
+    public RepositoryMethodMetadata lookupMethod(Class<?> repoClass, Method method)
+    {
+        return lookupComponent(repoClass).getMethodsMetadata().get(method);
+    }
+    
+    public RepositoryMethodMetadata lookupMethod(RepositoryMetadata metadata, Method method)
+    {
+        return metadata.getMethodsMetadata().get(method);
+    }
+
+    public Map<Class<?>, RepositoryMetadata> getRepositories()
+    {
+        return repositoriesMetadata;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataInitializer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataInitializer.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataInitializer.java
new file mode 100644
index 0000000..c2755b5
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataInitializer.java
@@ -0,0 +1,143 @@
+/*
+ * 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 java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.enterprise.context.ApplicationScoped;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.persistence.FlushModeType;
+
+import org.apache.deltaspike.data.api.EntityManagerConfig;
+import org.apache.deltaspike.data.api.EntityManagerResolver;
+
+@ApplicationScoped
+public class RepositoryMetadataInitializer
+{
+    private static final Logger log = Logger.getLogger(RepositoryMetadataInitializer.class.getName());
+
+    @Inject
+    private RepositoryMethodMetadataInitializer methodMetadataInitializer;
+    
+    @Inject
+    private EntityMetadataInitializer entityMetadataInitializer;
+    
+    public RepositoryMetadata init(Class<?> repositoryClass, BeanManager beanManager)
+    {
+        RepositoryMetadata repositoryMetadata = new RepositoryMetadata(repositoryClass);
+        
+        repositoryMetadata.setEntityManagerResolverClass(extractEntityManagerResolver(repositoryClass));
+        repositoryMetadata.setEntityManagerFlushMode(extractEntityManagerFlushMode(repositoryClass));
+
+        if (repositoryMetadata.getEntityManagerResolverClass() != null)
+        {
+            Set<Bean<?>> beans = beanManager.getBeans(repositoryMetadata.getEntityManagerResolverClass());
+            Class<? extends Annotation> scope = beanManager.resolve(beans).getScope();
+
+            repositoryMetadata.setEntityManagerResolverIsNormalScope(beanManager.isNormalScope(scope));
+        }
+        else
+        {
+            repositoryMetadata.setEntityManagerResolverIsNormalScope(false);
+        }
+        
+        repositoryMetadata.setEntityMetadata(entityMetadataInitializer.init(repositoryMetadata));
+
+        initializeMethodsMetadata(repositoryMetadata, beanManager);
+        
+        return repositoryMetadata;
+    }
+
+    private void initializeMethodsMetadata(RepositoryMetadata repositoryMetadata, BeanManager beanManager)
+    {
+        repositoryMetadata.setMethodsMetadata(new HashMap<Method, RepositoryMethodMetadata>());
+        
+        Set<Class<?>> allImplemented = new HashSet<Class<?>>();
+        collectClasses(repositoryMetadata.getRepositoryClass(), allImplemented);
+        log.log(Level.FINER, "collectClasses(): Found {0} for {1}",
+                new Object[] { allImplemented, repositoryMetadata.getRepositoryClass() });
+
+        for (Class<?> implemented : allImplemented)
+        {
+            Method[] repoClassMethods = implemented.getDeclaredMethods();
+            for (Method repoClassMethod : repoClassMethods)
+            {
+                RepositoryMethodMetadata methodMetadata =
+                        methodMetadataInitializer.init(repositoryMetadata, repoClassMethod, beanManager);
+                repositoryMetadata.getMethodsMetadata().put(repoClassMethod, methodMetadata);
+            }
+        }
+    }
+
+    private void collectClasses(Class<?> cls, Set<Class<?>> result)
+    {
+        if (cls == null || cls == Object.class)
+        {
+            return;
+        }
+        
+        result.add(cls);
+        
+        for (Class<?> child : cls.getInterfaces())
+        {
+            collectClasses(child, result);
+        }
+        
+        collectClasses(cls.getSuperclass(), result);
+    }
+
+    private Class<? extends EntityManagerResolver> extractEntityManagerResolver(Class<?> clazz)
+    {
+        EntityManagerConfig config = extractEntityManagerConfig(clazz);
+        if (config != null && !EntityManagerResolver.class.equals(config.entityManagerResolver()))
+        {
+            return config.entityManagerResolver();
+        }
+        return null;
+    }
+
+    private FlushModeType extractEntityManagerFlushMode(Class<?> clazz)
+    {
+        EntityManagerConfig config = extractEntityManagerConfig(clazz);
+        if (config != null)
+        {
+            return config.flushMode();
+        }
+        return null;
+    }
+
+    private EntityManagerConfig extractEntityManagerConfig(Class<?> clazz)
+    {
+        if (clazz.isAnnotationPresent(EntityManagerConfig.class))
+        {
+            return clazz.getAnnotation(EntityManagerConfig.class);
+        }
+        return null;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethod.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethod.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethod.java
deleted file mode 100644
index 0522b32..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethod.java
+++ /dev/null
@@ -1,257 +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 org.apache.deltaspike.core.util.StringUtils.isNotEmpty;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.persistence.LockModeType;
-
-import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
-import org.apache.deltaspike.core.api.provider.BeanProvider;
-import org.apache.deltaspike.core.api.provider.DependentProvider;
-import org.apache.deltaspike.core.util.OptionalUtil;
-import org.apache.deltaspike.data.api.Modifying;
-import org.apache.deltaspike.data.api.Query;
-import org.apache.deltaspike.data.api.SingleResultType;
-import org.apache.deltaspike.data.api.mapping.MappingConfig;
-import org.apache.deltaspike.data.api.mapping.QueryInOutMapper;
-import org.apache.deltaspike.data.impl.builder.MethodExpressionException;
-import org.apache.deltaspike.data.impl.builder.part.QueryRoot;
-import org.apache.deltaspike.data.impl.builder.result.QueryProcessor;
-import org.apache.deltaspike.data.impl.builder.result.QueryProcessorFactory;
-import org.apache.deltaspike.data.impl.handler.CdiQueryInvocationContext;
-import org.apache.deltaspike.data.impl.util.bean.DependentProviderDestroyable;
-
-/**
- * Stores information about a specific method of a Repository:
- * <ul>
- * <li>The reference to the Method reflection object</li>
- * <li>Whether this method delegates, is annotated or is parsed</li>
- * <li>A reference to the parent Repository</li>
- * <li>For parsed Repository methods, also the JPQL string is cached</li>
- * </ul>
- */
-public class RepositoryMethod
-{
-
-    private final Method method;
-    private final MethodType methodType;
-    private final MethodPrefix methodPrefix;
-    private final RepositoryComponent repo;
-    private final QueryRoot queryRoot;
-    private final QueryProcessor queryProcessor;
-    private final Class<? extends QueryInOutMapper<?>> mapper;
-    private final boolean isOptional;
-
-    private volatile Boolean queryInOutMapperIsNormalScope;
-
-    public RepositoryMethod(Method method, RepositoryComponent repo)
-    {
-        this.method = method;
-        this.repo = repo;
-        this.methodPrefix = new MethodPrefix(repo.getCustomMethodPrefix(), method.getName());
-        this.methodType = extractMethodType();
-        this.queryRoot = initQueryRoot();
-        this.queryProcessor = QueryProcessorFactory.newInstance(method, methodPrefix).build();
-        this.mapper = extractMapper(method, repo);
-        this.isOptional = OptionalUtil.isOptionalReturned(this.method);
-    }
-
-    public boolean returns(Class<?> returnType)
-    {
-        return returnType.equals(method.getReturnType());
-    }
-
-    public QueryInOutMapper<?> getQueryInOutMapperInstance(CdiQueryInvocationContext context)
-    {
-        if (!hasQueryInOutMapper())
-        {
-            return null;
-        }
-        QueryInOutMapper<?> result = null;
-        lazyInit();
-        if (!queryInOutMapperIsNormalScope)
-        {
-            final DependentProvider<? extends QueryInOutMapper<?>> mappedProvider = BeanProvider.getDependent(mapper);
-            result = mappedProvider.get();
-            context.addDestroyable(new DependentProviderDestroyable(mappedProvider));
-        }
-        else
-        {
-            result = BeanProvider.getContextualReference(mapper);
-        }
-        return result;
-    }
-
-    private MethodType extractMethodType()
-    {
-        if (isAnnotated())
-        {
-            return MethodType.ANNOTATED;
-        }
-        if (isMethodExpression())
-        {
-            return MethodType.PARSE;
-        }
-        return MethodType.DELEGATE;
-    }
-
-    private QueryRoot initQueryRoot()
-    {
-        if (methodType == MethodType.PARSE)
-        {
-            return QueryRoot.create(method.getName(), repo, methodPrefix);
-        }
-        return QueryRoot.UNKNOWN_ROOT;
-    }
-
-    private boolean isAnnotated()
-    {
-        if (method.isAnnotationPresent(Query.class))
-        {
-            Query query = method.getAnnotation(Query.class);
-            return isValid(query);
-        }
-        return false;
-    }
-
-    private boolean isValid(Query query)
-    {
-        return isNotEmpty(query.value()) || isNotEmpty(query.named());
-    }
-
-    private boolean isMethodExpression()
-    {
-        if (!Modifier.isAbstract(method.getModifiers()))
-        {
-            return false;
-        }
-        try
-        {
-            QueryRoot.create(method.getName(), repo, methodPrefix);
-            return true;
-        }
-        catch (MethodExpressionException e)
-        {
-            return false;
-        }
-    }
-
-    private Class<? extends QueryInOutMapper<?>> extractMapper(Method queryMethod, RepositoryComponent repoComponent)
-    {
-        if (queryMethod.isAnnotationPresent(MappingConfig.class))
-        {
-            return queryMethod.getAnnotation(MappingConfig.class).value();
-        }
-        if (repoComponent.getRepositoryClass().isAnnotationPresent(MappingConfig.class))
-        {
-            return repoComponent.getRepositoryClass().getAnnotation(MappingConfig.class).value();
-        }
-        return null;
-    }
-
-    //don't trigger this lookup during ProcessAnnotatedType
-    private void lazyInit()
-    {
-        if (queryInOutMapperIsNormalScope == null)
-        {
-            init(BeanManagerProvider.getInstance().getBeanManager());
-        }
-    }
-
-    private synchronized void init(BeanManager beanManager)
-    {
-        if (queryInOutMapperIsNormalScope != null)
-        {
-            return;
-        }
-
-        if (beanManager != null)
-        {
-            final Set<Bean<?>> beans = beanManager.getBeans(mapper);
-            final Class<? extends Annotation> scope = beanManager.resolve(beans).getScope();
-            queryInOutMapperIsNormalScope = beanManager.isNormalScope(scope);
-        }
-        else
-        {
-            queryInOutMapperIsNormalScope = false;
-        }
-    }
-
-    public MethodType getMethodType()
-    {
-        return methodType;
-    }
-
-    public RepositoryComponent getRepository()
-    {
-        return repo;
-    }
-
-    public QueryRoot getQueryRoot()
-    {
-        return queryRoot;
-    }
-
-    public QueryProcessor getQueryProcessor()
-    {
-        return queryProcessor;
-    }
-
-    public boolean hasQueryInOutMapper()
-    {
-        return mapper != null;
-    }
-
-    public int getDefinedMaxResults()
-    {
-        return this.methodPrefix.getDefinedMaxResults();
-    }
-
-    public SingleResultType getSingleResultStyle()
-    {
-        if (method.isAnnotationPresent(Query.class))
-        {
-            return method.getAnnotation(Query.class).singleResult();
-        }
-        return methodPrefix.getSingleResultStyle();
-    }
-
-    public boolean requiresTransaction()
-    {
-        boolean hasLockMode = false;
-        if (method.isAnnotationPresent(Query.class))
-        {
-            hasLockMode = !method.getAnnotation(Query.class).lock().equals(LockModeType.NONE);
-        }
-        return hasLockMode || method.isAnnotationPresent(Modifying.class);
-    }
-
-    public boolean isOptional()
-    {
-        return this.isOptional;
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadata.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadata.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadata.java
new file mode 100644
index 0000000..bb4bdb2
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadata.java
@@ -0,0 +1,155 @@
+/*
+ * 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 java.lang.reflect.Method;
+import org.apache.deltaspike.data.api.Modifying;
+import org.apache.deltaspike.data.api.Query;
+import org.apache.deltaspike.data.api.mapping.QueryInOutMapper;
+import org.apache.deltaspike.data.impl.builder.part.QueryRoot;
+import org.apache.deltaspike.data.impl.builder.result.QueryProcessor;
+
+public class RepositoryMethodMetadata
+{
+    private Method method;
+    private RepositoryMethodType methodType;
+    private RepositoryMethodPrefix methodPrefix;
+    
+    private Query query;
+    private Modifying modifying;
+    
+    private QueryRoot queryRoot;
+    private QueryProcessor queryProcessor;
+
+    private Class<? extends QueryInOutMapper<?>> queryInOutMapperClass;
+    private boolean queryInOutMapperIsNormalScope;
+    
+    private boolean optionalAsReturnType;
+
+    public RepositoryMethodMetadata()
+    {
+        
+    }
+    
+    public RepositoryMethodMetadata(Method method)
+    {
+        this.method = method;
+    }
+    
+    public Method getMethod()
+    {
+        return method;
+    }
+
+    public void setMethod(Method method)
+    {
+        this.method = method;
+    }
+
+    public RepositoryMethodType getMethodType()
+    {
+        return methodType;
+    }
+
+    public void setMethodType(RepositoryMethodType methodType)
+    {
+        this.methodType = methodType;
+    }
+
+    public RepositoryMethodPrefix getMethodPrefix()
+    {
+        return methodPrefix;
+    }
+
+    public void setMethodPrefix(RepositoryMethodPrefix methodPrefix)
+    {
+        this.methodPrefix = methodPrefix;
+    }
+
+    public QueryRoot getQueryRoot()
+    {
+        return queryRoot;
+    }
+
+    public void setQueryRoot(QueryRoot queryRoot)
+    {
+        this.queryRoot = queryRoot;
+    }
+
+    public QueryProcessor getQueryProcessor()
+    {
+        return queryProcessor;
+    }
+
+    public void setQueryProcessor(QueryProcessor queryProcessor)
+    {
+        this.queryProcessor = queryProcessor;
+    }
+
+    public Class<? extends QueryInOutMapper<?>> getQueryInOutMapperClass()
+    {
+        return queryInOutMapperClass;
+    }
+
+    public void setQueryInOutMapperClass(Class<? extends QueryInOutMapper<?>> queryInOutMapperClass)
+    {
+        this.queryInOutMapperClass = queryInOutMapperClass;
+    }
+
+    public boolean isQueryInOutMapperIsNormalScope()
+    {
+        return queryInOutMapperIsNormalScope;
+    }
+
+    public void setQueryInOutMapperIsNormalScope(boolean queryInOutMapperIsNormalScope)
+    {
+        this.queryInOutMapperIsNormalScope = queryInOutMapperIsNormalScope;
+    }
+
+    public boolean isOptionalAsReturnType()
+    {
+        return optionalAsReturnType;
+    }
+
+    public void setOptionalAsReturnType(boolean optionalAsReturnType)
+    {
+        this.optionalAsReturnType = optionalAsReturnType;
+    }
+
+    public Query getQuery()
+    {
+        return query;
+    }
+
+    public void setQuery(Query query)
+    {
+        this.query = query;
+    }
+
+    public Modifying getModifying() 
+    {
+        return modifying;
+    }
+
+    public void setModifying(Modifying modifying)
+    {
+        this.modifying = modifying;
+    } 
+    
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadataInitializer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadataInitializer.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadataInitializer.java
new file mode 100644
index 0000000..6552411
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadataInitializer.java
@@ -0,0 +1,170 @@
+/*
+ * 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 org.apache.deltaspike.core.util.StringUtils.isNotEmpty;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Set;
+import javax.enterprise.context.ApplicationScoped;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.deltaspike.core.util.OptionalUtil;
+import org.apache.deltaspike.data.api.Modifying;
+import org.apache.deltaspike.data.api.Query;
+import org.apache.deltaspike.data.api.Repository;
+import org.apache.deltaspike.data.api.mapping.MappingConfig;
+import org.apache.deltaspike.data.api.mapping.QueryInOutMapper;
+import org.apache.deltaspike.data.impl.builder.MethodExpressionException;
+import org.apache.deltaspike.data.impl.builder.part.QueryRoot;
+import org.apache.deltaspike.data.impl.builder.result.QueryProcessorFactory;
+
+@ApplicationScoped
+public class RepositoryMethodMetadataInitializer
+{
+    public RepositoryMethodMetadata init(RepositoryMetadata repositoryMetadata, Method method, BeanManager beanManager)
+    {
+        RepositoryMethodMetadata repositoryMethodMetadata = new RepositoryMethodMetadata();
+        
+        repositoryMethodMetadata.setMethod(method);
+
+        repositoryMethodMetadata.setQuery(method.isAnnotationPresent(Query.class)
+                ? method.getAnnotation(Query.class) : null);
+        repositoryMethodMetadata.setModifying(method.isAnnotationPresent(Modifying.class)
+                ? method.getAnnotation(Modifying.class) : null);
+        
+        
+        repositoryMethodMetadata.setMethodPrefix(new RepositoryMethodPrefix(
+                    repositoryMetadata.getRepositoryClass().getAnnotation(Repository.class).methodPrefix(),
+                    method.getName()));
+        repositoryMethodMetadata.setMethodType(
+                extractMethodType(repositoryMetadata, repositoryMethodMetadata));
+        
+        repositoryMethodMetadata.setQueryProcessor(
+                QueryProcessorFactory.newInstance(method, repositoryMethodMetadata.getMethodPrefix()).build());
+        
+        repositoryMethodMetadata.setQueryInOutMapperClass(
+                extractMapper(method, repositoryMetadata));
+        
+        repositoryMethodMetadata.setOptionalAsReturnType(
+                OptionalUtil.isOptionalReturned(method));
+
+        initQueryRoot(repositoryMetadata, repositoryMethodMetadata);
+        initQueryInOutMapperIsNormalScope(repositoryMetadata, repositoryMethodMetadata, beanManager);
+
+        return repositoryMethodMetadata;
+    }
+
+    private RepositoryMethodType extractMethodType(RepositoryMetadata repositoryMetadata,
+            RepositoryMethodMetadata repositoryMethodMetadata)
+    {
+        if (isAnnotated(repositoryMethodMetadata))
+        {
+            return RepositoryMethodType.ANNOTATED;
+        }
+        
+        if (isMethodExpression(repositoryMetadata, repositoryMethodMetadata))
+        {
+            return RepositoryMethodType.PARSE;
+        }
+        
+        return RepositoryMethodType.DELEGATE;
+    }
+
+    private void initQueryRoot(RepositoryMetadata repositoryMetadata, RepositoryMethodMetadata methodMetadata)
+    {
+        if (methodMetadata.getMethodType() == RepositoryMethodType.PARSE)
+        {
+            methodMetadata.setQueryRoot(
+                    QueryRoot.create(methodMetadata.getMethod().getName(),
+                            repositoryMetadata,
+                            methodMetadata.getMethodPrefix()));
+        }
+        else
+        {
+            methodMetadata.setQueryRoot(QueryRoot.UNKNOWN_ROOT);
+        }
+    }
+    
+    private void initQueryInOutMapperIsNormalScope(RepositoryMetadata repositoryMetadata,
+            RepositoryMethodMetadata repositoryMethodMetadata, BeanManager beanManager)
+    {
+        if (repositoryMethodMetadata.getQueryInOutMapperClass() != null)
+        {
+            Set<Bean<?>> beans = beanManager.getBeans(repositoryMethodMetadata.getQueryInOutMapperClass());
+            Class<? extends Annotation> scope = beanManager.resolve(beans).getScope();
+            repositoryMethodMetadata.setQueryInOutMapperIsNormalScope(beanManager.isNormalScope(scope));
+        }
+    }
+
+    private boolean isAnnotated(RepositoryMethodMetadata repositoryMethodMetadata)
+    {
+        if (repositoryMethodMetadata.getQuery() != null)
+        {
+            return isValid(repositoryMethodMetadata.getQuery());
+        }
+        return false;
+    }
+
+    private boolean isValid(Query query)
+    {
+        return isNotEmpty(query.value()) || isNotEmpty(query.named());
+    }
+
+    private boolean isMethodExpression(RepositoryMetadata repositoryMetadata,
+            RepositoryMethodMetadata repositoryMethodMetadata)
+    {
+        if (!Modifier.isAbstract(repositoryMethodMetadata.getMethod().getModifiers()))
+        {
+            return false;
+        }
+        
+        try
+        {
+            QueryRoot.create(repositoryMethodMetadata.getMethod().getName(),
+                    repositoryMetadata,
+                    repositoryMethodMetadata.getMethodPrefix());
+            return true;
+        }
+        catch (MethodExpressionException e)
+        {
+            return false;
+        }
+    }
+
+    private Class<? extends QueryInOutMapper<?>> extractMapper(Method queryMethod,
+            RepositoryMetadata repositoryMetadata)
+    {
+        if (queryMethod.isAnnotationPresent(MappingConfig.class))
+        {
+            return queryMethod.getAnnotation(MappingConfig.class).value();
+        }
+        
+        if (repositoryMetadata.getRepositoryClass().isAnnotationPresent(MappingConfig.class))
+        {
+            return repositoryMetadata.getRepositoryClass().getAnnotation(MappingConfig.class).value();
+        }
+        
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodPrefix.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodPrefix.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodPrefix.java
new file mode 100644
index 0000000..a166e08
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodPrefix.java
@@ -0,0 +1,188 @@
+/*
+ * 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 org.apache.deltaspike.data.api.SingleResultType;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class RepositoryMethodPrefix
+{
+    public static final String DEFAULT_PREFIX = "findBy";
+    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 static final String FIND_ALL_PREFIX = "findAll";
+
+    private static final String FIND_FIRST_PREFIX = "find(First|Top)(\\d+)(By)*";
+    private static final String FIND_FIRST_PREFIX_PATTERN = FIND_FIRST_PREFIX + "(.*)";
+    private static final Pattern DIGIT_PATTERN = Pattern.compile("\\d+");
+
+    private final String customPrefix;
+    private final String methodName;
+    private int definedMaxResults = 0;
+
+    public RepositoryMethodPrefix(String customPrefix, String methodName)
+    {
+        this.customPrefix = customPrefix;
+        this.methodName = methodName;
+        if (this.methodName != null)
+        {
+            this.parseMaxResults();
+        }
+    }
+
+    public String removePrefix(String queryPart)
+    {
+        if (hasCustomPrefix() && queryPart.startsWith(customPrefix))
+        {
+            return queryPart.substring(customPrefix.length());
+        }
+        KnownQueryPrefix known = KnownQueryPrefix.fromMethodName(queryPart);
+        if (known != null)
+        {
+            return known.removePrefix(queryPart);
+        }
+        return queryPart;
+    }
+
+    public boolean hasCustomPrefix()
+    {
+        return !"".equals(customPrefix);
+    }
+
+    public String getCustomPrefix()
+    {
+        return customPrefix;
+    }
+
+    public String getPrefix()
+    {
+        if (hasCustomPrefix())
+        {
+            return customPrefix;
+        }
+        KnownQueryPrefix prefix = KnownQueryPrefix.fromMethodName(methodName);
+        if (prefix != null)
+        {
+            return prefix.getPrefix();
+        }
+        return "";
+    }
+
+    public SingleResultType getSingleResultStyle()
+    {
+        KnownQueryPrefix prefix = KnownQueryPrefix.fromMethodName(methodName);
+        if (prefix != null)
+        {
+            return prefix.getStyle();
+        }
+        return SingleResultType.JPA;
+    }
+
+    public boolean isDelete()
+    {
+        return this.getPrefix().equalsIgnoreCase(DEFAULT_DELETE_PREFIX) ||
+                this.getPrefix().equalsIgnoreCase(DEFAULT_REMOVE_PREFIX);
+    }
+
+    public int getDefinedMaxResults()
+    {
+        return definedMaxResults;
+    }
+
+    private void parseMaxResults()
+    {
+        if (this.methodName.matches(FIND_FIRST_PREFIX_PATTERN))
+        {
+            Matcher matcher = DIGIT_PATTERN.matcher(this.methodName);
+            if (matcher.find())
+            {
+                this.definedMaxResults = Integer.parseInt(matcher.group());
+            }
+        }
+    }
+
+    private enum KnownQueryPrefix
+    {
+        DEFAULT(DEFAULT_PREFIX, SingleResultType.JPA),
+        ALL(FIND_ALL_PREFIX, SingleResultType.JPA),
+        FIND_FIRST(FIND_FIRST_PREFIX, SingleResultType.JPA)
+        {
+            @Override
+            public boolean matches(String name)
+            {
+                return name.matches(FIND_FIRST_PREFIX_PATTERN);
+            }
+            @Override
+            public String removePrefix(String queryPart)
+            {
+                return queryPart.replaceFirst(FIND_FIRST_PREFIX,"");
+            }
+        },
+        OPTIONAL(DEFAULT_OPT_PREFIX,SingleResultType.OPTIONAL),
+        ANY(DEFAULT_ANY_PREFIX, SingleResultType.ANY),
+        DELETE_DEFAULT(DEFAULT_DELETE_PREFIX, SingleResultType.ANY),
+        REMOVE_DEFAULT(DEFAULT_REMOVE_PREFIX, SingleResultType.ANY);
+
+        private final String prefix;
+        private final SingleResultType singleResultType;
+
+        KnownQueryPrefix(String prefix, SingleResultType singleResultType)
+        {
+            this.prefix = prefix;
+            this.singleResultType = singleResultType;
+        }
+
+        public String removePrefix(String queryPart)
+        {
+            return queryPart.substring(prefix.length());
+        }
+
+        public String getPrefix()
+        {
+            return prefix;
+        }
+
+        public SingleResultType getStyle()
+        {
+            return this.singleResultType;
+        }
+
+        public boolean matches(String name)
+        {
+            return name.startsWith(getPrefix());
+        }
+
+        public static KnownQueryPrefix fromMethodName(String name)
+        {
+            for (KnownQueryPrefix mapping : values())
+            {
+                if (mapping.matches(name))
+                {
+                    return mapping;
+                }
+            }
+            return null;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodType.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodType.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodType.java
new file mode 100644
index 0000000..44c9e43
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodType.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+
+/**
+ * Repository method type. Stands for
+ * <ul>
+ * <li>Delegated methods - the Repository has a concrete implementation for this or the method is implemented in the
+ * {@link org.apache.deltaspike.data.impl.handler.EntityRepositoryHandler}.</li>
+ * <li>Annotated method - the query is defined via a Query annotation.</li>
+ * <li>The method defines a query expression by its name.</li>
+ * </ul>
+ */
+public enum RepositoryMethodType
+{
+
+    DELEGATE, ANNOTATED, PARSE
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/AnnotationMetadataExtractor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/AnnotationMetadataExtractor.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/AnnotationMetadataExtractor.java
deleted file mode 100644
index 46bedc8..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/AnnotationMetadataExtractor.java
+++ /dev/null
@@ -1,41 +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.extractor;
-
-import org.apache.deltaspike.data.api.Repository;
-import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
-import org.apache.deltaspike.data.impl.util.EntityUtils;
-
-public class AnnotationMetadataExtractor implements MetadataExtractor
-{
-
-    @Override
-    public RepositoryEntity extract(Class<?> repoClass)
-    {
-        Repository repo = repoClass.getAnnotation(Repository.class);
-        Class<?> repoEntity = repo.forEntity();
-        boolean isEntityClass = !Object.class.equals(repoEntity) && EntityUtils.isEntityClass(repoEntity);
-        if (isEntityClass)
-        {
-            return new RepositoryEntity(repoEntity, EntityUtils.primaryKeyClass(repoEntity));
-        }
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/MetadataExtractor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/MetadataExtractor.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/MetadataExtractor.java
deleted file mode 100644
index 93cd939..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/MetadataExtractor.java
+++ /dev/null
@@ -1,34 +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.extractor;
-
-import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
-
-public interface MetadataExtractor
-{
-
-    /**
-     * Read entity meta data for a class.
-     *
-     * @return Meta data packed in a {@link RepositoryEntity},
-     * or {@code null} if the extractor was not able to find data.
-     */
-    RepositoryEntity extract(Class<?> repoClass);
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractor.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractor.java
deleted file mode 100644
index 043ab88..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractor.java
+++ /dev/null
@@ -1,99 +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.extractor;
-
-import java.io.Serializable;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
-import org.apache.deltaspike.data.impl.util.EntityUtils;
-
-public class TypeMetadataExtractor implements MetadataExtractor
-{
-
-    private static final Logger log = Logger.getLogger(TypeMetadataExtractor.class.getName());
-
-    @Override
-    public RepositoryEntity extract(Class<?> repoClass)
-    {
-        for (Type inf : repoClass.getGenericInterfaces())
-        {
-            RepositoryEntity result = extractFrom(inf);
-            if (result != null)
-            {
-                return result;
-            }
-        }
-        RepositoryEntity result = extractFrom(repoClass.getGenericSuperclass());
-        if (result != null)
-        {
-            return result;
-        }
-        for (Type intf : repoClass.getGenericInterfaces())
-        {
-            result = extractFrom(intf);
-            if (result != null)
-            {
-                return result;
-            }
-        }
-        if (repoClass.getSuperclass() != null)
-        {
-            return extract(repoClass.getSuperclass());
-        }
-        return null;
-    }
-
-    @SuppressWarnings("unchecked")
-    private RepositoryEntity extractFrom(Type type)
-    {
-        log.log(Level.FINER, "extractFrom: type = {0}", type);
-        if (!(type instanceof ParameterizedType))
-        {
-            return null;
-        }
-        
-        ParameterizedType parametrizedType = (ParameterizedType) type;
-        Type[] genericTypes = parametrizedType.getActualTypeArguments();
-        
-        RepositoryEntity result = null;
-        
-        // don't use a foreach here, we must be sure that the we first get the entity type
-        for (int i = 0; i < genericTypes.length; i++)
-        {
-            Type genericType = genericTypes[i];
-            
-            if (genericType instanceof Class && EntityUtils.isEntityClass((Class<?>) genericType))
-            {
-                result = new RepositoryEntity((Class<?>) genericType);
-                continue;
-            }
-            if (result != null && genericType instanceof Class)
-            {
-                result.setPrimaryKeyClass((Class<? extends Serializable>) genericType);
-                return result;
-            }
-        }
-        return result;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/param/Parameters.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/param/Parameters.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/param/Parameters.java
index d5e74b8..177c56b 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/param/Parameters.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/param/Parameters.java
@@ -32,7 +32,7 @@ import org.apache.deltaspike.data.api.FirstResult;
 import org.apache.deltaspike.data.api.MaxResults;
 import org.apache.deltaspike.data.api.QueryParam;
 import org.apache.deltaspike.data.api.mapping.QueryInOutMapper;
-import org.apache.deltaspike.data.impl.meta.RepositoryMethod;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata;
 
 /**
  * Convenience class to manage method and query parameters.
@@ -62,7 +62,7 @@ public final class Parameters
         return new Parameters(empty, DEFAULT_MAX, DEFAULT_FIRST);
     }
 
-    public static Parameters create(Method method, Object[] parameters, RepositoryMethod repositoryMethod)
+    public static Parameters create(Method method, Object[] parameters, RepositoryMethodMetadata repositoryMethod)
     {
         int max = extractSizeRestriction(method, repositoryMethod);
         int first = DEFAULT_FIRST;
@@ -143,13 +143,13 @@ public final class Parameters
         return firstResult;
     }
 
-    private static int extractSizeRestriction(Method method, RepositoryMethod repositoryMethod)
+    private static int extractSizeRestriction(Method method, RepositoryMethodMetadata repositoryMethod)
     {
-        if (method.isAnnotationPresent(org.apache.deltaspike.data.api.Query.class))
+        if (repositoryMethod.getQuery() != null)
         {
-            return method.getAnnotation(org.apache.deltaspike.data.api.Query.class).max();
+            return repositoryMethod.getQuery().max();
         }
-        return repositoryMethod.getDefinedMaxResults();
+        return repositoryMethod.getMethodPrefix().getDefinedMaxResults();
     }
 
     @SuppressWarnings("unchecked")

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java
index 2e3eab0..fe89dbe 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java
@@ -22,7 +22,10 @@ import java.lang.reflect.Method;
 import javax.enterprise.context.ApplicationScoped;
 
 import javax.inject.Inject;
+import javax.persistence.LockModeType;
 import org.apache.deltaspike.core.util.ClassUtils;
+import org.apache.deltaspike.data.api.Modifying;
+import org.apache.deltaspike.data.api.Query;
 
 import org.apache.deltaspike.data.impl.builder.QueryBuilder;
 import org.apache.deltaspike.data.impl.handler.CdiQueryInvocationContext;
@@ -81,14 +84,24 @@ public class TransactionalQueryRunner implements QueryRunner
 
     private boolean needsTransaction(CdiQueryInvocationContext context)
     {
-        boolean requiresTx = false;
-        Method method = context.getMethod();
-        if (ClassUtils.containsMethod(EntityRepositoryHandler.class, method))
+        if (ClassUtils.containsMethod(EntityRepositoryHandler.class, context.getMethod()))
         {
-            Method executed = ClassUtils.extractMethod(EntityRepositoryHandler.class, method);
-            requiresTx = executed.isAnnotationPresent(RequiresTransaction.class);
+            Method executed = ClassUtils.extractMethod(EntityRepositoryHandler.class, context.getMethod());
+            if (executed.isAnnotationPresent(RequiresTransaction.class))
+            {
+                return true;
+            }
+        }
+
+        Query query = context.getRepositoryMethodMetadata().getQuery();
+        Modifying modifying = context.getRepositoryMethodMetadata().getModifying();
+        
+        if ((query != null && !query.lock().equals(LockModeType.NONE)) || modifying != null)
+        {
+            return true;
         }
-        return requiresTx || context.getRepositoryMethod().requiresTransaction();
+        
+        return false;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
index 70edf67..02528d9 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
@@ -21,9 +21,9 @@ package org.apache.deltaspike.data.impl.builder.part;
 import static org.junit.Assert.assertEquals;
 
 import org.apache.deltaspike.data.impl.builder.MethodExpressionException;
-import org.apache.deltaspike.data.impl.meta.MethodPrefix;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
-import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodPrefix;
+import org.apache.deltaspike.data.impl.meta.EntityMetadata;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 import org.apache.deltaspike.data.test.domain.Simple;
 import org.apache.deltaspike.data.test.service.SimpleFetchRepository;
 import org.apache.deltaspike.data.test.service.SimpleRepository;
@@ -31,8 +31,8 @@ import org.junit.Test;
 
 public class QueryRootTest
 {
-    private final RepositoryComponent repo = new RepositoryComponent(SimpleRepository.class, new RepositoryEntity(Simple.class, Long.class));
-    private final RepositoryComponent repoFetchBy = new RepositoryComponent(SimpleFetchRepository.class, new RepositoryEntity(Simple.class, Long.class));
+    private final RepositoryMetadata repo = new RepositoryMetadata(SimpleRepository.class, new EntityMetadata(Simple.class, "Simple", Long.class));
+    private final RepositoryMetadata repoFetchBy = new RepositoryMetadata(SimpleFetchRepository.class, new EntityMetadata(Simple.class, "Simple", Long.class));
 
     @Test
     public void should_create_simple_query()
@@ -129,7 +129,7 @@ public class QueryRootTest
                         "where e.name = ?1";
 
         // when
-        String result = QueryRoot.create(name, repoFetchBy, new MethodPrefix("fetchBy", name)).getJpqlQuery().trim();
+        String result = QueryRoot.create(name, repoFetchBy, new RepositoryMethodPrefix("fetchBy", name)).getJpqlQuery().trim();
 
         // then
         assertEquals(expected, result);
@@ -167,9 +167,9 @@ public class QueryRootTest
         assertEquals(expected, result);
     }
 
-    private MethodPrefix prefix(final String name)
+    private RepositoryMethodPrefix prefix(final String name)
     {
-        return new MethodPrefix("", name);
+        return new RepositoryMethodPrefix("", name);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/CdiQueryContextHolderTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/CdiQueryContextHolderTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/CdiQueryContextHolderTest.java
index da72af5..1d07023 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/CdiQueryContextHolderTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/CdiQueryContextHolderTest.java
@@ -22,10 +22,12 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
 import java.lang.reflect.Method;
+import org.apache.deltaspike.data.api.Repository;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodPrefix;
+import org.apache.deltaspike.data.impl.meta.EntityMetadata;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
-import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
-import org.apache.deltaspike.data.impl.meta.RepositoryMethod;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata;
 import org.apache.deltaspike.data.test.domain.Simple;
 import org.apache.deltaspike.data.test.service.SimpleRepository;
 import org.junit.Test;
@@ -76,7 +78,7 @@ public class CdiQueryContextHolderTest
 
     private CdiQueryInvocationContext dummyInvocationContext()
     {
-        return new CdiQueryInvocationContext(null, dummyMethod(), null, dummyRepoMethod(), null);
+        return new CdiQueryInvocationContext(null, dummyMethod(), null, dummyRepo(), dummyRepoMethod(dummyRepo()), null);
     }
 
     private Method dummyMethod()
@@ -91,13 +93,18 @@ public class CdiQueryContextHolderTest
         }
     }
 
-    private RepositoryMethod dummyRepoMethod()
+    private RepositoryMethodMetadata dummyRepoMethod(RepositoryMetadata metadata)
     {
-        return new RepositoryMethod(dummyMethod(), dummyRepo());
+        RepositoryMethodMetadata methodMetadata = new RepositoryMethodMetadata(dummyMethod());
+        methodMetadata.setMethodPrefix(new RepositoryMethodPrefix(
+                    metadata.getRepositoryClass().getAnnotation(Repository.class).methodPrefix(),
+                    dummyMethod().getName()));
+        
+        return methodMetadata;
     }
 
-    private RepositoryComponent dummyRepo()
+    private RepositoryMetadata dummyRepo()
     {
-        return new RepositoryComponent(SimpleRepository.class, new RepositoryEntity(Simple.class));
+        return new RepositoryMetadata(SimpleRepository.class, new EntityMetadata(Simple.class));
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/MethodPrefixTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/MethodPrefixTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/MethodPrefixTest.java
index bcfa0a2..559d421 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/MethodPrefixTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/MethodPrefixTest.java
@@ -27,7 +27,7 @@ public class MethodPrefixTest
     @Test
     public void shouldParseArbitraryMethodFindPrefix()
     {
-        MethodPrefix methodPrefix = new MethodPrefix("","findTop20ByName");
+        RepositoryMethodPrefix methodPrefix = new RepositoryMethodPrefix("","findTop20ByName");
 
         String resultingQuery = methodPrefix.removePrefix("findTop20ByName");
 
@@ -37,7 +37,7 @@ public class MethodPrefixTest
     @Test
     public void shouldParseFirst20MethodFindPrefix()
     {
-        MethodPrefix methodPrefix = new MethodPrefix("","findFirst20ByName");
+        RepositoryMethodPrefix methodPrefix = new RepositoryMethodPrefix("","findFirst20ByName");
 
         String resultingQuery = methodPrefix.removePrefix("findFirst20ByName");
 
@@ -47,7 +47,7 @@ public class MethodPrefixTest
     @Test
     public void shouldParseDefinedMaxResults()
     {
-        MethodPrefix methodPrefix = new MethodPrefix("","findFirst20ByName");
+        RepositoryMethodPrefix methodPrefix = new RepositoryMethodPrefix("","findFirst20ByName");
 
         int maxResults = methodPrefix.getDefinedMaxResults();
 
@@ -57,7 +57,7 @@ public class MethodPrefixTest
     @Test
     public void shouldNotParseNonMatchingMethodName()
     {
-        MethodPrefix methodPrefix = new MethodPrefix("","findAnyByName");
+        RepositoryMethodPrefix methodPrefix = new RepositoryMethodPrefix("","findAnyByName");
 
         int maxResults = methodPrefix.getDefinedMaxResults();
 
@@ -67,7 +67,7 @@ public class MethodPrefixTest
     @Test
     public void shouldParseOrderByEmailDesc()
     {
-        MethodPrefix methodPrefix = new MethodPrefix("","findFirst3OrderByEmailDesc");
+        RepositoryMethodPrefix methodPrefix = new RepositoryMethodPrefix("","findFirst3OrderByEmailDesc");
 
         String resultingQuery = methodPrefix.removePrefix("findFirst3OrderByEmailDesc");
 
@@ -77,7 +77,7 @@ public class MethodPrefixTest
     @Test
     public void shouldParseOrderByEmail()
     {
-        MethodPrefix methodPrefix = new MethodPrefix("","findFirst3OrderByEmail");
+        RepositoryMethodPrefix methodPrefix = new RepositoryMethodPrefix("","findFirst3OrderByEmail");
 
         String resultingQuery = methodPrefix.removePrefix("findFirst3OrderByEmail");
 
@@ -87,7 +87,7 @@ public class MethodPrefixTest
     @Test
     public void shouldParseFindAllOrderByName()
     {
-        MethodPrefix methodPrefix = new MethodPrefix("","findAllOrderByName");
+        RepositoryMethodPrefix methodPrefix = new RepositoryMethodPrefix("","findAllOrderByName");
 
         String resultingQuery = methodPrefix.removePrefix("findAllOrderByName");
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/extractor/AnnotationMetadataExtractorTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/extractor/AnnotationMetadataExtractorTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/extractor/AnnotationMetadataExtractorTest.java
deleted file mode 100644
index 7919990..0000000
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/extractor/AnnotationMetadataExtractorTest.java
+++ /dev/null
@@ -1,84 +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.extractor;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import org.apache.deltaspike.data.api.Repository;
-import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
-import org.apache.deltaspike.data.test.domain.Simple;
-import org.apache.deltaspike.data.test.service.RepositoryInterface;
-import org.junit.Test;
-
-public class AnnotationMetadataExtractorTest
-{
-
-    @Test
-    public void should_extract_entity_class_from_repo_annotation()
-    {
-        // given
-        AnnotationMetadataExtractor extractor = new AnnotationMetadataExtractor();
-
-        // when
-        RepositoryEntity result = extractor.extract(RepositoryInterface.class);
-
-        // then
-        assertNotNull(result);
-        assertEquals(Simple.class, result.getEntityClass());
-        assertEquals(Long.class, result.getPrimaryKeyClass());
-    }
-
-    @Test
-    public void should_throw_excption_when_annotation_with_entity_class_not_present()
-    {
-        // given
-        AnnotationMetadataExtractor extractor = new AnnotationMetadataExtractor();
-
-        // when
-        RepositoryEntity result = extractor.extract(NoEntityPresentRepository.class);
-
-        // then
-        assertNull(result);
-    }
-
-    @Test
-    public void should_throw_exception_when_annotation_with_non_entity_class()
-    {
-        // given
-        AnnotationMetadataExtractor extractor = new AnnotationMetadataExtractor();
-
-        // when
-        RepositoryEntity result = extractor.extract(NonEntityRepository.class);
-
-        // then
-        assertNull(result);
-    }
-
-    @Repository
-    private static class NoEntityPresentRepository
-    {
-    }
-
-    @Repository(forEntity = Object.class)
-    private static class NonEntityRepository
-    {
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractorTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractorTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractorTest.java
deleted file mode 100644
index d36d998..0000000
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractorTest.java
+++ /dev/null
@@ -1,64 +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.extractor;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
-import org.apache.deltaspike.data.impl.meta.extractor.MetadataExtractor;
-import org.apache.deltaspike.data.impl.meta.extractor.TypeMetadataExtractor;
-import org.apache.deltaspike.data.test.domain.Simple;
-import org.apache.deltaspike.data.test.service.RepositoryInterface;
-import org.apache.deltaspike.data.test.service.SimpleRepository;
-import org.junit.Test;
-
-public class TypeMetadataExtractorTest
-{
-
-    @Test
-    public void should_extract_from_class()
-    {
-        // given
-        MetadataExtractor extractor = new TypeMetadataExtractor();
-
-        // when
-        RepositoryEntity result = extractor.extract(SimpleRepository.class);
-
-        // then
-        assertNotNull(result);
-        assertEquals(Simple.class, result.getEntityClass());
-        assertEquals(Long.class, result.getPrimaryKeyClass());
-    }
-
-    @Test
-    public void should_not_extract_from_annotation()
-    {
-        // given
-        MetadataExtractor extractor = new TypeMetadataExtractor();
-
-        // when
-        RepositoryEntity result = extractor.extract(RepositoryInterface.class);
-
-        // then
-        assertNull(result);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java
index 15f9295..d5d2553 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java
@@ -18,12 +18,12 @@
  */
 package org.apache.deltaspike.data.impl.meta.unit;
 
+import org.apache.deltaspike.data.impl.meta.EntityMetadata;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
 import org.apache.deltaspike.data.impl.util.EntityUtils;
 import org.apache.deltaspike.data.test.domain.Parent;
 import org.apache.deltaspike.data.test.domain.TeeId;
@@ -126,9 +126,9 @@ public class PersistenceUnitsTest
         // given
 
         // when
-        RepositoryEntity entity1 = lookupMetadata(MappedOne.class);
-        RepositoryEntity entity2 = lookupMetadata(MappedTwo.class);
-        RepositoryEntity entity3 = lookupMetadata(MappedThree.class);
+        EntityMetadata entity1 = lookupMetadata(MappedOne.class);
+        EntityMetadata entity2 = lookupMetadata(MappedTwo.class);
+        EntityMetadata entity3 = lookupMetadata(MappedThree.class);
 
         // then
         assertNotNull(entity1);
@@ -138,12 +138,12 @@ public class PersistenceUnitsTest
         assertEquals(Long.class, entity3.getPrimaryKeyClass());
     }
 
-    protected RepositoryEntity lookupMetadata(Class<?> entityClass)
+    protected EntityMetadata lookupMetadata(Class<?> entityClass)
     {
         EntityDescriptor entity = PersistenceUnitDescriptorProvider.getInstance().find(entityClass);
         if (entity != null)
         {
-            return new RepositoryEntity(entityClass, EntityUtils.primaryKeyClass(entityClass));
+            return new EntityMetadata(entityClass, EntityUtils.primaryKeyClass(entityClass));
         }
         return null;
     }


[2/2] deltaspike git commit: DELTASPIKE-1070 Refactor RepositoryComponent/s

Posted by ta...@apache.org.
DELTASPIKE-1070 Refactor RepositoryComponent/s

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

Branch: refs/heads/master
Commit: 46a3b6759fabb55fd2b913b9f7b4635687d0c5d7
Parents: fbf62e3
Author: Thomas Andraschko <ta...@apache.org>
Authored: Sun Jun 4 02:00:14 2017 +0200
Committer: Thomas Andraschko <ta...@apache.org>
Committed: Sun Jun 4 02:00:14 2017 +0200

----------------------------------------------------------------------
 .../data/spi/QueryInvocationContext.java        |   1 -
 .../data/impl/RepositoryExtension.java          |  81 ++----
 .../impl/builder/AnnotatedQueryBuilder.java     |   4 +-
 .../data/impl/builder/DelegateQueryBuilder.java |   4 +-
 .../data/impl/builder/MethodQueryBuilder.java   |   6 +-
 .../data/impl/builder/QueryBuilderFactory.java  |  22 +-
 .../data/impl/builder/part/AndQueryPart.java    |   4 +-
 .../builder/part/BasePropertyQueryPart.java     |   7 +-
 .../data/impl/builder/part/OrQueryPart.java     |   4 +-
 .../impl/builder/part/OrderByQueryPart.java     |   6 +-
 .../impl/builder/part/PropertyQueryPart.java    |   4 +-
 .../data/impl/builder/part/QueryPart.java       |   4 +-
 .../data/impl/builder/part/QueryRoot.java       |  16 +-
 .../builder/result/QueryProcessorFactory.java   |  13 +-
 .../impl/handler/CdiQueryInvocationContext.java | 100 +++++--
 .../impl/handler/EntityManagerRefLookup.java    |  15 +-
 .../impl/handler/EntityRepositoryHandler.java   |   2 +-
 .../data/impl/handler/QueryHandler.java         |  29 +-
 .../data/impl/meta/EntityMetadata.java          | 101 +++++++
 .../impl/meta/EntityMetadataInitializer.java    | 118 +++++++++
 .../deltaspike/data/impl/meta/MethodPrefix.java | 188 -------------
 .../deltaspike/data/impl/meta/MethodType.java   |  36 ---
 .../data/impl/meta/QueryInvocation.java         |   2 +-
 .../data/impl/meta/QueryInvocationLiteral.java  |   6 +-
 .../data/impl/meta/RepositoryComponent.java     | 263 -------------------
 .../data/impl/meta/RepositoryComponents.java    | 129 ---------
 .../impl/meta/RepositoryComponentsFactory.java  |  44 ----
 .../data/impl/meta/RepositoryEntity.java        | 101 -------
 .../data/impl/meta/RepositoryMetadata.java      | 107 ++++++++
 .../impl/meta/RepositoryMetadataHandler.java    | 111 ++++++++
 .../meta/RepositoryMetadataInitializer.java     | 143 ++++++++++
 .../data/impl/meta/RepositoryMethod.java        | 257 ------------------
 .../impl/meta/RepositoryMethodMetadata.java     | 155 +++++++++++
 .../RepositoryMethodMetadataInitializer.java    | 170 ++++++++++++
 .../data/impl/meta/RepositoryMethodPrefix.java  | 188 +++++++++++++
 .../data/impl/meta/RepositoryMethodType.java    |  36 +++
 .../extractor/AnnotationMetadataExtractor.java  |  41 ---
 .../impl/meta/extractor/MetadataExtractor.java  |  34 ---
 .../meta/extractor/TypeMetadataExtractor.java   |  99 -------
 .../deltaspike/data/impl/param/Parameters.java  |  12 +-
 .../data/impl/tx/TransactionalQueryRunner.java  |  25 +-
 .../data/impl/builder/part/QueryRootTest.java   |  16 +-
 .../impl/handler/CdiQueryContextHolderTest.java |  23 +-
 .../data/impl/meta/MethodPrefixTest.java        |  14 +-
 .../AnnotationMetadataExtractorTest.java        |  84 ------
 .../extractor/TypeMetadataExtractorTest.java    |  64 -----
 .../impl/meta/unit/PersistenceUnitsTest.java    |  12 +-
 47 files changed, 1361 insertions(+), 1540 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/spi/QueryInvocationContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/spi/QueryInvocationContext.java b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/spi/QueryInvocationContext.java
index daab9d8..a92d29b 100644
--- a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/spi/QueryInvocationContext.java
+++ b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/spi/QueryInvocationContext.java
@@ -26,7 +26,6 @@ import java.lang.reflect.Method;
  */
 public interface QueryInvocationContext
 {
-
     /**
      * Entity Manager used for the query.
      */

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
index 7c2fa15..0bd76fb 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
@@ -19,15 +19,12 @@
 package org.apache.deltaspike.data.impl;
 
 import java.lang.reflect.InvocationHandler;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.ArrayList;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.enterprise.event.Observes;
-import javax.enterprise.inject.spi.AfterBeanDiscovery;
 import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.BeforeShutdown;
 import javax.enterprise.inject.spi.Extension;
@@ -38,7 +35,6 @@ import org.apache.deltaspike.core.util.ClassDeactivationUtils;
 import org.apache.deltaspike.data.api.AbstractEntityRepository;
 import org.apache.deltaspike.data.api.AbstractFullEntityRepository;
 import org.apache.deltaspike.data.api.Repository;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponents;
 
 /**
  * The main extension class for Repositories, based on PartialBeans. Handles following events:<br/>
@@ -56,18 +52,15 @@ import org.apache.deltaspike.data.impl.meta.RepositoryComponents;
  */
 public class RepositoryExtension implements Extension, Deactivatable
 {
+    private static final Logger LOG = Logger.getLogger(RepositoryExtension.class.getName());
 
-    private static final Logger log = Logger.getLogger(RepositoryExtension.class.getName());
-
-    private static RepositoryComponents staticComponents = new RepositoryComponents();
-
-    private final List<RepositoryDefinitionException> definitionExceptions =
-            new LinkedList<RepositoryDefinitionException>();
+    // TODO: Hack still required?
+    private static final ArrayList<Class<?>> REPOSITORY_CLASSES = new ArrayList<Class<?>>();
 
+    private final ArrayList<Class<?>> repositoryClasses = new ArrayList<Class<?>>();
+    
     private Boolean isActivated = true;
 
-    private RepositoryComponents components = new RepositoryComponents();
-
     void beforeBeanDiscovery(@Observes BeforeBeanDiscovery before)
     {
         isActivated = ClassDeactivationUtils.isActivated(getClass());
@@ -85,44 +78,21 @@ public class RepositoryExtension implements Extension, Deactivatable
         {
             event.veto();
         }
-
         else if (isRepository(event.getAnnotatedType()))
         {
-            Class<X> repoClass = event.getAnnotatedType().getJavaClass();
-            try
-            {
-                log.log(Level.FINER, "getHandlerClass: Repository annotation detected on {0}",
-                        event.getAnnotatedType());
-                if (Deactivatable.class.isAssignableFrom(repoClass)
-                        && !ClassDeactivationUtils.isActivated((Class<? extends Deactivatable>) repoClass))
-                {
-                    log.log(Level.FINER, "Class {0} is Deactivated", repoClass);
-                    return;
-                }
-                components.add(repoClass);
-                staticComponents.add(repoClass);
-            }
-            catch (RepositoryDefinitionException e)
-            {
-                definitionExceptions.add(e);
-            }
-            catch (Exception e)
+            Class<X> repositoryClass = event.getAnnotatedType().getJavaClass();
+
+            LOG.log(Level.FINER, "getHandlerClass: Repository annotation detected on {0}",
+                    event.getAnnotatedType());
+            if (Deactivatable.class.isAssignableFrom(repositoryClass)
+                    && !ClassDeactivationUtils.isActivated((Class<? extends Deactivatable>) repositoryClass))
             {
-                definitionExceptions.add(new RepositoryDefinitionException(repoClass, e));
+                LOG.log(Level.FINER, "Class {0} is Deactivated", repositoryClass);
+                return;
             }
-        }
-    }
 
-    <X> void addDefinitionErrors(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager)
-    {
-        if (!isActivated)
-        {
-            return;
-        }
-
-        for (RepositoryDefinitionException ex : definitionExceptions)
-        {
-            afterBeanDiscovery.addDefinitionError(ex);
+            repositoryClasses.add(repositoryClass);
+            REPOSITORY_CLASSES.add(repositoryClass);
         }
     }
 
@@ -139,27 +109,28 @@ public class RepositoryExtension implements Extension, Deactivatable
         return javaClass.equals(AbstractEntityRepository.class) ||
                javaClass.equals(AbstractFullEntityRepository.class);
     }
-
-    public RepositoryComponents getComponents()
+    
+    public ArrayList<Class<?>> getRepositoryClasses()
     {
-        RepositoryComponents result = new RepositoryComponents();
-        if (components.getRepositories().isEmpty() && !staticComponents.getRepositories().isEmpty())
+        ArrayList<Class<?>> result = new ArrayList<Class<?>>();
+
+        if (repositoryClasses.isEmpty() && !REPOSITORY_CLASSES.isEmpty())
         {
-            result.addAll(staticComponents.getRepositories());
+            result.addAll(REPOSITORY_CLASSES);
         }
 
-        if (!components.getRepositories().isEmpty())
+        if (!repositoryClasses.isEmpty())
         {
-            result.addAll(components.getRepositories());
+            result.addAll(repositoryClasses);
         }
 
         return result;
     }
-
+    
     protected void cleanup(@Observes BeforeShutdown beforeShutdown)
     {
         //we can reset it in any case,
         //because every application produced a copy as application-scoped bean (see RepositoryComponentsFactory)
-        staticComponents.getRepositories().clear();
+        REPOSITORY_CLASSES.clear();
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/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 7c94043..c27a6c6 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,7 +20,7 @@ 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.MethodType;
+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 +37,7 @@ import static org.apache.deltaspike.core.util.StringUtils.isNotEmpty;
 /**
  * Create the query based on method annotations.
  */
-@QueryInvocation(MethodType.ANNOTATED)
+@QueryInvocation(RepositoryMethodType.ANNOTATED)
 @ApplicationScoped
 public class AnnotatedQueryBuilder extends QueryBuilder
 {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/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 c17a1f6..e42ee19 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,12 @@ 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.MethodType;
+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(MethodType.DELEGATE)
+@QueryInvocation(RepositoryMethodType.DELEGATE)
 @ApplicationScoped
 public class DelegateQueryBuilder extends QueryBuilder
 {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/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 850d97f..f9efd1e 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,11 @@ 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.MethodType;
+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(MethodType.PARSE)
+@QueryInvocation(RepositoryMethodType.PARSE)
 @ApplicationScoped
 public class MethodQueryBuilder extends QueryBuilder
 {
@@ -42,7 +42,7 @@ public class MethodQueryBuilder extends QueryBuilder
     private Query createJpaQuery(CdiQueryInvocationContext context)
     {
         Parameters params = context.getParams();
-        QueryRoot root = context.getRepositoryMethod().getQueryRoot();
+        QueryRoot root = context.getRepositoryMethodMetadata().getQueryRoot();
         String jpqlQuery = context.applyQueryStringPostProcessors(root.getJpqlQuery());
         context.setQueryString(jpqlQuery);
         params.updateValues(root.getParameterUpdates());

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/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 9c5625d..77a8653 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
@@ -18,9 +18,9 @@
  */
 package org.apache.deltaspike.data.impl.builder;
 
-import static org.apache.deltaspike.data.impl.meta.MethodType.ANNOTATED;
-import static org.apache.deltaspike.data.impl.meta.MethodType.DELEGATE;
-import static org.apache.deltaspike.data.impl.meta.MethodType.PARSE;
+import static org.apache.deltaspike.data.impl.meta.RepositoryMethodType.ANNOTATED;
+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;
@@ -29,15 +29,15 @@ import javax.enterprise.context.ApplicationScoped;
 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.MethodType;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodType;
 import org.apache.deltaspike.data.impl.meta.QueryInvocationLiteral;
-import org.apache.deltaspike.data.impl.meta.RepositoryMethod;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata;
 
 @ApplicationScoped
 public class QueryBuilderFactory
 {
-    private static final Map<MethodType, QueryInvocationLiteral> LITERALS =
-            new HashMap<MethodType, QueryInvocationLiteral>()
+    private static final Map<RepositoryMethodType, QueryInvocationLiteral> LITERALS =
+            new HashMap<RepositoryMethodType, QueryInvocationLiteral>()
             {
                 private static final long serialVersionUID = 1L;
 
@@ -48,14 +48,16 @@ public class QueryBuilderFactory
                 }
             };
 
-    public QueryBuilder build(RepositoryMethod method, CdiQueryInvocationContext context)
+    public QueryBuilder build(RepositoryMethodMetadata methodMetadata, CdiQueryInvocationContext context)
     {
         QueryBuilder builder = BeanProvider.getContextualReference(
-                QueryBuilder.class, LITERALS.get(method.getMethodType()));
-        if (method.returns(QueryResult.class))
+                QueryBuilder.class, LITERALS.get(methodMetadata.getMethodType()));
+
+        if (QueryResult.class.equals(methodMetadata.getMethod().getReturnType()))
         {
             return new WrappedQueryBuilder(builder);
         }
+
         return builder;
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/AndQueryPart.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/AndQueryPart.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/AndQueryPart.java
index 643395b..2b6747e 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/AndQueryPart.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/AndQueryPart.java
@@ -19,7 +19,7 @@
 package org.apache.deltaspike.data.impl.builder.part;
 
 import org.apache.deltaspike.data.impl.builder.QueryBuilderContext;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 
 class AndQueryPart extends ConnectingQueryPart
 {
@@ -30,7 +30,7 @@ class AndQueryPart extends ConnectingQueryPart
     }
 
     @Override
-    protected QueryPart build(String queryPart, String method, RepositoryComponent repo)
+    protected QueryPart build(String queryPart, String method, RepositoryMetadata repo)
     {
         children.add(new PropertyQueryPart().build(queryPart, method, repo));
         return this;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/BasePropertyQueryPart.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/BasePropertyQueryPart.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/BasePropertyQueryPart.java
index 13d2ac1..a2ac886 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/BasePropertyQueryPart.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/BasePropertyQueryPart.java
@@ -19,7 +19,7 @@
 package org.apache.deltaspike.data.impl.builder.part;
 
 import org.apache.deltaspike.data.impl.builder.MethodExpressionException;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 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;
@@ -27,12 +27,11 @@ import org.apache.deltaspike.data.impl.property.query.PropertyQuery;
 
 abstract class BasePropertyQueryPart extends QueryPart
 {
-
     static final String SEPARATOR = "_";
 
-    void validate(String name, String method, RepositoryComponent repo)
+    void validate(String name, String method, RepositoryMetadata repo)
     {
-        Class<?> current = repo.getEntityClass();
+        Class<?> current = repo.getEntityMetadata().getEntityClass();
         if (name == null)
         {
             throw new MethodExpressionException(null, repo.getRepositoryClass(), method);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrQueryPart.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrQueryPart.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrQueryPart.java
index 8060165..d54ff04 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrQueryPart.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrQueryPart.java
@@ -21,7 +21,7 @@ package org.apache.deltaspike.data.impl.builder.part;
 import static org.apache.deltaspike.data.impl.util.QueryUtils.splitByKeyword;
 
 import org.apache.deltaspike.data.impl.builder.QueryBuilderContext;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 
 
 class OrQueryPart extends ConnectingQueryPart
@@ -33,7 +33,7 @@ class OrQueryPart extends ConnectingQueryPart
     }
 
     @Override
-    protected QueryPart build(String queryPart, String method, RepositoryComponent repo)
+    protected QueryPart build(String queryPart, String method, RepositoryMetadata repo)
     {
         String[] andParts = splitByKeyword(queryPart, "And");
         boolean first = true;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrderByQueryPart.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrderByQueryPart.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrderByQueryPart.java
index f1ebb3b..c4b241e 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrderByQueryPart.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/OrderByQueryPart.java
@@ -31,19 +31,17 @@ import java.util.TreeSet;
 
 import org.apache.deltaspike.data.impl.builder.QueryBuilder;
 import org.apache.deltaspike.data.impl.builder.QueryBuilderContext;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
-
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 
 public class OrderByQueryPart extends BasePropertyQueryPart
 {
-
     private static final String KEYWORD_ASC = "Asc";
     private static final String KEYWORD_DESC = "Desc";
 
     private final List<OrderByQueryAttribute> attributes = new LinkedList<OrderByQueryAttribute>();
 
     @Override
-    protected QueryPart build(String queryPart, String method, RepositoryComponent repo)
+    protected QueryPart build(String queryPart, String method, RepositoryMetadata repo)
     {
         Set<String> collect = new TreeSet<String>();
         List<String> ascSplit = new LinkedList<String>();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/PropertyQueryPart.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/PropertyQueryPart.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/PropertyQueryPart.java
index e0fe3aa..88d1e58 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/PropertyQueryPart.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/PropertyQueryPart.java
@@ -25,7 +25,7 @@ import java.text.MessageFormat;
 import org.apache.deltaspike.data.impl.builder.QueryBuilder;
 import org.apache.deltaspike.data.impl.builder.QueryBuilderContext;
 import org.apache.deltaspike.data.impl.builder.QueryOperator;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 import org.apache.deltaspike.data.impl.param.ToUpperStringParameterUpdate;
 
 class PropertyQueryPart extends BasePropertyQueryPart
@@ -35,7 +35,7 @@ class PropertyQueryPart extends BasePropertyQueryPart
     private QueryOperator comparator;
 
     @Override
-    protected QueryPart build(String queryPart, String method, RepositoryComponent repo)
+    protected QueryPart build(String queryPart, String method, RepositoryMetadata repo)
     {
         comparator = QueryOperator.Equal;
         name = uncapitalize(queryPart);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryPart.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryPart.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryPart.java
index 45acb05..4329895 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryPart.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryPart.java
@@ -23,14 +23,14 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.deltaspike.data.impl.builder.QueryBuilderContext;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 
 public abstract class QueryPart
 {
 
     protected List<QueryPart> children = new LinkedList<QueryPart>();
 
-    protected abstract QueryPart build(String queryPart, String method, RepositoryComponent repo);
+    protected abstract QueryPart build(String queryPart, String method, RepositoryMetadata repo);
 
     protected abstract QueryPart buildQuery(QueryBuilderContext ctx);
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryRoot.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryRoot.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryRoot.java
index 767efa1..80ec18d 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryRoot.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/part/QueryRoot.java
@@ -29,8 +29,8 @@ import java.util.logging.Logger;
 import org.apache.deltaspike.data.impl.builder.MethodExpressionException;
 import org.apache.deltaspike.data.impl.builder.QueryBuilder;
 import org.apache.deltaspike.data.impl.builder.QueryBuilderContext;
-import org.apache.deltaspike.data.impl.meta.MethodPrefix;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodPrefix;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 import org.apache.deltaspike.data.impl.param.ParameterUpdate;
 
 /**
@@ -39,25 +39,25 @@ import org.apache.deltaspike.data.impl.param.ParameterUpdate;
 public class QueryRoot extends QueryPart
 {
 
-    public static final QueryRoot UNKNOWN_ROOT = new QueryRoot("null-object", new MethodPrefix("", null));
+    public static final QueryRoot UNKNOWN_ROOT = new QueryRoot("null-object", new RepositoryMethodPrefix("", null));
 
     private static final Logger log = Logger.getLogger(QueryRoot.class.getName());
 
     private final String entityName;
-    private final MethodPrefix methodPrefix;
+    private final RepositoryMethodPrefix methodPrefix;
 
     private String jpqlQuery;
     private List<ParameterUpdate> paramUpdates;
 
-    protected QueryRoot(String entityName, MethodPrefix methodPrefix)
+    protected QueryRoot(String entityName, RepositoryMethodPrefix methodPrefix)
     {
         this.entityName = entityName;
         this.methodPrefix = methodPrefix;
     }
 
-    public static QueryRoot create(String method, RepositoryComponent repo, MethodPrefix prefix)
+    public static QueryRoot create(String method, RepositoryMetadata repo, RepositoryMethodPrefix prefix)
     {
-        QueryRoot root = new QueryRoot(repo.getEntityName(), prefix);
+        QueryRoot root = new QueryRoot(repo.getEntityMetadata().getEntityName(), prefix);
         root.build(method, method, repo);
         root.createJpql();
         return root;
@@ -74,7 +74,7 @@ public class QueryRoot extends QueryPart
     }
 
     @Override
-    protected QueryPart build(String queryPart, String method, RepositoryComponent repo)
+    protected QueryPart build(String queryPart, String method, RepositoryMetadata repo)
     {
         String[] orderByParts = splitByKeyword(queryPart, "OrderBy");
         if (hasQueryConditions(orderByParts))

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java
index 4bc5777..247a4a2 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java
@@ -30,21 +30,21 @@ import org.apache.deltaspike.data.api.Modifying;
 import org.apache.deltaspike.data.api.QueryResult;
 import org.apache.deltaspike.data.api.SingleResultType;
 import org.apache.deltaspike.data.impl.handler.CdiQueryInvocationContext;
-import org.apache.deltaspike.data.impl.meta.MethodPrefix;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodPrefix;
 
 public final class QueryProcessorFactory
 {
 
     private final Method method;
-    private final MethodPrefix methodPrefix;
+    private final RepositoryMethodPrefix methodPrefix;
 
     private QueryProcessorFactory(Method method)
     {
         this.method = method;
-        this.methodPrefix = new MethodPrefix("", method.getName());
+        this.methodPrefix = new RepositoryMethodPrefix("", method.getName());
     }
 
-    private QueryProcessorFactory(Method method, MethodPrefix methodPrefix)
+    private QueryProcessorFactory(Method method, RepositoryMethodPrefix methodPrefix)
     {
         this.method = method;
         this.methodPrefix = methodPrefix;
@@ -55,7 +55,7 @@ public final class QueryProcessorFactory
         return new QueryProcessorFactory(method);
     }
 
-    public static QueryProcessorFactory newInstance(Method method, MethodPrefix methodPrefix)
+    public static QueryProcessorFactory newInstance(Method method, RepositoryMethodPrefix methodPrefix)
     {
         return new QueryProcessorFactory(method, methodPrefix);
     }
@@ -151,7 +151,8 @@ public final class QueryProcessorFactory
                     List<Object> queryResult = query.getResultList();
                     result = !queryResult.isEmpty() ? queryResult.get(0) : null;
             }
-            if (context.isOptional())
+            
+            if (context.isOptionalAsReturnType())
             {
                 return OptionalUtil.wrap(result);
             }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java
index 1adee68..09611f7 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java
@@ -27,15 +27,20 @@ import javax.persistence.EntityManager;
 import javax.persistence.LockModeType;
 import javax.persistence.Query;
 import javax.persistence.QueryHint;
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.api.provider.DependentProvider;
 
 import org.apache.deltaspike.data.api.EntityGraph;
 import org.apache.deltaspike.data.api.SingleResultType;
 import org.apache.deltaspike.data.api.mapping.QueryInOutMapper;
 import org.apache.deltaspike.data.impl.graph.EntityGraphHelper;
-import org.apache.deltaspike.data.impl.meta.RepositoryMethod;
+import org.apache.deltaspike.data.impl.meta.EntityMetadata;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata;
 import org.apache.deltaspike.data.impl.param.Parameters;
 import org.apache.deltaspike.data.impl.property.Property;
 import org.apache.deltaspike.data.impl.util.EntityUtils;
+import org.apache.deltaspike.data.impl.util.bean.DependentProviderDestroyable;
 import org.apache.deltaspike.data.impl.util.bean.Destroyable;
 import org.apache.deltaspike.data.spi.QueryInvocationContext;
 
@@ -44,27 +49,31 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
 
     private final EntityManager entityManager;
     private final Parameters params;
-    private final Class<?> entityClass;
     private final Object proxy;
     private final Method method;
     private final Object[] args;
-    private final RepositoryMethod repoMethod;
+    
+    private final RepositoryMetadata repositoryMetadata;
+    private final RepositoryMethodMetadata repositoryMethodMetadata;
+    
     private final List<QueryStringPostProcessor> queryPostProcessors;
     private final List<JpaQueryPostProcessor> jpaPostProcessors;
     private final List<Destroyable> cleanup;
 
     private String queryString;
 
-    public CdiQueryInvocationContext(Object proxy, Method method, Object[] args, RepositoryMethod repoMethod,
-                                     EntityManager entityManager)
+    public CdiQueryInvocationContext(Object proxy, Method method, Object[] args,
+            RepositoryMetadata repositoryMetadata,
+            RepositoryMethodMetadata repositoryMethodMetadata, EntityManager entityManager)
     {
-        this.entityManager = entityManager;
-        this.args = args == null ? new Object[]{} : args;
-        this.params = Parameters.create(method, this.args, repoMethod);
         this.proxy = proxy;
         this.method = method;
-        this.repoMethod = repoMethod;
-        this.entityClass = repoMethod.getRepository().getEntityClass();
+        this.args = args == null ? new Object[]{} : args;
+        this.repositoryMetadata = repositoryMetadata;
+        this.repositoryMethodMetadata = repositoryMethodMetadata;
+        this.entityManager = entityManager;
+        
+        this.params = Parameters.create(method, this.args, repositoryMethodMetadata);
         this.queryPostProcessors = new LinkedList<QueryStringPostProcessor>();
         this.jpaPostProcessors = new LinkedList<JpaQueryPostProcessor>();
         this.cleanup = new LinkedList<Destroyable>();
@@ -97,15 +106,13 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
     {
         try
         {
-            Property<Serializable> versionProperty =
-                    repoMethod.getRepository().getRepositoryEntity().getVersionProperty();
+            Property<Serializable> versionProperty = repositoryMetadata.getEntityMetadata().getVersionProperty();
             if (versionProperty != null)
             {
                 return versionProperty.getValue(entity) == null;
             }
 
-            Property<Serializable> primaryKeyProperty =
-                    repoMethod.getRepository().getRepositoryEntity().getPrimaryKeyProperty();
+            Property<Serializable> primaryKeyProperty = repositoryMetadata.getEntityMetadata().getPrimaryKeyProperty();
             if (EntityUtils.primaryKeyValue(entity, primaryKeyProperty) == null)
             {
                 return true;
@@ -128,13 +135,13 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
     @Override
     public Class<?> getEntityClass()
     {
-        return entityClass;
+        return repositoryMetadata.getEntityMetadata().getEntityClass();
     }
 
     @Override
     public Class<?> getRepositoryClass()
     {
-        return repoMethod.getRepository().getRepositoryClass();
+        return repositoryMetadata.getRepositoryClass();
     }
 
     public Object proceed() throws Exception
@@ -238,7 +245,7 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
 
     public Object executeQuery(Query jpaQuery)
     {
-        return repoMethod.getQueryProcessor().executeQuery(jpaQuery, this);
+        return repositoryMethodMetadata.getQueryProcessor().executeQuery(jpaQuery, this);
     }
 
     public Parameters getParams()
@@ -246,11 +253,6 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
         return params;
     }
 
-    public RepositoryMethod getRepositoryMethod()
-    {
-        return repoMethod;
-    }
-
     public String getQueryString()
     {
         return queryString;
@@ -268,18 +270,41 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
 
     public boolean hasQueryInOutMapper()
     {
-        return repoMethod.hasQueryInOutMapper();
+        return repositoryMethodMetadata.getQueryInOutMapperClass() != null;
     }
 
     public QueryInOutMapper<?> getQueryInOutMapper()
     {
-        return repoMethod.getQueryInOutMapperInstance(this);
+        if (repositoryMethodMetadata.getQueryInOutMapperClass() == null)
+        {
+            return null;
+        }
+
+        QueryInOutMapper<?> result = null;
+        if (repositoryMethodMetadata.isQueryInOutMapperIsNormalScope())
+        {
+            result = BeanProvider.getContextualReference(repositoryMethodMetadata.getQueryInOutMapperClass());
+        }
+        else
+        {
+            DependentProvider<? extends QueryInOutMapper<?>> mappedProvider =
+                    BeanProvider.getDependent(repositoryMethodMetadata.getQueryInOutMapperClass());
+            
+            result = mappedProvider.get();
+            
+            this.addDestroyable(new DependentProviderDestroyable(mappedProvider));
+        }
+        
+        return result;
     }
 
     public SingleResultType getSingleResultStyle()
     {
-        SingleResultType baseSingleResultType = repoMethod.getSingleResultStyle();
-        if (repoMethod.isOptional() && baseSingleResultType == SingleResultType.JPA)
+        SingleResultType baseSingleResultType = repositoryMethodMetadata.getQuery() != null
+                ? repositoryMethodMetadata.getQuery().singleResult()
+                : repositoryMethodMetadata.getMethodPrefix().getSingleResultStyle();
+        
+        if (repositoryMethodMetadata.isOptionalAsReturnType() && baseSingleResultType == SingleResultType.JPA)
         {
             return SingleResultType.OPTIONAL;
         }
@@ -334,7 +359,9 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
             return;
         }
         
-        Object graph = EntityGraphHelper.getEntityGraph(getEntityManager(), entityClass, entityGraphAnn);
+        Object graph = EntityGraphHelper.getEntityGraph(getEntityManager(),
+                repositoryMetadata.getEntityMetadata().getEntityClass(),
+                entityGraphAnn);
         query.setHint(entityGraphAnn.type().getHintName(), graph);
     }
 
@@ -356,8 +383,23 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
         return false;
     }
 
-    public boolean isOptional()
+    public boolean isOptionalAsReturnType()
+    {
+        return this.repositoryMethodMetadata.isOptionalAsReturnType();
+    }
+
+    public RepositoryMetadata getRepositoryMetadata()
     {
-        return this.repoMethod.isOptional();
+        return repositoryMetadata;
     }
+
+    public EntityMetadata getEntityMetadata()
+    {
+        return repositoryMetadata.getEntityMetadata();
+    }
+    
+    public RepositoryMethodMetadata getRepositoryMethodMetadata()
+    {
+        return repositoryMethodMetadata;
+    } 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerRefLookup.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerRefLookup.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerRefLookup.java
index a7066cc..3bec649 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerRefLookup.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerRefLookup.java
@@ -27,7 +27,7 @@ import javax.persistence.EntityManager;
 import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
 
 import org.apache.deltaspike.core.api.provider.BeanProvider;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
 import org.apache.deltaspike.jpa.spi.entitymanager.ActiveEntityManagerHolder;
 
 @ApplicationScoped
@@ -74,16 +74,15 @@ public class EntityManagerRefLookup
         }
     }
     
-    public EntityManagerRef lookupReference(final RepositoryComponent repository)
+    public EntityManagerRef lookupReference(final RepositoryMetadata repositoryMetadata)
     {
         EntityManagerRef ref = new EntityManagerRef();
 
-        if (repository.hasEntityManagerResolver())
+        if (repositoryMetadata.getEntityManagerResolverClass() != null)
         {
-            ref.setEntityManagerResolverClass(
-                    repository.getEntityManagerResolverClass());
+            ref.setEntityManagerResolverClass(repositoryMetadata.getEntityManagerResolverClass());
             
-            if (repository.isEntityManagerResolverIsNormalScope())
+            if (repositoryMetadata.isEntityManagerResolverIsNormalScope())
             {
                 ref.setEntityManagerResolver(
                         BeanProvider.getContextualReference(ref.getEntityManagerResolverClass()));
@@ -127,9 +126,9 @@ public class EntityManagerRefLookup
             }
         }
 
-        if (repository.hasEntityManagerFlushMode())
+        if (repositoryMetadata.getEntityManagerFlushMode() != null)
         {
-            ref.getEntityManager().setFlushMode(repository.getEntityManagerFlushMode());
+            ref.getEntityManager().setFlushMode(repositoryMetadata.getEntityManagerFlushMode());
         }
 
         return ref;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/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 2c731f8..2eb1cce 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
@@ -268,7 +268,7 @@ public class EntityRepositoryHandler<E, PK extends Serializable>
 
     public String entityName()
     {
-        return context.getRepositoryMethod().getRepository().getRepositoryEntity().getEntityName();
+        return context.getEntityMetadata().getEntityName();
     }
 
     // ----------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java
index d83e227..455bffd 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java
@@ -18,7 +18,6 @@
  */
 package org.apache.deltaspike.data.impl.handler;
 
-import org.apache.deltaspike.core.api.lifecycle.Initialized;
 import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.util.AnnotationUtils;
 import org.apache.deltaspike.core.util.ExceptionUtils;
@@ -29,9 +28,7 @@ import org.apache.deltaspike.data.api.QueryInvocationException;
 import org.apache.deltaspike.data.api.Repository;
 import org.apache.deltaspike.data.impl.builder.QueryBuilder;
 import org.apache.deltaspike.data.impl.builder.QueryBuilderFactory;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
-import org.apache.deltaspike.data.impl.meta.RepositoryComponents;
-import org.apache.deltaspike.data.impl.meta.RepositoryMethod;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadataHandler;
 import org.apache.deltaspike.jpa.api.transaction.Transactional;
 import org.apache.deltaspike.jpa.spi.entitymanager.ActiveEntityManagerHolder;
 import org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy;
@@ -49,6 +46,8 @@ import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.enterprise.context.ApplicationScoped;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodMetadata;
 
 /**
  * Entry point for query processing.
@@ -63,8 +62,7 @@ public class QueryHandler implements Serializable, InvocationHandler
     private QueryBuilderFactory queryBuilderFactory;
 
     @Inject
-    @Initialized
-    private RepositoryComponents components;
+    private RepositoryMetadataHandler metadataHandler;
 
     @Inject
     private CdiQueryContextHolder context;
@@ -137,13 +135,15 @@ public class QueryHandler implements Serializable, InvocationHandler
         try
         {
             List<Class<?>> candidates = ProxyUtils.getProxyAndBaseTypes(proxy.getClass());
-            RepositoryComponent repo = components.lookupComponent(candidates);
-            RepositoryMethod repoMethod = components.lookupMethod(repo, method);
+            RepositoryMetadata repositoryMetadata = metadataHandler.lookupComponent(candidates);
+            RepositoryMethodMetadata repositoryMethodMetadata =
+                    metadataHandler.lookupMethod(repositoryMetadata, method);
 
-            entityManagerRef = entityManagerRefLookup.lookupReference(repo);
-            queryContext = createContext(proxy, method, args, entityManagerRef.getEntityManager(), repoMethod);
+            entityManagerRef = entityManagerRefLookup.lookupReference(repositoryMetadata);
+            queryContext = createContext(proxy, method, args, entityManagerRef.getEntityManager(),
+                    repositoryMetadata, repositoryMethodMetadata);
             
-            QueryBuilder builder = queryBuilderFactory.build(repoMethod, queryContext);
+            QueryBuilder builder = queryBuilderFactory.build(repositoryMethodMetadata, queryContext);
             Object result = runner.executeQuery(builder, queryContext);
             return result;
         }
@@ -171,10 +171,11 @@ public class QueryHandler implements Serializable, InvocationHandler
     }
 
     private CdiQueryInvocationContext createContext(Object proxy, Method method,
-            Object[] args, EntityManager entityManager, RepositoryMethod repoMethod)
+            Object[] args, EntityManager entityManager, RepositoryMetadata repositoryMetadata,
+            RepositoryMethodMetadata repositoryMethodMetadata)
     {
-        CdiQueryInvocationContext queryContext = new CdiQueryInvocationContext(proxy, method, args, repoMethod,
-                entityManager);
+        CdiQueryInvocationContext queryContext = new CdiQueryInvocationContext(proxy, method, args,
+                repositoryMetadata, repositoryMethodMetadata, entityManager);
         context.set(queryContext);
         queryContext.initMapper();
         return queryContext;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadata.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadata.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadata.java
new file mode 100644
index 0000000..bfa9f82
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadata.java
@@ -0,0 +1,101 @@
+/*
+ * 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 java.io.Serializable;
+import org.apache.deltaspike.data.impl.property.Property;
+
+public class EntityMetadata
+{
+    private Class<?> entityClass;
+    private Property<Serializable> primaryKeyProperty;
+    private Class<? extends Serializable> primaryKeyClass;
+    private Property<Serializable> versionProperty;
+    private String entityName;
+
+    public EntityMetadata(Class<?> entityClass)
+    {
+        this.entityClass = entityClass;
+    }
+    
+    public EntityMetadata(Class<?> entityClass,
+            Class<? extends Serializable> primaryKeyClass)
+    {
+        this.entityClass = entityClass;
+        this.primaryKeyClass = primaryKeyClass;
+    }
+    
+    public EntityMetadata(Class<?> entityClass, String entityName,
+            Class<? extends Serializable> primaryKeyClass)
+    {
+        this.entityClass = entityClass;
+        this.entityName = entityName;
+        this.primaryKeyClass = primaryKeyClass;
+    }
+    
+    public Class<?> getEntityClass()
+    {
+        return entityClass;
+    }
+
+    public void setEntityClass(Class<?> entityClass)
+    {
+        this.entityClass = entityClass;
+    }
+
+    public Class<? extends Serializable> getPrimaryKeyClass()
+    {
+        return primaryKeyClass;
+    }
+
+    public void setPrimaryKeyClass(Class<? extends Serializable> primaryKeyClass)
+    {
+        this.primaryKeyClass = primaryKeyClass;
+    }
+
+    public Property<Serializable> getPrimaryKeyProperty()
+    {
+        return primaryKeyProperty;
+    }
+
+    public void setPrimaryKeyProperty(Property<Serializable> primaryKeyProperty)
+    {
+        this.primaryKeyProperty = primaryKeyProperty;
+    }
+
+    public Property<Serializable> getVersionProperty()
+    {
+        return versionProperty;
+    }
+
+    public void setVersionProperty(Property<Serializable> versionProperty)
+    {
+        this.versionProperty = versionProperty;
+    }
+
+    public String getEntityName()
+    {
+        return entityName;
+    }
+
+    public void setEntityName(String entityName)
+    {
+        this.entityName = entityName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadataInitializer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadataInitializer.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadataInitializer.java
new file mode 100644
index 0000000..98edcbc
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadataInitializer.java
@@ -0,0 +1,118 @@
+/*
+ * 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 java.io.Serializable;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.enterprise.context.ApplicationScoped;
+import org.apache.deltaspike.data.api.Repository;
+import org.apache.deltaspike.data.impl.util.EntityUtils;
+
+@ApplicationScoped
+public class EntityMetadataInitializer
+{
+    private static final Logger LOG = Logger.getLogger(EntityMetadataInitializer.class.getName());
+    
+    public EntityMetadata init(RepositoryMetadata metadata)
+    {
+        EntityMetadata entityMetadata = extract(metadata.getRepositoryClass());
+        
+        entityMetadata.setPrimaryKeyProperty(EntityUtils.primaryKeyProperty(entityMetadata.getEntityClass()));
+        entityMetadata.setVersionProperty(EntityUtils.getVersionProperty(entityMetadata.getEntityClass()));
+        entityMetadata.setEntityName(EntityUtils.entityName(entityMetadata.getEntityClass()));
+
+        return entityMetadata;
+    }
+    
+    private EntityMetadata extract(Class<?> repositoryClass)
+    {
+        // get from annotation
+        Repository repository = repositoryClass.getAnnotation(Repository.class);
+        Class<?> entityClass = repository.forEntity();
+        boolean isEntityClass = !Object.class.equals(entityClass) && EntityUtils.isEntityClass(entityClass);
+        if (isEntityClass)
+        {
+            return new EntityMetadata(entityClass, EntityUtils.primaryKeyClass(entityClass));
+        }
+        
+        // get from type
+        for (Type inf : repositoryClass.getGenericInterfaces())
+        {
+            EntityMetadata result = extractFromType(inf);
+            if (result != null)
+            {
+                return result;
+            }
+        }
+
+        EntityMetadata entityMetadata = extractFromType(repositoryClass.getGenericSuperclass());
+        if (entityMetadata != null)
+        {
+            return entityMetadata;
+        }
+        for (Type intf : repositoryClass.getGenericInterfaces())
+        {
+            entityMetadata = extractFromType(intf);
+            if (entityMetadata != null)
+            {
+                return entityMetadata;
+            }
+        }
+        if (repositoryClass.getSuperclass() != null)
+        {
+            return extract(repositoryClass.getSuperclass());
+        }
+        return null;
+    }
+
+    private EntityMetadata extractFromType(Type type)
+    {
+        LOG.log(Level.FINER, "extractFrom: type = {0}", type);
+
+        if (!(type instanceof ParameterizedType))
+        {
+            return null;
+        }
+        
+        ParameterizedType parametrizedType = (ParameterizedType) type;
+        Type[] genericTypes = parametrizedType.getActualTypeArguments();
+        
+        EntityMetadata result = null;
+        
+        // don't use a foreach here, we must be sure that the we first get the entity type
+        for (Type genericType : genericTypes)
+        {
+            if (genericType instanceof Class && EntityUtils.isEntityClass((Class<?>) genericType))
+            {
+                result = new EntityMetadata((Class<?>) genericType);
+                continue;
+            }
+
+            if (result != null && genericType instanceof Class)
+            {
+                result.setPrimaryKeyClass((Class<? extends Serializable>) genericType);
+                return result;
+            }
+        }
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/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
deleted file mode 100644
index b93e45c..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodPrefix.java
+++ /dev/null
@@ -1,188 +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 org.apache.deltaspike.data.api.SingleResultType;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class MethodPrefix
-{
-    public static final String DEFAULT_PREFIX = "findBy";
-    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 static final String FIND_ALL_PREFIX = "findAll";
-
-    private static final String FIND_FIRST_PREFIX = "find(First|Top)(\\d+)(By)*";
-    private static final String FIND_FIRST_PREFIX_PATTERN = FIND_FIRST_PREFIX + "(.*)";
-    private static final Pattern DIGIT_PATTERN = Pattern.compile("\\d+");
-
-    private final String customPrefix;
-    private final String methodName;
-    private int definedMaxResults = 0;
-
-    public MethodPrefix(String customPrefix, String methodName)
-    {
-        this.customPrefix = customPrefix;
-        this.methodName = methodName;
-        if (this.methodName != null)
-        {
-            this.parseMaxResults();
-        }
-    }
-
-    public String removePrefix(String queryPart)
-    {
-        if (hasCustomPrefix() && queryPart.startsWith(customPrefix))
-        {
-            return queryPart.substring(customPrefix.length());
-        }
-        KnownQueryPrefix known = KnownQueryPrefix.fromMethodName(queryPart);
-        if (known != null)
-        {
-            return known.removePrefix(queryPart);
-        }
-        return queryPart;
-    }
-
-    public boolean hasCustomPrefix()
-    {
-        return !"".equals(customPrefix);
-    }
-
-    public String getCustomPrefix()
-    {
-        return customPrefix;
-    }
-
-    public String getPrefix()
-    {
-        if (hasCustomPrefix())
-        {
-            return customPrefix;
-        }
-        KnownQueryPrefix prefix = KnownQueryPrefix.fromMethodName(methodName);
-        if (prefix != null)
-        {
-            return prefix.getPrefix();
-        }
-        return "";
-    }
-
-    public SingleResultType getSingleResultStyle()
-    {
-        KnownQueryPrefix prefix = KnownQueryPrefix.fromMethodName(methodName);
-        if (prefix != null)
-        {
-            return prefix.getStyle();
-        }
-        return SingleResultType.JPA;
-    }
-
-    public boolean isDelete()
-    {
-        return this.getPrefix().equalsIgnoreCase(DEFAULT_DELETE_PREFIX) ||
-                this.getPrefix().equalsIgnoreCase(DEFAULT_REMOVE_PREFIX);
-    }
-
-    int getDefinedMaxResults()
-    {
-        return definedMaxResults;
-    }
-
-    private void parseMaxResults()
-    {
-        if (this.methodName.matches(FIND_FIRST_PREFIX_PATTERN))
-        {
-            Matcher matcher = DIGIT_PATTERN.matcher(this.methodName);
-            if (matcher.find())
-            {
-                this.definedMaxResults = Integer.parseInt(matcher.group());
-            }
-        }
-    }
-
-    private enum KnownQueryPrefix
-    {
-        DEFAULT(DEFAULT_PREFIX, SingleResultType.JPA),
-        ALL(FIND_ALL_PREFIX, SingleResultType.JPA),
-        FIND_FIRST(FIND_FIRST_PREFIX, SingleResultType.JPA)
-        {
-            @Override
-            public boolean matches(String name)
-            {
-                return name.matches(FIND_FIRST_PREFIX_PATTERN);
-            }
-            @Override
-            public String removePrefix(String queryPart)
-            {
-                return queryPart.replaceFirst(FIND_FIRST_PREFIX,"");
-            }
-        },
-        OPTIONAL(DEFAULT_OPT_PREFIX,SingleResultType.OPTIONAL),
-        ANY(DEFAULT_ANY_PREFIX, SingleResultType.ANY),
-        DELETE_DEFAULT(DEFAULT_DELETE_PREFIX, SingleResultType.ANY),
-        REMOVE_DEFAULT(DEFAULT_REMOVE_PREFIX, SingleResultType.ANY);
-
-        private final String prefix;
-        private final SingleResultType singleResultType;
-
-        KnownQueryPrefix(String prefix, SingleResultType singleResultType)
-        {
-            this.prefix = prefix;
-            this.singleResultType = singleResultType;
-        }
-
-        public String removePrefix(String queryPart)
-        {
-            return queryPart.substring(prefix.length());
-        }
-
-        public String getPrefix()
-        {
-            return prefix;
-        }
-
-        public SingleResultType getStyle()
-        {
-            return this.singleResultType;
-        }
-
-        public boolean matches(String name)
-        {
-            return name.startsWith(getPrefix());
-        }
-
-        public static KnownQueryPrefix fromMethodName(String name)
-        {
-            for (KnownQueryPrefix mapping : values())
-            {
-                if (mapping.matches(name))
-                {
-                    return mapping;
-                }
-            }
-            return null;
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodType.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodType.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodType.java
deleted file mode 100644
index aa8e493..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/MethodType.java
+++ /dev/null
@@ -1,36 +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;
-
-
-/**
- * Repository method type. Stands for
- * <ul>
- * <li>Delegated methods - the Repository has a concrete implementation for this or the method is implemented in the
- * {@link org.apache.deltaspike.data.impl.handler.EntityRepositoryHandler}.</li>
- * <li>Annotated method - the query is defined via a Query annotation.</li>
- * <li>The method defines a query expression by its name.</li>
- * </ul>
- */
-public enum MethodType
-{
-
-    DELEGATE, ANNOTATED, PARSE
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/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
index 89cab42..bbd900b 100644
--- 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
@@ -41,6 +41,6 @@ import javax.inject.Qualifier;
 public @interface QueryInvocation
 {
 
-    MethodType value();
+    RepositoryMethodType value();
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/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
index f95d9ef..a21143c 100644
--- 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
@@ -30,15 +30,15 @@ public class QueryInvocationLiteral extends AnnotationLiteral<QueryInvocation>
 
     private static final long serialVersionUID = 1L;
 
-    private final MethodType methodType;
+    private final RepositoryMethodType methodType;
 
-    public QueryInvocationLiteral(MethodType methodType)
+    public QueryInvocationLiteral(RepositoryMethodType methodType)
     {
         this.methodType = methodType;
     }
 
     @Override
-    public MethodType value()
+    public RepositoryMethodType value()
     {
         return methodType;
     }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponent.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponent.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponent.java
deleted file mode 100644
index a98b558..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponent.java
+++ /dev/null
@@ -1,263 +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 java.io.Serializable;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.persistence.FlushModeType;
-
-import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
-import org.apache.deltaspike.data.api.EntityManagerConfig;
-import org.apache.deltaspike.data.api.EntityManagerResolver;
-import org.apache.deltaspike.data.api.Repository;
-
-/**
- * Stores information about a specific Repository. Extracts information about:
- * <ul>
- * <li>The Repository class</li>
- * <li>The target entity the Repository is for</li>
- * <li>The primary key class</li>
- * <li>All methods of the Repository.</li>
- * </ul>
- */
-public class RepositoryComponent
-{
-
-    private static final Logger log = Logger.getLogger(RepositoryComponent.class.getName());
-
-    private volatile Boolean entityManagerResolverIsNormalScope;
-
-    private final Class<?> repoClass;
-    private final RepositoryEntity repositoryEntity;
-    private final Class<? extends EntityManagerResolver> entityManagerResolver;
-    private final FlushModeType entityManagerFlushMode;
-
-    private final Map<Method, RepositoryMethod> methods = new HashMap<Method, RepositoryMethod>();
-
-    public RepositoryComponent(Class<?> repoClass, RepositoryEntity repositoryEntity)
-    {
-        if (repositoryEntity == null)
-        {
-            throw new IllegalArgumentException("repositoryEntity cannot be null");
-        }
-        this.repoClass = repoClass;
-        this.repositoryEntity = repositoryEntity;
-        this.entityManagerResolver = extractEntityManagerResolver(repoClass);
-        this.entityManagerFlushMode = extractEntityManagerFlushMode(repoClass);
-    }
-
-    //don't trigger this lookup during ProcessAnnotatedType
-    private void lazyInit()
-    {
-        if (entityManagerResolverIsNormalScope == null)
-        {
-            init(BeanManagerProvider.getInstance().getBeanManager());
-        }
-    }
-
-    private synchronized void init(BeanManager beanManager)
-    {
-        if (entityManagerResolverIsNormalScope != null)
-        {
-            return;
-        }
-        initialize();
-        if (entityManagerResolver != null && beanManager != null)
-        {
-            final Set<Bean<?>> beans = beanManager.getBeans(entityManagerResolver);
-            final Class<? extends Annotation> scope = beanManager.resolve(beans).getScope();
-            entityManagerResolverIsNormalScope = beanManager.isNormalScope(scope);
-        }
-        else
-        {
-            entityManagerResolverIsNormalScope = false;
-        }
-    }
-
-    public boolean isEntityManagerResolverIsNormalScope()
-    {
-        lazyInit();
-        return entityManagerResolverIsNormalScope;
-    }
-
-    public String getEntityName()
-    {
-        return repositoryEntity.getEntityName();
-    }
-
-    /**
-     * Looks up method meta data by a Method object.
-     *
-     * @param method    The Repository method.
-     * @return Method meta data.
-     */
-    public RepositoryMethod lookupMethod(Method method)
-    {
-        lazyInit();
-        return methods.get(method);
-    }
-
-    /**
-     * Looks up the method type by a Method object.
-     *
-     * @param method    The Repository method.
-     * @return Method meta data.
-     */
-    public MethodType lookupMethodType(Method method)
-    {
-        return lookupMethod(method).getMethodType();
-    }
-
-    /**
-     * Gets the entity class related the Repository.
-     *
-     * @return The class of the entity related to the Repository.
-     */
-    public Class<?> getEntityClass()
-    {
-        return repositoryEntity.getEntityClass();
-    }
-
-    /**
-     * Gets the entity primary key class related the Repository.
-     *
-     * @return The class of the entity primary key related to the Repository.
-     */
-    public Class<? extends Serializable> getPrimaryKey()
-    {
-        return repositoryEntity.getPrimaryKeyClass();
-    }
-    
-    public RepositoryEntity getRepositoryEntity()
-    {
-        return repositoryEntity;
-    }
-    
-    /**
-     * Returns the original Repository class this meta data is related to.
-     *
-     * @return The class of the Repository.
-     */
-    public Class<?> getRepositoryClass()
-    {
-        return repoClass;
-    }
-
-    public boolean hasEntityManagerResolver()
-    {
-        return getEntityManagerResolverClass() != null;
-    }
-
-    public Class<? extends EntityManagerResolver> getEntityManagerResolverClass()
-    {
-        return entityManagerResolver;
-    }
-
-    public boolean hasEntityManagerFlushMode()
-    {
-        return entityManagerFlushMode != null;
-    }
-
-    public FlushModeType getEntityManagerFlushMode()
-    {
-        return entityManagerFlushMode;
-    }
-
-    private void initialize()
-    {
-        Collection<Class<?>> allImplemented = collectClasses();
-        for (Class<?> implemented : allImplemented)
-        {
-            Method[] repoClassMethods = implemented.getDeclaredMethods();
-            for (Method repoClassMethod : repoClassMethods)
-            {
-                RepositoryMethod repoMethod = new RepositoryMethod(repoClassMethod, this);
-                methods.put(repoClassMethod, repoMethod);
-            }
-        }
-    }
-
-    private Set<Class<?>> collectClasses()
-    {
-        Set<Class<?>> result = new HashSet<Class<?>>();
-        collectClasses(repoClass, result);
-        log.log(Level.FINER, "collectClasses(): Found {0} for {1}", new Object[] { result, repoClass });
-        return result;
-    }
-
-    private void collectClasses(Class<?> cls, Set<Class<?>> result)
-    {
-        if (cls == null || cls == Object.class)
-        {
-            return;
-        }
-        result.add(cls);
-        for (Class<?> child : cls.getInterfaces())
-        {
-            collectClasses(child, result);
-        }
-        collectClasses(cls.getSuperclass(), result);
-    }
-
-    private Class<? extends EntityManagerResolver> extractEntityManagerResolver(Class<?> clazz)
-    {
-        EntityManagerConfig config = extractEntityManagerConfig(clazz);
-        if (config != null && !EntityManagerResolver.class.equals(config.entityManagerResolver()))
-        {
-            return config.entityManagerResolver();
-        }
-        return null;
-    }
-
-    private FlushModeType extractEntityManagerFlushMode(Class<?> clazz)
-    {
-        EntityManagerConfig config = extractEntityManagerConfig(clazz);
-        if (config != null)
-        {
-            return config.flushMode();
-        }
-        return null;
-    }
-
-    private EntityManagerConfig extractEntityManagerConfig(Class<?> clazz)
-    {
-        if (clazz.isAnnotationPresent(EntityManagerConfig.class))
-        {
-            return clazz.getAnnotation(EntityManagerConfig.class);
-        }
-        return null;
-    }
-
-    public String getCustomMethodPrefix()
-    {
-        return repoClass.getAnnotation(Repository.class).methodPrefix();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponents.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponents.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponents.java
deleted file mode 100644
index 8eec5dd..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponents.java
+++ /dev/null
@@ -1,129 +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 org.apache.deltaspike.data.impl.RepositoryDefinitionException;
-import org.apache.deltaspike.data.impl.meta.extractor.AnnotationMetadataExtractor;
-import org.apache.deltaspike.data.impl.meta.extractor.MetadataExtractor;
-import org.apache.deltaspike.data.impl.meta.extractor.TypeMetadataExtractor;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Convenience class to access Repository and Repository method meta data.
- * Acts as repository for Repository related meta data.
- */
-public class RepositoryComponents
-{
-    private final Map<Class<?>, RepositoryComponent> repos = new ConcurrentHashMap<Class<?>, RepositoryComponent>();
-
-    private final List<MetadataExtractor> extractors = Arrays.asList(new AnnotationMetadataExtractor(),
-            new TypeMetadataExtractor());
-
-    /**
-     * Add a Repository class to the meta data repository.
-     *
-     * @param repoClass  The repo class.
-     */
-    public void add(Class<?> repoClass)
-    {
-        RepositoryEntity entityClass = extractEntityMetaData(repoClass);
-        RepositoryComponent repo = new RepositoryComponent(repoClass, entityClass);
-        repos.put(repoClass, repo);
-    }
-
-    /**
-     * Repository access - lookup the Repository component meta data from a list of candidate classes.
-     * Depending on the implementation, proxy objects might have been modified so the actual class
-     * does not match the original Repository class.
-     *
-     * @param candidateClasses  List of candidates to check.
-     * @return A {@link RepositoryComponent} corresponding to the repoClass parameter.
-     */
-    public RepositoryComponent lookupComponent(List<Class<?>> candidateClasses)
-    {
-        for (Class<?> repoClass : candidateClasses)
-        {
-            if (repos.containsKey(repoClass))
-            {
-                return repos.get(repoClass);
-            }
-        }
-        throw new RuntimeException("Unknown Repository classes " + candidateClasses);
-    }
-
-    /**
-     * Repository access - lookup the Repository component meta data for a specific Repository class.
-     *
-     * @param repoClass  The Repository class to lookup the method for
-     * @return A {@link RepositoryComponent} corresponding to the repoClass parameter.
-     */
-    public RepositoryComponent lookupComponent(Class<?> repoClass)
-    {
-        if (repos.containsKey(repoClass))
-        {
-            return repos.get(repoClass);
-        }
-        throw new RuntimeException("Unknown Repository class " + repoClass.getName());
-    }
-
-    /**
-     * Repository access - lookup method information for a specific Repository class.
-     *
-     * @param repoClass The Repository class to lookup the method for
-     * @param method    The Method object to get Repository meta data for.
-     * @return A {@link RepositoryMethod} corresponding to the method parameter.
-     */
-    public RepositoryMethod lookupMethod(Class<?> repoClass, Method method)
-    {
-        return lookupComponent(repoClass).lookupMethod(method);
-    }
-    
-    public RepositoryMethod lookupMethod(RepositoryComponent component, Method method)
-    {
-        return component.lookupMethod(method);
-    }
-
-    private RepositoryEntity extractEntityMetaData(Class<?> repoClass)
-    {
-        for (MetadataExtractor extractor : extractors)
-        {
-            RepositoryEntity entity = extractor.extract(repoClass);
-            if (entity != null)
-            {
-                return entity;
-            }
-        }
-        throw new RepositoryDefinitionException(repoClass);
-    }
-
-    public Map<Class<?>, RepositoryComponent> getRepositories()
-    {
-        return repos;
-    }
-
-    public void addAll(Map<Class<?>, RepositoryComponent> repositories)
-    {
-        this.repos.putAll(repositories);
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/46a3b675/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponentsFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponentsFactory.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponentsFactory.java
deleted file mode 100644
index 19cd451..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponentsFactory.java
+++ /dev/null
@@ -1,44 +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.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
-import javax.inject.Inject;
-
-import org.apache.deltaspike.core.api.lifecycle.Initialized;
-import org.apache.deltaspike.data.impl.RepositoryExtension;
-
-/**
- * Repository components producer.
- */
-public class RepositoryComponentsFactory
-{
-
-    @Inject
-    private RepositoryExtension extension;
-    
-    @Produces
-    @ApplicationScoped
-    @Initialized
-    public RepositoryComponents producer()
-    {
-        return extension.getComponents();
-    }
-}