Class H2Utils


  • public class H2Utils
    extends Object
    H2 utility methods.
    • Field Detail

      • EMPTY_COLUMNS

        public static final org.h2.table.IndexColumn[] EMPTY_COLUMNS
    • Method Detail

      • equals

        public static boolean equals​(org.h2.table.IndexColumn c1,
                                     org.h2.table.IndexColumn c2)
        Parameters:
        c1 - First column.
        c2 - Second column.
        Returns:
        true If they are the same.
      • tableCreateSql

        public static String tableCreateSql​(H2TableDescriptor tbl)
        Prepare SQL statement for CREATE TABLE command.
        Parameters:
        tbl - Table descriptor.
        Returns:
        SQL.
      • indexCreateSql

        public static String indexCreateSql​(String fullTblName,
                                            org.h2.index.Index h2Idx,
                                            boolean ifNotExists)
        Generate CREATE INDEX SQL statement for given params.
        Parameters:
        fullTblName - Fully qualified table name.
        h2Idx - H2 index.
        ifNotExists - Quietly skip index creation if it exists.
        Returns:
        Statement string.
      • indexColumnsSql

        public static String indexColumnsSql​(org.h2.table.IndexColumn[] idxCols)
        Generate String represenation of given indexed columns.
        Parameters:
        idxCols - Indexed columns.
        Returns:
        String represenation of given indexed columns.
      • indexDropSql

        public static String indexDropSql​(String schemaName,
                                          String idxName,
                                          boolean ifExists)
        Generate CREATE INDEX SQL statement for given params.
        Parameters:
        schemaName - Quoted schema name.
        idxName - Index name.
        ifExists - Quietly skip index drop if it exists.
        Returns:
        Statement string.
      • createSpatialIndex

        public static GridH2IndexBase createSpatialIndex​(GridH2Table tbl,
                                                         IndexDescriptor idxDesc,
                                                         List<org.h2.table.IndexColumn> cols)
        Create spatial index.
        Parameters:
        tbl - Table.
        idxDesc - Index descriptor.
        cols - Columns.
      • checkSpatialIndexEnabled

        public static boolean checkSpatialIndexEnabled()
        Check if spatial indexes are enabled.
      • withQuotes

        public static String withQuotes​(String str)
        Add quotes around the name.
        Parameters:
        str - String.
        Returns:
        String with quotes.
      • session

        public static org.h2.engine.Session session​(H2PooledConnection c)
        Parameters:
        c - Connection.
        Returns:
        Session.
      • session

        public static org.h2.engine.Session session​(Connection c)
        Parameters:
        c - Connection.
        Returns:
        Session.
      • setupConnection

        public static void setupConnection​(H2PooledConnection conn,
                                           QueryContext qctx,
                                           boolean distributedJoins,
                                           boolean enforceJoinOrder)
        Parameters:
        conn - Connection to use.
        qctx - Query context.
        distributedJoins - If distributed joins are enabled.
        enforceJoinOrder - Enforce join order of tables.
      • setupConnection

        public static void setupConnection​(H2PooledConnection conn,
                                           QueryContext qctx,
                                           boolean distributedJoins,
                                           boolean enforceJoinOrder,
                                           boolean lazy)
        Parameters:
        conn - Connection to use.
        qctx - Query context.
        distributedJoins - If distributed joins are enabled.
        enforceJoinOrder - Enforce join order of tables.
        lazy - Lazy query execution mode.
      • resetSession

        public static void resetSession​(H2PooledConnection conn)
        Clean up session for further reuse.
        Parameters:
        conn - Connection to use.
      • context

        public static QueryContext context​(org.h2.engine.Session ses)
        Parameters:
        ses - Session.
        Returns:
        Query context.
      • zeroCursor

        public static QueryCursorImpl<List<?>> zeroCursor()
        Returns:
        Single-column, single-row cursor with 0 as number of updated records.
      • checkAndStartNotStartedCache

        public static boolean checkAndStartNotStartedCache​(GridKernalContext ctx,
                                                           GridCacheContextInfo<?,​?> cacheInfo)
        Check that given cache is not started and start it for such case.
        Parameters:
        cacheInfo - Cache context info.
        Returns:
        true in case not started and has been started.
      • toRowMessage

        public static GridH2RowMessage toRowMessage​(org.h2.result.Row row)
        Parameters:
        row - Row.
        Returns:
        Row message.
      • retryException

        public static GridH2RetryException retryException​(String msg)
        Create retry exception for distributed join.
        Parameters:
        msg - Message.
        Returns:
        Exception.
      • bubbleUp

        public static <Z> void bubbleUp​(Z[] arr,
                                        int off,
                                        Comparator<Z> cmp)
        Parameters:
        arr - Array.
        off - Offset.
        cmp - Comparator.
      • queryEngine

        public static String queryEngine()
        Returns:
        Query engine name.
      • getter

        public static <T,​R> H2Utils.Getter<T,​R> getter​(Class<? extends T> cls,
                                                                   String fldName)
        Parameters:
        cls - Class.
        fldName - Fld name.
      • setter

        public static <T,​R> H2Utils.Setter<T,​R> setter​(Class<? extends T> cls,
                                                                   String fldName)
        Parameters:
        cls - Class.
        fldName - Fld name.