added flushMode also for Hibernate queries

This commit is contained in:
Timo Westkämper 2011-08-15 09:45:07 +03:00
parent 4a598f497e
commit e98bbdc839

View File

@ -11,6 +11,7 @@ import java.util.Map;
import javax.annotation.Nullable;
import org.hibernate.FlushMode;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.ScrollMode;
@ -45,13 +46,18 @@ public abstract class AbstractHibernateQuery<Q extends AbstractHibernateQuery<Q>
private static final Logger logger = LoggerFactory.getLogger(HibernateQuery.class);
@Nullable
private Boolean cacheable, readOnly;
@Nullable
private String cacheRegion;
private int fetchSize = 0;
private final Map<Path<?>,LockMode> lockModes = new HashMap<Path<?>,LockMode>();
@Nullable
private FlushMode flushMode;
private final SessionHolder session;
@ -143,6 +149,9 @@ public abstract class AbstractHibernateQuery<Q extends AbstractHibernateQuery<Q>
for (Map.Entry<Path<?>, LockMode> entry : lockModes.entrySet()){
query.setLockMode(entry.getKey().toString(), entry.getValue());
}
if (flushMode != null) {
query.setFlushMode(flushMode);
}
if (modifiers != null && modifiers.isRestricting()) {
if (modifiers.getLimit() != null) {
@ -322,6 +331,15 @@ public abstract class AbstractHibernateQuery<Q extends AbstractHibernateQuery<Q>
lockModes.put(path, lockMode);
return (Q)this;
}
/**
* Override the current session flush mode, just for this query.
*/
@SuppressWarnings("unchecked")
public Q setFlushMode(FlushMode flushMode) {
this.flushMode = flushMode;
return (Q)this;
}
/**
* Entities retrieved by this query will be loaded in