ch.sahits.codegen.java.model.util
Class SQLProvider

java.lang.Object
  extended by ch.sahits.codegen.java.model.util.SQLProvider

public final class SQLProvider
extends java.lang.Object

This class produces different SQL statement strings based on the database model DataBaseTable

Since:
0.9.0
Author:
Andi Hotz

Constructor Summary
SQLProvider(DataBaseTable _model)
          Initialize the model
SQLProvider(DataBaseTable _model, boolean exteranlValue)
          Initialize the model
 
Method Summary
 java.lang.String getInsertSQL(java.util.List<Pair> values)
          Generate the insert SQL for the listed values
 java.lang.String getSelectAllSQL()
          Generate the insert SQL to select all records of a table
 java.lang.String getSelectByIndex(java.util.List<Pair> values, java.lang.String indexName)
          Generate the select SQL by the index of the given name.
 java.lang.String getSelectByIndex(java.util.List<Pair> values, java.lang.String indexName, java.util.List<java.lang.String> select)
          Generate the select SQL with only specified fields by the index of the given name.
 java.lang.String getSelectUnique(java.util.List<Pair> values)
          Generate the select SQL by the unique index which's name starts with 'PK_'.
 java.lang.String getSelectUnique(java.util.List<Pair> values, java.util.List<java.lang.String> select)
          Generate the select SQL with only specified fields by the unique index which's name starts with 'PK_'.
 java.lang.String getUpdateAllSQL(java.util.List<Pair> values)
          Generates an update SQL for all records in the database
 java.lang.String getUpdateSQL(java.util.List<Pair> values)
          Generate an update SQL for all fields of the model that are not contained in the unique index that name does not start with 'PK_'.
 java.lang.String getUpdateSQL(java.util.List<Pair> values, java.lang.String indexName)
          Generate an update SQL for all fields of the model that are not contained in the indicated index.
 java.lang.String getWhereClause(DataBaseTableIndex index, java.util.List<Pair> values)
          Create the partial String of the where clause based on the index and the provided values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLProvider

public SQLProvider(DataBaseTable _model)
Initialize the model

Parameters:
_model - of the table

SQLProvider

public SQLProvider(DataBaseTable _model,
                   boolean exteranlValue)
Initialize the model

Parameters:
_model - of the table
exteranlValue - Flag indicating if the values are values or method calls
Method Detail

getUpdateSQL

public java.lang.String getUpdateSQL(java.util.List<Pair> values)
Generate an update SQL for all fields of the model that are not contained in the unique index that name does not start with 'PK_'. If there are several unique indexes that start with 'PK_' only the first will be used. Should you explicitly wish to use another use the method getUpdateSQL(List)

Parameters:
values - List of key value pairs that correspondent with the database fields that are to be updated
Returns:
update sql

getUpdateSQL

public java.lang.String getUpdateSQL(java.util.List<Pair> values,
                                     java.lang.String indexName)
Generate an update SQL for all fields of the model that are not contained in the indicated index.

Parameters:
values - List of key value pairs that correspondent with the database fields that are to be updated
indexName - name of the index
Returns:
update sql

getUpdateAllSQL

public java.lang.String getUpdateAllSQL(java.util.List<Pair> values)
Generates an update SQL for all records in the database

Parameters:
values - List of key value pairs that correspondent with the database fields that are to be updated
Returns:
update sql

getInsertSQL

public java.lang.String getInsertSQL(java.util.List<Pair> values)
Generate the insert SQL for the listed values

Parameters:
values - List of key value pairs that correspondent with the database fields that are to be inserted
Returns:
insert SQL

getSelectAllSQL

public java.lang.String getSelectAllSQL()
Generate the insert SQL to select all records of a table

Returns:
the select SQL

getSelectUnique

public java.lang.String getSelectUnique(java.util.List<Pair> values)
Generate the select SQL by the unique index which's name starts with 'PK_'. If there are several unique indexes that start with 'PK_' only the first will be used. Should you explicitly wish to use another use the method getSelectByIndex(List,String,List)

Parameters:
values - List of key value pairs that correspondent with the database fields that are to be updated
Returns:
the select SQL

getSelectByIndex

public java.lang.String getSelectByIndex(java.util.List<Pair> values,
                                         java.lang.String indexName)
Generate the select SQL by the index of the given name.

Parameters:
values - List of key value pairs that correspondent with the database fields that are to be updated
indexName - name of the index
Returns:
the select SQL

getSelectUnique

public java.lang.String getSelectUnique(java.util.List<Pair> values,
                                        java.util.List<java.lang.String> select)
Generate the select SQL with only specified fields by the unique index which's name starts with 'PK_'. If there are several unique indexes that start with 'PK_' only the first will be used. Should you explicitly wish to use another use the method getSelectByIndex(List,String,List)

Parameters:
values - List of key value pairs that correspondent with the database fields that are to be updated
select - List of the fields to show up in the select statement
Returns:
the select SQL

getSelectByIndex

public java.lang.String getSelectByIndex(java.util.List<Pair> values,
                                         java.lang.String indexName,
                                         java.util.List<java.lang.String> select)
Generate the select SQL with only specified fields by the index of the given name.

Parameters:
values - List of key value pairs that correspondent with the database fields that are to be updated
indexName - name of the index
select - List of the fields to show up in the select statement
Returns:
the select SQL

getWhereClause

public java.lang.String getWhereClause(DataBaseTableIndex index,
                                       java.util.List<Pair> values)
Create the partial String of the where clause based on the index and the provided values

Parameters:
index - to be used
values - List with values
Returns:
where clause