/// <summary> /// Dispose of any associated DataReaderDao /// </summary> /// public void Dispose() { if (ServiceFacade.UseRemoteServices) { Mobius.Services.Native.INativeSession nativeClient = ServiceFacade.CreateNativeSessionProxy(); Services.Native.NativeMethodTransportObject resultObject = ServiceFacade.InvokeNativeMethod(nativeClient, (int)Services.Native.ServiceCodes.MobiusAnnotationService, (int)Services.Native.ServiceOpCodes.MobiusAnnotationService.DisposeInstance, new Services.Native.NativeMethodTransportObject(new object[] { instanceId })); ((System.ServiceModel.IClientChannel)nativeClient).Close(); return; } else { Instance.Dispose(); } }
/// <summary> /// Fast insert/update of a single row including creation of the AnnotationDao object, transaction and header update /// </summary> /// <param name="vo"></param> /// <returns></returns> public static long InsertUpdateRowAndUserObjectHeader(AnnotationVo vo) { bool newRow = vo.rslt_id <= 0; AnnotationDao dao = new AnnotationDao(); dao.BeginTransaction(); long rsltId = dao.InsertUpdateRow(vo); dao.Commit(); dao.Dispose(); UserObject uo = UserObjectDao.ReadHeader(vo.mthd_vrsn_id); if (uo != null) { uo.UpdateDateTime = DateTime.Now; if (newRow) { uo.Count++; } UserObjectDao.UpdateHeader(uo); } return(rsltId); }
/// <summary> /// Perform a deep clone of an annotation table UserObject including the underlying data /// </summary> /// <param name="uo"></param> /// <returns></returns> public static UserObject DeepClone(UserObject uo) { UserObject uo2 = uo.Clone(); long oldCode, newCode; // Create a copy of the user object including remapping of the codes AnnotationDao dao = new AnnotationDao(); MetaTable mt = MetaTable.Deserialize(uo.Content); // deserialize metatable xml int newMethodCode = UserObjectDao.GetNextId(); uo2.Id = newMethodCode; // store in UserObject id as well mt.Code = newMethodCode.ToString(); mt.Name = "ANNOTATION_" + mt.Code; mt.Label = uo.Name; Dictionary <long, long> codeMap = new Dictionary <long, long>(); foreach (MetaColumn mc in mt.MetaColumns) { if (!Lex.IsNullOrEmpty(mc.ResultCode)) { if (!long.TryParse(mc.ResultCode, out oldCode)) { continue; } newCode = dao.GetNextIdLong(); codeMap[oldCode] = newCode; mc.Name = "R_" + newCode; mc.ResultCode = newCode.ToString(); } } // Write import state if checking for updates if (mt.ImportParms != null && mt.ImportParms.CheckForFileUpdates) { UserObject udisUo = new UserObject(UserObjectType.ImportState, uo2.Owner, mt.Name); UserDataImportState udis = new UserDataImportState(); udis.UserDatabase = false; // indicate annotation table udis.UserDataObjectId = uo2.Id; // store id of annotation table user object udis.ClientFile = mt.ImportParms.FileName; udis.CheckForFileUpdates = mt.ImportParms.CheckForFileUpdates; udis.ClientFileModified = mt.ImportParms.ClientFileModified; udis.FileName = mt.ImportParms.FileName; udisUo.Description = udis.Serialize(); // serialize to description UserObjectDao.Write(udisUo); } // Copy the data dao.BeginTransaction(); dao.BufferInserts(true); dao.OpenReader(uo.Id); Dictionary <long, long> groupMap = new Dictionary <long, long>(); int readCount = 0; while (true) { AnnotationVo vo = dao.Read(); if (vo == null) { break; } if (!codeMap.ContainsKey(vo.rslt_typ_id)) { continue; } vo.rslt_typ_id = codeMap[vo.rslt_typ_id]; // map the result code vo.rslt_id = dao.GetNextIdLong(); // new result id vo.mthd_vrsn_id = newMethodCode; if (!groupMap.ContainsKey(vo.rslt_grp_id)) // map the group id { groupMap[vo.rslt_grp_id] = dao.GetNextIdLong(); } vo.rslt_grp_id = groupMap[vo.rslt_grp_id]; dao.Insert(vo); readCount++; if (readCount % 1000 == 0) { dao.ExecuteBufferedInserts(); dao.Commit(); } } dao.ExecuteBufferedInserts(); dao.Commit(); dao.Dispose(); uo2.Count = groupMap.Count; // update the count uo2.CreationDateTime = uo2.UpdateDateTime = DateTime.Now; uo2.Content = mt.Serialize(); return(uo2); }
/// <summary> /// Reorder the rows in an annotation table /// </summary> /// <param name="methodId"></param> /// <returns></returns> public static long ReorderRows(long methodId) { AnnotationDao dao = null; DbCommandMx cmd = null; string sql = null, ttName = null; int insCnt = 0; try { dao = new AnnotationDao(); dao.BeginTransaction(); cmd = dao.DbCmd; ttName = "tt_" + methodId; try // delete just in case { cmd.PrepareAndExecuteNonReader("truncate table " + ttName, logExceptions: false); cmd.PrepareAndExecuteNonReader("drop table " + ttName, logExceptions: false); } catch (Exception ex) { ex = ex; } // Create temp table & copy data for method sql = "create global temporary table " + ttName + @" on commit preserve rows as select* from mbs_owner.mbs_adw_rslt where mthd_vrsn_id = " + methodId; cmd.PrepareAndExecuteNonReader(sql); // Delete existing data sql = @"delete from mbs_owner.mbs_adw_rslt where mthd_vrsn_id = " + methodId; int delCnt = cmd.PrepareAndExecuteNonReader(sql); // Reinsert from temp table in desired order into new blocks (e.g. APPEND hint) sql = @"insert /*+ APPEND */ into mbs_owner.mbs_adw_rslt select* from " + ttName + @" order by ext_cmpnd_id_nbr, rslt_grp_id, rslt_id" ; insCnt = cmd.PrepareAndExecuteNonReader(sql); cmd.Commit(); // commit try // remove temp table { cmd.PrepareAndExecuteNonReader("truncate table " + ttName, logExceptions: false); cmd.PrepareAndExecuteNonReader("drop table " + ttName, logExceptions: false); } catch (Exception ex) { ex = ex; } dao.Dispose(); } catch (Exception ex) { string msg = "Exception for Annotation Table: " + ttName + " "; DebugLog.Message(msg + DebugLog.FormatExceptionMessage(ex)); try { cmd.Rollback(); // rollback if failed cmd.PrepareAndExecuteNonReader("truncate table " + ttName, logExceptions: false); cmd.PrepareAndExecuteNonReader("drop table " + ttName, logExceptions: false); } catch (Exception ex2) { ex2 = ex2; } try { dao.Dispose(); } catch (Exception ex3) { ex3 = ex3; } throw new Exception(msg, ex); } return(insCnt); }