Class 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 Detail

      • database

        public final Database database
      • dialect

        public final Dialect dialect
      • softDeleteEnabled

        public final boolean softDeleteEnabled
      • proxiesEnabled

        public final boolean proxiesEnabled
      • 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
      • getBinariesSql

        protected List<String> getBinariesSql
      • getBinariesColumns

        protected List<Column> getBinariesColumns
    • Constructor Detail

      • 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 Detail

      • getDatabase

        public Database getDatabase()
      • getSelectRootIdSql

        public String getSelectRootIdSql()
      • getSelectRootIdWhatColumn

        public Column getSelectRootIdWhatColumn()
      • getInsertRootIdSql

        public String getInsertRootIdSql()
      • getInsertRootIdColumns

        public List<Column> getInsertRootIdColumns()
      • 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
      • 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

      • getMaximumArgsForIn

        public int getMaximumArgsForIn()