org.ujorm.orm.template
Class AliasTable<UJO extends OrmUjo>

java.lang.Object
  extended by org.ujorm.orm.template.AliasTable<UJO>

public class AliasTable<UJO extends OrmUjo>
extends Object

The experimental class for building any SQL statement using Ujorm Keys.
Example:

import static org.ujorm.orm.template.AliasTable.Build.*;
 public void example() {
     OrmHandler handler = createHandler();
     AliasTable<Order> order = handler.tableOf(Order.class, "order");
     AliasTable<Item> item = handler.tableOf(Item.class, "item");

     String sql
             = SELECT(order.column(Order.CREATED), item.column(Item.NOTE))
             + FROM (order, item)
             + WHERE(order.column(Order.ID), " = ", item.column(Item.ORDER));

     String sqlExpected = "SELECT order.CREATED, item.NOTE "
             + "FROM db1.ord_order order, db1.ord_item item "
             + "WHERE order.ID = item.fk_order";

     assertEquals(sqlExpected, sql);
 }


Nested Class Summary
static class AliasTable.Build
          Static building methods.
 
Constructor Summary
  AliasTable(Class<UJO> table, String alias, OrmHandler handler)
           
protected AliasTable(TableWrapper table, OrmHandler handler)
           
 
Method Summary
 String allColumns()
          Call the column() method for all Keys of Ujorm
 String allColumns(boolean includeKeyAlias)
          Call the column() method for all Keys of Ujorm
<T> String
column(Key<UJO,T> key)
          Print one columnAs including alias
<T> String
columnAs(Key<UJO,T> key)
          Returns one column including an default special alias name after the 'AS' phrase.
<T> String
columnAs(Key<UJO,T> key, CharSequence columnAlias)
          Returns one column including the required alias name after the 'AS' phrase.
<T> String
columnAs(String expression, Key<UJO,T> key)
          Print one columnAs including alias
protected  MetaColumn findColumnModel(Key<UJO,?> key)
          Find Column Model or throw an IllegalArgumentException.
protected  SqlDialect getDialect()
          Returns SQL Dialect
 TableWrapper getTableModel()
          Get table Alias
static
<UJO extends OrmUjo>
AliasTable<UJO>
of(Class<UJO> table, OrmHandler handler)
          Create new Alias with default name
static
<UJO extends OrmUjo>
AliasTable<UJO>
of(Class<UJO> table, String alias, OrmHandler handler)
          Create new Alias with required name
protected  StringBuilder printColumn(MetaColumn column, CharSequence columnAlias, StringBuilder out)
          Returns one column including an default special alias after the 'AS' phrase.
 String table()
          Returns Table with Alias
 String toString()
          Return the same result as table
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AliasTable

public AliasTable(Class<UJO> table,
                  String alias,
                  OrmHandler handler)

AliasTable

protected AliasTable(TableWrapper table,
                     OrmHandler handler)
Method Detail

getDialect

protected SqlDialect getDialect()
Returns SQL Dialect


getTableModel

public TableWrapper getTableModel()
Get table Alias


table

public String table()
             throws IllegalStateException
Returns Table with Alias

Throws:
IllegalStateException

columnAs

public <T> String columnAs(String expression,
                           Key<UJO,T> key)
                throws IllegalStateException
Print one columnAs including alias

Throws:
IllegalStateException

column

public <T> String column(Key<UJO,T> key)
              throws IllegalStateException
Print one columnAs including alias

Throws:
IllegalStateException

columnAs

public <T> String columnAs(Key<UJO,T> key)
                throws IllegalStateException
Returns one column including an default special alias name after the 'AS' phrase.

Throws:
IllegalStateException

columnAs

public <T> String columnAs(Key<UJO,T> key,
                           CharSequence columnAlias)
                throws IllegalStateException
Returns one column including the required alias name after the 'AS' phrase.

Parameters:
key - Related key
columnAlias - an alias String or a Key instance for the key Name, the null value use an Key name.
Returns:
Returns one column including the required alias name after the 'AS' phrase.
Throws:
IllegalStateException

allColumns

public String allColumns()
                  throws IllegalStateException
Call the column() method for all Keys of Ujorm

Throws:
IllegalStateException

allColumns

public String allColumns(boolean includeKeyAlias)
                  throws IllegalStateException
Call the column() method for all Keys of Ujorm

Throws:
IllegalStateException

toString

public String toString()
Return the same result as table

Overrides:
toString in class Object

printColumn

protected StringBuilder printColumn(MetaColumn column,
                                    CharSequence columnAlias,
                                    StringBuilder out)
                             throws IllegalStateException
Returns one column including an default special alias after the 'AS' phrase.

Parameters:
key - Related key
columnAlias - an alias name or a Key instance, the null value use an Key name.
Returns:
Returns one column including an default special alias.
Throws:
IllegalStateException

findColumnModel

protected MetaColumn findColumnModel(Key<UJO,?> key)
                              throws IllegalArgumentException
Find Column Model or throw an IllegalArgumentException.

Throws:
IllegalArgumentException

of

public static <UJO extends OrmUjo> AliasTable<UJO> of(Class<UJO> table,
                                                      String alias,
                                                      OrmHandler handler)
Create new Alias with required name


of

public static <UJO extends OrmUjo> AliasTable<UJO> of(Class<UJO> table,
                                                      OrmHandler handler)
Create new Alias with default name



Copyright 2013, Pavel Ponec