Class SQLInfo

java.lang.Object
org.nuxeo.ecm.core.storage.sql.jdbc.SQLInfo

public class SQLInfo extends Object
This singleton generates and holds the actual SQL DDL and DML statements for the operations needed by the Mapper, given a Model.

It is specific to one SQL dialect.

  • Field Details

    • database

      public final Database database
    • dialect

      public final Dialect dialect
    • softDeleteEnabled

      public final boolean softDeleteEnabled
    • proxiesEnabled

      public final boolean proxiesEnabled
    • selectFragmentById

      public final Map<String,SQLInfo.SQLInfoSelect> selectFragmentById
    • createClusterNodeSql

      protected String createClusterNodeSql
    • createClusterNodeColumns

      protected List<Column> createClusterNodeColumns
    • deleteClusterNodeSql

      protected String deleteClusterNodeSql
    • deleteClusterNodeColumn

      protected Column deleteClusterNodeColumn
    • deleteClusterInvalsSql

      protected String deleteClusterInvalsSql
    • deleteClusterInvalsColumn

      protected Column deleteClusterInvalsColumn
    • clusterInvalidationsColumns

      protected List<Column> clusterInvalidationsColumns
    • sqlStatements

      protected Map<String,List<SQLStatement>> sqlStatements
    • sqlStatementsProperties

      public Map<String,Serializable> sqlStatementsProperties
    • getBinariesSql

      protected List<String> getBinariesSql
    • getBinariesColumns

      protected List<Column> getBinariesColumns
  • Constructor Details

    • SQLInfo

      public SQLInfo(Model model, Dialect dialect, boolean requiresClusterSQL)
      Generates and holds the needed SQL statements given a Model and a Dialect.
      Parameters:
      model - the model
      dialect - the SQL dialect
  • Method Details

    • getDatabase

      public Database getDatabase()
    • getSelectRootIdSql

      public String getSelectRootIdSql()
    • getSelectRootIdWhatColumn

      public Column getSelectRootIdWhatColumn()
    • getInsertRootIdSql

      public String getInsertRootIdSql()
    • getInsertRootIdColumns

      public List<Column> getInsertRootIdColumns()
    • getSelection

      public SQLInfo.SQLInfoSelection getSelection(SelectionType type)
    • getSelectChildrenIdsAndTypesSql

      public String getSelectChildrenIdsAndTypesSql(boolean excludeSpecialChildren, boolean excludeRegularChildren)
    • getSelectChildrenIdsAndTypesWhatColumns

      public List<Column> getSelectChildrenIdsAndTypesWhatColumns()
    • getSelectDescendantsInfoSql

      public String getSelectDescendantsInfoSql()
    • getSelectDescendantsInfoWhatColumns

      public List<Column> getSelectDescendantsInfoWhatColumns()
    • getCreateClusterNodeSql

      public String getCreateClusterNodeSql()
    • getCreateClusterNodeColumns

      public List<Column> getCreateClusterNodeColumns()
    • getDeleteClusterNodeSql

      public String getDeleteClusterNodeSql()
    • getDeleteClusterNodeColumn

      public Column getDeleteClusterNodeColumn()
    • getDeleteClusterInvalsSql

      public String getDeleteClusterInvalsSql()
    • getDeleteClusterInvalsColumn

      public Column getDeleteClusterInvalsColumn()
    • getClusterNodeIdType

      public int getClusterNodeIdType()
    • getClusterInvalidationsColumns

      public List<Column> getClusterInvalidationsColumns()
    • getInsertSql

      public String getInsertSql(String tableName)
      Returns the SQL INSERT to add a row. The columns that represent sequences that are implicitly auto-incremented aren't included.
      Parameters:
      tableName - the table name
      Returns:
      the SQL INSERT statement
    • getInsertColumns

      public List<Column> getInsertColumns(String tableName)
      Returns the list of columns to use for an INSERT statement getInsertSql(java.lang.String).
      Parameters:
      tableName - the table name
      Returns:
      the list of columns
    • getIdEqualsClause

      public String getIdEqualsClause(String tableName)
      Returns the clause used to match a given row by id in the given table.

      Takes into account soft deletes.

      Parameters:
      tableName - the table name
      Returns:
      the clause, like table.id = ?
    • getSoftDeleteClause

      public String getSoftDeleteClause(String tableName)
      Returns AND isdeleted IS NULL if this is the hierarchy table and soft delete is activated.
      Parameters:
      tableName - the table name
      Returns:
      the clause
    • getSoftDeleteClause

      public String getSoftDeleteClause()
      Returns null or AND isdeleted IS NULL if soft delete is activated.
      Returns:
      the clause, or null
    • getUpdateById

      public SQLInfo.SQLInfoSelect getUpdateById(String tableName, RowMapper.RowUpdate rowu)
       UPDATE tableName SET key1 = ?, key2 = ?, ... WHERE id = ? AND condition1 = ? AND condition2 IS NULL ...
       
    • getUpdateByIdForKeys

      public Update getUpdateByIdForKeys(String tableName, List<String> keys)
    • getSelectFragmentsByIds

      public SQLInfo.SQLInfoSelect getSelectFragmentsByIds(String tableName, int nids)
      Select by ids for all values of several fragments.
    • getSelectFragmentsByIds

      public SQLInfo.SQLInfoSelect getSelectFragmentsByIds(String tableName, int nids, String[] orderBys, Set<String> skipColumns)
      Select by ids for all values of several fragments (maybe ordered along columns -- for collection fragments retrieval).
    • getSelectAncestorsIds

      public SQLInfo.SQLInfoSelect getSelectAncestorsIds()
      Select all ancestors ids for several fragments.

      Fast alternative to the slowest iterative getSelectParentIds(int).

      Returns:
      null if it's not possible in one call in this dialect
    • getSelectParentIds

      public SQLInfo.SQLInfoSelect getSelectParentIds(int nids)
      Select parentid by ids for all values of several fragments.
    • getSelectChildrenNodeInfos

      public SQLInfo.SQLInfoSelect getSelectChildrenNodeInfos(int nids)
      Selects all children (not complex) for several parent ids.
    • getDeleteSql

      public String getDeleteSql(String tableName)
      Returns the SQL DELETE to delete a row. The primary key columns are free parameters.
      Parameters:
      tableName - the table name
      Returns:
      the SQL DELETE statement
    • getDeleteSql

      public String getDeleteSql(String tableName, int n)
      Returns the SQL DELETE to delete several rows. The primary key columns are free parameters.
      Parameters:
      tableName - the table name
      n - the number of rows to delete
      Returns:
      the SQL DELETE statement with a IN for the keys
    • getSoftDeleteSql

      public String getSoftDeleteSql()
      Returns the SQL to soft-delete several rows. The array of ids and the time are free parameters.
      Returns:
      the SQL statement
    • getSoftDeleteCleanupSql

      public String getSoftDeleteCleanupSql()
      Returns the SQL to clean (hard-delete) soft-deleted rows. The max and beforeTime are free parameters.
      Returns:
      the SQL statement
    • getCopyHier

      public SQLInfo.SQLInfoSelect getCopyHier(boolean explicitName, boolean resetVersion)
    • getCopySql

      public String getCopySql(String tableName)
    • getCopyIdColumn

      public Column getCopyIdColumn(String tableName)
    • initSQL

      protected void initSQL(boolean requiresClusterSQL)
      Creates all the sql from the models.
    • initClusterSQL

      protected void initClusterSQL()
    • initRepositorySQL

      protected void initRepositorySQL()
      Creates the SQL for the table holding global repository information. This includes the id of the hierarchy root node.
    • initHierarchySQL

      protected void initHierarchySQL()
      Creates the SQL for the table holding hierarchy information.
    • initSelectDescendantsSQL

      protected void initSelectDescendantsSQL()
    • initAncestorsSQL

      protected void initAncestorsSQL()
      Creates the SQL for the table holding ancestors information.

      This table holds trigger-updated information extracted from the recursive parent-child relationship in the hierarchy table.

    • initFragmentSQL

      protected void initFragmentSQL(String tableName)
      Creates the SQL for one fragment (simple or collection).
    • initSelections

      protected void initSelections()
    • makeSelect

      public SQLInfo.SQLInfoSelect makeSelect(Table table, String[] orderBys, String... freeColumns)
      Basic SELECT x, y, z FROM table WHERE a = ? AND b = ?

      with optional ORDER BY x, y DESC

    • makeSelect

      public SQLInfo.SQLInfoSelect makeSelect(Table table, String from, List<String> clauses, String[] orderBys, String... freeColumns)
      Same as above but the FROM can be passed in, to allow JOINs.
    • initSQLStatements

      public void initSQLStatements(Map<String,Serializable> testProps, List<String> sqlInitFiles) throws IOException
      Throws:
      IOException
    • executeSQLStatements

      public void executeSQLStatements(String category, String ddlMode, Connection connection, JDBCLogger logger, SQLStatement.ListCollector ddlCollector) throws SQLException
      Executes the SQL statements for the given category.
      Throws:
      SQLException
    • getMaximumArgsForIn

      public int getMaximumArgsForIn()