[#2172] Add <T> set(Field<T>, Select<? extends Record1<T>>) methods

to UPDATE, MERGE and INSERT statements
This commit is contained in:
Lukas Eder 2013-02-07 15:29:14 +01:00
parent d0e471e857
commit 32a166a198
13 changed files with 76 additions and 8 deletions

View File

@ -444,15 +444,27 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
assertEquals(Integer.valueOf(3), author.getValue(TAuthor_ID()));
assertEquals("Hornby", author.getValue(TAuthor_LAST_NAME()));
assertEquals(1,
create().update(TAuthor())
.set(TAuthor_ID(), ID4)
.set(TAuthor_LAST_NAME(), create().select(val("Hitchcock")).<String> asField())
.where(TAuthor_ID().equal(3))
.execute();
.execute());
author = create().fetchOne(TAuthor(), TAuthor_LAST_NAME().equal("Hitchcock"));
assertEquals(Integer.valueOf(4), author.getValue(TAuthor_ID()));
assertEquals("Hitchcock", author.getValue(TAuthor_LAST_NAME()));
assertEquals(1,
create().update(TAuthor())
.set(TAuthor_ID(), select(inline(5)))
.set(TAuthor_LAST_NAME(), select(val("Hesse")))
.where(TAuthor_ID().equal(4))
.execute());
author = create().fetchOne(TAuthor(), TAuthor_LAST_NAME().equal("Hesse"));
assertEquals(Integer.valueOf(5), author.getValue(TAuthor_ID()));
assertEquals("Hesse", author.getValue(TAuthor_LAST_NAME()));
}
@Test

View File

@ -153,7 +153,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
Insert<A> insert1 =
create().insertInto(TAuthor())
.set(TAuthor_ID(), 1)
.set(TAuthor_FIRST_NAME(), null)
.set(TAuthor_FIRST_NAME(), (String) null)
.set(TAuthor_LAST_NAME(), "Koontz");
assertEquals(

View File

@ -9,6 +9,6 @@ class GenerateAll {
InsertDSL::main(args);
Records::main(args);
Rows::main(args);
Update::main(args);
UpdateDSL::main(args);
}
}

View File

@ -146,6 +146,7 @@ class InsertDSL extends Generators {
«ENDFOR»
import org.jooq.InsertValuesStepN;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Result;
import org.jooq.Select;
import org.jooq.Table;
@ -295,6 +296,11 @@ class InsertDSL extends Generators {
return this;
}
@Override
public final <T> InsertImpl set(Field<T> field, Select<? extends Record1<T>> value) {
return set(field, value.<T>asField());
}
@Override
public final InsertImpl set(Map<? extends Field<?>, ?> map) {
if (onDuplicateKeyUpdate) {

View File

@ -40,10 +40,10 @@ import org.jooq.Constants
/**
* @author Lukas Eder
*/
class Update extends Generators {
class UpdateDSL extends Generators {
def static void main(String[] args) {
val update = new Update();
val update = new UpdateDSL();
update.generateUpdateQuery();
update.generateUpdateQueryImpl();
update.generateUpdateSetFirstStep();

View File

@ -78,6 +78,13 @@ public interface InsertOnDuplicateSetStep<R extends Record> {
@Support({ CUBRID, DB2, HSQLDB, MYSQL, ORACLE, SQLSERVER, SYBASE })
<T> InsertOnDuplicateSetMoreStep<R> set(Field<T> field, Field<T> value);
/**
* Set values for <code>UPDATE</code> in the <code>INSERT</code> statement's
* <code>ON DUPLICATE KEY UPDATE</code> clause
*/
@Support({ CUBRID, DB2, HSQLDB, MYSQL, ORACLE, SQLSERVER, SYBASE })
<T> InsertOnDuplicateSetMoreStep<R> set(Field<T> field, Select<? extends Record1<T>> value);
/**
* Set multiple values for <code>UPDATE</code> in the <code>INSERT</code>
* statement's <code>ON DUPLICATE KEY UPDATE</code> clause

View File

@ -63,19 +63,25 @@ import org.jooq.impl.Executor;
public interface InsertSetStep<R extends Record> {
/**
* Set a value for a field in the <code>UPDATE</code> statement
* Set a value for a field in the <code>INSERT</code> statement
*/
@Support
<T> InsertSetMoreStep<R> set(Field<T> field, T value);
/**
* Set a value for a field in the <code>UPDATE</code> statement
* Set a value for a field in the <code>INSERT</code> statement
*/
@Support
<T> InsertSetMoreStep<R> set(Field<T> field, Field<T> value);
/**
* Set a value for a field in the <code>UPDATE</code> statement
* Set a value for a field in the <code>INSERT</code> statement
*/
@Support
<T> InsertSetMoreStep<R> set(Field<T> field, Select<? extends Record1<T>> value);
/**
* Set a value for a field in the <code>INSERT</code> statement
* <p>
* Please assure that key/value pairs have matching <code>&lt;T&gt;</code>
* types. Values can either be of type <code>&lt;T&gt;</code> or

View File

@ -79,6 +79,13 @@ public interface MergeMatchedSetStep<R extends Record> {
@Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE })
<T> MergeMatchedSetMoreStep<R> set(Field<T> field, Field<T> value);
/**
* Set values for <code>UPDATE</code> in the <code>MERGE</code> statement's
* <code>WHEN MATCHED</code> clause
*/
@Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE })
<T> MergeMatchedSetMoreStep<R> set(Field<T> field, Select<? extends Record1<T>> value);
/**
* Set multiple values for <code>UPDATE</code> in the <code>MERGE</code>
* statement's <code>WHEN MATCHED</code> clause.

View File

@ -79,6 +79,13 @@ public interface MergeNotMatchedSetStep<R extends Record> {
@Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE })
<T> MergeNotMatchedSetMoreStep<R> set(Field<T> field, Field<T> value);
/**
* Set values for <code>INSERT</code> in the <code>MERGE</code> statement's
* <code>WHEN NOT MATCHED</INSERT> clause
*/
@Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE })
<T> MergeMatchedSetMoreStep<R> set(Field<T> field, Select<? extends Record1<T>> value);
/**
* Set multiple values for <code>INSERT</code> in the <code>MERGE</code>
* statement's <code>WHEN NOT MATCHED</code> clause.

View File

@ -66,6 +66,12 @@ public interface UpdateSetStep<R extends Record> {
@Support
<T> UpdateSetMoreStep<R> set(Field<T> field, Field<T> value);
/**
* Set a value for a field in the <code>UPDATE</code> statement
*/
@Support
<T> UpdateSetMoreStep<R> set(Field<T> field, Select<? extends Record1<T>> value);
/**
* Set a value for a field in the <code>UPDATE</code> statement
* <p>

View File

@ -73,6 +73,7 @@ import org.jooq.InsertValuesStep21;
import org.jooq.InsertValuesStep22;
import org.jooq.InsertValuesStepN;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Result;
import org.jooq.Select;
import org.jooq.Table;
@ -447,6 +448,11 @@ class InsertImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
return this;
}
@Override
public final <T> InsertImpl set(Field<T> field, Select<? extends Record1<T>> value) {
return set(field, value.<T>asField());
}
@Override
public final InsertImpl set(Map<? extends Field<?>, ?> map) {
if (onDuplicateKeyUpdate) {

View File

@ -110,6 +110,7 @@ import org.jooq.MergeUsingStep;
import org.jooq.Operator;
import org.jooq.QueryPart;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.RenderContext;
import org.jooq.Row;
import org.jooq.Select;
@ -675,6 +676,11 @@ implements
return this;
}
@Override
public final <T> MergeImpl set(Field<T> field, Select<? extends Record1<T>> value) {
return set(field, value.<T>asField());
}
@Override
public final MergeImpl set(Map<? extends Field<?>, ?> map) {
if (matchedClause) {

View File

@ -137,6 +137,11 @@ final class UpdateImpl<R extends Record>
return this;
}
@Override
public final <T> UpdateImpl<R> set(Field<T> field, Select<? extends Record1<T>> value) {
return set(field, value.<T>asField());
}
@Override
public final UpdateImpl<R> set(Map<? extends Field<?>, ?> map) {
getDelegate().addValues(map);