org.silverpeas.jdbc
Class JdbcSqlQuery

java.lang.Object
  extended by org.silverpeas.jdbc.JdbcSqlQuery

public class JdbcSqlQuery
extends Object

This class permits to build easily a SQL query with parameters. It permits also to execute directly the query.

Author:
Yohann Chastagnier

Nested Class Summary
static class JdbcSqlQuery.Configuration
          Context of execution that has to be taken into account.
 
Method Summary
 JdbcSqlQuery addField(String fieldName, String definition)
          Centralization in order to populate the prepare statement parameters (FOR TABLE CREATION ONLY).
 JdbcSqlQuery addInsertParam(String paramName, Object paramValue)
          Centralization in order to populate the prepare statement parameters for insertion.
 JdbcSqlQuery addSaveParam(String paramName, Object paramValue, boolean isInsert)
          Centralization in order to populate the prepare statement parameters.
 JdbcSqlQuery addSqlPart(String sqlPart, Collection<?> paramValues)
          Centralization in order to populate the prepare statement parameters.
 JdbcSqlQuery addSqlPart(String sqlPart, Object... paramValue)
          Centralization in order to populate the prepare statement parameters.
 JdbcSqlQuery addUpdateParam(String paramName, Object paramValue)
          Centralization in order to populate the prepare statement parameters for update.
 JdbcSqlQuery and(String sqlPart, Collection<?> paramValues)
          Centralization in order to populate the prepare statement parameters.
 JdbcSqlQuery and(String sqlPart, Object... paramValue)
          Centralization in order to populate the prepare statement parameters.
static JdbcSqlQuery create(String sqlPart, Collection<?> paramValue)
          Creates a new instance of the SQL builder initialized with the given sql part.
static JdbcSqlQuery create(String sqlPart, Object... paramValue)
          Creates a new instance of the SQL builder initialized with the given sql part.
static JdbcSqlQuery createCountFor(String tableName)
          Creates a new instance of the SQL builder initialized for count.
static JdbcSqlQuery createDeleteFor(String tableName)
          Creates a new instance of the SQL builder initialized for delete.
static JdbcSqlQuery createDropFor(String tableName)
          Creates a new instance of the SQL builder initialized for delete.
static JdbcSqlQuery createInsertFor(String tableName)
          Creates a new instance of the SQL builder initialized for insert.
static JdbcSqlQuery createSelect(String sqlPart, Collection<?> paramValue)
          Creates a new instance of the SQL builder initialized with the given sql part.
static JdbcSqlQuery createSelect(String sqlPart, Object... paramValue)
          Creates a new instance of the SQL builder initialized with the given sql part.
static JdbcSqlQuery createTable(String tableName)
          Creates a new instance of the SQL builder initialized for table creation.
static JdbcSqlQuery createUpdateFor(String tableName)
          Creates a new instance of the SQL builder initialized for update.
 long execute()
          Modify executor.
<ROW_ENTITY>
List<ROW_ENTITY>
execute(SelectResultRowProcess<ROW_ENTITY> process)
          Select executor.
<ROW_ENTITY>
ROW_ENTITY
executeUnique(SelectResultRowProcess<ROW_ENTITY> process)
          Select executor.
 Collection<?> getParameters()
          Gets the parameters to apply to the SQL query.
 String getSqlQuery()
          Gets the built SQL query.
 JdbcSqlQuery in(Collection<?> parameters)
          Centralization in order to build easily a SQL in clause.
 JdbcSqlQuery in(Object... parameters)
          Centralization in order to build easily a SQL in clause.
static boolean isSqlDefined(String sqlValue)
          Indicates if the specified value is defined in point of view of SQL.
 JdbcSqlQuery or(String sqlPart, Collection<?> paramValues)
          Centralization in order to populate the prepare statement parameters.
 JdbcSqlQuery or(String sqlPart, Object... paramValue)
          Centralization in order to populate the prepare statement parameters.
static
<ENTITY> ENTITY
unique(List<ENTITY> entities)
          Gets from a entity list the unique entity expected.
 JdbcSqlQuery where(String sqlPart, Collection<?> paramValues)
          Centralization in order to populate the prepare statement parameters.
 JdbcSqlQuery where(String sqlPart, Object... paramValue)
          Centralization in order to populate the prepare statement parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isSqlDefined

public static boolean isSqlDefined(String sqlValue)
Indicates if the specified value is defined in point of view of SQL.

Parameters:
sqlValue - the value to verify.
Returns:
true if defined, false otherwise.

unique

public static <ENTITY> ENTITY unique(List<ENTITY> entities)
Gets from a entity list the unique entity expected.

Parameters:
entities - the entity list.
Returns:
the unique entity result.
Throws:
IllegalArgumentException - if it exists more than one entity in the specified list.

create

public static JdbcSqlQuery create(String sqlPart,
                                  Object... paramValue)
Creates a new instance of the SQL builder initialized with the given sql part.

Parameters:
sqlPart - the sql part to append.
paramValue - the value of parameters included into the given sqlPart.
Returns:
the instance of the new builder.

create

public static JdbcSqlQuery create(String sqlPart,
                                  Collection<?> paramValue)
Creates a new instance of the SQL builder initialized with the given sql part.

Parameters:
sqlPart - the sql part to append.
paramValue - the value of parameters included into the given sqlPart.
Returns:
the instance of the new builder.

createSelect

public static JdbcSqlQuery createSelect(String sqlPart,
                                        Object... paramValue)
Creates a new instance of the SQL builder initialized with the given sql part.

Parameters:
sqlPart - the sql part to append.
paramValue - the value of parameters included into the given sqlPart.
Returns:
the instance of the new builder.

createSelect

public static JdbcSqlQuery createSelect(String sqlPart,
                                        Collection<?> paramValue)
Creates a new instance of the SQL builder initialized with the given sql part.

Parameters:
sqlPart - the sql part to append.
paramValue - the value of parameters included into the given sqlPart.
Returns:
the instance of the new builder.

createCountFor

public static JdbcSqlQuery createCountFor(String tableName)
Creates a new instance of the SQL builder initialized for count.

Parameters:
tableName - the table name aimed by the count.
Returns:
the instance of the new builder.

createTable

public static JdbcSqlQuery createTable(String tableName)
Creates a new instance of the SQL builder initialized for table creation.

Parameters:
tableName - the table name aimed by the insert.
Returns:
the instance of the new builder.

createInsertFor

public static JdbcSqlQuery createInsertFor(String tableName)
Creates a new instance of the SQL builder initialized for insert.

Parameters:
tableName - the table name aimed by the insert.
Returns:
the instance of the new builder.

createUpdateFor

public static JdbcSqlQuery createUpdateFor(String tableName)
Creates a new instance of the SQL builder initialized for update.

Parameters:
tableName - the table name aimed by the update.
Returns:
the instance of the new builder.

createDeleteFor

public static JdbcSqlQuery createDeleteFor(String tableName)
Creates a new instance of the SQL builder initialized for delete.

Parameters:
tableName - the table name aimed by the delete.
Returns:
the instance of the new builder.

createDropFor

public static JdbcSqlQuery createDropFor(String tableName)
Creates a new instance of the SQL builder initialized for delete.

Parameters:
tableName - the table name aimed by the drop.
Returns:
the instance of the new builder.

getSqlQuery

public String getSqlQuery()
Gets the built SQL query.

Returns:
the SQL query.

getParameters

public Collection<?> getParameters()
Gets the parameters to apply to the SQL query.

Returns:
the parameters to apply to the SQL query.

addField

public JdbcSqlQuery addField(String fieldName,
                             String definition)
Centralization in order to populate the prepare statement parameters (FOR TABLE CREATION ONLY).

Parameters:
fieldName - the name of the field to define.
definition - the definition of the field.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

where

public JdbcSqlQuery where(String sqlPart,
                          Object... paramValue)
Centralization in order to populate the prepare statement parameters.

Parameters:
sqlPart - the SQL part that contains the parameter.
paramValue - the value of parameters included into the given sqlPart.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

where

public JdbcSqlQuery where(String sqlPart,
                          Collection<?> paramValues)
Centralization in order to populate the prepare statement parameters.

Parameters:
sqlPart - the SQL part that contains the parameter.
paramValues - the value of parameters included into the given sqlPart.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

and

public JdbcSqlQuery and(String sqlPart,
                        Object... paramValue)
Centralization in order to populate the prepare statement parameters.

Parameters:
sqlPart - the SQL part that contains the parameter.
paramValue - the value of parameters included into the given sqlPart.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

and

public JdbcSqlQuery and(String sqlPart,
                        Collection<?> paramValues)
Centralization in order to populate the prepare statement parameters.

Parameters:
sqlPart - the SQL part that contains the parameter.
paramValues - the value of parameters included into the given sqlPart.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

or

public JdbcSqlQuery or(String sqlPart,
                       Object... paramValue)
Centralization in order to populate the prepare statement parameters.

Parameters:
sqlPart - the SQL part that contains the parameter.
paramValue - the value of parameters included into the given sqlPart.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

or

public JdbcSqlQuery or(String sqlPart,
                       Collection<?> paramValues)
Centralization in order to populate the prepare statement parameters.

Parameters:
sqlPart - the SQL part that contains the parameter.
paramValues - the value of parameters included into the given sqlPart.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

addSqlPart

public JdbcSqlQuery addSqlPart(String sqlPart,
                               Object... paramValue)
Centralization in order to populate the prepare statement parameters.

Parameters:
sqlPart - the SQL part that contains the parameter.
paramValue - the value of parameters included into the given sqlPart.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

addSqlPart

public JdbcSqlQuery addSqlPart(String sqlPart,
                               Collection<?> paramValues)
Centralization in order to populate the prepare statement parameters.

Parameters:
sqlPart - the SQL part that contains the parameter.
paramValues - the value of parameters included into the given sqlPart.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

in

public JdbcSqlQuery in(Collection<?> parameters)
Centralization in order to build easily a SQL in clause.

Parameters:
parameters - the parameters to append to the given SQL query.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

in

public JdbcSqlQuery in(Object... parameters)
Centralization in order to build easily a SQL in clause.

Parameters:
parameters - the parameters to append to the given SQL query.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

addInsertParam

public JdbcSqlQuery addInsertParam(String paramName,
                                   Object paramValue)
Centralization in order to populate the prepare statement parameters for insertion.

Parameters:
paramName - the name of the parameter to add into update fields part.
paramValue - the value of the parameter.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

addUpdateParam

public JdbcSqlQuery addUpdateParam(String paramName,
                                   Object paramValue)
Centralization in order to populate the prepare statement parameters for update.

Parameters:
paramName - the name of the parameter to add into update fields part.
paramValue - the value of the parameter.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

addSaveParam

public JdbcSqlQuery addSaveParam(String paramName,
                                 Object paramValue,
                                 boolean isInsert)
Centralization in order to populate the prepare statement parameters.

Parameters:
paramName - the name of the parameter to add into update fields part.
paramValue - the value of the parameter.
isInsert - indicates if the SQL built is an INSERT or an UPDATE one.
Returns:
the instance of JdbcSqlQuery that represents the SQL query.

execute

public <ROW_ENTITY> List<ROW_ENTITY> execute(SelectResultRowProcess<ROW_ENTITY> process)
                         throws SQLException
Select executor.

Throws:
SQLException

executeUnique

public <ROW_ENTITY> ROW_ENTITY executeUnique(SelectResultRowProcess<ROW_ENTITY> process)
                         throws SQLException
Select executor.

Throws:
SQLException

execute

public long execute()
             throws SQLException
Modify executor.

Throws:
SQLException


Copyright © 2016 Silverpeas. All Rights Reserved.