io.ebean.delegate.DelegateQuery Maven / Gradle / Ivy
package io.ebean.delegate;
import io.ebean.EbeanServer;
import io.ebean.Filter;
import io.ebean.Query;
import io.ebean.SqlQuery;
import java.util.Set;
/**
* Wraps an underlying EbeanServer.
*
* Can you used for testing purposes when you want to create a test double that
* only replaces some of the underlying functionality of the EbeanServer.
*/
public class DelegateQuery {
protected EbeanServer delegate;
protected EbeanServer owner;
/**
* Construct with a EbeanServer to delegate to by default.
*
* This delegate will be used on all method calls that are not overwritten.
*/
public DelegateQuery(EbeanServer delegate, EbeanServer owner) {
this.delegate = delegate;
this.owner = owner;
}
public Query delegateToThisServer(Query sourceQuery) {
return DelegateOrmQuery.copy(sourceQuery, owner);
}
public Query findNative(Class beanType, String nativeSql) {
return delegateToThisServer(delegate.findNative(beanType, nativeSql));
}
public Query createQuery(Class beanType) {
return delegateToThisServer(delegate.createQuery(beanType));
}
public Query find(Class beanType) {
return delegateToThisServer(delegate.find(beanType));
}
public Filter filter(Class beanType) {
return delegate.filter(beanType);
}
public SqlQuery createSqlQuery(String sql) {
return delegate.createSqlQuery(sql);
}
public T getReference(Class beanType, Object id) {
return delegate.getReference(beanType, id);
}
public Set validateQuery(Query query) {
return delegate.validateQuery(query);
}
public Query createQuery(Class beanType, String eql) {
return delegate.createQuery(beanType, eql);
}
public Query createNamedQuery(Class beanType, String namedQuery) {
return delegate.createNamedQuery(beanType, namedQuery);
}
}