All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jaregu.database.queries.dialect.Oracle12PlusDialect Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.4.1
Show newest version
package com.jaregu.database.queries.dialect;

import java.util.ArrayList;
import java.util.List;

import com.jaregu.database.queries.building.Query;
import com.jaregu.database.queries.building.QueryImpl;

public class Oracle12PlusDialect extends DefaultDialectImpl {

	@Override
	public Query toPagedQuery(Query query, Pageable pageable) {
		if (pageable.getLimit() != null) {
			List parameters = new ArrayList<>(query.getParameters().size() + 2);
			parameters.addAll(query.getParameters());
			StringBuilder newSql = new StringBuilder(query.getSql()).append("\n");
			if (pageable.getOffset() != null) {
				newSql.append("OFFSET ? ");
				parameters.add(pageable.getOffset());
			}
			newSql.append("ROWS FETCH NEXT ? ROWS ONLY");
			parameters.add(pageable.getLimit());

			return new QueryImpl(newSql.toString(), parameters, query.getAttributes(), this);
		}
		return query;
	}
}