com.jaregu.database.queries.dialect.DefaultDialectImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of queries Show documentation
Show all versions of queries Show documentation
Java based SQL templating project. Store your queries in *.sql files and build queries for execution. Supports simple expressions and conditional clauses and interface proxying for java-sql bridge.
package com.jaregu.database.queries.dialect;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.jaregu.database.queries.building.Query;
import com.jaregu.database.queries.building.QueryImpl;
public class DefaultDialectImpl implements Dialect {
@Override
public Query toOrderedQuery(Query query, Orderable orderable) {
List items;
if (orderable != null && (items = orderable.getOrderBy()) != null && !items.isEmpty()) {
StringBuilder newSql = new StringBuilder("SELECT x.* FROM /* ORDER BY wrapper by default dialect */ (\n")
.append(query.getSql()).append("\n) x ORDER BY ");
Iterator iterator = items.iterator();
newSql.append(iterator.next());
while (iterator.hasNext()) {
newSql.append(", ").append(iterator.next());
}
return new QueryImpl(newSql.toString(), query.getParameters(), query.getAttributes(), this);
}
return query;
}
@Override
public Query toPagedQuery(Query query, Pageable pageable) {
if (pageable.getLimit() != null) {
List