use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.
the class SqlParser method parseOrderByWord.
protected void parseOrderByWord() {
validate();
OrderByClauseNode node = new OrderByClauseNode(token);
if (isInSelectStatementNode()) {
removeNodesTo(SelectStatementNode.class);
SelectStatementNode selectStatementNode = peek();
selectStatementNode.setOrderByClauseNode(node);
} else {
appendNode(node);
}
push(node);
}
use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.
the class H2PagingTransformer method visitSelectStatementNode.
@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
if (processed) {
return node;
}
processed = true;
OrderByClauseNode originalOrderBy = node.getOrderByClauseNode();
OrderByClauseNode orderBy;
if (originalOrderBy != null) {
orderBy = new OrderByClauseNode(originalOrderBy.getWordNode());
for (SqlNode child : originalOrderBy.getChildren()) {
orderBy.appendNode(child);
}
} else {
orderBy = new OrderByClauseNode("");
}
orderBy.appendNode(new FragmentNode(" limit "));
if (limit > 0) {
orderBy.appendNode(new FragmentNode(String.valueOf(limit)));
} else {
orderBy.appendNode(new FragmentNode("-1"));
}
if (offset >= 0) {
orderBy.appendNode(new FragmentNode(" offset "));
orderBy.appendNode(new FragmentNode(String.valueOf(offset)));
}
SelectStatementNode result = new SelectStatementNode();
result.setSelectClauseNode(node.getSelectClauseNode());
result.setFromClauseNode(node.getFromClauseNode());
result.setWhereClauseNode(node.getWhereClauseNode());
result.setGroupByClauseNode(node.getGroupByClauseNode());
result.setHavingClauseNode(node.getHavingClauseNode());
result.setOrderByClauseNode(orderBy);
result.setForUpdateClauseNode(node.getForUpdateClauseNode());
result.setOptionClauseNode(node.getOptionClauseNode());
return result;
}
use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.
the class MssqlPagingTransformer method visitSelectStatementNode.
@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
if (processed) {
return node;
}
processed = true;
if (!forceOffsetFetch && offset <= 0) {
return super.appendTopNode(node);
}
OrderByClauseNode originalOrderBy = node.getOrderByClauseNode();
if (originalOrderBy == null) {
throw new JdbcException(Message.DOMA2201);
}
OrderByClauseNode orderBy = new OrderByClauseNode(originalOrderBy.getWordNode());
for (SqlNode child : originalOrderBy.getChildren()) {
orderBy.appendNode(child);
}
String offset = this.offset <= 0 ? "0" : String.valueOf(this.offset);
orderBy.appendNode(new FragmentNode(" offset "));
orderBy.appendNode(new FragmentNode(offset));
orderBy.appendNode(new FragmentNode(" rows"));
if (this.limit > 0) {
orderBy.appendNode(new FragmentNode(" fetch next "));
orderBy.appendNode(new FragmentNode(String.valueOf(this.limit)));
orderBy.appendNode(new FragmentNode(" rows only"));
}
SelectStatementNode result = new SelectStatementNode();
result.setSelectClauseNode(node.getSelectClauseNode());
result.setFromClauseNode(node.getFromClauseNode());
result.setWhereClauseNode(node.getWhereClauseNode());
result.setGroupByClauseNode(node.getGroupByClauseNode());
result.setHavingClauseNode(node.getHavingClauseNode());
result.setOrderByClauseNode(orderBy);
result.setForUpdateClauseNode(node.getForUpdateClauseNode());
result.setOptionClauseNode(node.getOptionClauseNode());
return result;
}
use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.
the class MysqlPagingTransformer method visitSelectStatementNode.
@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
if (processed) {
return node;
}
processed = true;
OrderByClauseNode originalOrderBy = node.getOrderByClauseNode();
OrderByClauseNode orderBy;
if (originalOrderBy != null) {
orderBy = new OrderByClauseNode(originalOrderBy.getWordNode());
for (SqlNode child : originalOrderBy.getChildren()) {
orderBy.appendNode(child);
}
} else {
orderBy = new OrderByClauseNode("");
}
String offset = this.offset <= 0 ? "0" : String.valueOf(this.offset);
String limit = this.limit <= 0 ? MAXIMUM_LIMIT : String.valueOf(this.limit);
orderBy.appendNode(new FragmentNode(" limit "));
orderBy.appendNode(new FragmentNode(offset));
orderBy.appendNode(new FragmentNode(", "));
orderBy.appendNode(new FragmentNode(limit));
SelectStatementNode result = new SelectStatementNode();
result.setSelectClauseNode(node.getSelectClauseNode());
result.setFromClauseNode(node.getFromClauseNode());
result.setWhereClauseNode(node.getWhereClauseNode());
result.setGroupByClauseNode(node.getGroupByClauseNode());
result.setHavingClauseNode(node.getHavingClauseNode());
result.setOrderByClauseNode(orderBy);
result.setForUpdateClauseNode(node.getForUpdateClauseNode());
result.setOptionClauseNode(node.getOptionClauseNode());
return result;
}
use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.
the class SqlitePagingTransformer method visitSelectStatementNode.
@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
if (processed) {
return node;
}
processed = true;
OrderByClauseNode originalOrderBy = node.getOrderByClauseNode();
OrderByClauseNode orderBy;
if (originalOrderBy != null) {
orderBy = new OrderByClauseNode(originalOrderBy.getWordNode());
for (SqlNode child : originalOrderBy.getChildren()) {
orderBy.appendNode(child);
}
} else {
orderBy = new OrderByClauseNode("");
}
String offset = this.offset <= 0 ? "0" : String.valueOf(this.offset);
String limit = this.limit <= 0 ? MAXIMUM_LIMIT : String.valueOf(this.limit);
orderBy.appendNode(new FragmentNode(" limit "));
orderBy.appendNode(new FragmentNode(limit));
orderBy.appendNode(new FragmentNode(" offset "));
orderBy.appendNode(new FragmentNode(offset));
SelectStatementNode result = new SelectStatementNode();
result.setSelectClauseNode(node.getSelectClauseNode());
result.setFromClauseNode(node.getFromClauseNode());
result.setWhereClauseNode(node.getWhereClauseNode());
result.setGroupByClauseNode(node.getGroupByClauseNode());
result.setHavingClauseNode(node.getHavingClauseNode());
result.setOrderByClauseNode(orderBy);
result.setForUpdateClauseNode(node.getForUpdateClauseNode());
result.setOptionClauseNode(node.getOptionClauseNode());
return result;
}
Aggregations