org.mentabean.jdbc
Class QueryBuilder

java.lang.Object
  extended by org.mentabean.jdbc.QueryBuilder

public class QueryBuilder
extends Object

Fluent QueryBuilder useful to create SQL queries

Author:
margel, erico

Nested Class Summary
 class QueryBuilder.Alias<T>
           
static interface QueryBuilder.Appendable<T>
           
static interface QueryBuilder.CanGroupBy
           
static interface QueryBuilder.CanLimit
           
static interface QueryBuilder.CanOrder
           
 class QueryBuilder.EndClause
           
 class QueryBuilder.EndClauseHaving
           
 class QueryBuilder.EndClauseWhere
           
 class QueryBuilder.Equals
           
 class QueryBuilder.From
           
 class QueryBuilder.GroupBy
           
static interface QueryBuilder.HasEndClause<T extends QueryBuilder.EndClause>
           
static interface QueryBuilder.HasInitClause<T extends QueryBuilder.InitClause>
           
 class QueryBuilder.Having
           
 class QueryBuilder.InitClause
           
 class QueryBuilder.InitClauseHaving
           
 class QueryBuilder.InitClauseWhere
           
 class QueryBuilder.Limit
           
 class QueryBuilder.Offset
           
 class QueryBuilder.On
          Class representing a 'pos-join' operation
 class QueryBuilder.OnEquals
           
 class QueryBuilder.Order
           
 class QueryBuilder.Ordering
           
 class QueryBuilder.PopulateUsing
           
 class QueryBuilder.Query
          Represents a query ready to execute
 class QueryBuilder.Select
           
 class QueryBuilder.UsingPK
           
 class QueryBuilder.Where
           
 
Constructor Summary
protected QueryBuilder(AnsiSQLBeanSession session)
           
 
Method Summary
<T> QueryBuilder.Alias<T>
aliasTo(Class<? extends T> clazz)
          Creates an alias to be used in this QueryBuilder.
<T> QueryBuilder.Alias<T>
aliasTo(Class<? extends T> clazz, String alias)
          Creates an alias to be used in this QueryBuilder
 QueryBuilder.Select select(QueryBuilder.Alias<?>... as)
          Builds an initial SELECT statement with given aliases
 QueryBuilder.Select select(Sentence... sentences)
          Builds an initial SELECT statement with given sentences
 QueryBuilder.From selectFrom(QueryBuilder.Alias<?> as)
          Builds an initial SELECT alias FROM alias statement.
Same as select(alias).from(alias)
 QueryBuilder subQuery()
          Creates a new QueryBuilder with the same session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryBuilder

protected QueryBuilder(AnsiSQLBeanSession session)
Method Detail

select

public QueryBuilder.Select select(QueryBuilder.Alias<?>... as)
Builds an initial SELECT statement with given aliases

Parameters:
as - - Alias(es) with properties that will be retrieved
Returns:
A new Select object

selectFrom

public QueryBuilder.From selectFrom(QueryBuilder.Alias<?> as)
Builds an initial SELECT alias FROM alias statement.
Same as select(alias).from(alias)

Parameters:
as - - Alias with properties that will be retrieved
Returns:
A new From object
See Also:
select(Alias...), Select#from(Alias)

select

public QueryBuilder.Select select(Sentence... sentences)
Builds an initial SELECT statement with given sentences

Parameters:
sentences - - Sentence(s) to insert in SELECT clause
Returns:
A new Select object

subQuery

public QueryBuilder subQuery()
Creates a new QueryBuilder with the same session. It's useful to build sub-queries from the main query

Returns:
The new QueryBuilder instance

aliasTo

public <T> QueryBuilder.Alias<T> aliasTo(Class<? extends T> clazz,
                                         String alias)
Creates an alias to be used in this QueryBuilder

Parameters:
clazz - - Bean class that will be mapped to a BeanConfig
alias - - String indicating the alia's name
Returns:
- The alias object

aliasTo

public <T> QueryBuilder.Alias<T> aliasTo(Class<? extends T> clazz)
Creates an alias to be used in this QueryBuilder. The alia's name is the simple name of the bean class

Parameters:
clazz - - Bean class that will be mapped to a BeanConfig
Returns:
- The alias object


Copyright © 2013. All Rights Reserved.