@Override public void printCollection(Vector items, ExpressionSQLPrinter printer) { if (items.size() == 1 && items.get(0) instanceof QueryKeyExpression && "deleteTs".equals(((QueryKeyExpression) items.get(0)).getName())) { if (!CubaUtil.isSoftDeletion()) { try { printer.getWriter().write("(0=0)"); return; } catch (IOException e) { throw new RuntimeException(e); } } } super.printCollection(items, printer); } }
@Override public void setSoftDeletion(boolean softDeletion) { this.softDeletion = softDeletion; CubaUtil.setSoftDeletion(softDeletion); CubaUtil.setOriginalSoftDeletion(softDeletion); }
@Override public ReadQuery prepareNestedBatchQuery(ObjectLevelReadQuery query) { if (org.eclipse.persistence.internal.helper.CubaUtil.isOriginalSoftDeletion()) { Boolean prevSoftDeletion = org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(true); try { return super.prepareNestedBatchQuery(query); } finally { org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(prevSoftDeletion); } } else { return super.prepareNestedBatchQuery(query); } } //cuba end
if (!org.eclipse.persistence.internal.helper.CubaUtil.isSoftDeletion()) { ReadQuery query = (ReadQuery) getQuery().clone(); query.setIsPrepared(false); softDeletionByMapping = oneToOneMapping.isSoftDeletionForValueHolder(); if (softDeletionByMapping && org.eclipse.persistence.internal.helper.CubaUtil.isSoftDeletion()) { ReadQuery query = (ReadQuery) getQuery().clone(); query.setIsPrepared(false); return session.executeQuery(query, getRow()); } else { Boolean prevSoftDeletion = org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(false); try { ReadQuery query = (ReadQuery) getQuery().clone(); return session.executeQuery(query, getRow()); } finally { org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(prevSoftDeletion);
&& org.eclipse.persistence.internal.helper.CubaUtil.isSoftDeletion() // cuba: do not cache queries when soft delete is disabled && org.eclipse.persistence.internal.helper.CubaUtil.isEnabledJPQLParseCache(); // cuba: do not cache queries in some cases DatabaseQuery databaseQuery = null; if (isCacheable) {
/** * INTERNAL: * Check if the object is invalid and refresh it. * This is used to ensure that no invalid objects are registered. */ public void checkAndRefreshInvalidObject(Object object, CacheKey cacheKey, ClassDescriptor descriptor) { if (isConsideredInvalid(object, cacheKey, descriptor)) { // cuba begin: always load refreshed object Boolean prevSoftDeletion = org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(false); try { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(object.getClass()); query.setSelectionId(cacheKey.getKey()); query.refreshIdentityMapResult(); query.setIsExecutionClone(true); this.executeQuery(query); } finally { org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(prevSoftDeletion); } // ReadObjectQuery query = new ReadObjectQuery(); // query.setReferenceClass(object.getClass()); // query.setSelectionId(cacheKey.getKey()); // query.refreshIdentityMapResult(); // query.setIsExecutionClone(true); // this.executeQuery(query); // cuba end } }
protected JpaQuery buildJPAQuery(String queryString, Class<T> resultClass) { boolean useJPQLCache = true; View view = views.isEmpty() ? null : views.get(0); if (view != null) { boolean useFetchGroup = view.loadPartialEntities(); for (View it : views) { FetchGroupDescription description = fetchGroupMgr.calculateFetchGroup(queryString, it, singleResultExpected, useFetchGroup); if (description.hasBatches()) { useJPQLCache = false; break; } } } if (!useJPQLCache) { CubaUtil.setEnabledJPQLParseCache(false); } try { if (resultClass != null) { return (JpaQuery) emDelegate.createQuery(queryString, resultClass); } else { return (JpaQuery) emDelegate.createQuery(queryString); } } finally { CubaUtil.setEnabledJPQLParseCache(true); } }
if (isDeleted && CubaUtil.isSoftDeletion()) { Boolean prevSoftDeletion = CubaUtil.setSoftDeletion(false); try { result = session.executeQuery(query); } finally { CubaUtil.setSoftDeletion(prevSoftDeletion);
public EntityManagerContextSynchronization(String store) { this.store = store; prevSoftDeletion = CubaUtil.setSoftDeletion(softDeletion); CubaUtil.setOriginalSoftDeletion(softDeletion); }
if (org.eclipse.persistence.internal.helper.CubaUtil.isSoftDeletion()) {
@Override public ReadQuery prepareNestedBatchQuery(ObjectLevelReadQuery query) { if (!softDeletionForBatch) { Boolean prevSoftDeletion = org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(false); try { return super.prepareNestedBatchQuery(query); } finally { org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(prevSoftDeletion); } } else if (org.eclipse.persistence.internal.helper.CubaUtil.isOriginalSoftDeletion()) { Boolean prevSoftDeletion = org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(true); try { return super.prepareNestedBatchQuery(query); } finally { org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(prevSoftDeletion); } } else { return super.prepareNestedBatchQuery(query); } } //cuba end
@Override public void suspend() { context = contextHolder.get(store); contextHolder.remove(store); CubaUtil.setSoftDeletion(prevSoftDeletion); CubaUtil.setOriginalSoftDeletion(prevSoftDeletion); }
/** * INTERNAL: * Check if the query is cached and prepare from it. * Return true if the query was cached. */ protected boolean prepareFromCachedQuery() { // PERF: Check if the equivalent expression query has already been prepared. // Only allow queries with default properties to be cached. boolean isCacheable = isExpressionQuery() && (!getQueryMechanism().isJPQLCallQueryMechanism()) && isDefaultPropertiesQuery() && (!getSession().isHistoricalSession()); DatabaseQuery cachedQuery = null; if (isCacheable) { cachedQuery = this.descriptor.getQueryManager().getCachedExpressionQuery(this); } else { return false; } if ((cachedQuery != null) && cachedQuery.isPrepared()) { prepareFromQuery(cachedQuery); setIsPrepared(true); return true; } // cuba begin if (org.eclipse.persistence.internal.helper.CubaUtil.isSoftDeletion()) { this.descriptor.getQueryManager().putCachedExpressionQuery(this); this.isCachedExpressionQuery = true; this.isExecutionClone = false; } // cuba end return false; }
@Override public void resume() { contextHolder.set(context, store); if (context != null) { CubaUtil.setSoftDeletion(context.isSoftDeletion()); CubaUtil.setOriginalSoftDeletion(context.isSoftDeletion()); } }
if (!org.eclipse.persistence.internal.helper.CubaUtil.isSoftDeletion()) { return null;
@Override public void afterCompletion(int status) { EntityManagerContext context = contextHolder.get(store); if (context != null) { List<Consumer<Integer>> list = context.getAttribute(RUN_AFTER_COMPLETION_ATTR); if (list != null && !list.isEmpty()) { contextHolder.remove(store); for (Consumer<Integer> consumer : list) { consumer.accept(status); } } } contextHolder.remove(store); CubaUtil.setSoftDeletion(prevSoftDeletion); CubaUtil.setOriginalSoftDeletion(prevSoftDeletion); }
if (!org.eclipse.persistence.internal.helper.CubaUtil.isSoftDeletion()) { if (targetQuery == this.selectionQuery) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone();
protected <T extends Entity> T internalMerge(T entity) { try { CubaUtil.setSoftDeletion(false); CubaUtil.setOriginalSoftDeletion(false); CubaUtil.setSoftDeletion(softDeletion); CubaUtil.setOriginalSoftDeletion(softDeletion);