[jOOQ/jOOQ#8753] Add Context#sql(long), sql(float), and sql(double)

Adds the methods Context#sql(long), sql(float), and sql(double). These
are used by the default converters in DefaultBinding for better
performance.

Note that there is no sql(boolean), since "true" and "false" are
expected to be treated as keywords and as such respect the keyword
rendering style.
This commit is contained in:
Knut Wannheden 2019-06-12 12:33:51 +02:00
parent 6f936994af
commit 55cefa0f5a
5 changed files with 77 additions and 5 deletions

View File

@ -289,6 +289,21 @@ public interface Context<C extends Context<C>> extends Scope {
*/
C sql(int sql);
/**
* Append some SQL to the context's contained {@link StringBuilder}.
*/
C sql(long sql);
/**
* Append some SQL to the context's contained {@link StringBuilder}.
*/
C sql(float sql);
/**
* Append some SQL to the context's contained {@link StringBuilder}.
*/
C sql(double sql);
/**
* Override the value of {@link Settings#isRenderFormatted()}.
*/

View File

@ -114,6 +114,24 @@ public interface RenderContext extends Context<RenderContext> {
@Override
RenderContext sql(int sql);
/**
* Append some SQL to the context's contained {@link StringBuilder}.
*/
@Override
RenderContext sql(long sql);
/**
* Append some SQL to the context's contained {@link StringBuilder}.
*/
@Override
RenderContext sql(float sql);
/**
* Append some SQL to the context's contained {@link StringBuilder}.
*/
@Override
RenderContext sql(double sql);
/**
* Recurse rendering.
*

View File

@ -177,6 +177,21 @@ abstract class AbstractBindContext extends AbstractContext<BindContext> implemen
return this;
}
@Override
public final BindContext sql(long sql) {
return this;
}
@Override
public final BindContext sql(float sql) {
return this;
}
@Override
public final BindContext sql(double sql) {
return this;
}
@Override
public final BindContext format(boolean format) {
return this;

View File

@ -1659,7 +1659,7 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
@Override
final void sqlInline0(BindingSQLContext<U> ctx, Byte value) {
ctx.render().sql(value.toString());
ctx.render().sql(value);
}
@Override
@ -2151,7 +2151,7 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
else
ctx.render().visit(K_CAST).sql('(').visit(inline("NaN")).sql(' ').visit(K_AS).sql(' ').visit(keyword(DOUBLE.getCastTypeName(ctx.configuration()))).sql(')');
else
ctx.render().sql(value.toString());
ctx.render().sql(value);
}
@Override
@ -2324,7 +2324,7 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
else
ctx.render().visit(K_CAST).sql('(').visit(inline("NaN")).sql(' ').visit(K_AS).sql(' ').visit(keyword(DOUBLE.getCastTypeName(ctx.configuration()))).sql(')');
else
ctx.render().sql(value.toString());
ctx.render().sql(value);
}
@Override
@ -2428,7 +2428,7 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
@Override
final void sqlInline0(BindingSQLContext<U> ctx, Long value) {
ctx.render().sql(value.toString());
ctx.render().sql(value);
}
@Override
@ -3485,7 +3485,7 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
@Override
final void sqlInline0(BindingSQLContext<U> ctx, Short value) {
ctx.render().sql(value.toString());
ctx.render().sql(value);
}
@Override

View File

@ -381,6 +381,30 @@ class DefaultRenderContext extends AbstractContext<RenderContext> implements Ren
return this;
}
@Override
public final RenderContext sql(long l) {
sql.append(l);
separator = false;
newline = false;
return this;
}
@Override
public final RenderContext sql(float f) {
sql.append(f);
separator = false;
newline = false;
return this;
}
@Override
public final RenderContext sql(double d) {
sql.append(d);
separator = false;
newline = false;
return this;
}
@Override
public final RenderContext formatNewLine() {
if (cachedRenderFormatted) {