用jooq选择条件

时间:2015-09-30 13:03:08

标签: java sql jooq

在SQL中,我可以执行类型为

的查询
init: function (successCallback, errorCallback) {

        var taskRegistered = false;
        var taskName = "Your Background Task Name";
        var background = Windows.ApplicationModel.Background;
        var iter = background.BackgroundTaskRegistration.allTasks.first();

        // check if service already started
        while (iter.hasCurrent) {
            var task = iter.current.value;

            if (task.name === taskName) {
                taskRegistered = true;
                break;
            }

            iter.moveNext();
        }

        if (taskRegistered) {
            successCallback();
        } else {
            Windows.ApplicationModel.Background.BackgroundExecutionManager.requestAccessAsync().then(function () {
                var builder = new Windows.ApplicationModel.Background.BackgroundTaskBuilder();

                builder.name = taskName;
                builder.taskEntryPoint = "CordovaApp.Library.UploadTask"; // namespace of my windows runtime component library
                builder.setTrigger(new Windows.ApplicationModel.Background.TimeTrigger(15, false));
                builder.addCondition(new Windows.ApplicationModel.Background.SystemCondition(Windows.ApplicationModel.Background.SystemConditionType.internetAvailable));

                return builder.register();
            }).done(function () {
                successCallback();
            }, function (err) {
                errorCallback(err);
            });
        }

    },

给我一​​份清单:

SELECT cost > 1000 AS above_k, name FROM products;

如何使用+---------+--------+ | above_k | name | +---------+--------+ | true | Gold | | false | Silver | +---------+--------+ 为类似查询建模? (显然)我不能这样做:

jooq

因为,没有方法ctx.select(Tables.PRODUCTS.COST.gt(1000)) 。或者,如果我只是想:

select(Condition condition)

有没有办法用jooq做到这一点?

1 个答案:

答案 0 :(得分:6)

SQL 1:

SELECT cost > 1000 AS above_k, name 
FROM products;

jOOQ 1:

ctx.select(field(PRODUCTS.COST.gt(1000)).as("above_k"), PRODUCTS.NAME)
   .from(PRODUCTS)
   .fetch();

请参阅DSL.field(Condition)

SQL 2:

SELECT cost*0.9 AS discounted_cost 
FROM products;

jOOQ 2:

ctx.select(PRODUCTS.COST.mul(0.9).as("discounted_cost"))
   .from(PRODUCTS)
   .fetch();

请参阅Field.mul(Number)Field.multiply(Number)