Class ConnectedQueryBuilder


  • public final class ConnectedQueryBuilder
    extends QueryBuilder

    Use this query builder with overloaded methods if the instance is supposed to be short-lived (e. g.: stored in a local variable), so that there's little chance that the underlying database connection is interrupted. Otherwise, use the base implementation whose methods additionally accept an instance of DBFunctions.

    Since:
    2017.2.1
    Author:
    Andrey Shcheglov <mailto:andrey.shcheglov@jetbrains.com>
    See Also:
    QueryBuilder, DBFunctions
    • Constructor Detail

      • ConnectedQueryBuilder

        public ConnectedQueryBuilder​(@NotNull
                                     DBFunctions dbf)

        Creates a new query builder with a persistent underlying database connection.

        Parameters:
        dbf - the database connection.
    • Method Detail

      • buildSchema

        public static void buildSchema​(@NotNull
                                       DBFunctions dbf,
                                       @NotNull
                                       SchemaDef schemaDef)
        Generates schema from schemaDef, without commit
        Parameters:
        dbf -
        schemaDef -
        Since:
        2018.2
      • genCreateSchemaCompletely

        @NotNull
        public String[] genCreateSchemaCompletely​(@NotNull
                                                  SchemaDef schema)

        Generates the complete DDL script for creating a database. Key and index definitions are inlined if possible. Temporary tables are included if they are permanent.

        Parameters:
        schema - the definition of the schema to generate.
        Returns:
        the generated DDL statements.
        See Also:
        QueryBuilder.genCreateSchemaCompletely(SchemaDef, DBFunctions)
      • genPerSessionScript

        @NotNull
        public String[] genPerSessionScript​(@NotNull
                                            SchemaDef schema)

        Generates the DDL script that should be executed at the beginning of each database session.

        Parameters:
        schema - the schema definition to extract temporary table definitions from.
        Returns:
        the generated DDL statements.
        See Also:
        QueryBuilder.genPerSessionScript(SchemaDef, DBFunctions)
      • genCreateTablesOnly

        @NotNull
        public String[] genCreateTablesOnly​(@NotNull
                                            SchemaDef schema,
                                            @NotNull
                                            Set<String> tableNames)

        Generates the DDL script for creating tables without indices (if any). For permanent tables, only clustered key definitions are issued. For temporary tables, all key and index definitions (if any) are issued.

        Parameters:
        schema - the schema definition to extract table definitions from.
        tableNames - the extra filter on the tables contained by schema (only the intersection of schema and tableNames is processed). If tableNames is empty, an empty array is returned.
        Returns:
        the generated DDL statements.
        See Also:
        QueryBuilder.genCreateTablesOnly(SchemaDef, Set, DBFunctions)
      • genCreateBackupTables

        @NotNull
        public String[] genCreateBackupTables​(@NotNull
                                              SchemaDef schema,
                                              @NotNull
                                              String suffix)

        Generates the DDL for all tables in the schema, with suffix appended to the name of each table.

        Parameters:
        schema - the schema definition to extract table definitions from.
        suffix - the suffix to append to the name of the table, or an empty string if table name transformation is not required.
        Returns:
        the generated DDL statements.
        See Also:
        QueryBuilder.genCreateBackupTables(SchemaDef, String, DBFunctions)
      • genCreateTableCompletely

        @NotNull
        public String[] genCreateTableCompletely​(@NotNull
                                                 TableDef table)

        Generates the DDL statement(s) for creating the specified table along with its keys and indices (if any). If the table contains no keys or indices or their definitions can be inlined, only a single DDL statement is returned.

        Parameters:
        table - the definition of the table to generate.
        Returns:
        the generated DDL statement(s).
        See Also:
        QueryBuilder.genCreateTableCompletely(TableDef, DBFunctions)