Add ability to set custom db hooks #PL-3721

This commit is contained in:
Andrey Tsarevskiy 2015-01-13 12:23:52 +00:00
parent b74faf5285
commit 24b890f9a7
4 changed files with 35 additions and 0 deletions

View File

@ -71,6 +71,8 @@ public class DataWorkerBean implements DataWorker {
if (!context.isSoftDeletion())
em.setSoftDeletion(false);
persistence.getEntityManagerContext().setDbHints(context.getDbHints());
// persist new
for (Entity entity : context.getCommitInstances()) {
if (PersistenceHelper.isNew(entity)) {
@ -173,6 +175,8 @@ public class DataWorkerBean implements DataWorker {
if (!context.isSoftDeletion())
em.setSoftDeletion(false);
persistence.getEntityManagerContext().setDbHints(context.getDbHints());
// persist new or merge detached
Set newInstanceIdSet = new HashSet(context.getNewInstanceIds());
for (Entity entity : context.getCommitInstances()) {
@ -268,6 +272,7 @@ public class DataWorkerBean implements DataWorker {
if (!context.isSoftDeletion())
em.setSoftDeletion(false);
persistence.getEntityManagerContext().setDbHints(context.getDbHints());
com.haulmont.cuba.core.Query query = createQuery(em, context);
final List<A> resultList = query.getResultList();
@ -311,6 +316,7 @@ public class DataWorkerBean implements DataWorker {
try {
final EntityManager em = persistence.getEntityManager();
em.setSoftDeletion(context.isSoftDeletion());
persistence.getEntityManagerContext().setDbHints(context.getDbHints());
boolean ensureDistinct = false;
if (configuration.getConfig(ServerConfig.class).getInMemoryDistinct() && context.getQuery() != null) {

View File

@ -4,6 +4,9 @@
*/
package com.haulmont.cuba.core.sys;
import java.util.HashMap;
import java.util.Map;
/**
* @author krivopustov
* @version $Id$
@ -12,6 +15,8 @@ public class EntityManagerContext {
private boolean softDeletion = true;
private Map<String, Object> dbHints = new HashMap<>();
public boolean isSoftDeletion() {
return softDeletion;
}
@ -19,4 +24,12 @@ public class EntityManagerContext {
public void setSoftDeletion(boolean softDeletion) {
this.softDeletion = softDeletion;
}
public Map<String, Object> getDbHints() {
return dbHints;
}
public void setDbHints(Map<String, Object> dbHints) {
this.dbHints = dbHints;
}
}

View File

@ -26,6 +26,7 @@ public class CommitContext implements Serializable {
protected Map<Object, View> views = new HashMap<>();
protected boolean softDeletion = true;
protected Map<String, Object> dbHints = new HashMap<>();
public CommitContext() {
}
@ -90,6 +91,13 @@ public class CommitContext implements Serializable {
return views;
}
/**
* @return custom hints which can be used later during query construction
*/
public Map<String, Object> getDbHints() {
return dbHints;
}
/**
* @return whether to use soft deletion for this commit
*/

View File

@ -28,6 +28,7 @@ public class LoadContext implements Serializable {
protected boolean useSecurityConstraints = true;
protected List<Query> prevQueries = new ArrayList<>();
protected int queryKey;
protected Map<String, Object> dbHints = new HashMap<>();
/**
* @param metaClass metaclass of the loaded entities
@ -168,6 +169,13 @@ public class LoadContext implements Serializable {
this.queryKey = queryKey;
}
/**
* @return custom hints which can be used later during query construction
*/
public Map<String, Object> getDbHints() {
return dbHints;
}
@Override
public String toString() {
return "LoadContext{" +