[#1570] Add Factory.condition(String, QueryPart...) similar to

Factory.field(String, QueryPart...)
This commit is contained in:
Lukas Eder 2012-07-14 13:43:44 +02:00
parent adf3848278
commit 1c42b05ad6
2 changed files with 32 additions and 3 deletions

View File

@ -1466,6 +1466,35 @@ public class Factory implements FactoryOperations {
return new SQLCondition(sql, bindings);
}
/**
* A custom SQL clause that can render arbitrary SQL elements.
* <p>
* This is useful for constructing more complex SQL syntax elements wherever
* <code>Condition</code> types are expected. An example for this are
* Postgres's various operators, some of which are missing in the jOOQ API.
* For instance, the "overlap" operator for arrays:
* <code><pre>ARRAY[1,4,3] && ARRAY[2,1]</pre></code>
* <p>
* The above Postgres operator can be expressed as such: <code><pre>
* condition("{0} && {1}", array1, array2);
* </pre></code>
* <p>
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
* guarantee syntax integrity. You may also create the possibility of
* malicious SQL injection. Be sure to properly use bind variables and/or
* escape literals when concatenated into SQL clauses! One way to escape
* literals is to use {@link #name(String...)} and similar methods
*
* @param sql The SQL
* @param parts The {@link QueryPart} objects that are rendered at the
* {numbered placeholder} locations
* @return A condition wrapping the plain SQL
*/
@Support
public static Condition condition(String sql, QueryPart... parts) {
return new SQLCondition(sql, parts);
}
/**
* {@inheritDoc}
*/

View File

@ -81,7 +81,7 @@ class RegexpLike extends AbstractCondition {
case HSQLDB: {
// [#1570] TODO: Replace this by Factory.condition(String, QueryPart...)
context.sql(Factory.field("{regexp_matches}({0}, {1})", Boolean.class, search, pattern));
context.sql(Factory.condition("{regexp_matches}({0}, {1})", search, pattern));
break;
}
@ -89,7 +89,7 @@ class RegexpLike extends AbstractCondition {
case POSTGRES: {
// [#1570] TODO: Replace this by Factory.condition(String, QueryPart...)
context.sql(Factory.field("{0} ~ {1}", Boolean.class, search, pattern));
context.sql(Factory.condition("{0} ~ {1}", search, pattern));
break;
}
@ -97,7 +97,7 @@ class RegexpLike extends AbstractCondition {
case ORACLE: {
// [#1570] TODO: Replace this by Factory.condition(String, QueryPart...)
context.sql(Factory.field("{regexp_like}({0}, {1})", Boolean.class, search, pattern));
context.sql(Factory.condition("{regexp_like}({0}, {1})", search, pattern));
break;
}