io.ebeaninternal.server.query.DefaultOrmQueryEngine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ebean Show documentation
Show all versions of ebean Show documentation
composite of common runtime dependencies for all platforms
package io.ebeaninternal.server.query;
import io.ebean.QueryIterator;
import io.ebean.Version;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.EntityBean;
import io.ebean.event.BeanFindController;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.server.core.OrmQueryEngine;
import io.ebeaninternal.server.core.OrmQueryRequest;
import io.ebeaninternal.server.core.SpiResultSet;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.persist.Binder;
import javax.persistence.PersistenceException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
/**
* Main Finder implementation.
*/
public class DefaultOrmQueryEngine implements OrmQueryEngine {
/**
* Find using predicates
*/
private final CQueryEngine queryEngine;
private final Binder binder;
/**
* Create the Finder.
*/
public DefaultOrmQueryEngine(CQueryEngine queryEngine, Binder binder) {
this.queryEngine = queryEngine;
this.binder = binder;
}
@Override
public PersistenceException translate(OrmQueryRequest request, String bindLog, String sql, SQLException e) {
return queryEngine.translate(request, bindLog, sql, e);
}
@Override
public boolean isMultiValueSupported(Class> cls) {
return binder.isMultiValueSupported(cls);
}
/**
* Flushes the jdbc batch by default unless explicitly turned off on the transaction.
*/
private void flushJdbcBatchOnQuery(OrmQueryRequest request) {
SpiTransaction t = request.getTransaction();
if (t.isFlushOnQuery()) {
// before we perform a query, we need to flush any
// previous persist requests that are queued/batched.
// The query may read data affected by those requests.
t.flushBatch();
}
}
@Override
public int delete(OrmQueryRequest request) {
flushJdbcBatchOnQuery(request);
return queryEngine.delete(request);
}
@Override
public int update(OrmQueryRequest request) {
flushJdbcBatchOnQuery(request);
return queryEngine.update(request);
}
@Override
public SpiResultSet findResultSet(OrmQueryRequest request) {
flushJdbcBatchOnQuery(request);
return queryEngine.findResultSet(request);
}
@Override
public int findCount(OrmQueryRequest request) {
flushJdbcBatchOnQuery(request);
return queryEngine.findCount(request);
}
@Override
public List findIds(OrmQueryRequest> request) {
flushJdbcBatchOnQuery(request);
return queryEngine.findIds(request);
}
@Override
public List findSingleAttributeList(OrmQueryRequest> request) {
flushJdbcBatchOnQuery(request);
return queryEngine.findSingleAttributeList(request);
}
@Override
public QueryIterator findIterate(OrmQueryRequest request) {
// LIMITATION: You can not use QueryIterator to load bean cache
flushJdbcBatchOnQuery(request);
return queryEngine.findIterate(request);
}
@Override
public List> findVersions(OrmQueryRequest request) {
flushJdbcBatchOnQuery(request);
return queryEngine.findVersions(request);
}
@Override
public BeanCollection findMany(OrmQueryRequest request) {
flushJdbcBatchOnQuery(request);
BeanFindController finder = request.getBeanFinder();
BeanCollection result;
if (finder != null && finder.isInterceptFindMany(request)) {
// intercept this request
result = finder.findMany(request);
} else {
result = queryEngine.findMany(request);
}
SpiQuery query = request.getQuery();
if (request.isBeanCachePut()) {
// load the individual beans into the bean cache
BeanDescriptor descriptor = request.getBeanDescriptor();
Collection c = result.getActualDetails();
descriptor.cacheBeanPutAll(c);
}
request.mergeCacheHits(result);
if (request.isQueryCachePut()) {
// load the query result into the query cache
result.setReadOnly(true);
request.putToQueryCache(result);
if (Boolean.FALSE.equals(query.isReadOnly())) {
result = result.getShallowCopy();
}
}
return result;
}
/**
* Find a single bean using its unique id.
*/
@Override
public T findId(OrmQueryRequest request) {
flushJdbcBatchOnQuery(request);
BeanFindController finder = request.getBeanFinder();
T result;
if (finder != null && finder.isInterceptFind(request)) {
result = finder.find(request);
} else {
result = queryEngine.find(request);
}
if (result != null && request.isBeanCachePut()) {
request.getBeanDescriptor().cacheBeanPut((EntityBean) result);
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy