// Method for executing abstract operation with BingoIndexData private static void _ExecuteBingoOperationChangeIndex (SqlString bingo_schema, bingoOperationDelegate operationDelegate, bingoGetIndexDataDelegate getBingoDataDelegate, BingoOp flags) { bingoOperationDelegate opWithIndex = (ctx_conn, conn, index_data) => { if (BingoCore.lib.bingoIndexBegin() != 1) throw new Exception(BingoCore.lib.bingoGetError()); try { index_data.fingerprints.init(ctx_conn); index_data.storage.validate(ctx_conn); operationDelegate(ctx_conn, conn, index_data); ContextFlags save_flags = ContextFlags.CMF; saveContext(ctx_conn, bingo_schema.Value, index_data.id.table_id, save_flags); } finally { BingoCore.lib.bingoIndexEnd(); } }; _ExecuteBingoOperation(bingo_schema, opWithIndex, getBingoDataDelegate, flags); }
// Method for executing abstract operation with BingoIndexData private static void _ExecuteBingoOperation(SqlString bingo_schema, bingoOperationDelegate operationDelegate, bingoGetIndexDataDelegate getBingoDataDelegate, BingoOp op_flags) { string table_name = "<Undef>"; BingoIndexID id = null; SqlConnection ext_conn = null; try { using (SqlConnection ctx_conn = new SqlConnection("context connection=true")) { ctx_conn.Open(); SqlConnection conn = ctx_conn; if ((op_flags & BingoOp.NON_CONTEXT_CONN) != 0) { string conn_string = String.Format( "server={0};integrated security=true;database={1};enlist=false", getServername(ctx_conn), ctx_conn.Database); ext_conn = new SqlConnection(conn_string); ext_conn.Open(); conn = ext_conn; } using (BingoSession session = new BingoSession()) { BingoCore.lib.bingoProfilingReset(false); BingoTimer timer = new BingoTimer("total"); BingoIndexData index_data = getBingoDataDelegate(ctx_conn, conn, bingo_schema); table_name = index_data.id.FullTableName(ctx_conn); id = index_data.id; if (index_data.locked) { BingoLog.logMessage("Attempt to get locked index for the table {0}", table_name); throw new Exception("Chemical index for the table '" + table_name + "' is locked"); } if ((op_flags & BingoOp.LOCK_INDEX) != 0) index_data.locked = true; ContextFlags flags = ContextFlags.NTHREADS | ContextFlags.FINGERPRINTS; if ((op_flags & BingoOp.LOAD_TAU_RULES) != 0) flags |= ContextFlags.TAU_RULES; if ((op_flags & BingoOp.LOAD_CMF) != 0) flags |= ContextFlags.CMF; prepareContext(ctx_conn, bingo_schema.Value, index_data.id.table_id, flags); index_data.syncContextParameters(ctx_conn, bingo_schema.Value); try { operationDelegate(ctx_conn, conn, index_data); } catch (Exception ex) { if ((Thread.CurrentThread.ThreadState & ThreadState.AbortRequested) != 0) Thread.ResetAbort(); BingoLog.logMessage("Exception {0} in {1}:\n{2}", ex.Message, ex.Source, ex.StackTrace); if ((op_flags & BingoOp.LOCK_INDEX) != 0) index_data.locked = false; if ((op_flags & BingoOp.DROP_ON_EXCEPTION) != 0) BingoIndexData.DropIndexData(conn, bingo_schema.Value, id, false); throw ex; } if ((op_flags & BingoOp.LOCK_INDEX) != 0) index_data.locked = false; timer.end(); if ((op_flags & BingoOp.NEED_STAT) != 0) BingoLog.logMessage("Statistics for table {0}:\n{1}\n", table_name, BingoCore.bingoProfilingGetStatistics(false)); } } } finally { if ((Thread.CurrentThread.ThreadState & ThreadState.AbortRequested) != 0) Thread.ResetAbort(); if (ext_conn != null) ext_conn.Close(); } }