public class NullExpression extends Object
Due to the three-valued logic in SQL, the two expressions "a = ?"
and "a <> ?"
would never
be true but rather "UNKNOWN" when the value substituted for the parameter is null.
Comparisons with null are done properly with the IS NULL operator like
"a IS NULL" or "NOT a IS NULL".
NullExpression
instances can be used to
a = ?
when the value is not null and a Is Null
when the value is null)
Object[]
of the bind variables to achieve conditional binding.
NullExpression ne1 = NullExpression.wrap("a1",v1); NullExpression ne2 = NullExpression.wrap("a2",v2); ServiceLocator.getStore().list(classname, "a0 = ? and "+ne1+" and not "+ne2",v0,ne1,ne2);If
v1 != null
and v2 == null
, then the resulting where clause would be
,the parameters fora0 = ? and a1 = ? and NOT a2 Is NULL
a0
and a1
will be set, no parameter will be used for a2
.
Note that usage for parameters in value lists of inserts and "set column = value" assignments of update statements is not intended
(see Nil
for this).
Modifier and Type | Method and Description |
---|---|
Object |
getValue()
Return the wrapped value.
|
String |
toString()
Constructs the appropriate expression depending on the value of getValue().
|
static NullExpression |
wrap(String attributeName,
Object value)
Wrap up an attribute name and a value for null expression construction.
|
public String toString()
toString
in class Object
Object.toString()
public Object getValue()
public static NullExpression wrap(String attributeName, Object value)
attributeName
- the name of the attributevalue
- the value to be wrapped (can be null)@enterprise 10.0.39049 Copyright © 2024 FREQUENTIS AG. All Rights Reserved.