mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
#2894 - Lack of setNullParameter() functionality on io.ebean.DtoQuery interface
This commit is contained in:
1 parent
3b5393dca6
commit
e87a06a713
5 files changed
+81
-20
No files matched your search
@@ -129,6 +129,11 @@ public interface DtoQuery<T> extends CancelableQuery {
|
|||||||
*/
|
*/
|
||||||
DtoQuery<T> setParameter(String name, Object value);
|
DtoQuery<T> setParameter(String name, Object value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind the named parameter to SQL NULL.
|
||||||
|
*/
|
||||||
|
DtoQuery<T> setNullParameter(String name, int jdbcType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind the named multi-value array parameter which we would use with Postgres ANY.
|
* Bind the named multi-value array parameter which we would use with Postgres ANY.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -141,6 +146,11 @@ public interface DtoQuery<T> extends CancelableQuery {
|
|||||||
*/
|
*/
|
||||||
DtoQuery<T> setParameter(int position, Object value);
|
DtoQuery<T> setParameter(int position, Object value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a positioned parameter to SQL NULL.
|
||||||
|
*/
|
||||||
|
DtoQuery<T> setNullParameter(int position, int jdbcType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the index of the first row of the results to return.
|
* Set the index of the first row of the results to return.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -759,6 +759,11 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
|
|||||||
*/
|
*/
|
||||||
BindParams getBindParams();
|
BindParams getBindParams();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the bind parameters ensuring it is initialised.
|
||||||
|
*/
|
||||||
|
BindParams initBindParams();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace the query detail. This is used by the AutoTune feature to as a
|
* Replace the query detail. This is used by the AutoTune feature to as a
|
||||||
* fast way to set the query properties and joins.
|
* fast way to set the query properties and joins.
|
||||||
|
|||||||
@@ -129,6 +129,26 @@ public final class DefaultDtoQuery<T> extends AbstractQuery implements SpiDtoQue
|
|||||||
return Optional.ofNullable(findOne());
|
return Optional.ofNullable(findOne());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DtoQuery<T> setNullParameter(String name, int jdbcType) {
|
||||||
|
if (ormQuery != null) {
|
||||||
|
ormQuery.initBindParams().setNullParameter(name, jdbcType);
|
||||||
|
} else {
|
||||||
|
bindParams.setNullParameter(name, jdbcType);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DtoQuery<T> setNullParameter(int position, int jdbcType) {
|
||||||
|
if (ormQuery != null) {
|
||||||
|
ormQuery.initBindParams().setNullParameter(position, jdbcType);
|
||||||
|
} else {
|
||||||
|
bindParams.setNullParameter(position, jdbcType);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DtoQuery<T> setParameter(int position, Object value) {
|
public DtoQuery<T> setParameter(int position, Object value) {
|
||||||
if (ormQuery != null) {
|
if (ormQuery != null) {
|
||||||
|
|||||||
@@ -1544,19 +1544,13 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Query<T> setParameter(Object value) {
|
public final Query<T> setParameter(Object value) {
|
||||||
if (bindParams == null) {
|
initBindParams().setNextParameter(value);
|
||||||
bindParams = new BindParams();
|
|
||||||
}
|
|
||||||
bindParams.setNextParameter(value);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Query<T> setParameters(Object... values) {
|
public final Query<T> setParameters(Object... values) {
|
||||||
if (bindParams == null) {
|
initBindParams().setNextParameters(values);
|
||||||
bindParams = new BindParams();
|
|
||||||
}
|
|
||||||
bindParams.setNextParameters(values);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1567,10 +1561,7 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final Query<T> setParameter(int position, Object value) {
|
public final Query<T> setParameter(int position, Object value) {
|
||||||
if (bindParams == null) {
|
initBindParams().setParameter(position, value);
|
||||||
bindParams = new BindParams();
|
|
||||||
}
|
|
||||||
bindParams.setParameter(position, value);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1586,10 +1577,7 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bindParams == null) {
|
initBindParams().setParameter(name, value);
|
||||||
bindParams = new BindParams();
|
|
||||||
}
|
|
||||||
bindParams.setParameter(name, value);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1598,10 +1586,7 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
|||||||
if (namedParams != null) {
|
if (namedParams != null) {
|
||||||
throw new IllegalStateException("setArrayParameter() not supported when EQL parsed query");
|
throw new IllegalStateException("setArrayParameter() not supported when EQL parsed query");
|
||||||
}
|
}
|
||||||
if (bindParams == null) {
|
initBindParams().setArrayParameter(name, values);
|
||||||
bindParams = new BindParams();
|
|
||||||
}
|
|
||||||
bindParams.setArrayParameter(name, values);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1789,6 +1774,14 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
|
|||||||
return bindParams;
|
return bindParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BindParams initBindParams() {
|
||||||
|
if (bindParams == null) {
|
||||||
|
bindParams = new BindParams();
|
||||||
|
}
|
||||||
|
return bindParams;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Query<T> where(Expression expression) {
|
public final Query<T> where(Expression expression) {
|
||||||
where().add(expression);
|
where().add(expression);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.tests.model.basic.Customer;
|
|||||||
import org.tests.model.basic.EBasicLog;
|
import org.tests.model.basic.EBasicLog;
|
||||||
import org.tests.model.basic.ResetBasicData;
|
import org.tests.model.basic.ResetBasicData;
|
||||||
|
|
||||||
|
import java.sql.Types;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -366,6 +367,38 @@ class DtoQueryTest extends BaseTestCase {
|
|||||||
assertThat(list).isNotEmpty();
|
assertThat(list).isNotEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ForPlatform(Platform.H2)
|
||||||
|
@Test
|
||||||
|
void dto3_setNullByPosition() {
|
||||||
|
ResetBasicData.reset();
|
||||||
|
|
||||||
|
List<DCust3> robs = server().findDto(DCust3.class, "select id, name, nvl(cast(? as int), 42) as totalOrders from o_customer where name like ?")
|
||||||
|
.setNullParameter(1, Types.INTEGER)
|
||||||
|
.setParameter(2, "Rob")
|
||||||
|
.setMaxRows(10)
|
||||||
|
.findList();
|
||||||
|
|
||||||
|
log.info(robs.toString());
|
||||||
|
assertThat(robs).isNotEmpty();
|
||||||
|
assertThat(robs.get(0).getTotalOrders()).isEqualTo(42);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ForPlatform(Platform.H2)
|
||||||
|
@Test
|
||||||
|
void dto3_setNullByName() {
|
||||||
|
ResetBasicData.reset();
|
||||||
|
|
||||||
|
List<DCust3> robs = server().findDto(DCust3.class, "select id, name, nvl(cast(:foo as int), 42) as totalOrders from o_customer where name like :bar")
|
||||||
|
.setNullParameter("foo", Types.INTEGER)
|
||||||
|
.setParameter("bar", "Rob")
|
||||||
|
.setMaxRows(10)
|
||||||
|
.findList();
|
||||||
|
|
||||||
|
log.info(robs.toString());
|
||||||
|
assertThat(robs).isNotEmpty();
|
||||||
|
assertThat(robs.get(0).getTotalOrders()).isEqualTo(42);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void dto3_findList_constructorMatch() {
|
void dto3_findList_constructorMatch() {
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|||||||
Reference in new issue
Block a user