public class SQLStatementGenerator extends Object
PreparedStatement
s.Constructor and Description |
---|
SQLStatementGenerator(SQLDialect dialect) |
Modifier and Type | Method and Description |
---|---|
String |
columnNameList(SQLValue[] columnNames,
boolean placeholders)
Generates a list of column names from the given
String array in the appropriate dialect. |
String |
delete(String tableName,
SQLCondition condition)
Generates a
DELETE statement for a given SQLDialect as follows:
DELETE FROM tableName [WHERE condition] |
SQLDialect |
getDialect() |
String |
innerJoin(String tableName1,
String tableName2,
SQLCondition joinCondition,
SQLCondition queryCondition,
SQLValue[] columnNames)
Generates a
SELECT/INNER JOIN statement for a given SQLDialect as follows:
SELECT columnList FROM tableName1 INNER JOIN tableName2 ON joinCondition [WHERE queryCondition] Whereby columnList is replaced by the wildcard character '* ' if it is null |
String |
insert(String tableName,
SQLValue[] columnNames)
Generates a
INSERT statement for the given SQLDialect as follows:
INSERT INTO tableName (columnName[0], columnName[1], ... columnName[n]) VALUES (? |
String |
placeholderList(int amount)
Generates a list of
PreparedStatement placeholders ('?') |
String |
select(String tableName,
SQLValue[] columnNames,
SQLCondition condition)
Generates a
SELECT statement for the given SQLDialect as follows:
For columnNames == null :SELECT * FROM tableName [WHERE condition] For columnNames ! |
String |
select(String tableName,
SQLValue[] columnNames,
SQLCondition condition,
SQLOrder[] orders)
Generates a
SELECT statement for the given SQLDialect as follows:
For columnNames == null :SELECT * FROM tableName [WHERE condition] For columnNames ! |
String |
selectDistinct(String tableName,
SQLValue[] columnNames,
SQLCondition condition)
Generates a
SELECT DISTINCT statement for the given SQLDialect as follows:
For columnNames == null :SELECT DISTINCT * FROM tableName [WHERE condition] For columnNames ! |
String |
selectDistinct(String tableName,
SQLValue[] columnNames,
SQLCondition condition,
SQLOrder[] orders)
Generates a
SELECT DISTINCT statement for the given SQLDialect as follows:
For columnNames == null :SELECT DISTINCT * FROM tableName [WHERE condition] For columnNames ! |
String |
update(String tableName,
SQLValue[] columnNames,
SQLCondition condition)
Generates a
UPDATE statement for a given SQLDialect as follows:
UPDATE tableName SET columnName[0]=? |
public SQLStatementGenerator(SQLDialect dialect)
dialect
- the SQLDialect
to usepublic String select(String tableName, SQLValue[] columnNames, SQLCondition condition)
SELECT
statement for the given SQLDialect
as follows:
columnNames
== null
:SELECT * FROM tableName [WHERE condition]
columnNames
!= null
:SELECT tableName.columnName[0], tableName.columnName[1], tableName.columName[n] FROM tableName WHERE condition
public String select(String tableName, SQLValue[] columnNames, SQLCondition condition, SQLOrder[] orders)
SELECT
statement for the given SQLDialect
as follows:
columnNames
== null
:SELECT * FROM tableName [WHERE condition]
columnNames
!= null
:SELECT tableName.columnName[0], tableName.columnName[1], tableName.columName[n] FROM tableName WHERE condition
public String selectDistinct(String tableName, SQLValue[] columnNames, SQLCondition condition)
SELECT DISTINCT
statement for the given SQLDialect
as follows:
columnNames
== null
:SELECT DISTINCT * FROM tableName [WHERE condition]
columnNames
!= null
:SELECT DISTINCT tableName.columnName[0], tableName.columnName[1], tableName.columName[n] FROM tableName WHERE condition
public String selectDistinct(String tableName, SQLValue[] columnNames, SQLCondition condition, SQLOrder[] orders)
SELECT DISTINCT
statement for the given SQLDialect
as follows:
columnNames
== null
:SELECT DISTINCT * FROM tableName [WHERE condition]
columnNames
!= null
:SELECT DISTINCT tableName.columnName[0], tableName.columnName[1], tableName.columName[n] FROM tableName WHERE condition
public String insert(String tableName, SQLValue[] columnNames)
INSERT
statement for the given SQLDialect
as follows:
INSERT INTO tableName (columnName[0], columnName[1], ... columnName[n]) VALUES (?, ?, ... ?)
public String update(String tableName, SQLValue[] columnNames, SQLCondition condition)
UPDATE
statement for a given SQLDialect
as follows:
UPDATE tableName SET columnName[0]=?, columnName[1]=?, columnName[n]=? [WHERE condition]
public String delete(String tableName, SQLCondition condition)
DELETE
statement for a given SQLDialect
as follows:
DELETE FROM tableName [WHERE condition]
tableName
- the table from which to delete a relationcondition
- the criteria to determine the relation or null
if all rows
should be deletedDELETE
statement.public String innerJoin(String tableName1, String tableName2, SQLCondition joinCondition, SQLCondition queryCondition, SQLValue[] columnNames)
SELECT/INNER JOIN
statement for a given SQLDialect
as follows:
SELECT columnList FROM tableName1 INNER JOIN tableName2 ON joinCondition [WHERE queryCondition]
columnList
is replaced by the wildcard character '*
' if it is null
tableName1
- the name of the first (left) tabletableName2
- the name of the second (right) tablejoinCondition
- the SQLCondition
on which to perform the joinqueryCondition
- optional SQLCondition
to limit the query furthercolumnNames
- the columns from which to select or null
to insert a wildcardSELECT/INNER JOIN
statementpublic String columnNameList(SQLValue[] columnNames, boolean placeholders)
columnNames
- an array of column names as SQLValue
splaceholders
- append a PreparedStatement
placeholder value ('=?')String
list of namespublic String placeholderList(int amount)
amount
- the amount of placeholers to put in the listPreparedStatement
placeholderspublic SQLDialect getDialect()
Copyright © 2017 Clazzes.org. All rights reserved.