Skip to content

Commit

Permalink
EntityManagerFactory.setCacheRetrieveMode() setCacheStoreMode() and N…
Browse files Browse the repository at this point in the history
…PE fix plus unit test (#2104)

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
  • Loading branch information
rfelcman committed Mar 26, 2024
1 parent a5c7f08 commit 0f4718a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024 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 @@ -14,6 +14,8 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import jakarta.persistence.CacheRetrieveMode;
import jakarta.persistence.CacheStoreMode;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.EntityTransaction;
Expand Down Expand Up @@ -46,7 +48,9 @@ public static Test suite() {
new EntityManagerTest("testGetReferenceForExistingEntity"),
new EntityManagerTest("testGetReferenceForNotExistingEntity"),
new EntityManagerTest("testLockOptionUtilsUnknownClass"),
new EntityManagerTest("testLockPessimisticWriteWithTimeout")
new EntityManagerTest("testLockPessimisticWriteWithTimeout"),
new EntityManagerTest("testSetCacheRetrieveMode"),
new EntityManagerTest("testSetCacheStoreMode")
);
}

Expand Down Expand Up @@ -169,4 +173,21 @@ public void run() {
}
}

public void testSetCacheRetrieveMode() {
try (EntityManager em = emf.createEntityManager();) {
em.setCacheRetrieveMode(CacheRetrieveMode.BYPASS);
assertEquals(CacheRetrieveMode.BYPASS, em.getCacheRetrieveMode());
} catch (Exception e) {
throw e;
}
}

public void testSetCacheStoreMode() {
try (EntityManager em = emf.createEntityManager();) {
em.setCacheStoreMode(CacheStoreMode.USE);
assertEquals(CacheStoreMode.USE, em.getCacheStoreMode());
} catch (Exception e) {
throw e;
}
}
}
Expand Up @@ -2970,6 +2970,9 @@ public CacheRetrieveMode getCacheRetrieveMode() {

@Override
public void setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) {
if (this.properties == null) {
this.properties = new HashMap<>();
}
FindOptionUtils.setCacheRetrieveMode(properties, cacheRetrieveMode);
}

Expand All @@ -2980,6 +2983,9 @@ public CacheStoreMode getCacheStoreMode() {

@Override
public void setCacheStoreMode(CacheStoreMode cacheStoreMode) {
if (this.properties == null) {
this.properties = new HashMap<>();
}
FindOptionUtils.setCacheStoreMode(properties, cacheStoreMode);
}

Expand Down

0 comments on commit 0f4718a

Please sign in to comment.