ca.krasnay.sqlbuilder
Class SelectCreator

java.lang.Object
  extended by ca.krasnay.sqlbuilder.AbstractSqlCreator
      extended by ca.krasnay.sqlbuilder.SelectCreator
All Implemented Interfaces:
Serializable, Cloneable, org.springframework.jdbc.core.PreparedStatementCreator

public class SelectCreator
extends AbstractSqlCreator
implements Cloneable

A Spring PreparedStatementCreator that you can use like a SelectBuilder. Example usage is as follows:

 PreparedStatementCreator psc = new SelectCreator()
 .column("name")
 .column("salary")
 .from("emp")
 .whereEquals("id", employeeId)
 .and("salary > :limit")
 .setParameter("limit", 100000);

 new JdbcTemplate(dataSource).query(psc, new RowMapper() { ... });
 

Author:
John Krasnay
See Also:
Serialized Form

Constructor Summary
  SelectCreator()
           
protected SelectCreator(SelectCreator other)
          Copy constructor.
 
Method Summary
 SelectCreator and(Predicate predicate)
           
 SelectCreator and(String expr)
           
 SelectCreator clone()
           
 SelectCreator column(String name)
           
 SelectCreator column(String name, boolean groupBy)
           
 org.springframework.jdbc.core.PreparedStatementCreator count(Dialect dialect)
          Returns a PreparedStatementCreator that returns a count of the rows that this creator would return.
 SelectCreator distinct()
           
 SelectCreator forUpdate()
           
 SelectCreator from(String table)
           
protected  AbstractSqlBuilder getBuilder()
          Returns the builder for this creator.
 List<UnionSelectCreator> getUnions()
           
 SelectCreator groupBy(String expr)
           
 SelectCreator having(String expr)
           
 SelectCreator join(String join)
           
 SelectCreator leftJoin(String join)
           
 SelectCreator noWait()
           
 SelectCreator orderBy(String name)
           
 SelectCreator orderBy(String name, boolean ascending)
           
 org.springframework.jdbc.core.PreparedStatementCreator page(Dialect dialect, int limit, int offset)
          Returns a PreparedStatementCreator that returns a page of the underlying result set.
 SelectCreator setParameter(String name, Object value)
          Sets a parameter for the creator.
 SubSelectCreator subSelectColumn(String alias)
           
 String toString()
           
 UnionSelectCreator union()
           
 SelectCreator where(Predicate predicate)
           
 SelectCreator where(String expr)
           
 SelectCreator whereEquals(String expr, Object value)
           
 SelectCreator whereIn(String expr, List<?> values)
           
 
Methods inherited from class ca.krasnay.sqlbuilder.AbstractSqlCreator
allocateParameter, createPreparedStatement, getPreparedStatementCreator
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SelectCreator

public SelectCreator()

SelectCreator

protected SelectCreator(SelectCreator other)
Copy constructor. Used by clone().

Parameters:
other - SelectCreator being cloned.
Method Detail

and

public SelectCreator and(String expr)

and

public SelectCreator and(Predicate predicate)

clone

public SelectCreator clone()
Overrides:
clone in class Object

column

public SelectCreator column(String name)

column

public SelectCreator column(String name,
                            boolean groupBy)

count

public org.springframework.jdbc.core.PreparedStatementCreator count(Dialect dialect)
Returns a PreparedStatementCreator that returns a count of the rows that this creator would return.

Parameters:
dialect - Database dialect.

distinct

public SelectCreator distinct()

forUpdate

public SelectCreator forUpdate()

from

public SelectCreator from(String table)

getBuilder

protected AbstractSqlBuilder getBuilder()
Description copied from class: AbstractSqlCreator
Returns the builder for this creator.

Specified by:
getBuilder in class AbstractSqlCreator

getUnions

public List<UnionSelectCreator> getUnions()

groupBy

public SelectCreator groupBy(String expr)

having

public SelectCreator having(String expr)

join

public SelectCreator join(String join)

leftJoin

public SelectCreator leftJoin(String join)

noWait

public SelectCreator noWait()

orderBy

public SelectCreator orderBy(String name)

orderBy

public SelectCreator orderBy(String name,
                             boolean ascending)

page

public org.springframework.jdbc.core.PreparedStatementCreator page(Dialect dialect,
                                                                   int limit,
                                                                   int offset)
Returns a PreparedStatementCreator that returns a page of the underlying result set.

Parameters:
dialect - Database dialect to use.
limit - Maximum number of rows to return.
offset - Index of the first row to return.

setParameter

public SelectCreator setParameter(String name,
                                  Object value)
Description copied from class: AbstractSqlCreator
Sets a parameter for the creator.

Overrides:
setParameter in class AbstractSqlCreator

subSelectColumn

public SubSelectCreator subSelectColumn(String alias)

toString

public String toString()
Overrides:
toString in class Object

union

public UnionSelectCreator union()

where

public SelectCreator where(String expr)

where

public SelectCreator where(Predicate predicate)

whereEquals

public SelectCreator whereEquals(String expr,
                                 Object value)

whereIn

public SelectCreator whereIn(String expr,
                             List<?> values)


Copyright © 2014. All rights reserved.