Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D44A6200CC0 for ; Sun, 4 Jun 2017 02:00:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D12C5160BCD; Sun, 4 Jun 2017 00:00:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B166F160BD1 for ; Sun, 4 Jun 2017 02:00:40 +0200 (CEST) Received: (qmail 32325 invoked by uid 500); 4 Jun 2017 00:00:39 -0000 Mailing-List: contact commits-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltaspike.apache.org Delivered-To: mailing list commits@deltaspike.apache.org Received: (qmail 32316 invoked by uid 99); 4 Jun 2017 00:00:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Jun 2017 00:00:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2D694E00C4; Sun, 4 Jun 2017 00:00:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tandraschko@apache.org To: commits@deltaspike.apache.org Date: Sun, 04 Jun 2017 00:00:39 -0000 Message-Id: <836e828396834cb6ae27ee1b1d271b49@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] deltaspike git commit: DELTASPIKE-1070 Refactor RepositoryComponent/s archived-at: Sun, 04 Jun 2017 00:00:43 -0000 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 primaryKeyClass; - private Property primaryKeyProperty; - private Property versionProperty; - private String entityName; - - public RepositoryEntity(Class entityClass) - { - this(entityClass, null); - } - - public RepositoryEntity(Class entityClass, Class 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 getPrimaryKeyClass() - { - return primaryKeyClass; - } - - public void setPrimaryKeyClass(Class primaryKeyClass) - { - this.primaryKeyClass = primaryKeyClass; - } - - public Property getVersionProperty() - { - return versionProperty; - } - - public void setVersionProperty(Property versionProperty) - { - this.versionProperty = versionProperty; - } - - public String getEntityName() - { - return entityName; - } - - public void setEntityName(String entityName) - { - this.entityName = entityName; - } - - public Property getPrimaryKeyProperty() - { - return primaryKeyProperty; - } - - public void setPrimaryKeyProperty(Property 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 methodsMetadata; + + private Class 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 getEntityManagerResolverClass() + { + return entityManagerResolverClass; + } + + public void setEntityManagerResolverClass(Class 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 getMethodsMetadata() + { + return methodsMetadata; + } + + public void setMethodsMetadata(Map 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, RepositoryMetadata> repositoriesMetadata = + new ConcurrentHashMap, 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> 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, 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> beans = beanManager.getBeans(repositoryMetadata.getEntityManagerResolverClass()); + Class 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()); + + Set> allImplemented = new HashSet>(); + 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> 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 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: - *
    - *
  • The reference to the Method reflection object
  • - *
  • Whether this method delegates, is annotated or is parsed
  • - *
  • A reference to the parent Repository
  • - *
  • For parsed Repository methods, also the JPQL string is cached
  • - *
- */ -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> 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> 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> 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> beans = beanManager.getBeans(mapper); - final Class 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> 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> getQueryInOutMapperClass() + { + return queryInOutMapperClass; + } + + public void setQueryInOutMapperClass(Class> 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> beans = beanManager.getBeans(repositoryMethodMetadata.getQueryInOutMapperClass()); + Class 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> 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 + *
    + *
  • 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}.
  • + *
  • Annotated method - the query is defined via a Query annotation.
  • + *
  • The method defines a query expression by its name.
  • + *
+ */ +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) 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; }