如何在Jooq中为常规添加OrderBy?

时间:2013-11-20 06:58:48

标签: java sql stored-procedures jooq

我正在使用以下代码

Transaction transaction = Transaction.current();
        SelectQuery<Record> selectQuery = transaction.selectQuery();
        selectQuery.addSelect(Folder.FOLDER.FOLDER_RSN, Routines.fFoldernumber(Folder.FOLDER.FOLDER_RSN).as("FolderNumber"),
                Folder.FOLDER.FOLDER_NAME, Folder.FOLDER.FOLDER_TYPE);
selectQuery.addFrom(FolderPeople.FOLDER_PEOPLE);

现在我想在FolderNumber上添加OrderBy,如下所示

selectQuery.addOrderBy("FolderNumber")

如何在上述情况下添加OrderBy?

1 个答案:

答案 0 :(得分:1)

由jOOQ生成的存储函数实现org.jooq.Field,因此您只需将它们添加到ORDER BY子句中:

selectQuery.addOrderBy(fFoldernumber(...));

您可能还想考虑创建存储函数调用的本地引用,而不是重复整个调用:

Field<?> folder = Routines.fFoldernumber(Folder.FOLDER.FOLDER_RSN).as("FolderNumber");
// ...
selectQuery.addSelect(..., folder);
selectQuery.addOrderBy(folder);