Class H2Utils
- java.lang.Object
-
- org.apache.ignite.internal.processors.query.h2.H2Utils
-
public class H2Utils extends Object
H2 utility methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classH2Utils.Getter<T,R>Field getter.static classH2Utils.Setter<T,R>Field getter.static classH2Utils.ValueRuntimeSimpleObject<T>
-
Field Summary
Fields Modifier and Type Field Description static org.h2.table.IndexColumn[]EMPTY_COLUMNSstatic StringQCTX_VARIABLE_NAMEQuery context H2 variable name.static List<GridQueryFieldMetadata>UPDATE_RESULT_METADummy metadata for update result.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidbindParameters(PreparedStatement stmt, @Nullable Collection<Object> params)Binds parameters to prepared statement.static <Z> voidbubbleUp(Z[] arr, int off, Comparator<Z> cmp)static booleancheckAndStartNotStartedCache(GridKernalContext ctx, GridCacheContextInfo<?,?> cacheInfo)Check that given cache is not started and start it for such case.static voidcheckQuery(IgniteH2Indexing idx, List<Integer> cacheIds, Collection<QueryTable> tbls)Check if query is valid.static booleancheckSpatialIndexEnabled()Check if spatial indexes are enabled.static List<Integer>collectCacheIds(IgniteH2Indexing idx, @Nullable Integer mainCacheId, Collection<QueryTable> tbls)Collect cache identifiers from two-step query.static QueryContextcontext(H2PooledConnection conn)static QueryContextcontext(org.h2.engine.Session ses)static Objectconvert(Object val, CacheObjectValueContext coCtx, int type)Convert value to column's expected type by means of H2.static GridH2IndexBasecreateSpatialIndex(GridH2Table tbl, IndexDescriptor idxDesc, List<org.h2.table.IndexColumn> cols)Create spatial index.static booleanequals(org.h2.table.IndexColumn c1, org.h2.table.IndexColumn c2)static StringgenerateFieldsQueryString(String qry, String tableAlias, H2TableDescriptor tbl)Generate SqlFieldsQuery string from SqlQuery.static <T,R>
H2Utils.Getter<T,R>getter(Class<? extends T> cls, String fldName)static StringindexColumnsSql(org.h2.table.IndexColumn[] idxCols)Generate String represenation of given indexed columns.static StringindexCreateSql(String fullTblName, org.h2.index.Index h2Idx, boolean ifNotExists)GenerateCREATE INDEXSQL statement for given params.static StringindexDropSql(String schemaName, String idxName, boolean ifExists)GenerateCREATE INDEXSQL statement for given params.static List<GridQueryFieldMetadata>meta(ResultSetMetaData rsMeta)static List<JdbcParameterMeta>parametersMeta(ParameterMetaData h2ParamsMeta)Converts h2 parameters metadata to Ignite one.static StringqueryEngine()static voidresetSession(H2PooledConnection conn)Clean up session for further reuse.static GridH2RetryExceptionretryException(String msg)Create retry exception for distributed join.static org.h2.engine.Sessionsession(Connection c)static org.h2.engine.Sessionsession(H2PooledConnection c)static <T,R>
H2Utils.Setter<T,R>setter(Class<? extends T> cls, String fldName)static voidsetupConnection(H2PooledConnection conn, QueryContext qctx, boolean distributedJoins, boolean enforceJoinOrder)static voidsetupConnection(H2PooledConnection conn, QueryContext qctx, boolean distributedJoins, boolean enforceJoinOrder, boolean lazy)static StringtableCreateSql(H2TableDescriptor tbl)Prepare SQL statement for CREATE TABLE command.static GridH2RowMessagetoRowMessage(org.h2.result.Row row)static StringwithQuotes(String str)Add quotes around the name.static org.h2.value.Valuewrap(CacheObjectValueContext coCtx, Object obj, int type)Wraps object to respectiveValue.static QueryCursorImpl<List<?>>zeroCursor()
-
-
-
Field Detail
-
QCTX_VARIABLE_NAME
public static final String QCTX_VARIABLE_NAME
Query context H2 variable name.- See Also:
- Constant Field Values
-
EMPTY_COLUMNS
public static final org.h2.table.IndexColumn[] EMPTY_COLUMNS
-
UPDATE_RESULT_META
public static final List<GridQueryFieldMetadata> UPDATE_RESULT_META
Dummy metadata for update result.
-
-
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:
trueIf 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)
GenerateCREATE INDEXSQL 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)
GenerateCREATE INDEXSQL 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.
-
meta
public static List<GridQueryFieldMetadata> meta(ResultSetMetaData rsMeta) throws SQLException
- Parameters:
rsMeta- Metadata.- Returns:
- List of fields metadata.
- Throws:
SQLException- If failed.
-
parametersMeta
public static List<JdbcParameterMeta> parametersMeta(ParameterMetaData h2ParamsMeta) throws IgniteCheckedException
Converts h2 parameters metadata to Ignite one.- Parameters:
h2ParamsMeta- parameters metadata returned by h2.- Returns:
- Descriptions of the parameters.
- Throws:
IgniteCheckedException
-
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(H2PooledConnection conn)
- Parameters:
conn- Connection to use.- Returns:
- Query context.
-
context
public static QueryContext context(org.h2.engine.Session ses)
- Parameters:
ses- Session.- Returns:
- Query context.
-
convert
public static Object convert(Object val, CacheObjectValueContext coCtx, int type) throws IgniteCheckedException
Convert value to column's expected type by means of H2.- Parameters:
val- Source value.coCtx- Cache object context.type- Expected column type to convert to.- Returns:
- Converted object.
- Throws:
IgniteCheckedException- if failed.
-
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:
truein case not started and has been started.
-
wrap
public static org.h2.value.Value wrap(CacheObjectValueContext coCtx, Object obj, int type) throws IgniteCheckedException
Wraps object to respectiveValue.- Parameters:
obj- Object.type- Value type.- Returns:
- Value.
- Throws:
IgniteCheckedException- If failed.
-
generateFieldsQueryString
public static String generateFieldsQueryString(String qry, String tableAlias, H2TableDescriptor tbl) throws IgniteCheckedException
Generate SqlFieldsQuery string from SqlQuery.- Parameters:
qry- Query string.tableAlias- table alias.tbl- Table to use.- Returns:
- Prepared statement.
- Throws:
IgniteCheckedException- In case of error.
-
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.
-
bindParameters
public static void bindParameters(PreparedStatement stmt, @Nullable @Nullable Collection<Object> params) throws IgniteCheckedException
Binds parameters to prepared statement.- Parameters:
stmt- Prepared statement.params- Parameters collection.- Throws:
IgniteCheckedException- If failed.
-
bubbleUp
public static <Z> void bubbleUp(Z[] arr, int off, Comparator<Z> cmp)- Parameters:
arr- Array.off- Offset.cmp- Comparator.
-
collectCacheIds
public static List<Integer> collectCacheIds(IgniteH2Indexing idx, @Nullable @Nullable Integer mainCacheId, Collection<QueryTable> tbls)
Collect cache identifiers from two-step query.- Parameters:
mainCacheId- Id of main cache.- Returns:
- Result.
-
checkQuery
public static void checkQuery(IgniteH2Indexing idx, List<Integer> cacheIds, Collection<QueryTable> tbls)
Check if query is valid.- Parameters:
idx- Indexing.cacheIds- Cache IDs.tbls- Tables.
-
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.
-
-