solomax commented on code in PR #156:
URL: https://github.com/apache/openjpa/pull/156#discussion_r3822671957


##########
openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java:
##########
@@ -721,22 +725,38 @@ public <T> T find(Class<T> cls, Object oid,
        @Override
        public <T> T find(Class<T> cls, Object oid, FindOption... options) {
                Map<String, Object> props = new HashMap<>();
+               LockModeType mode = parseFindOptions(props, options);
+               return find(cls, oid, mode, props);
+       }
+
+       /**
+        * Translates the given JPA 3.2 {@link FindOption}s into kernel level 
properties, which are put into the
+        * given (modifiable) property map, and returns the {@link 
LockModeType} found among the options, if any.
+        * Unknown (custom) options are ignored.
+        *
+        * @param props the map to receive the translated properties, never null
+        * @param options the options to translate, may be null or empty
+        * @return the lock mode given among the options or null if none was 
given
+        */
+       private LockModeType parseFindOptions(Map<String, Object> props, 
FindOption... options) {
                LockModeType mode = null;
-               for (FindOption opt: options) {
-                       if (opt instanceof LockModeType lmt) {
-                               mode = lmt;
-                       } else if (opt instanceof CacheRetrieveMode crm) {
-                               props.put(JPAProperties.CACHE_RETRIEVE_MODE, 
crm);
-                       } else if (opt instanceof CacheStoreMode csm) {
-                               props.put(JPAProperties.CACHE_STORE_MODE, csm);
-                       } else if (opt instanceof PessimisticLockScope pls) {
-                               props.put(JPAProperties.LOCK_SCOPE, pls);
-                       } else if (opt instanceof Timeout timeout) {
-                               props.put(JPAProperties.LOCK_TIMEOUT, 
timeout.milliseconds());
+               if (options != null) {

Review Comment:
   Maybe this one can be flattened a bit with:
   
   ```
   if (options == null) {
       return mode;
   }
   ```
   
   ? :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to