DbSetup:多个SQL Update

时间:2015-02-11 15:56:22

标签: sql dbsetup

如何添加多个更新sql语句?在这个例子中,ID为2,3,4,5

的人
public static final Operation INSERT_LANGUAGE_DATA = 
    Operations.sequenceOf(Operations.insertInto("LANGUAGE")
        .columns("ID","DWH_CODE", "LANGUAGE" ,"NAME")
        .values(1, 0, "en", "language.english")
        .values(2, 7, "cs", "language.czech")
        .values(3, 1, "de", "language.german")
        .values(4, 2, "es", "language.spanish")
        .values(5, 3, "fr", "language.french")
        .build(),
        sql("UPDATE CUSTOMER set LANGUAGE_ID = 1 where ID = 1")
        );

1 个答案:

答案 0 :(得分:1)

您可以按顺序添加每个语句:

sql()将SQL查询作为参数。它返回OperationOperations.sequenceOf()将Operation实例作为参数。

所以你可以做到

Operations.sequenceOf(
    insertInto(...)
        .columns(...)
        .values(...)
        .build(), // first operation of the sequence
    sql("..."), // second operation of the sequence
    sql("...")); // third operation of the sequence

或者你可以做到

Operations.sequenceOf(
    insertInto(...)
        .columns(...)
        .values(...)
        .build(), // first operation of the sequence
    sql("...", // first SQL statement of the SQL operation
        "...")); // second SQL statement of the SQL operation

也就是说,在插入语言后,您不必更新客户。相反,您应首先插入语言,然后插入客户,这将直接引用先前创建的语言。