Skip to content

Commit

Permalink
Fixed build issues with JPA API 3.2
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus authored and lukasj committed Sep 20, 2023
1 parent c89e4b5 commit f1fb9f6
Show file tree
Hide file tree
Showing 15 changed files with 974 additions and 196 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023 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
Expand All @@ -24,6 +24,7 @@
//javase imports

import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceConfiguration;
import jakarta.persistence.spi.PersistenceProvider;
import jakarta.persistence.spi.PersistenceUnitInfo;
import jakarta.persistence.spi.ProviderUtil;
Expand Down Expand Up @@ -128,6 +129,13 @@ public EntityManagerFactory createEntityManagerFactory(String emName, Map map) {
return null;
}
}

// Not used, added in JPA 3.2
@Override
public EntityManagerFactory createEntityManagerFactory(PersistenceConfiguration configuration) {
return null;
}

@Override
public ProviderUtil getProviderUtil() {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023 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
Expand Down Expand Up @@ -5681,7 +5681,7 @@ public void testMetamodel_entity_Method() {
// test variant path: null causes IAE
expectedIAExceptionThrown = false;
try {
EntityType<Manufacturer> aType = metamodel.entity(null);
EntityType<Manufacturer> aType = metamodel.entity((Class<Manufacturer>) null);
} catch (IllegalArgumentException iae) {
expectedIAExceptionThrown = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

package org.eclipse.persistence.testing.tests.jpa.persistence32;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityTransaction;
import junit.framework.Test;
Expand All @@ -24,7 +20,6 @@
import org.eclipse.persistence.jpa.JpaEntityManagerFactory;
import org.eclipse.persistence.testing.framework.jpa.junit.JUnitTestCase;
import org.eclipse.persistence.testing.models.jpa.persistence32.Persistence32TableCreator;
import org.eclipse.persistence.testing.models.jpa.persistence32.Pokemon;
import org.eclipse.persistence.testing.models.jpa.persistence32.Type;

public class EntityManagerFactoryTest extends JUnitTestCase {
Expand Down Expand Up @@ -59,10 +54,10 @@ public static Test suite() {
TestSuite suite = new TestSuite();
suite.setName("EntityManagerFactoryTest");
suite.addTest(new EntityManagerFactoryTest("testSetup"));
suite.addTest(new EntityManagerFactoryTest("testWithApplicationManagedTransaction"));
suite.addTest(new EntityManagerFactoryTest("testWithApplicationManagedTransactionVoid"));
suite.addTest(new EntityManagerFactoryTest("testWithUserManagedTransaction"));
suite.addTest(new EntityManagerFactoryTest("testWithUserManagedTransactionVoid"));
// suite.addTest(new EntityManagerFactoryTest("testWithApplicationManagedTransaction"));
// suite.addTest(new EntityManagerFactoryTest("testWithApplicationManagedTransactionVoid"));
// suite.addTest(new EntityManagerFactoryTest("testWithUserManagedTransaction"));
// suite.addTest(new EntityManagerFactoryTest("testWithUserManagedTransactionVoid"));
return suite;
}

Expand Down Expand Up @@ -113,6 +108,8 @@ public void testSetup() {
}
}

// TODO-API-3.2 - rewrite using new API
/*
public void testWithApplicationManagedTransaction() {
Pokemon pokemon = emf.withTransaction((em -> {
Map<Integer, Type> types = new HashMap<>(24);
Expand Down Expand Up @@ -179,5 +176,5 @@ public void testWithUserManagedTransactionVoid() {
}));
verifyObjectInEntityManager(pokemon[0], getPersistenceUnitName());
}

*/
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023 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
Expand All @@ -21,6 +21,8 @@
// - 350487: JPA 2.1 Specification defined support for Stored Procedure Calls
// 08/11/2012-2.5 Guy Pelletier
// - 393867: Named queries do not work when using EM level Table Per Tenant Multitenancy.
// 08/23/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.internal.jpa;

import java.util.ArrayList;
Expand All @@ -31,6 +33,8 @@
import java.util.List;
import java.util.Map;

import jakarta.persistence.CacheRetrieveMode;
import jakarta.persistence.CacheStoreMode;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
import jakarta.persistence.LockTimeoutException;
Expand Down Expand Up @@ -296,6 +300,79 @@ public EJBQueryImpl setLockMode(LockModeType lockMode) {
return (EJBQueryImpl) super.setLockMode(lockMode);
}

/**
* The cache retrieval mode that will be in effect during query execution.
*
* @since 4.1
*/
// TODO-API-3.2
@Override
public CacheRetrieveMode getCacheRetrieveMode() {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* Set the cache retrieval mode that is in effect during query execution.
* This cache retrieval mode overrides the cache retrieve mode in use by the entity manager.
*
* @param cacheRetrieveMode cache retrieval mode
* @return the same query instance
* @since 4.1
*/
// TODO-API-3.2
@Override
public TypedQuery<X> setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* The cache storage mode that will be in effect during query execution.
*
* @since 4.1
*/
// TODO-API-3.2
@Override
public CacheStoreMode getCacheStoreMode() {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* Set the cache storage mode that is in effect during query execution.
* This cache storage mode overrides the cache storage mode in use by the entity manager.
*
* @param cacheStoreMode cache storage mode
* @return the same query instance
* @since 4.1
*/
// TODO-API-3.2
@Override
public TypedQuery<X> setCacheStoreMode(CacheStoreMode cacheStoreMode) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* The query timeout.
*
* @since 4.1
*/
// TODO-API-3.2
@Override
public Integer getTimeout() {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* Set the query timeout.
*
* @param timeout the timeout, or {@code null} to indicate no timeout
* @return the same query instance
* @since 4.1
*/
@Override
public TypedQuery<X> setTimeout(Integer timeout) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* Non-standard method to return results of a ReadQuery that has a
* containerPolicy that returns objects as a collection rather than a List
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023 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
Expand All @@ -13,6 +13,8 @@
// Contributors:
// 09 Jan 2013-2.5 Gordon Yorke
// - 397772: JPA 2.1 Entity Graph Support
// 08/23/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.internal.jpa;

import java.util.ArrayList;
Expand Down Expand Up @@ -79,14 +81,20 @@ public String getName() {
}

// TODO-API-3.2
//@Override
@Override
public void addAttributeNode(String attributeName) {
if (!isMutable) {
throw new IllegalStateException(ExceptionLocalization.buildMessage("immutable_entitygraph"));
}
addAttributeNodeImpl(attributeName);
}

// TODO-API-3.2
@Override
public void removeAttributeNode(String attributeName) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

@Override
public void addAttributeNodes(String... attributeNames) {
if (!isMutable) {
Expand All @@ -98,14 +106,20 @@ public void addAttributeNodes(String... attributeNames) {
}

// TODO-API-3.2
//@Override
@Override
public void addAttributeNode(Attribute<? super X, ?> attribute) {
if (!isMutable) {
throw new IllegalStateException(ExceptionLocalization.buildMessage("immutable_entitygraph"));
}
addAttributeNodeImpl(attribute.getName());
}

// TODO-API-3.2
@Override
public void removeAttributeNode(Attribute<? super X, ?> attribute) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

@Override
@SafeVarargs
public final void addAttributeNodes(Attribute<? super X, ?>... attributes) {
Expand All @@ -117,6 +131,12 @@ public final void addAttributeNodes(Attribute<? super X, ?>... attributes) {
}
}

// TODO-API-3.2
@Override
public void removeAttributeNodes(Attribute.PersistentAttributeType nodeTypes) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

// Add an attribute node of given name to the entity graph.
private void addAttributeNodeImpl(String attributeName) {
if (descriptor.getMappingForAttributeName(attributeName) == null) {
Expand Down Expand Up @@ -146,8 +166,8 @@ public <T> Subgraph<T> addSubgraph(Attribute<? super X, T> attribute) {
return addSubgraph(attribute.getName(), type);
}

// TODO-API-3.2: Implementace sem!
//@Override
// TODO-API-3.2
@Override
public <S extends X> Subgraph<S> addTreatedSubgraph(Class<S> type) {
if (!this.isMutable) {
throw new IllegalStateException(ExceptionLocalization.buildMessage("immutable_entitygraph"));
Expand All @@ -173,7 +193,7 @@ public <T> Subgraph<? extends T> addSubclassSubgraph(Class<? extends T> type) {
}

// TODO-API-3.2: alias pro addSubgraph se st. attr
//@Override
@Override
public <Y> Subgraph<Y> addTreatedSubgraph(Attribute<? super X, ? super Y> attribute, Class<Y> type) {
return addSubgraph(attribute.getName(), type);
}
Expand Down

0 comments on commit f1fb9f6

Please sign in to comment.