Skip to content

Commit

Permalink
[#2414] [#2436] [#2437] Added ParamType
Browse files Browse the repository at this point in the history
- [#2414] Add Setting to influence parameter rendering (indexed,
named, inlined)
- [#2436] Add Query.getSQL(ParamType) and deprecate
Query.getSQL(boolean)
- [#2437] Add RenderContext.paramType() and deprecate
RenderContext.inline() and .namedParams()
  • Loading branch information
lukaseder committed May 3, 2013
1 parent 2b6c704 commit aa74f02
Show file tree
Hide file tree
Showing 29 changed files with 556 additions and 109 deletions.
6 changes: 4 additions & 2 deletions jOOQ-test/src/org/jooq/test/_/PrettyPrinter.java
Expand Up @@ -35,6 +35,8 @@
*/
package org.jooq.test._;

import static org.jooq.conf.ParamType.INLINED;

import java.util.concurrent.atomic.AtomicInteger;

import org.jooq.DSLContext;
Expand Down Expand Up @@ -84,7 +86,7 @@ public void renderEnd(ExecuteContext ctx) {
System.out.println(normal.renderInlined(ctx.query()));
System.out.println();
System.out.println(pretty.renderContext()
.inline(true)
.paramType(INLINED)
.render(ctx.query()));
}

Expand All @@ -93,7 +95,7 @@ else if (ctx.routine() != null) {
System.out.println(normal.renderInlined(ctx.routine()));
System.out.println();
System.out.println(pretty.renderContext()
.inline(true)
.paramType(INLINED)
.render(ctx.routine()));
}

Expand Down
4 changes: 3 additions & 1 deletion jOOQ-test/src/org/jooq/test/_/testcases/BenchmarkTests.java
Expand Up @@ -35,6 +35,8 @@
*/
package org.jooq.test._.testcases;

import static org.jooq.conf.ParamType.INDEXED;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -151,7 +153,7 @@ public void testBenchmarkSelect() throws Exception {
}

private void testBenchmarkReuseSQLString(DSLContext create, int repetitions) throws Exception {
String sql = createSelect(create).getSQL(false);
String sql = createSelect(create).getSQL(INDEXED);
PreparedStatement pst = getConnection().prepareStatement(sql);
pst.setLong(1, 1);
pst.setString(2, RANDOM);
Expand Down
5 changes: 3 additions & 2 deletions jOOQ-test/src/org/jooq/test/_/testcases/FetchTests.java
Expand Up @@ -45,6 +45,7 @@
import static org.jooq.SQLDialect.H2;
import static org.jooq.SQLDialect.ORACLE;
import static org.jooq.SQLDialect.POSTGRES;
import static org.jooq.conf.ParamType.INLINED;
import static org.jooq.impl.DSL.count;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.val;
Expand Down Expand Up @@ -424,7 +425,7 @@ public void testFetchWithoutResults() throws Exception {
create().update(TAuthor())
.set(TAuthor_FIRST_NAME(), "Hugo")
.where(TAuthor_ID().equal(100))
.getSQL(true));
.getSQL(INLINED));

assertNotNull(result);
assertEquals(0, result.size());
Expand All @@ -434,7 +435,7 @@ public void testFetchWithoutResults() throws Exception {
create().update(TAuthor())
.set(TAuthor_FIRST_NAME(), "Hugo")
.where(TAuthor_ID().equal(100))
.getSQL(true));
.getSQL(INLINED));

assertNotNull(result);
assertEquals(0, results.size());
Expand Down
10 changes: 6 additions & 4 deletions jOOQ-test/src/org/jooq/test/_/testcases/PlainSQLTests.java
Expand Up @@ -42,6 +42,8 @@
import static junit.framework.Assert.assertTrue;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.SQLDialect.H2;
import static org.jooq.conf.ParamType.INDEXED;
import static org.jooq.conf.ParamType.INLINED;
import static org.jooq.conf.StatementType.STATIC_STATEMENT;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.fieldByName;
Expand All @@ -60,8 +62,8 @@

import org.jooq.BindContext;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.jooq.Cursor;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.FutureResult;
import org.jooq.QueryPart;
Expand Down Expand Up @@ -427,7 +429,7 @@ public void testPlainSQLWithQueryParts() throws Exception {
public void testPlainSQLResultQuery() throws Exception {
// [#1749] TODO Firebird renders CAST(? as VARCHAR(...)) bind values with sizes
// pre-calculated. Hence the param needs to have some min length...
String sql = create().select(param("p", "abc").as("p")).getSQL(false);
String sql = create().select(param("p", "abc").as("p")).getSQL(INDEXED);
ResultQuery<Record> q = create().resultQuery(sql, "10");

Result<Record> fetch1 = q.fetch();
Expand Down Expand Up @@ -518,7 +520,7 @@ public void testCustomSQL() throws Exception {
public void toSQL(RenderContext context) {
context.configuration().data("Foo-Field", "Baz");

if (context.inline()) {
if (context.paramType() == INLINED) {
context.sql(TBook_ID().getName() + " * 2");
}

Expand Down Expand Up @@ -553,7 +555,7 @@ public void toSQL(RenderContext context) {
context.sql(IDx2);
context.sql(" > ");

if (context.inline()) {
if (context.paramType() == INLINED) {
context.sql("3");
}
else {
Expand Down
2 changes: 1 addition & 1 deletion jOOQ/pom.xml
Expand Up @@ -39,7 +39,7 @@
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<bindingDirectory>src/main/resources/xjb</bindingDirectory>
<schemaIncludes>
<include>jooq-runtime-3.0.0.xsd</include>
<include>jooq-runtime-3.1.0.xsd</include>
</schemaIncludes>
<generatePackage>org.jooq.conf</generatePackage>
<args>
Expand Down
2 changes: 1 addition & 1 deletion jOOQ/src/main/java/org/jooq/Context.java
Expand Up @@ -146,7 +146,7 @@ public interface Context<C extends Context<C>> {
* must assure that calling {@link #nextIndex()} is followed by setting a
* bind value to {@link BindContext#statement()}</li>
* <li>When rendering unnamed bind variables with
* {@link RenderContext#namedParams()} being to <code>true</code></li>
* {@link RenderContext#paramType()} being to <code>NAMED</code></li>
* </ul>
*/
int nextIndex();
Expand Down
4 changes: 2 additions & 2 deletions jOOQ/src/main/java/org/jooq/DSLContext.java
Expand Up @@ -61,6 +61,7 @@

import javax.annotation.Generated;

import org.jooq.conf.ParamType;
import org.jooq.conf.Settings;
import org.jooq.conf.StatementType;
import org.jooq.exception.DataAccessException;
Expand Down Expand Up @@ -165,8 +166,7 @@ public interface DSLContext {
* <li> <code>{@link RenderContext#declareFields()} == false</code></li>
* <li> <code>{@link RenderContext#declareTables()} == false</code></li>
* <li> <code>{@link RenderContext#format()} == false</code></li>
* <li> <code>{@link RenderContext#inline()} == false</code></li>
* <li> <code>{@link RenderContext#namedParams()} == false</code></li>
* <li> <code>{@link RenderContext#paramType()} == {@link ParamType#INDEXED}</code></li>
* <li> <code>{@link RenderContext#qualify()} == true</code></li>
* <li> <code>{@link RenderContext#subquery()} == false</code></li>
* </ul>
Expand Down
20 changes: 20 additions & 0 deletions jOOQ/src/main/java/org/jooq/Query.java
Expand Up @@ -41,6 +41,7 @@
import java.util.List;
import java.util.Map;

import org.jooq.conf.ParamType;
import org.jooq.conf.Settings;
import org.jooq.conf.StatementType;
import org.jooq.exception.DataAccessException;
Expand Down Expand Up @@ -139,9 +140,28 @@ public interface Query extends QueryPart, Attachable {
* @param inline Whether to inline bind variables. This overrides values in
* {@link Settings#getStatementType()}
* @return The generated SQL
* @deprecated - [#2414] - 3.1.0 - Use {@link #getSQL(ParamType)} instead
*/
@Deprecated
String getSQL(boolean inline);

/**
* Retrieve the SQL code rendered by this Query.
* <p>
* [#1520] Note that the query actually being executed might not contain any
* bind variables, in case the number of bind variables exceeds your SQL
* dialect's maximum number of supported bind variables. This is not
* reflected by this method, which will only use <code>paramType</code>
* argument to decide whether to render bind values.
* <p>
* See {@link #getSQL()} for more details.
*
* @param paramType How to render parameters. This overrides values in
* {@link Settings#getStatementType()}
* @return The generated SQL
*/
String getSQL(ParamType paramType);

/**
* Retrieve the bind values that will be bound by this Query. This
* <code>List</code> cannot be modified. To modify bind values, use
Expand Down

0 comments on commit aa74f02

Please sign in to comment.