diff --git a/jOOQ-test/src/org/jooq/test/h2/F.java b/jOOQ-test/src/org/jooq/test/h2/F.java index ed0147df54..903af88163 100644 --- a/jOOQ-test/src/org/jooq/test/h2/F.java +++ b/jOOQ-test/src/org/jooq/test/h2/F.java @@ -37,6 +37,7 @@ package org.jooq.test.h2; import static org.jooq.impl.Factory.count; import static org.jooq.impl.Factory.max; +import static org.jooq.impl.Factory.sign; import static org.jooq.impl.SQLDataType.INTEGER; import static org.jooq.test.h2.generatedclasses.tables.TAuthor.T_AUTHOR; import static org.jooq.test.h2.generatedclasses.tables.TBook.T_BOOK; @@ -98,7 +99,7 @@ public class F { H2Factory create = create(connection); Integer result = - create.select(count().sign()) + create.select(sign(count())) .from(T_AUTHOR) .where(TAuthor.FIRST_NAME.equal(authorName)) .or(TAuthor.LAST_NAME.equal(authorName)) diff --git a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java index 4d72fcdcc3..54a07f2e30 100644 --- a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java +++ b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java @@ -47,9 +47,19 @@ import static org.jooq.SQLDialect.DB2; import static org.jooq.SQLDialect.MYSQL; import static org.jooq.SQLDialect.SQLSERVER; import static org.jooq.SQLDialect.SYBASE; +import static org.jooq.impl.Factory.abs; +import static org.jooq.impl.Factory.acos; +import static org.jooq.impl.Factory.asin; +import static org.jooq.impl.Factory.atan; +import static org.jooq.impl.Factory.atan2; import static org.jooq.impl.Factory.avg; import static org.jooq.impl.Factory.cast; import static org.jooq.impl.Factory.castNull; +import static org.jooq.impl.Factory.ceil; +import static org.jooq.impl.Factory.cos; +import static org.jooq.impl.Factory.cosh; +import static org.jooq.impl.Factory.cot; +import static org.jooq.impl.Factory.coth; import static org.jooq.impl.Factory.count; import static org.jooq.impl.Factory.countDistinct; import static org.jooq.impl.Factory.countOver; @@ -60,28 +70,42 @@ import static org.jooq.impl.Factory.currentTime; import static org.jooq.impl.Factory.currentTimestamp; import static org.jooq.impl.Factory.currentUser; import static org.jooq.impl.Factory.decode; +import static org.jooq.impl.Factory.deg; import static org.jooq.impl.Factory.denseRankOver; import static org.jooq.impl.Factory.e; +import static org.jooq.impl.Factory.exp; import static org.jooq.impl.Factory.falseCondition; import static org.jooq.impl.Factory.field; +import static org.jooq.impl.Factory.floor; import static org.jooq.impl.Factory.function; import static org.jooq.impl.Factory.grouping; import static org.jooq.impl.Factory.groupingId; import static org.jooq.impl.Factory.groupingSets; +import static org.jooq.impl.Factory.ln; +import static org.jooq.impl.Factory.log; import static org.jooq.impl.Factory.max; import static org.jooq.impl.Factory.median; import static org.jooq.impl.Factory.min; import static org.jooq.impl.Factory.one; import static org.jooq.impl.Factory.percentRankOver; import static org.jooq.impl.Factory.pi; +import static org.jooq.impl.Factory.power; +import static org.jooq.impl.Factory.rad; import static org.jooq.impl.Factory.rand; import static org.jooq.impl.Factory.rankOver; import static org.jooq.impl.Factory.rollup; +import static org.jooq.impl.Factory.round; import static org.jooq.impl.Factory.rowNumberOver; +import static org.jooq.impl.Factory.sign; +import static org.jooq.impl.Factory.sin; +import static org.jooq.impl.Factory.sinh; +import static org.jooq.impl.Factory.sqrt; import static org.jooq.impl.Factory.stddevPop; import static org.jooq.impl.Factory.stddevSamp; import static org.jooq.impl.Factory.sum; import static org.jooq.impl.Factory.table; +import static org.jooq.impl.Factory.tan; +import static org.jooq.impl.Factory.tanh; import static org.jooq.impl.Factory.trueCondition; import static org.jooq.impl.Factory.two; import static org.jooq.impl.Factory.val; @@ -5233,23 +5257,23 @@ public abstract class jOOQAbstractTest< assertNotNull(rand); // Some rounding functions - Field f1a = val(1.111f).round(); - Field f2a = val(1.111f).round(2); - Field f3a = val(1.111f).floor(); - Field f4a = val(1.111f).ceil(); - Field f1b = val(-1.111).round(); - Field f2b = val(-1.111).round(2); - Field f3b = val(-1.111).floor(); - Field f4b = val(-1.111).ceil(); + Field f1a = round(1.111f); + Field f2a = round(1.111f, 2); + Field f3a = floor(1.111f); + Field f4a = ceil(1.111f); + Field f1b = round(-1.111); + Field f2b = round(-1.111, 2); + Field f3b = floor(-1.111); + Field f4b = ceil(-1.111); - Field f1c = val(2.0f).round(); - Field f2c = val(2.0f).round(2); - Field f3c = val(2.0f).floor(); - Field f4c = val(2.0f).ceil(); - Field f1d = val(-2.0).round(); - Field f2d = val(-2.0).round(2); - Field f3d = val(-2.0).floor(); - Field f4d = val(-2.0).ceil(); + Field f1c = round(2.0f); + Field f2c = round(2.0f, 2); + Field f3c = floor(2.0f); + Field f4c = ceil(2.0f); + Field f1d = round(-2.0); + Field f2d = round(-2.0, 2); + Field f3d = floor(-2.0); + Field f4d = ceil(-2.0); // Some arbitrary checks on having multiple select clauses Record record = @@ -5302,15 +5326,15 @@ public abstract class jOOQAbstractTest< default: { // Exponentials, logarithms and roots // ---------------------------------- - Field m1 = val(2).sqrt(); - Field m2 = val(4).sqrt().round(); - Field m3 = val(2).exp(); - Field m4 = val(0).exp().round(); - Field m5 = val(-2).exp(); - Field m6 = val(2).ln(); - Field m7 = val(16).log(4).round(); - Field m8 = val(2).power(4).round(); - Field m9 = val(2).sqrt().power(2).sqrt().power(2).round(); + Field m1 = sqrt(2); + Field m2 = round(sqrt(4)); + Field m3 = exp(2); + Field m4 = round(exp(0)); + Field m5 = exp(-2); + Field m6 = ln(2); + Field m7 = round(log(16, 4)); + Field m8 = round(power(2, 4)); + Field m9 = round(power(sqrt(power(sqrt(2), 2)), 2)); record = create().select(m1, m2, m3, m4, m5, m6, m7, m8, m9).fetchOne(); @@ -5328,22 +5352,22 @@ public abstract class jOOQAbstractTest< // Trigonometry // ------------ - Field t1 = val(Math.PI / 6 + 0.00001).sin(); - Field t2 = val(Math.PI / 6).cos(); - Field t3 = val(Math.PI / 6).tan(); - Field t4 = val(Math.PI / 6).cot(); - Field t6 = val(1.1).deg().rad(); - Field t7 = val(Math.PI / 6).asin(); - Field t8 = val(Math.PI / 6).acos(); - Field t9 = val(Math.PI / 6).atan(); - Field ta = val(1).atan2(1).deg().round(); + Field t1 = sin(Math.PI / 6 + 0.00001); + Field t2 = cos(Math.PI / 6); + Field t3 = tan(Math.PI / 6); + Field t4 = cot(Math.PI / 6); + Field t6 = rad(deg(1.1)); + Field t7 = asin(Math.PI / 6); + Field t8 = acos(Math.PI / 6); + Field t9 = atan(Math.PI / 6); + Field ta = round(deg(atan2(1, 1))); // Hyperbolic functions // -------------------- - Field tb = val(1.0).sinh() - .div(val(1.0).cosh()) - .mul(val(1.0).tanh()) - .mul(val(1.0).coth().power(2).add(0.1)); + Field tb = sinh(1.0) + .div(cosh(1.0)) + .mul(tanh(1.0)) + .mul(power(coth(1.0), 2).add(0.1)); record = create().select(t1, t2, t3, t4, t6, t7, t8, t9, ta, tb).fetchOne(); @@ -5366,11 +5390,11 @@ public abstract class jOOQAbstractTest< // The sign function record = create().select( - val(2).sign(), - val(1).sign(), - val(0).sign(), - val(-1).sign(), - val(-2).sign()).fetchOne(); + sign(2), + sign(1), + sign(0), + sign(-1), + sign(-2)).fetchOne(); assertNotNull(record); assertEquals(Integer.valueOf(1), record.getValue(0)); @@ -5381,11 +5405,11 @@ public abstract class jOOQAbstractTest< // The abs function record = create().select( - val(2).abs(), - val(1).abs(), - val(0).abs(), - val(-1).abs(), - val(-2).abs()).fetchOne(); + abs(2), + abs(1), + abs(0), + abs(-1), + abs(-2)).fetchOne(); assertNotNull(record); assertEquals(Integer.valueOf(2), record.getValue(0)); diff --git a/jOOQ/src/main/java/org/jooq/Field.java b/jOOQ/src/main/java/org/jooq/Field.java index bee7672c92..e924d28605 100644 --- a/jOOQ/src/main/java/org/jooq/Field.java +++ b/jOOQ/src/main/java/org/jooq/Field.java @@ -560,262 +560,6 @@ public interface Field extends NamedTypeProviderQueryPart, AliasProvider shr(Field value); - // ------------------------------------------------------------------------ - // Mathematical functions created from this field - // ------------------------------------------------------------------------ - - /** - * Get the sign of a numeric field: sign(field) - *

- * This renders the sign function where available: - *

sign([this])
- * ... or simulates it elsewhere (without bind variables on values -1, 0, 1): - *
-     * CASE WHEN [this] > 0 THEN 1
-     *      WHEN [this] < 0 THEN -1
-     *      ELSE 0
-     * END
-     */
-    Field sign();
-
-    /**
-     * Get the absolute value of a numeric field: abs(field)
-     * 

- * This renders the same on all dialects: - *

abs([this])
- */ - Field abs(); - - /** - * Get rounded value of a numeric field: round(field) - *

- * This renders the round function where available: - *

round([this]) or
-     * round([this], 0)
- * ... or simulates it elsewhere using floor and ceil - */ - Field round(); - - /** - * Get rounded value of a numeric field: round(field, decimals) - *

- * This renders the round function where available: - *

round([this], [decimals])
- * ... or simulates it elsewhere using floor and ceil - */ - Field round(int decimals); - - /** - * Get the largest integer value not greater than [this] - *

- * This renders the floor function where available: - *

floor([this])
- * ... or simulates it elsewhere using round: - *
round([this] - 0.499999999999999)
- */ - Field floor(); - - /** - * Get the smallest integer value not less than [this] - *

- * This renders the ceil or ceiling function where available: - *

ceil([this]) or
-     * ceiling([this])
- * ... or simulates it elsewhere using round: - *
round([this] + 0.499999999999999)
- */ - Field ceil(); - - /** - * Get the sqrt(field) function - *

- * This renders the sqrt function where available: - *

sqrt([this])
... or simulates it elsewhere using - * power (which in turn may also be simulated using ln and exp functions): - *
power([this], 0.5)
- */ - Field sqrt(); - - /** - * Get the exp(field) function, taking this field as the power of e - *

- * This renders the same on all dialects: - *

exp([this])
- */ - Field exp(); - - /** - * Get the ln(field) function, taking the natural logarithm of this field - *

- * This renders the ln or log function where available: - *

ln([this]) or
-     * log([this])
- */ - Field ln(); - - /** - * Get the log(field, base) function - *

- * This renders the log function where available: - *

log([this])
... or simulates it elsewhere (in - * most RDBMS) using the natural logarithm: - *
ln([this]) / ln([base])
- */ - Field log(int base); - - /** - * Get the power(field, exponent) function - *

- * This renders the power function where available: - *

power([this], [exponent])
... or simulates it - * elsewhere using ln and exp: - *
exp(ln([this]) * [exponent])
- */ - Field power(Number exponent); - - /** - * Get the power(field, exponent) function - *

- * This renders the power function where available: - *

power([this], [exponent])
... or simulates it - * elsewhere using ln and exp: - *
exp(ln([this]) * [exponent])
- */ - Field power(Field exponent); - - /** - * Get the arc cosine(field) function - *

- * This renders the acos function where available: - *

acos([this])
- */ - Field acos(); - - /** - * Get the arc sine(field) function - *

- * This renders the asin function where available: - *

asin([this])
- */ - Field asin(); - - /** - * Get the arc tangent(field) function - *

- * This renders the atan function where available: - *

atan([this])
- */ - Field atan(); - - /** - * Get the arc tangent 2(field, y) function - *

- * This renders the atan2 or atn2 function where available: - *

atan2([this]) or
-     * atn2([this])
- */ - Field atan2(Number y); - - /** - * Get the arc tangent 2(field, y) function - *

- * This renders the atan2 or atn2 function where available: - *

atan2([this]) or
-     * atn2([this])
- */ - Field atan2(Field y); - - /** - * Get the cosine(field) function - *

- * This renders the cos function where available: - *

cos([this])
- */ - Field cos(); - - /** - * Get the sine(field) function - *

- * This renders the sin function where available: - *

sin([this])
- */ - Field sin(); - - /** - * Get the tangent(field) function - *

- * This renders the tan function where available: - *

tan([this])
- */ - Field tan(); - - /** - * Get the cotangent(field) function - *

- * This renders the cot function where available: - *

cot([this])
... or simulates it elsewhere using - * sin and cos:
cos([this]) / sin([this])
- */ - Field cot(); - - /** - * Get the hyperbolic sine function: sinh(field) - *

- * This renders the sinh function where available: - *

sinh([this])
... or simulates it elsewhere using - * exp:
(exp([this] * 2) - 1) / (exp([this] * 2))
- */ - Field sinh(); - - /** - * Get the hyperbolic cosine function: cosh(field) - *

- * This renders the cosh function where available: - *

cosh([this])
... or simulates it elsewhere using - * exp:
(exp([this] * 2) + 1) / (exp([this] * 2))
- */ - Field cosh(); - - /** - * Get the hyperbolic tangent function: tanh(field) - *

- * This renders the tanh function where available: - *

tanh([this])
... or simulates it elsewhere using - * exp: - *
(exp([this] * 2) - 1) / (exp([this] * 2) + 1)
- */ - Field tanh(); - - /** - * Get the hyperbolic cotangent function: coth(field) - *

- * This is not supported by any RDBMS, but simulated using exp exp: - *

(exp([this] * 2) + 1) / (exp([this] * 2) - 1)
- */ - Field coth(); - - /** - * Calculate degrees from radians from this field - *

- * This renders the degrees function where available: - *

degrees([this])
... or simulates it elsewhere: - *
[this] * 180 / PI
- */ - Field deg(); - - /** - * Calculate radians from degrees from this field - *

- * This renders the degrees function where available: - *

degrees([this])
... or simulates it elsewhere: - *
[this] * PI / 180
- */ - Field rad(); - - // ------------------------------------------------------------------------ - // Aggregate functions created from this field - // ------------------------------------------------------------------------ - // ------------------------------------------------------------------------ // Analytic (or window) functions created from this field // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java index d96d8b6066..bae8cc8d0f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java @@ -491,40 +491,6 @@ abstract class AbstractField extends AbstractNamedTypeProviderQueryPart im // Functions created from this field // ------------------------------------------------------------------------ - @Override - public final Field sign() { - return new Sign(this); - } - - @Override - public final Field abs() { - return function("abs", getDataType(), this); - } - - @Override - public final Field round() { - return new Round(this); - } - - @Override - public final Field round(int decimals) { - return new Round(this, decimals); - } - - @Override - public final Field floor() { - return new Floor(this); - } - - @Override - public final Field ceil() { - return new Ceil(this); - } - - // ------------------------------------------------------------------------ - // Mathematical functions created from this field - // ------------------------------------------------------------------------ - @Override public final Field greatest(T... others) { return greatest(vals(others).toArray(new Field[0])); @@ -545,115 +511,6 @@ abstract class AbstractField extends AbstractNamedTypeProviderQueryPart im return new Least(getDataType(), JooqUtil.combine(this, others)); } - @Override - public final Field sqrt() { - return new Sqrt(this); - } - - @Override - public final Field exp() { - return function("exp", SQLDataType.NUMERIC, this); - } - - @Override - public final Field ln() { - return new Ln(this); - } - - @Override - public final Field log(int base) { - return new Ln(this, base); - } - - @Override - public final Field power(Number exponent) { - return power(val(exponent)); - } - - @Override - public Field power(Field exponent) { - return new Power(this, exponent); - } - - @Override - public final Field acos() { - return function("acos", SQLDataType.NUMERIC, this); - } - - @Override - public final Field asin() { - return function("asin", SQLDataType.NUMERIC, this); - } - - @Override - public final Field atan() { - return function("atan", SQLDataType.NUMERIC, this); - } - - @Override - public final Field atan2(Number y) { - return atan2(val(y)); - } - - @Override - public final Field atan2(Field y) { - if (y == null) { - return atan2((Number) null); - } - - return new Function(Term.ATAN2, SQLDataType.NUMERIC, this, y); - } - - @Override - public final Field cos() { - return function("cos", SQLDataType.NUMERIC, this); - } - - @Override - public final Field sin() { - return function("sin", SQLDataType.NUMERIC, this); - } - - @Override - public final Field tan() { - return function("tan", SQLDataType.NUMERIC, this); - } - - @Override - public final Field cot() { - return new Cot(this); - } - - @Override - public final Field sinh() { - return new Sinh(this); - } - - @Override - public final Field cosh() { - return new Cosh(this); - } - - @Override - public final Field tanh() { - return new Tanh(this); - } - - @Override - public final Field coth() { - return mul(2).exp().add(1).div(mul(2).exp().sub(1)); - } - - @Override - public final Field deg() { - return new Degrees(this); - } - - @Override - public final Field rad() { - return new Radians(this); - } - // ------------------------------------------------------------------------ // Other functions created from this field // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/impl/Ceil.java b/jOOQ/src/main/java/org/jooq/impl/Ceil.java index b627e6421b..fff5e86c40 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Ceil.java +++ b/jOOQ/src/main/java/org/jooq/impl/Ceil.java @@ -36,6 +36,7 @@ package org.jooq.impl; import static org.jooq.impl.Factory.function; +import static org.jooq.impl.Factory.round; import org.jooq.Configuration; import org.jooq.Field; @@ -43,7 +44,7 @@ import org.jooq.Field; /** * @author Lukas Eder */ -class Ceil extends AbstractFunction { +class Ceil extends AbstractFunction { /** * Generated UID @@ -64,7 +65,7 @@ class Ceil extends AbstractFunction { // evaluate "ceil" if unavailable case SQLITE: - return argument.add(0.499999999999999).round(); + return round(argument.add(0.499999999999999)); case ASE: case H2: diff --git a/jOOQ/src/main/java/org/jooq/impl/Cosh.java b/jOOQ/src/main/java/org/jooq/impl/Cosh.java index 32914529b4..6f63a6a11f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Cosh.java +++ b/jOOQ/src/main/java/org/jooq/impl/Cosh.java @@ -35,6 +35,7 @@ */ package org.jooq.impl; +import static org.jooq.impl.Factory.exp; import static org.jooq.impl.Factory.function; import static org.jooq.impl.Factory.one; import static org.jooq.impl.Factory.two; @@ -52,11 +53,11 @@ class Cosh extends AbstractFunction { /** * Generated UID */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = -7273879239726265322L; - private final Field argument; + private final Field argument; - Cosh(Field argument) { + Cosh(Field argument) { super("cosh", SQLDataType.NUMERIC, argument); this.argument = argument; @@ -72,7 +73,7 @@ class Cosh extends AbstractFunction { case POSTGRES: case SQLSERVER: case SYBASE: - return argument.mul(two()).exp().add(one()).div(argument.exp().mul(two())); + return exp(argument.mul(two())).add(one()).div(exp(argument).mul(two())); default: return function("cosh", SQLDataType.NUMERIC, argument); diff --git a/jOOQ/src/main/java/org/jooq/impl/Cot.java b/jOOQ/src/main/java/org/jooq/impl/Cot.java index 833a49eeb5..0db08695ed 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Cot.java +++ b/jOOQ/src/main/java/org/jooq/impl/Cot.java @@ -35,7 +35,9 @@ */ package org.jooq.impl; +import static org.jooq.impl.Factory.cos; import static org.jooq.impl.Factory.function; +import static org.jooq.impl.Factory.sin; import java.math.BigDecimal; @@ -50,11 +52,11 @@ class Cot extends AbstractFunction { /** * Generated UID */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = -7273879239726265322L; - private final Field argument; + private final Field argument; - Cot(Field argument) { + Cot(Field argument) { super("cot", SQLDataType.NUMERIC, argument); this.argument = argument; @@ -65,7 +67,7 @@ class Cot extends AbstractFunction { switch (configuration.getDialect()) { case INGRES: case ORACLE: - return argument.cos().div(argument.sin()); + return cos(argument).div(sin(argument)); default: return function("cot", SQLDataType.NUMERIC, argument); diff --git a/jOOQ/src/main/java/org/jooq/impl/Euler.java b/jOOQ/src/main/java/org/jooq/impl/Euler.java index fc23a95cbb..851d654c73 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Euler.java +++ b/jOOQ/src/main/java/org/jooq/impl/Euler.java @@ -35,6 +35,7 @@ */ package org.jooq.impl; +import static org.jooq.impl.Factory.exp; import static org.jooq.impl.Factory.function; import static org.jooq.impl.Factory.literal; import static org.jooq.impl.Factory.one; @@ -72,7 +73,7 @@ class Euler extends AbstractFunction { case POSTGRES: case SQLSERVER: case SYBASE: - return one().exp(); + return exp(one()); case SQLITE: return literal(Math.E, BigDecimal.class); diff --git a/jOOQ/src/main/java/org/jooq/impl/Expression.java b/jOOQ/src/main/java/org/jooq/impl/Expression.java index ade585087b..98d87eb215 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Expression.java +++ b/jOOQ/src/main/java/org/jooq/impl/Expression.java @@ -56,6 +56,7 @@ import static org.jooq.impl.ExpressionOperator.SHL; import static org.jooq.impl.ExpressionOperator.SHR; import static org.jooq.impl.Factory.function; import static org.jooq.impl.Factory.literal; +import static org.jooq.impl.Factory.power; import java.sql.SQLException; import java.util.Arrays; @@ -136,10 +137,10 @@ class Expression extends AbstractFunction { // Many dialects don't support shifts. Use multiplication/division instead else if (SHL == operator && asList(ASE, DB2, H2, HSQLDB, INGRES, ORACLE, SQLSERVER, SYBASE).contains(dialect)) { - return lhs.mul(literal(2).power(rhsAsNumber())); + return lhs.mul(power(literal(2), rhsAsNumber())); } else if (SHR == operator && asList(ASE, DB2, H2, HSQLDB, INGRES, ORACLE, SQLSERVER, SYBASE).contains(dialect)) { - return lhs.div(literal(2).power(rhsAsNumber())); + return lhs.div(power(literal(2), rhsAsNumber())); } // These operators are not supported in any dialect diff --git a/jOOQ/src/main/java/org/jooq/impl/Factory.java b/jOOQ/src/main/java/org/jooq/impl/Factory.java index 49f9effc67..f8e5b73a4a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Factory.java +++ b/jOOQ/src/main/java/org/jooq/impl/Factory.java @@ -1759,6 +1759,10 @@ public class Factory implements Configuration { return (Field[]) castFields; } + // ------------------------------------------------------------------------ + // Construction of special grouping functions + // ------------------------------------------------------------------------ + /** * Create a ROLLUP(field1, field2, .., fieldn) grouping field *

@@ -1950,6 +1954,619 @@ public class Factory implements Configuration { return function("grouping_id", Integer.class, fields); } + // ------------------------------------------------------------------------ + // Mathematical functions + // ------------------------------------------------------------------------ + + /** + * Get the sign of a numeric field: sign(field) + *

+ * This renders the sign function where available: + *

sign([this])
+ * ... or simulates it elsewhere (without bind variables on values -1, 0, 1): + *
+     * CASE WHEN [this] > 0 THEN 1
+     *      WHEN [this] < 0 THEN -1
+     *      ELSE 0
+     * END
+     */
+    public static Field sign(Number value) {
+        return sign(val(value));
+    }
+
+    /**
+     * Get the sign of a numeric field: sign(field)
+     * 

+ * This renders the sign function where available: + *

sign([this])
+ * ... or simulates it elsewhere (without bind variables on values -1, 0, 1): + *
+     * CASE WHEN [this] > 0 THEN 1
+     *      WHEN [this] < 0 THEN -1
+     *      ELSE 0
+     * END
+     */
+    public static Field sign(Field field) {
+        return new Sign(field);
+    }
+
+    /**
+     * Get the absolute value of a numeric field: abs(field)
+     * 

+ * This renders the same on all dialects: + *

abs([this])
+ */ + public static Field abs(T value) { + return abs(val(value)); + } + + /** + * Get the absolute value of a numeric field: abs(field) + *

+ * This renders the same on all dialects: + *

abs([this])
+ */ + public static Field abs(Field field) { + return function("abs", field.getDataType(), field); + } + + /** + * Get rounded value of a numeric field: round(field) + *

+ * This renders the round function where available: + *

round([this]) or
+     * round([this], 0)
+ * ... or simulates it elsewhere using floor and ceil + */ + public static Field round(T value) { + return round(val(value)); + } + + /** + * Get rounded value of a numeric field: round(field) + *

+ * This renders the round function where available: + *

round([this]) or
+     * round([this], 0)
+ * ... or simulates it elsewhere using floor and ceil + */ + public static Field round(Field field) { + return new Round(field); + } + + /** + * Get rounded value of a numeric field: round(field, decimals) + *

+ * This renders the round function where available: + *

round([this], [decimals])
+ * ... or simulates it elsewhere using floor and ceil + */ + public static Field round(T value, int decimals) { + return round(val(value), decimals); + } + + /** + * Get rounded value of a numeric field: round(field, decimals) + *

+ * This renders the round function where available: + *

round([this], [decimals])
+ * ... or simulates it elsewhere using floor and ceil + */ + public static Field round(Field field, int decimals) { + return new Round(field, decimals); + } + + /** + * Get the largest integer value not greater than [this] + *

+ * This renders the floor function where available: + *

floor([this])
+ * ... or simulates it elsewhere using round: + *
round([this] - 0.499999999999999)
+ */ + public static Field floor(T value) { + return floor(val(value)); + } + + /** + * Get the largest integer value not greater than [this] + *

+ * This renders the floor function where available: + *

floor([this])
+ * ... or simulates it elsewhere using round: + *
round([this] - 0.499999999999999)
+ */ + public static Field floor(Field field) { + return new Floor(field); + } + + /** + * Get the smallest integer value not less than [this] + *

+ * This renders the ceil or ceiling function where available: + *

ceil([this]) or
+     * ceiling([this])
+ * ... or simulates it elsewhere using round: + *
round([this] + 0.499999999999999)
+ */ + public static Field ceil(T value) { + return ceil(val(value)); + } + + /** + * Get the smallest integer value not less than [this] + *

+ * This renders the ceil or ceiling function where available: + *

ceil([this]) or
+     * ceiling([this])
+ * ... or simulates it elsewhere using round: + *
round([this] + 0.499999999999999)
+ */ + public static Field ceil(Field field) { + return new Ceil(field); + } + + /** + * Get the sqrt(field) function + *

+ * This renders the sqrt function where available: + *

sqrt([this])
... or simulates it elsewhere using + * power (which in turn may also be simulated using ln and exp functions): + *
power([this], 0.5)
+ */ + public static Field sqrt(Number value) { + return sqrt(val(value)); + } + + /** + * Get the sqrt(field) function + *

+ * This renders the sqrt function where available: + *

sqrt([this])
... or simulates it elsewhere using + * power (which in turn may also be simulated using ln and exp functions): + *
power([this], 0.5)
+ */ + public static Field sqrt(Field field) { + return new Sqrt(field); + } + + /** + * Get the exp(field) function, taking this field as the power of e + *

+ * This renders the same on all dialects: + *

exp([this])
+ */ + public static Field exp(Number value) { + return exp(val(value)); + } + + /** + * Get the exp(field) function, taking this field as the power of e + *

+ * This renders the same on all dialects: + *

exp([this])
+ */ + public static Field exp(Field field) { + return function("exp", SQLDataType.NUMERIC, field); + } + + /** + * Get the ln(field) function, taking the natural logarithm of this field + *

+ * This renders the ln or log function where available: + *

ln([this]) or
+     * log([this])
+ */ + public static Field ln(Number value) { + return ln(val(value)); + } + + /** + * Get the ln(field) function, taking the natural logarithm of this field + *

+ * This renders the ln or log function where available: + *

ln([this]) or
+     * log([this])
+ */ + public static Field ln(Field field) { + return new Ln(field); + } + + /** + * Get the log(field, base) function + *

+ * This renders the log function where available: + *

log([this])
... or simulates it elsewhere (in + * most RDBMS) using the natural logarithm: + *
ln([this]) / ln([base])
+ */ + public static Field log(Number value, int base) { + return log(val(value), base); + } + + /** + * Get the log(field, base) function + *

+ * This renders the log function where available: + *

log([this])
... or simulates it elsewhere (in + * most RDBMS) using the natural logarithm: + *
ln([this]) / ln([base])
+ */ + public static Field log(Field field, int base) { + return new Ln(field, base); + } + + /** + * Get the power(field, exponent) function + *

+ * This renders the power function where available: + *

power([this], [exponent])
... or simulates it + * elsewhere using ln and exp: + *
exp(ln([this]) * [exponent])
+ */ + public static Field power(Number value, Number exponent) { + return power(val(value), val(exponent)); + } + + /** + * Get the power(field, exponent) function + *

+ * This renders the power function where available: + *

power([this], [exponent])
... or simulates it + * elsewhere using ln and exp: + *
exp(ln([this]) * [exponent])
+ */ + public static Field power(Field field, Number exponent) { + return power(field, val(exponent)); + } + + /** + * Get the power(field, exponent) function + *

+ * This renders the power function where available: + *

power([this], [exponent])
... or simulates it + * elsewhere using ln and exp: + *
exp(ln([this]) * [exponent])
+ */ + public static Field power(Number value, Field exponent) { + return power(val(value), exponent); + } + + /** + * Get the power(field, exponent) function + *

+ * This renders the power function where available: + *

power([this], [exponent])
... or simulates it + * elsewhere using ln and exp: + *
exp(ln([this]) * [exponent])
+ */ + public static Field power(Field field, Field exponent) { + return new Power(field, exponent); + } + + /** + * Get the arc cosine(field) function + *

+ * This renders the acos function where available: + *

acos([this])
+ */ + public static Field acos(Number value) { + return acos(val(value)); + } + + /** + * Get the arc cosine(field) function + *

+ * This renders the acos function where available: + *

acos([this])
+ */ + public static Field acos(Field field) { + return function("acos", SQLDataType.NUMERIC, field); + } + + /** + * Get the arc sine(field) function + *

+ * This renders the asin function where available: + *

asin([this])
+ */ + public static Field asin(Number value) { + return asin(val(value)); + } + + /** + * Get the arc sine(field) function + *

+ * This renders the asin function where available: + *

asin([this])
+ */ + public static Field asin(Field field) { + return function("asin", SQLDataType.NUMERIC, field); + } + + /** + * Get the arc tangent(field) function + *

+ * This renders the atan function where available: + *

atan([this])
+ */ + public static Field atan(Number value) { + return atan(val(value)); + } + + /** + * Get the arc tangent(field) function + *

+ * This renders the atan function where available: + *

atan([this])
+ */ + public static Field atan(Field field) { + return function("atan", SQLDataType.NUMERIC, field); + } + + /** + * Get the arc tangent 2(field, y) function + *

+ * This renders the atan2 or atn2 function where available: + *

atan2([this]) or
+     * atn2([this])
+ */ + public static Field atan2(Number x, Number y) { + return atan2(val(x), val(y)); + } + + /** + * Get the arc tangent 2(field, y) function + *

+ * This renders the atan2 or atn2 function where available: + *

atan2([this]) or
+     * atn2([this])
+ */ + public static Field atan2(Field x, Number y) { + return atan2(x, val(y)); + } + + /** + * Get the arc tangent 2(field, y) function + *

+ * This renders the atan2 or atn2 function where available: + *

atan2([this]) or
+     * atn2([this])
+ */ + public static Field atan2(Number x, Field y) { + return atan2(val(x), y); + } + + /** + * Get the arc tangent 2(field, y) function + *

+ * This renders the atan2 or atn2 function where available: + *

atan2([this]) or
+     * atn2([this])
+ */ + public static Field atan2(Field x, Field y) { + if (y == null) { + return atan2(x, (Number) null); + } + + return new Function(Term.ATAN2, SQLDataType.NUMERIC, x, y); + } + + /** + * Get the cosine(field) function + *

+ * This renders the cos function where available: + *

cos([this])
+ */ + public static Field cos(Number value) { + return cos(val(value)); + } + + /** + * Get the cosine(field) function + *

+ * This renders the cos function where available: + *

cos([this])
+ */ + public static Field cos(Field field) { + return function("cos", SQLDataType.NUMERIC, field); + } + + /** + * Get the sine(field) function + *

+ * This renders the sin function where available: + *

sin([this])
+ */ + public static Field sin(Number value) { + return sin(val(value)); + } + + /** + * Get the sine(field) function + *

+ * This renders the sin function where available: + *

sin([this])
+ */ + public static Field sin(Field field) { + return function("sin", SQLDataType.NUMERIC, field); + } + + /** + * Get the tangent(field) function + *

+ * This renders the tan function where available: + *

tan([this])
+ */ + public static Field tan(Number value) { + return tan(val(value)); + } + + /** + * Get the tangent(field) function + *

+ * This renders the tan function where available: + *

tan([this])
+ */ + public static Field tan(Field field) { + return function("tan", SQLDataType.NUMERIC, field); + } + + /** + * Get the cotangent(field) function + *

+ * This renders the cot function where available: + *

cot([this])
... or simulates it elsewhere using + * sin and cos:
cos([this]) / sin([this])
+ */ + public static Field cot(Number value) { + return cot(val(value)); + } + + /** + * Get the cotangent(field) function + *

+ * This renders the cot function where available: + *

cot([this])
... or simulates it elsewhere using + * sin and cos:
cos([this]) / sin([this])
+ */ + public static Field cot(Field field) { + return new Cot(field); + } + + /** + * Get the hyperbolic sine function: sinh(field) + *

+ * This renders the sinh function where available: + *

sinh([this])
... or simulates it elsewhere using + * exp:
(exp([this] * 2) - 1) / (exp([this] * 2))
+ */ + public static Field sinh(Number value) { + return sinh(val(value)); + } + + /** + * Get the hyperbolic sine function: sinh(field) + *

+ * This renders the sinh function where available: + *

sinh([this])
... or simulates it elsewhere using + * exp:
(exp([this] * 2) - 1) / (exp([this] * 2))
+ */ + public static Field sinh(Field field) { + return new Sinh(field); + } + + /** + * Get the hyperbolic cosine function: cosh(field) + *

+ * This renders the cosh function where available: + *

cosh([this])
... or simulates it elsewhere using + * exp:
(exp([this] * 2) + 1) / (exp([this] * 2))
+ */ + public static Field cosh(Number value) { + return cosh(val(value)); + } + + /** + * Get the hyperbolic cosine function: cosh(field) + *

+ * This renders the cosh function where available: + *

cosh([this])
... or simulates it elsewhere using + * exp:
(exp([this] * 2) + 1) / (exp([this] * 2))
+ */ + public static Field cosh(Field field) { + return new Cosh(field); + } + + /** + * Get the hyperbolic tangent function: tanh(field) + *

+ * This renders the tanh function where available: + *

tanh([this])
... or simulates it elsewhere using + * exp: + *
(exp([this] * 2) - 1) / (exp([this] * 2) + 1)
+ */ + public static Field tanh(Number value) { + return tanh(val(value)); + } + + /** + * Get the hyperbolic tangent function: tanh(field) + *

+ * This renders the tanh function where available: + *

tanh([this])
... or simulates it elsewhere using + * exp: + *
(exp([this] * 2) - 1) / (exp([this] * 2) + 1)
+ */ + public static Field tanh(Field field) { + return new Tanh(field); + } + + /** + * Get the hyperbolic cotangent function: coth(field) + *

+ * This is not supported by any RDBMS, but simulated using exp exp: + *

(exp([this] * 2) + 1) / (exp([this] * 2) - 1)
+ */ + public static Field coth(Number value) { + return coth(val(value)); + } + + /** + * Get the hyperbolic cotangent function: coth(field) + *

+ * This is not supported by any RDBMS, but simulated using exp exp: + *

(exp([this] * 2) + 1) / (exp([this] * 2) - 1)
+ */ + public static Field coth(Field field) { + return exp(field.mul(2)).add(1).div(exp(field.mul(2)).sub(1)); + } + + /** + * Calculate degrees from radians from this field + *

+ * This renders the degrees function where available: + *

degrees([this])
... or simulates it elsewhere: + *
[this] * 180 / PI
+ */ + public static Field deg(Number value) { + return deg(val(value)); + } + + /** + * Calculate degrees from radians from this field + *

+ * This renders the degrees function where available: + *

degrees([this])
... or simulates it elsewhere: + *
[this] * 180 / PI
+ */ + public static Field deg(Field field) { + return new Degrees(field); + } + + /** + * Calculate radians from degrees from this field + *

+ * This renders the degrees function where available: + *

degrees([this])
... or simulates it elsewhere: + *
[this] * PI / 180
+ */ + public static Field rad(Number value) { + return rad(val(value)); + } + + /** + * Calculate radians from degrees from this field + *

+ * This renders the degrees function where available: + *

degrees([this])
... or simulates it elsewhere: + *
[this] * PI / 180
+ */ + public static Field rad(Field field) { + return new Radians(field); + } + + // ------------------------------------------------------------------------- // Aggregate functions // ------------------------------------------------------------------------- @@ -1992,14 +2609,14 @@ public class Factory implements Configuration { /** * Get the sum over a numeric field: sum(field) */ - public static Field sum(Field field) { + public static Field sum(Field field) { return function("sum", SQLDataType.NUMERIC, field); } /** * Get the average over a numeric field: avg(field) */ - public static Field avg(Field field) { + public static Field avg(Field field) { return function("avg", SQLDataType.NUMERIC, field); } @@ -2013,7 +2630,7 @@ public class Factory implements Configuration { *
  • Sybase SQL Anywhere
  • * */ - public static Field median(Field field) { + public static Field median(Field field) { return function("median", SQLDataType.NUMERIC, field); } @@ -2034,7 +2651,7 @@ public class Factory implements Configuration { *
  • Sybase SQL Anywhere
  • * */ - public static Field stddevPop(Field field) { + public static Field stddevPop(Field field) { return new Function(Term.STDDEV_POP, SQLDataType.NUMERIC, field); } @@ -2055,7 +2672,7 @@ public class Factory implements Configuration { *
  • Sybase SQL Anywhere
  • * */ - public static Field stddevSamp(Field field) { + public static Field stddevSamp(Field field) { return new Function(Term.STDDEV_SAMP, SQLDataType.NUMERIC, field); } @@ -2076,7 +2693,7 @@ public class Factory implements Configuration { *
  • Sybase SQL Anywhere
  • * */ - public static Field varPop(Field field) { + public static Field varPop(Field field) { return new Function(Term.VAR_POP, SQLDataType.NUMERIC, field); } @@ -2095,7 +2712,7 @@ public class Factory implements Configuration { *
  • Sybase SQL Anywhere
  • * */ - public static Field varSamp(Field field) { + public static Field varSamp(Field field) { return new Function(Term.VAR_SAMP, SQLDataType.NUMERIC, field); } diff --git a/jOOQ/src/main/java/org/jooq/impl/Floor.java b/jOOQ/src/main/java/org/jooq/impl/Floor.java index 95b37ecc79..0910920dc7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Floor.java +++ b/jOOQ/src/main/java/org/jooq/impl/Floor.java @@ -36,6 +36,7 @@ package org.jooq.impl; import static org.jooq.impl.Factory.function; +import static org.jooq.impl.Factory.round; import org.jooq.Configuration; import org.jooq.Field; @@ -43,7 +44,7 @@ import org.jooq.Field; /** * @author Lukas Eder */ -class Floor extends AbstractFunction { +class Floor extends AbstractFunction { /** * Generated UID @@ -64,7 +65,7 @@ class Floor extends AbstractFunction { // evaluate "floor" if unavailable case SQLITE: - return argument.sub(0.499999999999999).round(); + return round(argument.sub(0.499999999999999)); default: return function("floor", getDataType(), argument); diff --git a/jOOQ/src/main/java/org/jooq/impl/Ln.java b/jOOQ/src/main/java/org/jooq/impl/Ln.java index 9934d056bd..ebb8ca6687 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Ln.java +++ b/jOOQ/src/main/java/org/jooq/impl/Ln.java @@ -37,6 +37,7 @@ package org.jooq.impl; import static org.jooq.impl.Factory.function; import static org.jooq.impl.Factory.literal; +import static org.jooq.impl.Factory.ln; import java.math.BigDecimal; @@ -51,16 +52,16 @@ class Ln extends AbstractFunction { /** * Generated UID */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = -7273879239726265322L; - private final Field argument; - private final Integer base; + private final Field argument; + private final Integer base; - Ln(Field argument) { + Ln(Field argument) { this(argument, null); } - Ln(Field argument, Integer base) { + Ln(Field argument, Integer base) { super("ln", SQLDataType.NUMERIC, argument); this.argument = argument; @@ -90,7 +91,7 @@ class Ln extends AbstractFunction { case INGRES: case SQLSERVER: case SYBASE: - return argument.ln().div(literal(base).ln()); + return ln(argument).div(ln(literal(base))); default: return function("log", SQLDataType.NUMERIC, literal(base), argument); diff --git a/jOOQ/src/main/java/org/jooq/impl/Pi.java b/jOOQ/src/main/java/org/jooq/impl/Pi.java index ffd4913297..3e972ad7c8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Pi.java +++ b/jOOQ/src/main/java/org/jooq/impl/Pi.java @@ -35,6 +35,7 @@ */ package org.jooq.impl; +import static org.jooq.impl.Factory.asin; import static org.jooq.impl.Factory.function; import static org.jooq.impl.Factory.literal; import static org.jooq.impl.Factory.one; @@ -64,7 +65,7 @@ class Pi extends AbstractFunction { switch (configuration.getDialect()) { case DB2: case ORACLE: - return one().asin().mul(two()); + return asin(one()).mul(two()); case SQLITE: return literal(Math.PI, BigDecimal.class); diff --git a/jOOQ/src/main/java/org/jooq/impl/Power.java b/jOOQ/src/main/java/org/jooq/impl/Power.java index 440b515eff..5e4abc5e1d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Power.java +++ b/jOOQ/src/main/java/org/jooq/impl/Power.java @@ -35,7 +35,9 @@ */ package org.jooq.impl; +import static org.jooq.impl.Factory.exp; import static org.jooq.impl.Factory.function; +import static org.jooq.impl.Factory.ln; import java.math.BigDecimal; @@ -50,12 +52,12 @@ class Power extends AbstractFunction { /** * Generated UID */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = -7273879239726265322L; - private final Field arg1; + private final Field arg1; private final Field arg2; - Power(Field arg1, Field arg2) { + Power(Field arg1, Field arg2) { super("ceil", SQLDataType.NUMERIC, arg1, arg2); this.arg1 = arg1; @@ -67,7 +69,7 @@ class Power extends AbstractFunction { switch (configuration.getDialect()) { case DERBY: case SQLITE: - return arg1.ln().mul(arg2).exp(); + return exp(ln(arg1).mul(arg2)); default: return function("power", SQLDataType.NUMERIC, getArguments()); diff --git a/jOOQ/src/main/java/org/jooq/impl/Round.java b/jOOQ/src/main/java/org/jooq/impl/Round.java index a38e04d8ac..9bc2c115f8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Round.java +++ b/jOOQ/src/main/java/org/jooq/impl/Round.java @@ -35,6 +35,8 @@ */ package org.jooq.impl; +import static org.jooq.impl.Factory.ceil; +import static org.jooq.impl.Factory.floor; import static org.jooq.impl.Factory.function; import static org.jooq.impl.Factory.val; @@ -46,7 +48,7 @@ import org.jooq.Field; /** * @author Lukas Eder */ -class Round extends AbstractFunction { +class Round extends AbstractFunction { /** * Generated UID @@ -76,18 +78,18 @@ class Round extends AbstractFunction { case DERBY: { if (decimals == 0) { return Factory.decode() - .when(argument.sub((Field) argument.floor()) - .lessThan((T) Double.valueOf(0.5)), argument.floor()) - .otherwise(argument.ceil()); + .when(argument.sub(floor(argument)) + .lessThan((T) Double.valueOf(0.5)), floor(argument)) + .otherwise(ceil(argument)); } else { Field factor = Factory.val(BigDecimal.ONE.movePointRight(decimals)); Field mul = argument.mul(factor); return Factory.decode() - .when(mul.sub((Field) mul.floor()) - .lessThan((T) Double.valueOf(0.5)), mul.floor().div(factor)) - .otherwise(mul.ceil().div(factor)); + .when(mul.sub(floor(mul)) + .lessThan((T) Double.valueOf(0.5)), floor(mul).div(factor)) + .otherwise(ceil(mul).div(factor)); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Sinh.java b/jOOQ/src/main/java/org/jooq/impl/Sinh.java index 36427d7f76..c22f0693b4 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Sinh.java +++ b/jOOQ/src/main/java/org/jooq/impl/Sinh.java @@ -35,6 +35,7 @@ */ package org.jooq.impl; +import static org.jooq.impl.Factory.exp; import static org.jooq.impl.Factory.function; import static org.jooq.impl.Factory.one; import static org.jooq.impl.Factory.two; @@ -52,11 +53,11 @@ class Sinh extends AbstractFunction { /** * Generated UID */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = -7273879239726265322L; - private final Field argument; + private final Field argument; - Sinh(Field argument) { + Sinh(Field argument) { super("sinh", SQLDataType.NUMERIC, argument); this.argument = argument; @@ -72,7 +73,7 @@ class Sinh extends AbstractFunction { case POSTGRES: case SQLSERVER: case SYBASE: - return argument.mul(two()).exp().sub(one()).div(argument.exp().mul(two())); + return exp(argument.mul(two())).sub(one()).div(exp(argument).mul(two())); default: return function("sinh", SQLDataType.NUMERIC, argument); diff --git a/jOOQ/src/main/java/org/jooq/impl/Sqrt.java b/jOOQ/src/main/java/org/jooq/impl/Sqrt.java index 8c5317ad63..41caafcab7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Sqrt.java +++ b/jOOQ/src/main/java/org/jooq/impl/Sqrt.java @@ -36,6 +36,7 @@ package org.jooq.impl; import static org.jooq.impl.Factory.function; +import static org.jooq.impl.Factory.power; import java.math.BigDecimal; @@ -50,11 +51,11 @@ class Sqrt extends AbstractFunction { /** * Generated UID */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = -7273879239726265322L; - private final Field argument; + private final Field argument; - Sqrt(Field argument) { + Sqrt(Field argument) { super("sqrt", SQLDataType.NUMERIC, argument); this.argument = argument; @@ -64,7 +65,7 @@ class Sqrt extends AbstractFunction { final Field getFunction0(Configuration configuration) { switch (configuration.getDialect()) { case SQLITE: - return argument.power(0.5); + return power(argument, 0.5); default: return function("sqrt", SQLDataType.NUMERIC, argument); diff --git a/jOOQ/src/main/java/org/jooq/impl/Tanh.java b/jOOQ/src/main/java/org/jooq/impl/Tanh.java index 6ef1af7803..63d801bf09 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Tanh.java +++ b/jOOQ/src/main/java/org/jooq/impl/Tanh.java @@ -35,6 +35,7 @@ */ package org.jooq.impl; +import static org.jooq.impl.Factory.exp; import static org.jooq.impl.Factory.function; import static org.jooq.impl.Factory.one; import static org.jooq.impl.Factory.two; @@ -52,11 +53,11 @@ class Tanh extends AbstractFunction { /** * Generated UID */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = -7273879239726265322L; - private final Field argument; + private final Field argument; - Tanh(Field argument) { + Tanh(Field argument) { super("tanh", SQLDataType.NUMERIC, argument); this.argument = argument; @@ -72,7 +73,7 @@ class Tanh extends AbstractFunction { case POSTGRES: case SQLSERVER: case SYBASE: - return argument.mul(two()).exp().sub(one()).div(argument.mul(two()).exp().add(one())); + return exp(argument.mul(two())).sub(one()).div(exp(argument.mul(two())).add(one())); default: return function("tanh", SQLDataType.NUMERIC, argument); diff --git a/jOOQ/src/test/java/org/jooq/test/jOOQTest.java b/jOOQ/src/test/java/org/jooq/test/jOOQTest.java index 0adc3dd2e0..a10928ed4c 100644 --- a/jOOQ/src/test/java/org/jooq/test/jOOQTest.java +++ b/jOOQ/src/test/java/org/jooq/test/jOOQTest.java @@ -48,6 +48,7 @@ import static org.jooq.impl.Factory.falseCondition; import static org.jooq.impl.Factory.field; import static org.jooq.impl.Factory.max; import static org.jooq.impl.Factory.min; +import static org.jooq.impl.Factory.round; import static org.jooq.impl.Factory.sum; import static org.jooq.impl.Factory.trueCondition; import static org.jooq.impl.Factory.val; @@ -935,7 +936,7 @@ public class jOOQTest { public final void testInsertSelect1() throws Exception { InsertQuery q = create.insertQuery(TABLE1); - q.addValue(FIELD_ID1, val(10).round()); + q.addValue(FIELD_ID1, round(val(10))); q.addValue(FIELD_NAME1, create.select(FIELD_NAME1).from(TABLE1).where(FIELD_ID1.equal(1)). asField()); assertEquals("insert into \"TABLE1\" (\"ID1\", \"NAME1\") values (round(10), (select \"TABLE1\".\"NAME1\" from \"TABLE1\" where \"TABLE1\".\"ID1\" = 1))", r_refI().render(q)); assertEquals("insert into \"TABLE1\" (\"ID1\", \"NAME1\") values (round(?), (select \"TABLE1\".\"NAME1\" from \"TABLE1\" where \"TABLE1\".\"ID1\" = ?))", r_ref().render(q));