Package org.apache.torque.sql
Class SqlBuilder
- java.lang.Object
-
- org.apache.torque.sql.SqlBuilder
-
public final class SqlBuilder extends Object
Factored out code that is used to process SQL tables. This code comes from BasePeer and is put here to reduce complexity in the BasePeer class. You should not use the methods here directly!- Version:
- $Id: SqlBuilder.java 1870542 2019-11-28 09:32:40Z tv $
- Author:
- Henning P. Schmiedehausen, Thomas Fischer
-
-
Field Summary
Fields Modifier and Type Field Description static String[]
FUNCTION_DELIMITERS
Delimiters for SQL functions.protected static org.apache.logging.log4j.Logger
log
Logging
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Query
buildQuery(Criteria crit)
Builds a Query from a criteria.static String
getFullTableName(String table, String dbName)
Fully qualify a table name with an optional schema reference.static TableMap
getTableMap(String tableName, String dbName)
Returns the table map for a table.static String
getUnqualifiedName(String name, String dbName)
Unqualify a table or column name.static List<WhereClausePsPartBuilder>
getWhereClausePsPartBuilders()
Returns the Builders which are responsible to render single where clause conditions.static String
guessFullTableFromCriteria(Criteria criteria)
Guesses a table name from a criteria by inspecting the first column in the criteria.
-
-
-
Field Detail
-
log
protected static final org.apache.logging.log4j.Logger log
Logging
-
FUNCTION_DELIMITERS
public static final String[] FUNCTION_DELIMITERS
Delimiters for SQL functions.
-
-
Method Detail
-
getWhereClausePsPartBuilders
public static List<WhereClausePsPartBuilder> getWhereClausePsPartBuilders()
Returns the Builders which are responsible to render single where clause conditions. The returned list can be modified in order to change the rendered SQL.- Returns:
- the current WhereClausePsPartBuilders, not null.
-
buildQuery
public static Query buildQuery(Criteria crit) throws TorqueException
Builds a Query from a criteria.- Parameters:
crit
- the criteria to build the query from, not null.- Returns:
- the corresponding query to the criteria.
- Throws:
TorqueException
- if an error occurs
-
getFullTableName
public static String getFullTableName(String table, String dbName) throws TorqueException
Fully qualify a table name with an optional schema reference.- Parameters:
table
- The table name to use. If null is passed in, null is returned.dbName
- The name of the database to which this tables belongs. If null is passed, the default database is used.- Returns:
- The table name to use inside the SQL statement. If null is passed into this method, null is returned.
- Throws:
TorqueException
- if Torque is not yet initialized.
-
getUnqualifiedName
public static String getUnqualifiedName(String name, String dbName) throws TorqueException
Unqualify a table or column name.- Parameters:
name
- the name to unqualify. If null is passed in, null is returned.dbName
- name of the database- Returns:
- The unqualified name.
- Throws:
TorqueException
- if the name cannot be determined.
-
guessFullTableFromCriteria
public static String guessFullTableFromCriteria(Criteria criteria) throws TorqueException
Guesses a table name from a criteria by inspecting the first column in the criteria.- Parameters:
criteria
- the criteria to guess the table name from.- Returns:
- the table name, not null.
- Throws:
TorqueException
- if the table name cannot be determined.
-
getTableMap
public static TableMap getTableMap(String tableName, String dbName) throws TorqueException
Returns the table map for a table.- Parameters:
tableName
- the name of the table.dbName
- the name of the database, null for the default db.- Returns:
- the table map for the table, not null.
- Throws:
TorqueException
- if the database or table is unknown.
-
-