Skip to content

Commit

Permalink
Review notes applied.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <[email protected]>
  • Loading branch information
Tomas-Kraus committed Nov 2, 2023
1 parent 2fcab49 commit e72944a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public EJBQueryImpl<X> setLockMode(LockModeType lockMode) {
// Based on EntityManagerImpl#getQueryHints(Object,OperationType)
@Override
public CacheRetrieveMode getCacheRetrieveMode() {
return FindOptionUtils.getCacheRetrieveMode(getDatabaseQuery().getProperties());
return FindOptionUtils.getCacheRetrieveMode(entityManager.getAbstractSession(), getDatabaseQuery().getProperties());
}

@Override
Expand All @@ -315,7 +315,7 @@ public TypedQuery<X> setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) {

@Override
public CacheStoreMode getCacheStoreMode() {
return FindOptionUtils.getCacheStoreMode(getDatabaseQuery().getProperties());
return FindOptionUtils.getCacheStoreMode(entityManager.getAbstractSession(), getDatabaseQuery().getProperties());
}

@Override
Expand All @@ -326,7 +326,7 @@ public TypedQuery<X> setCacheStoreMode(CacheStoreMode cacheStoreMode) {

@Override
public Integer getTimeout() {
return FindOptionUtils.getTimeout(getDatabaseQuery().getProperties());
return FindOptionUtils.getTimeout(entityManager.getAbstractSession(), getDatabaseQuery().getProperties());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2918,7 +2918,7 @@ public LockModeType getLockMode(Object entity) {

@Override
public CacheRetrieveMode getCacheRetrieveMode() {
return FindOptionUtils.getCacheRetrieveMode(properties);
return FindOptionUtils.getCacheRetrieveMode(getAbstractSession(), properties);
}

@Override
Expand All @@ -2928,7 +2928,7 @@ public void setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) {

@Override
public CacheStoreMode getCacheStoreMode() {
return FindOptionUtils.getCacheStoreMode(properties);
return FindOptionUtils.getCacheStoreMode(getAbstractSession(), properties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
import jakarta.persistence.LockModeType;
import jakarta.persistence.PessimisticLockScope;
import jakarta.persistence.Timeout;
import jakarta.persistence.TypedQuery;
import org.eclipse.persistence.config.QueryHints;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.logging.AbstractSessionLog;
import org.eclipse.persistence.logging.SessionLog;
import org.eclipse.persistence.queries.DatabaseQuery;

/**
* {@link FindOption} processing tools.
Expand Down Expand Up @@ -151,16 +148,16 @@ static Options parse(Map<String, Object> properties, FindOption... options) {
}

// Based on EntityManagerImpl#getQueryHints(Object,OperationType)
static CacheRetrieveMode getCacheRetrieveMode(Map<?, Object> properties) {
static CacheRetrieveMode getCacheRetrieveMode(AbstractSession session, Map<?, Object> properties) {
// QueryHints property
Object propertyValue = properties.get(QueryHints.CACHE_RETRIEVE_MODE);
if (propertyValue instanceof CacheRetrieveMode) {
return (CacheRetrieveMode) propertyValue;
} else if (propertyValue != null) {
AbstractSessionLog.getLog().log(SessionLog.WARNING,
SessionLog.QUERY,
"unknown_cacheRetrieveMode_type",
propertyValue.getClass().getName());
session.log(SessionLog.WARNING,
SessionLog.QUERY,
"unknown_cacheRetrieveMode_type",
propertyValue.getClass().getName());
}
// Default value according to JPA spec.
return CacheRetrieveMode.USE;
Expand All @@ -171,16 +168,16 @@ static void setCacheRetrieveMode(Map<?, Object> properties, CacheRetrieveMode ca
((Map<String, Object>)properties).put(QueryHints.CACHE_RETRIEVE_MODE, cacheRetrieveMode);
}

static CacheStoreMode getCacheStoreMode(Map<?, Object> properties) {
static CacheStoreMode getCacheStoreMode(AbstractSession session, Map<?, Object> properties) {
// QueryHints property
Object propertyValue = properties.get(QueryHints.CACHE_STORE_MODE);
if (propertyValue instanceof CacheStoreMode) {
return (CacheStoreMode) propertyValue;
} else if (propertyValue != null) {
AbstractSessionLog.getLog().log(SessionLog.WARNING,
SessionLog.QUERY,
"unknown_cacheStoreMode_type",
propertyValue.getClass().getName());
session.log(SessionLog.WARNING,
SessionLog.QUERY,
"unknown_cacheStoreMode_type",
propertyValue.getClass().getName());
}
// Default value according to JPA spec.
return CacheStoreMode.USE;
Expand All @@ -191,17 +188,17 @@ static void setCacheStoreMode(Map<?, Object> properties, CacheStoreMode cacheSto
((Map<String, Object>)properties).put(QueryHints.CACHE_STORE_MODE, cacheStoreMode);
}

static Integer getTimeout(Map<?, Object> properties) {
static Integer getTimeout(AbstractSession session, Map<?, Object> properties) {
// QueryHints.QUERY_TIMEOUT_UNIT may contain TimeUnit
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
Object propertyValue = properties.get(QueryHints.QUERY_TIMEOUT_UNIT);
if (propertyValue instanceof TimeUnit) {
timeUnit = (TimeUnit)propertyValue;
} else if (propertyValue != null) {
AbstractSessionLog.getLog().log(SessionLog.WARNING,
SessionLog.QUERY,
"unknown_queryTimeoutUnit_type",
propertyValue.getClass().getName());
session.log(SessionLog.WARNING,
SessionLog.QUERY,
"unknown_queryTimeoutUnit_type",
propertyValue.getClass().getName());
}
// QueryHints.QUERY_TIMEOUT must be converted from actual units to milliseconds
propertyValue = properties.get(QueryHints.QUERY_TIMEOUT);
Expand All @@ -212,17 +209,17 @@ static Integer getTimeout(Map<?, Object> properties) {
long value = Long.parseLong(s);
return (int)TimeUnit.MILLISECONDS.convert(value, timeUnit);
} catch (NumberFormatException e) {
AbstractSessionLog.getLog().log(SessionLog.WARNING,
SessionLog.QUERY,
"error_queryTimeoutParse",
s,
e.getLocalizedMessage());
session.log(SessionLog.WARNING,
SessionLog.QUERY,
"error_queryTimeoutParse",
s,
e.getLocalizedMessage());
}
} else {
AbstractSessionLog.getLog().log(SessionLog.WARNING,
SessionLog.QUERY,
"unknown_queryTimeout_type",
propertyValue.getClass().getName());
session.log(SessionLog.WARNING,
SessionLog.QUERY,
"unknown_queryTimeout_type",
propertyValue.getClass().getName());
}
// Return default value (means no timeout was set)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ public StoredProcedureQueryImpl setFlushMode(FlushModeType flushMode) {

@Override
public CacheRetrieveMode getCacheRetrieveMode() {
return FindOptionUtils.getCacheRetrieveMode(getDatabaseQuery().getProperties());
return FindOptionUtils.getCacheRetrieveMode(entityManager.getAbstractSession(), getDatabaseQuery().getProperties());
}

@Override
Expand All @@ -893,7 +893,7 @@ public StoredProcedureQueryImpl setCacheRetrieveMode(CacheRetrieveMode cacheRetr

@Override
public CacheStoreMode getCacheStoreMode() {
return FindOptionUtils.getCacheStoreMode(getDatabaseQuery().getProperties());
return FindOptionUtils.getCacheStoreMode(entityManager.getAbstractSession(), getDatabaseQuery().getProperties());
}

@Override
Expand All @@ -904,7 +904,7 @@ public StoredProcedureQueryImpl setCacheStoreMode(CacheStoreMode cacheStoreMode)

@Override
public Integer getTimeout() {
return FindOptionUtils.getTimeout(getDatabaseQuery().getProperties());
return FindOptionUtils.getTimeout(entityManager.getAbstractSession(), getDatabaseQuery().getProperties());
}

@Override
Expand Down

0 comments on commit e72944a

Please sign in to comment.