use of org.seasar.doma.internal.jdbc.sql.node.FragmentNode 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.FragmentNode in project doma by domaframework.
the class Mssql2008ForUpdateTransformer method visitSelectStatementNode.
@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
if (processed) {
return node;
}
processed = true;
StringBuilder buf = new StringBuilder(100).append("with (updlock, rowlock");
if (forUpdateType == SelectForUpdateType.NOWAIT) {
buf.append(", nowait");
}
buf.append(") ");
FromClauseNode originalFrom = node.getFromClauseNode();
FromClauseNode from = new FromClauseNode(originalFrom.getWordNode());
for (SqlNode child : originalFrom.getChildren()) {
from.appendNode(child);
}
from.appendNode(new FragmentNode(buf.toString()));
SelectStatementNode result = new SelectStatementNode();
result.setSelectClauseNode(node.getSelectClauseNode());
result.setFromClauseNode(from);
result.setWhereClauseNode(node.getWhereClauseNode());
result.setGroupByClauseNode(node.getGroupByClauseNode());
result.setHavingClauseNode(node.getHavingClauseNode());
result.setOrderByClauseNode(node.getOrderByClauseNode());
result.setOptionClauseNode(node.getOptionClauseNode());
return result;
}
use of org.seasar.doma.internal.jdbc.sql.node.FragmentNode in project doma by domaframework.
the class Mssql2008PagingTransformer method appendTopNode.
protected SqlNode appendTopNode(SelectStatementNode node) {
SelectClauseNode select = new SelectClauseNode(node.getSelectClauseNode().getWordNode());
select.appendNode(new FragmentNode(" top (" + limit + ")"));
for (SqlNode child : node.getSelectClauseNode().getChildren()) {
select.appendNode(child);
}
SelectStatementNode result = new SelectStatementNode();
result.setSelectClauseNode(select);
result.setFromClauseNode(node.getFromClauseNode());
result.setWhereClauseNode(node.getWhereClauseNode());
result.setGroupByClauseNode(node.getGroupByClauseNode());
result.setHavingClauseNode(node.getHavingClauseNode());
result.setOrderByClauseNode(node.getOrderByClauseNode());
result.setForUpdateClauseNode(node.getForUpdateClauseNode());
result.setOptionClauseNode(node.getOptionClauseNode());
return result;
}
use of org.seasar.doma.internal.jdbc.sql.node.FragmentNode 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.FragmentNode in project doma by domaframework.
the class MysqlCountGettingTransformer method visitSelectStatementNode.
@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
if (processed) {
return node;
}
processed = true;
SelectClauseNode select = new SelectClauseNode("select");
select.appendNode(new FragmentNode(" found_rows()"));
SelectStatementNode result = new SelectStatementNode();
result.setSelectClauseNode(select);
return result;
}
Aggregations