[#847] Query.getSQL() doesn't render dialect-specific SQL when Query is constructed using the fluent API

This commit is contained in:
Lukas Eder 2011-10-02 13:09:49 +00:00
parent 1fa0d8a573
commit e59b065994
14 changed files with 206 additions and 192 deletions

View File

@ -972,14 +972,13 @@ public abstract class jOOQAbstractTest<
Select<?> select =
create().select(TBook_ID(), TBook_ID().mul(6).div(2).div(3))
.from(TBook())
.orderBy(TBook_ID(), TBook_ID().div(2));
.orderBy(TBook_ID(), TBook_ID().mod(2));
assertEquals(
Arrays.asList(6, 2, 3, 2),
select.getBindValues());
// [#847] TODO: Run more tests like this one to ensure that
// Query.getSQL() returns dialect-specific SQL
log.info("Executing", select.getSQL());
PreparedStatement stmt = connection.prepareStatement(select.getSQL());
int i = 0;
for (Object value : select.getBindValues()) {

View File

@ -0,0 +1,81 @@
/**
* Copyright (c) 2009-2011, Lukas Eder, lukas.eder@gmail.com
* All rights reserved.
*
* This software is licensed to you under the Apache License, Version 2.0
* (the "License"); You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* . Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* . Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* . Neither the name "jOOQ" nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package org.jooq.impl;
import java.sql.SQLException;
import java.util.List;
import org.jooq.Attachable;
import org.jooq.AttachableInternal;
import org.jooq.BindContext;
import org.jooq.QueryPart;
import org.jooq.RenderContext;
/**
* @author Lukas Eder
*/
abstract class AbstractDelegatingQueryPart<Q extends QueryPart> extends AbstractQueryPart {
/**
* Generated UID
*/
private static final long serialVersionUID = 6710523592699040547L;
private final Q delegate;
AbstractDelegatingQueryPart(Q delegate) {
super(delegate.internalAPI(AttachableInternal.class).getConfiguration());
this.delegate = delegate;
}
@Override
public final void toSQL(RenderContext context) {
context.sql(delegate);
}
@Override
public final void bind(BindContext context) throws SQLException {
context.bind(delegate);
}
@Override
public final List<Attachable> getAttachables() {
return getAttachables(delegate);
}
final Q getDelegate() {
return delegate;
}
}

View File

@ -40,19 +40,20 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import org.jooq.Attachable;
import org.jooq.BindContext;
import org.jooq.Cursor;
import org.jooq.Field;
import org.jooq.FutureResult;
import org.jooq.Record;
import org.jooq.RecordHandler;
import org.jooq.RenderContext;
import org.jooq.Result;
import org.jooq.Select;
import org.jooq.Table;
abstract class AbstractDelegatingSelect<R extends Record> extends AbstractQueryPart
/**
* @author Lukas Eder
*/
abstract class AbstractDelegatingSelect<R extends Record>
extends AbstractDelegatingQueryPart<Select<R>>
implements Select<R> {
/**
@ -60,239 +61,222 @@ abstract class AbstractDelegatingSelect<R extends Record> extends AbstractQueryP
*/
private static final long serialVersionUID = 3382400928803573548L;
protected final Select<R> query;
AbstractDelegatingSelect(Select<R> query) {
this.query = query;
}
@Override
public final List<Attachable> getAttachables() {
return getAttachables(query);
super(query);
}
@Override
public final Class<? extends R> getRecordType() {
return query.getRecordType();
return getDelegate().getRecordType();
}
@Override
public final List<Field<?>> getSelect() {
return query.getSelect();
}
@Override
public final void toSQL(RenderContext context) {
context.sql(query);
}
@Override
public final void bind(BindContext context) throws SQLException {
context.bind(query);
return getDelegate().getSelect();
}
@Override
public final Result<R> getResult() {
return query.getResult();
return getDelegate().getResult();
}
@Override
public final Result<R> fetch() throws SQLException {
return query.fetch();
return getDelegate().fetch();
}
@Override
public final Cursor<R> fetchLazy() throws SQLException {
return query.fetchLazy();
return getDelegate().fetchLazy();
}
@Override
public final List<Result<Record>> fetchMany() throws SQLException {
return query.fetchMany();
return getDelegate().fetchMany();
}
@Override
public final <T> List<T> fetch(Field<T> field) throws SQLException {
return query.fetch(field);
return getDelegate().fetch(field);
}
@Override
public final List<?> fetch(int fieldIndex) throws SQLException {
return query.fetch(fieldIndex);
return getDelegate().fetch(fieldIndex);
}
@Override
public final <T> List<T> fetch(int fieldIndex, Class<? extends T> type) throws SQLException {
return query.fetch(fieldIndex, type);
return getDelegate().fetch(fieldIndex, type);
}
@Override
public final List<?> fetch(String fieldName) throws SQLException {
return query.fetch(fieldName);
return getDelegate().fetch(fieldName);
}
@Override
public final <T> List<T> fetch(String fieldName, Class<? extends T> type) throws SQLException {
return query.fetch(fieldName, type);
return getDelegate().fetch(fieldName, type);
}
@Override
public final <T> T fetchOne(Field<T> field) throws SQLException {
return query.fetchOne(field);
return getDelegate().fetchOne(field);
}
@Override
public final Object fetchOne(int fieldIndex) throws SQLException {
return query.fetchOne(fieldIndex);
return getDelegate().fetchOne(fieldIndex);
}
@Override
public final <T> T fetchOne(int fieldIndex, Class<? extends T> type) throws SQLException {
return query.fetchOne(fieldIndex, type);
return getDelegate().fetchOne(fieldIndex, type);
}
@Override
public final Object fetchOne(String fieldName) throws SQLException {
return query.fetchOne(fieldName);
return getDelegate().fetchOne(fieldName);
}
@Override
public final <T> T fetchOne(String fieldName, Class<? extends T> type) throws SQLException {
return query.fetchOne(fieldName, type);
return getDelegate().fetchOne(fieldName, type);
}
@Override
public final R fetchOne() throws SQLException {
return query.fetchOne();
return getDelegate().fetchOne();
}
@Override
public final R fetchAny() throws SQLException {
return query.fetchAny();
return getDelegate().fetchAny();
}
@Override
public final <K> Map<K, R> fetchMap(Field<K> key) throws SQLException {
return query.fetchMap(key);
return getDelegate().fetchMap(key);
}
@Override
public final <K, V> Map<K, V> fetchMap(Field<K> key, Field<V> value) throws SQLException {
return query.fetchMap(key, value);
return getDelegate().fetchMap(key, value);
}
@Override
public final List<Map<String, Object>> fetchMaps() throws SQLException {
return query.fetchMaps();
return getDelegate().fetchMaps();
}
@Override
public final Map<String, Object> fetchOneMap() throws SQLException {
return query.fetchOneMap();
return getDelegate().fetchOneMap();
}
@Override
public final Object[][] fetchArrays() throws SQLException {
return query.fetchArrays();
return getDelegate().fetchArrays();
}
@Override
public final Object[] fetchArray(int fieldIndex) throws SQLException {
return query.fetchArray(fieldIndex);
return getDelegate().fetchArray(fieldIndex);
}
@Override
public final <T> T[] fetchArray(int fieldIndex, Class<? extends T> type) throws SQLException {
return query.fetchArray(fieldIndex, type);
return getDelegate().fetchArray(fieldIndex, type);
}
@Override
public final Object[] fetchArray(String fieldName) throws SQLException {
return query.fetchArray(fieldName);
return getDelegate().fetchArray(fieldName);
}
@Override
public final <T> T[] fetchArray(String fieldName, Class<? extends T> type) throws SQLException {
return query.fetchArray(fieldName, type);
return getDelegate().fetchArray(fieldName, type);
}
@Override
public final <T> T[] fetchArray(Field<T> field) throws SQLException {
return query.fetchArray(field);
return getDelegate().fetchArray(field);
}
@Override
public final Object[] fetchOneArray() throws SQLException {
return query.fetchOneArray();
return getDelegate().fetchOneArray();
}
@Override
public final <T> List<T> fetchInto(Class<? extends T> type) throws SQLException {
return query.fetchInto(type);
return getDelegate().fetchInto(type);
}
@Override
public final <H extends RecordHandler<R>> H fetchInto(H handler) throws SQLException {
return query.fetchInto(handler);
return getDelegate().fetchInto(handler);
}
@Override
public final FutureResult<R> fetchLater() throws SQLException {
return query.fetchLater();
return getDelegate().fetchLater();
}
@Override
public final FutureResult<R> fetchLater(ExecutorService executor) throws SQLException {
return query.fetchLater(executor);
return getDelegate().fetchLater(executor);
}
@Override
public final int execute() throws SQLException {
return query.execute();
return getDelegate().execute();
}
@Override
public final Table<R> asTable() {
return query.asTable();
return getDelegate().asTable();
}
@Override
public final Table<R> asTable(String alias) {
return query.asTable(alias);
return getDelegate().asTable(alias);
}
@Override
public final <T> Field<T> asField() {
return query.asField();
return getDelegate().asField();
}
@Override
public final <T> Field<T> asField(String alias) {
return query.asField(alias);
return getDelegate().asField(alias);
}
@Override
public final <T> Field<T> getField(Field<T> field) {
return query.asTable().getField(field);
return getDelegate().asTable().getField(field);
}
@Override
public final Field<?> getField(String name) {
return query.asTable().getField(name);
return getDelegate().asTable().getField(name);
}
@Override
public final Field<?> getField(int index) {
return query.asTable().getField(index);
return getDelegate().asTable().getField(index);
}
@Override
public final List<Field<?>> getFields() {
return query.asTable().getFields();
return getDelegate().asTable().getFields();
}
@Override
public final int getIndex(Field<?> field) throws IllegalArgumentException {
return query.asTable().getIndex(field);
return getDelegate().asTable().getIndex(field);
}
}

View File

@ -53,15 +53,8 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query {
private static final long serialVersionUID = -8046199737354507547L;
private static final JooqLogger log = JooqLogger.getLogger(AbstractQuery.class);
final AttachableImpl attachable;
AbstractQuery(Configuration configuration) {
this.attachable = new AttachableImpl(this, configuration);
}
@Override
public final void attach(Configuration configuration) {
attachable.attach(configuration);
super(configuration);
}
@Override
@ -70,9 +63,9 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query {
StopWatch watch = new StopWatch();
// Let listeners provide a configuration to this query
Configuration configuration = ConfigurationRegistry.provideFor(attachable.getConfiguration());
Configuration configuration = ConfigurationRegistry.provideFor(getConfiguration());
if (configuration == null) {
configuration = attachable.getConfiguration();
configuration = getConfiguration();
}
Connection connection = configuration.getConnection();

View File

@ -65,12 +65,16 @@ import org.jooq.Table;
*/
abstract class AbstractQueryPart implements QueryPartInternal, AttachableInternal {
private static final long serialVersionUID = 2078114876079493107L;
private static final long serialVersionUID = 2078114876079493107L;
private final AttachableImpl attachable;
private final AttachableImpl attachable;
AbstractQueryPart() {
this.attachable = new AttachableImpl(this, DefaultConfiguration.DEFAULT_CONFIGURATION);
this(DefaultConfiguration.DEFAULT_CONFIGURATION);
}
AbstractQueryPart(Configuration configuration) {
this.attachable = new AttachableImpl(this, configuration);
}
@Override

View File

@ -62,22 +62,22 @@ abstract class AbstractSelect<R extends Record> extends AbstractResultQuery<R> i
@Override
public final Select<R> union(Select<R> select) {
return new Union<R>(attachable.getConfiguration(), this, select, CombineOperator.UNION);
return new Union<R>(getConfiguration(), this, select, CombineOperator.UNION);
}
@Override
public final Select<R> unionAll(Select<R> select) {
return new Union<R>(attachable.getConfiguration(), this, select, CombineOperator.UNION_ALL);
return new Union<R>(getConfiguration(), this, select, CombineOperator.UNION_ALL);
}
@Override
public final Select<R> except(Select<R> select) {
return new Union<R>(attachable.getConfiguration(), this, select, CombineOperator.EXCEPT);
return new Union<R>(getConfiguration(), this, select, CombineOperator.EXCEPT);
}
@Override
public final Select<R> intersect(Select<R> select) {
return new Union<R>(attachable.getConfiguration(), this, select, CombineOperator.INTERSECT);
return new Union<R>(getConfiguration(), this, select, CombineOperator.INTERSECT);
}
@SuppressWarnings("unchecked")

View File

@ -119,7 +119,7 @@ abstract class AbstractStoreQuery<R extends TableRecord<R>> extends AbstractQuer
}
else {
try {
A record = JooqUtil.newArrayRecord(field.getType(), attachable.getConfiguration());
A record = JooqUtil.newArrayRecord(field.getType(), getConfiguration());
record.setList(value);
addValue(field, record);
}

View File

@ -75,4 +75,13 @@ final class DefaultConfiguration implements Configuration {
* No further instances
*/
private DefaultConfiguration() {}
// -------------------------------------------------------------------------
// The Object API
// -------------------------------------------------------------------------
@Override
public String toString() {
return new Factory(getConnection(), getDialect(), getSchemaMapping()).toString();
}
}

View File

@ -37,16 +37,12 @@ package org.jooq.impl;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import org.jooq.Attachable;
import org.jooq.BindContext;
import org.jooq.Condition;
import org.jooq.Configuration;
import org.jooq.DeleteConditionStep;
import org.jooq.DeleteWhereStep;
import org.jooq.Operator;
import org.jooq.RenderContext;
import org.jooq.Select;
import org.jooq.Table;
import org.jooq.TableRecord;
@ -55,7 +51,9 @@ import org.jooq.exception.DetachedException;
/**
* @author Lukas Eder
*/
class DeleteImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
class DeleteImpl<R extends TableRecord<R>>
extends AbstractDelegatingQueryPart<DeleteQueryImpl<R>>
implements
// Cascading interface implementations for Delete behaviour
DeleteWhereStep,
@ -66,41 +64,24 @@ class DeleteImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
*/
private static final long serialVersionUID = 2747566322757517382L;
private final DeleteQueryImpl<R> delegate;
DeleteImpl(Configuration configuration, Table<R> table) {
delegate = new DeleteQueryImpl<R>(configuration, table);
super(new DeleteQueryImpl<R>(configuration, table));
}
@Override
public final int execute() throws SQLException, DetachedException {
return delegate.execute();
}
@Override
public final void toSQL(RenderContext context) {
context.sql(delegate);
}
@Override
public final void bind(BindContext context) throws SQLException {
context.bind(delegate);
}
@Override
public final List<Attachable> getAttachables() {
return getAttachables(delegate);
return getDelegate().execute();
}
@Override
public final DeleteImpl<R> where(Condition... conditions) {
delegate.addConditions(conditions);
getDelegate().addConditions(conditions);
return this;
}
@Override
public final DeleteImpl<R> where(Collection<Condition> conditions) {
delegate.addConditions(conditions);
getDelegate().addConditions(conditions);
return this;
}
@ -126,7 +107,7 @@ class DeleteImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
@Override
public final DeleteImpl<R> and(Condition condition) {
delegate.addConditions(condition);
getDelegate().addConditions(condition);
return this;
}
@ -157,7 +138,7 @@ class DeleteImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
@Override
public final DeleteImpl<R> or(Condition condition) {
delegate.addConditions(Operator.OR, condition);
getDelegate().addConditions(Operator.OR, condition);
return this;
}

View File

@ -42,9 +42,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.jooq.Attachable;
import org.jooq.AttachableInternal;
import org.jooq.BindContext;
import org.jooq.Configuration;
import org.jooq.Field;
import org.jooq.InsertOnDuplicateSetMoreStep;
@ -53,7 +50,6 @@ import org.jooq.InsertResultStep;
import org.jooq.InsertSetMoreStep;
import org.jooq.InsertSetStep;
import org.jooq.InsertValuesStep;
import org.jooq.RenderContext;
import org.jooq.Result;
import org.jooq.Table;
import org.jooq.TableRecord;
@ -62,7 +58,9 @@ import org.jooq.exception.DetachedException;
/**
* @author Lukas Eder
*/
class InsertImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
class InsertImpl<R extends TableRecord<R>>
extends AbstractDelegatingQueryPart<InsertQuery<R>>
implements
// Cascading interface implementations for Insert behaviour
InsertValuesStep,
@ -75,12 +73,11 @@ class InsertImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
*/
private static final long serialVersionUID = 4222898879771679107L;
private final InsertQuery<R> delegate;
private final List<Field<?>> fields;
private boolean onDuplicateKeyUpdate;
InsertImpl(Configuration configuration, Table<R> into, Collection<? extends Field<?>> fields) {
this.delegate = new InsertQueryImpl<R>(configuration, into);
super(new InsertQueryImpl<R>(configuration, into));
this.fields = new ArrayList<Field<?>>(fields);
}
@ -88,24 +85,9 @@ class InsertImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
// The QueryPart API
// -------------------------------------------------------------------------
@Override
public final void toSQL(RenderContext context) {
context.sql(delegate);
}
@Override
public final void bind(BindContext context) throws SQLException {
context.bind(delegate);
}
@Override
public final List<Attachable> getAttachables() {
return internalAPI(AttachableInternal.class).getAttachables();
}
@Override
public final int execute() throws SQLException, DetachedException {
return delegate.execute();
return getDelegate().execute();
}
// -------------------------------------------------------------------------
@ -132,9 +114,9 @@ class InsertImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
throw new IllegalArgumentException("The number of values must match the number of fields");
}
delegate.newRecord();
getDelegate().newRecord();
for (int i = 0; i < fields.size(); i++) {
delegate.addValue(fields.get(i), values.get(i));
getDelegate().addValue(fields.get(i), values.get(i));
}
return this;
@ -143,17 +125,17 @@ class InsertImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
@Override
public final InsertImpl<R> onDuplicateKeyUpdate() {
onDuplicateKeyUpdate = true;
delegate.onDuplicateKeyUpdate(true);
getDelegate().onDuplicateKeyUpdate(true);
return this;
}
@Override
public final InsertImpl<R> set(Field<?> field, Object value) {
if (onDuplicateKeyUpdate) {
delegate.addValueForUpdate(field, value);
getDelegate().addValueForUpdate(field, value);
}
else {
delegate.addValue(field, value);
getDelegate().addValue(field, value);
}
return this;
@ -162,10 +144,10 @@ class InsertImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
@Override
public final InsertImpl<R> set(Field<?> field, Field<?> value) {
if (onDuplicateKeyUpdate) {
delegate.addValueForUpdate(field, value);
getDelegate().addValueForUpdate(field, value);
}
else {
delegate.addValue(field, value);
getDelegate().addValue(field, value);
}
return this;
@ -174,10 +156,10 @@ class InsertImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
@Override
public final InsertImpl<R> set(Map<? extends Field<?>, ?> map) {
if (onDuplicateKeyUpdate) {
delegate.addValuesForUpdate(map);
getDelegate().addValuesForUpdate(map);
}
else {
delegate.addValues(map);
getDelegate().addValues(map);
}
return this;
@ -185,37 +167,37 @@ class InsertImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
@Override
public final InsertSetStep newRecord() {
delegate.newRecord();
getDelegate().newRecord();
return this;
}
@Override
public final InsertResultStep returning() {
delegate.setReturning();
getDelegate().setReturning();
return this;
}
@Override
public final InsertResultStep returning(Field<?>... f) {
delegate.setReturning(f);
getDelegate().setReturning(f);
return this;
}
@Override
public final InsertResultStep returning(Collection<? extends Field<?>> f) {
delegate.setReturning(f);
getDelegate().setReturning(f);
return this;
}
@Override
public final Result<?> fetch() throws SQLException {
delegate.execute();
return delegate.getReturnedRecords();
getDelegate().execute();
return getDelegate().getReturnedRecords();
}
@Override
public final TableRecord<?> fetchOne() throws SQLException {
delegate.execute();
return delegate.getReturnedRecord();
getDelegate().execute();
return getDelegate().getReturnedRecord();
}
}

View File

@ -92,7 +92,7 @@ class SQLResultQuery extends AbstractResultQuery<Record> {
@Override
protected final List<Field<?>> getFields(ResultSetMetaData meta) throws SQLException {
Configuration configuration = attachable.getConfiguration();
Configuration configuration = getConfiguration();
return new MetaDataFieldProvider(configuration, meta).getFields();
}

View File

@ -120,7 +120,7 @@ class SelectImpl extends AbstractDelegatingSelect<Record> implements
@Override
public final SelectQuery getQuery() {
return (SelectQuery) query;
return (SelectQuery) getDelegate();
}
@Override
@ -435,22 +435,22 @@ class SelectImpl extends AbstractDelegatingSelect<Record> implements
@Override
public final SelectImpl union(Select<Record> select) {
return new SelectImpl(query.union(select));
return new SelectImpl(getDelegate().union(select));
}
@Override
public final SelectImpl unionAll(Select<Record> select) {
return new SelectImpl(query.unionAll(select));
return new SelectImpl(getDelegate().unionAll(select));
}
@Override
public final SelectImpl except(Select<Record> select) {
return new SelectImpl(query.except(select));
return new SelectImpl(getDelegate().except(select));
}
@Override
public final SelectImpl intersect(Select<Record> select) {
return new SelectImpl(query.intersect(select));
return new SelectImpl(getDelegate().intersect(select));
}
@Override

View File

@ -94,7 +94,7 @@ class SimpleSelectImpl<R extends Record> extends AbstractDelegatingSelect<R>
@Override
public final SimpleSelectQuery<R> getQuery() {
return (SimpleSelectQuery<R>) query;
return (SimpleSelectQuery<R>) getDelegate();
}
@Override

View File

@ -37,16 +37,12 @@ package org.jooq.impl;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.jooq.Attachable;
import org.jooq.BindContext;
import org.jooq.Condition;
import org.jooq.Configuration;
import org.jooq.Field;
import org.jooq.Operator;
import org.jooq.RenderContext;
import org.jooq.Select;
import org.jooq.Table;
import org.jooq.TableRecord;
@ -60,7 +56,9 @@ import org.jooq.exception.DetachedException;
*
* @author Lukas Eder
*/
final class UpdateImpl<R extends TableRecord<R>> extends AbstractQueryPart implements
final class UpdateImpl<R extends TableRecord<R>>
extends AbstractDelegatingQueryPart<UpdateQuery<R>>
implements
// Cascading interface implementations for Update behaviour
UpdateSetMoreStep,
@ -71,59 +69,42 @@ final class UpdateImpl<R extends TableRecord<R>> extends AbstractQueryPart imple
*/
private static final long serialVersionUID = -2444876472650065331L;
private final UpdateQuery<R> delegate;
UpdateImpl(Configuration configuration, Table<R> table) {
delegate = new UpdateQueryImpl<R>(configuration, table);
super(new UpdateQueryImpl<R>(configuration, table));
}
@Override
public final int execute() throws SQLException, DetachedException {
return delegate.execute();
}
@Override
public final void toSQL(RenderContext context) {
context.sql(delegate);
}
@Override
public final void bind(BindContext context) throws SQLException {
context.bind(delegate);
}
@Override
public final List<Attachable> getAttachables() {
return getAttachables(delegate);
return getDelegate().execute();
}
@Override
public final UpdateSetMoreStep set(Field<?> field, Object value) {
delegate.addValue(field, value);
getDelegate().addValue(field, value);
return this;
}
@Override
public final UpdateSetMoreStep set(Field<?> field, Field<?> value) {
delegate.addValue(field, value);
getDelegate().addValue(field, value);
return this;
}
@Override
public final UpdateSetMoreStep set(Map<? extends Field<?>, ?> map) {
delegate.addValues(map);
getDelegate().addValues(map);
return this;
}
@Override
public final UpdateImpl<R> where(Condition... conditions) {
delegate.addConditions(conditions);
getDelegate().addConditions(conditions);
return this;
}
@Override
public final UpdateImpl<R> where(Collection<Condition> conditions) {
delegate.addConditions(conditions);
getDelegate().addConditions(conditions);
return this;
}
@ -149,7 +130,7 @@ final class UpdateImpl<R extends TableRecord<R>> extends AbstractQueryPart imple
@Override
public final UpdateImpl<R> and(Condition condition) {
delegate.addConditions(condition);
getDelegate().addConditions(condition);
return this;
}
@ -180,7 +161,7 @@ final class UpdateImpl<R extends TableRecord<R>> extends AbstractQueryPart imple
@Override
public final UpdateImpl<R> or(Condition condition) {
delegate.addConditions(Operator.OR, condition);
getDelegate().addConditions(Operator.OR, condition);
return this;
}