/** * @param stmt Statement to rewrite, if needed. * @param inTx Whether there is an active transaction. * @return Query with {@code key} and {@code val} columns appended to the list of columns, * if it's an {@code FOR UPDATE} query, or {@code null} if nothing has to be done. */ @NotNull public static String rewriteQueryForUpdateIfNeeded(GridSqlStatement stmt, boolean inTx) { // We have checked above that it's not an UNION query, so it's got to be SELECT. assert stmt instanceof GridSqlSelect; GridSqlSelect sel = (GridSqlSelect)stmt; // How'd we get here otherwise? assert sel.isForUpdate(); if (inTx) { GridSqlAst from = sel.from(); GridSqlTable gridTbl = from instanceof GridSqlTable ? (GridSqlTable)from : ((GridSqlAlias)from).child(); GridH2Table tbl = gridTbl.dataTable(); Column keyCol = tbl.getColumn(0); sel.addColumn(new GridSqlAlias("_key_" + IgniteUuid.vmId(), new GridSqlColumn(keyCol, null, keyCol.getName()), true), true); } // We need to remove this flag for final flag we'll feed to H2. sel.forUpdate(false); return sel.getSQL(); }
/** * @param stmt Statement to rewrite, if needed. * @param inTx Whether there is an active transaction. * @return Query with {@code key} and {@code val} columns appended to the list of columns, * if it's an {@code FOR UPDATE} query, or {@code null} if nothing has to be done. */ @NotNull public static String rewriteQueryForUpdateIfNeeded(GridSqlStatement stmt, boolean inTx) { // We have checked above that it's not an UNION query, so it's got to be SELECT. assert stmt instanceof GridSqlSelect; GridSqlSelect sel = (GridSqlSelect)stmt; // How'd we get here otherwise? assert sel.isForUpdate(); if (inTx) { GridSqlAst from = sel.from(); GridSqlTable gridTbl = from instanceof GridSqlTable ? (GridSqlTable)from : ((GridSqlAlias)from).child(); GridH2Table tbl = gridTbl.dataTable(); Column keyCol = tbl.getColumn(0); sel.addColumn(new GridSqlAlias("_key_" + IgniteUuid.vmId(), new GridSqlColumn(keyCol, null, keyCol.getName()), true), true); } // We need to remove this flag for final flag we'll feed to H2. sel.forUpdate(false); return sel.getSQL(); }