[jOOQ/jOOQ#10644] Add Settings.transformUnneededArithmeticExpressions to
optimise arithmetic prior to SQL generation - Added commutative / associative flag to ExpressionOperator - Transform identity operations - Transform null operations - Transform * 0 operations - Transform inlined +, -, *, / operations
This commit is contained in:
parent
c8d9a5b991
commit
f57d5d8af4
@ -72,6 +72,7 @@ import static org.jooq.impl.ExpressionOperator.BIT_NOR;
|
||||
import static org.jooq.impl.ExpressionOperator.BIT_OR;
|
||||
import static org.jooq.impl.ExpressionOperator.BIT_XNOR;
|
||||
import static org.jooq.impl.ExpressionOperator.BIT_XOR;
|
||||
import static org.jooq.impl.ExpressionOperator.MULTIPLY;
|
||||
import static org.jooq.impl.ExpressionOperator.SHL;
|
||||
import static org.jooq.impl.ExpressionOperator.SHR;
|
||||
import static org.jooq.impl.ExpressionOperator.SUBTRACT;
|
||||
@ -114,6 +115,7 @@ import org.jooq.SQLDialect;
|
||||
import org.jooq.conf.TransformUnneededArithmeticExpressions;
|
||||
import org.jooq.exception.DataTypeException;
|
||||
import org.jooq.impl.Tools.DataExtendedKey;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.types.DayToSecond;
|
||||
import org.jooq.types.Interval;
|
||||
import org.jooq.types.YearToMonth;
|
||||
@ -266,6 +268,69 @@ final class Expression<T> extends AbstractField<T> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -49,12 +49,12 @@ enum ExpressionOperator {
|
||||
/**
|
||||
* Concatenation
|
||||
*/
|
||||
CONCAT("||"),
|
||||
CONCAT("||", true, false),
|
||||
|
||||
/**
|
||||
* Addition
|
||||
*/
|
||||
ADD("+"),
|
||||
ADD("+", true, true),
|
||||
|
||||
/**
|
||||
* Subtraction
|
||||
@ -64,7 +64,7 @@ enum ExpressionOperator {
|
||||
/**
|
||||
* Multiplication
|
||||
*/
|
||||
MULTIPLY("*"),
|
||||
MULTIPLY("*", true, true),
|
||||
|
||||
/**
|
||||
* Division
|
||||
@ -84,25 +84,25 @@ enum ExpressionOperator {
|
||||
/**
|
||||
* Bitwise and
|
||||
*/
|
||||
BIT_AND("&"),
|
||||
BIT_AND("&", true, true),
|
||||
|
||||
/**
|
||||
* Bitwise or
|
||||
*/
|
||||
BIT_OR("|"),
|
||||
BIT_OR("|", true, true),
|
||||
|
||||
/**
|
||||
* Bitwise xor
|
||||
*/
|
||||
BIT_XOR("^"),
|
||||
BIT_XOR("^", true, true),
|
||||
|
||||
/**
|
||||
* Bitwise and
|
||||
* Bitwise nand
|
||||
*/
|
||||
BIT_NAND("~&"),
|
||||
|
||||
/**
|
||||
* Bitwise or
|
||||
* Bitwise nor
|
||||
*/
|
||||
BIT_NOR("~|"),
|
||||
|
||||
@ -123,19 +123,35 @@ enum ExpressionOperator {
|
||||
|
||||
;
|
||||
|
||||
private final String sql;
|
||||
private final Name name;
|
||||
private final String sql;
|
||||
private final Name name;
|
||||
private final boolean associative;
|
||||
private final boolean commutative;
|
||||
|
||||
private ExpressionOperator(String sql) {
|
||||
this.sql = sql;
|
||||
this.name = DSL.name(name().toLowerCase());
|
||||
this(sql, false, false);
|
||||
}
|
||||
|
||||
public String toSQL() {
|
||||
private ExpressionOperator(String sql, boolean associative, boolean commutative) {
|
||||
this.sql = sql;
|
||||
this.name = DSL.name(name().toLowerCase());
|
||||
this.associative = associative;
|
||||
this.commutative = commutative;
|
||||
}
|
||||
|
||||
final String toSQL() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public Name toName() {
|
||||
final Name toName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
final boolean associative() {
|
||||
return associative;
|
||||
}
|
||||
|
||||
final boolean commutative() {
|
||||
return commutative;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user