| /* |
| * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0, |
| * or the Eclipse Distribution License v. 1.0 which is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
| */ |
| |
| // Contributors: |
| // Oracle - initial API and implementation |
| // |
| package org.eclipse.persistence.jpa.tests.jpql; |
| |
| import java.lang.reflect.Member; |
| import java.util.HashMap; |
| import java.util.Map; |
| import jpql.query.AbstractProduct; |
| import jpql.query.Address; |
| import jpql.query.Alias; |
| import jpql.query.CodeAssist; |
| import jpql.query.Customer; |
| import jpql.query.Dept; |
| import jpql.query.Employee; |
| import jpql.query.Home; |
| import jpql.query.LargeProject; |
| import jpql.query.Order; |
| import jpql.query.Phone; |
| import jpql.query.Product; |
| import jpql.query.Project; |
| import jpql.query.ShelfLife; |
| import jpql.query.SmallProject; |
| import jpql.query.ZipCode; |
| import org.eclipse.persistence.jpa.jpql.tools.spi.IManagedTypeProvider; |
| import org.eclipse.persistence.jpa.jpql.tools.spi.IMappingBuilder; |
| import org.eclipse.persistence.jpa.tests.jpql.tools.spi.java.JavaManagedTypeProvider; |
| |
| /** |
| * The default implementation of {@link JPQLQueryTestHelper} used by the unit-tests. |
| * |
| * @version 2.5 |
| * @since 2.3 |
| * @author Pascal Filion |
| */ |
| public abstract class JavaJPQLQueryTestHelper implements JPQLQueryTestHelper { |
| |
| /** |
| * The external forms of the ORM configurations mapped to the file name. |
| */ |
| private Map<String, IORMConfiguration> ormConfigurations; |
| |
| /** |
| * The external form of the persistence unit. |
| */ |
| private JavaManagedTypeProvider persistenceUnit; |
| |
| /** |
| * Creates |
| * |
| * @return mapping builder |
| */ |
| protected abstract IMappingBuilder<Member> buildMappingBuilder(); |
| |
| @Override |
| public IORMConfiguration getORMConfiguration(String ormXmlFileName) { |
| |
| if (ormConfigurations == null) { |
| ormConfigurations = new HashMap<>(); |
| } |
| |
| IORMConfiguration ormConfiguration = ormConfigurations.get(ormXmlFileName); |
| |
| if (ormConfiguration == null) { |
| ormConfiguration = new JavaORMConfiguration(buildMappingBuilder(), ormXmlFileName); |
| ormConfigurations.put(ormXmlFileName, ormConfiguration); |
| } |
| |
| return ormConfiguration; |
| } |
| |
| @Override |
| public IManagedTypeProvider getPersistenceUnit() { |
| if (persistenceUnit == null) { |
| persistenceUnit = new JavaManagedTypeProvider(buildMappingBuilder()); |
| initializeManagedTypeProvider(); |
| } |
| return persistenceUnit; |
| } |
| |
| private void initializeManagedTypeProvider() { |
| persistenceUnit.addMappedSuperclass(AbstractProduct.class); |
| persistenceUnit.addEntity(Address.class); |
| persistenceUnit.addEntity(Alias.class); |
| persistenceUnit.addEntity(CodeAssist.class); |
| persistenceUnit.addEntity(Customer.class); |
| persistenceUnit.addEntity(Dept.class); |
| persistenceUnit.addEntity(Employee.class); |
| persistenceUnit.addEntity(Home.class); |
| persistenceUnit.addEntity(LargeProject.class); |
| persistenceUnit.addEntity(Order.class); |
| persistenceUnit.addEntity(Phone.class); |
| persistenceUnit.addEntity(Product.class); |
| persistenceUnit.addEntity(Project.class); |
| persistenceUnit.addEntity(SmallProject.class); |
| persistenceUnit.addEmbeddable(Employee.EmbeddedAddress.class); |
| persistenceUnit.addEmbeddable(ShelfLife.class); |
| persistenceUnit.addEmbeddable(ZipCode.class); |
| } |
| |
| @Override |
| public void setUp() { |
| } |
| |
| @Override |
| public void setUpBefore() { |
| } |
| |
| @Override |
| public void tearDown() { |
| } |
| |
| @Override |
| public void tearDownAfter() { |
| } |
| } |