private List <OMQuery> FetchQueriesForAClass(string className) { List <OMQuery> qList = new List <OMQuery>(); IObjectSet objSet; try { IObjectContainer container = Db4oClient.OMNConnection; IQuery query = container.Query(); query.Constrain(typeof(ConnectionDetails)); query.Descend("m_connParam").Descend("m_connection").Constrain(currConnParams.Connection); objSet = query.Execute(); if (objSet != null && objSet.Count > 0) { ConnectionDetails connectionDetails = (ConnectionDetails)objSet.Next(); qList.AddRange(connectionDetails.QueryList.Where(q => q != null && q.BaseClass.Equals(className))); CompareQueryTimestamps comp = new CompareQueryTimestamps(); qList.Sort(comp); } else { return(null); } } catch (Exception oEx) { LoggingHelper.HandleException(oEx); } return(qList); }
private List <OMQuery> FetchAllQueries() { container = Db4oClient.RecentConn; IQuery query = container.Query(); query.Constrain(typeof(RecentQueries)); IObjectSet os = query.Execute(); List <RecentQueries> recConnections = new List <RecentQueries>(); while (os.HasNext()) { recConnections.Add((RecentQueries)os.Next()); } List <OMQuery> QryList = new List <OMQuery>(); foreach (RecentQueries recCon in recConnections) { foreach (OMQuery q in recCon.QueryList) { if (q != null) { QryList.Add(q); } } } CompareQueryTimestamps comp = new CompareQueryTimestamps(); QryList.Sort(comp); return(QryList); }
private List <OMQuery> FetchAllQueries() { try { IObjectContainer container = Db4oClient.OMNConnection; IQuery query = container.Query(); query.Constrain(typeof(ConnectionDetails)); IObjectSet os = query.Execute(); List <ConnectionDetails> recConnections = new List <ConnectionDetails>(); while (os.HasNext()) { recConnections.Add((ConnectionDetails)os.Next()); } List <OMQuery> QryList = (from recCon in recConnections from q in recCon.QueryList where q != null select q).ToList(); CompareQueryTimestamps comp = new CompareQueryTimestamps(); QryList.Sort(comp); return(QryList); } catch (Exception oEx) { LoggingHelper.HandleException(oEx); return(null); } }
public List <OMQuery> FetchQueriesForAClass(string className) { List <OMQuery> qList = new List <OMQuery>(); IObjectSet objSet; try { container = Db4oClient.RecentConn; IQuery query = container.Query(); query.Constrain(typeof(RecentQueries)); query.Descend("m_connParam").Descend("m_connection").Constrain(m_connParam.Connection); objSet = query.Execute(); if (objSet != null && objSet.Count > 0) { RecentQueries recentQueries = (RecentQueries)objSet.Next(); foreach (OMQuery q in recentQueries.QueryList) { if (q != null && q.BaseClass.Equals(className)) { qList.Add(q); } } CompareQueryTimestamps comp = new CompareQueryTimestamps(); qList.Sort(comp); } else { return(null); } } catch (Exception oEx) { LoggingHelper.HandleException(oEx); container = null; Db4oClient.CloseRecentConnectionFile(); } return(qList); }
//public RecentQueries PopulateParameters(DateTime date) //{ // this.Timestamp = date; // this.ConnParam = m_connParam; // return this; //} public void AddQueryToList(OMQuery query) { try { container = Db4oClient.RecentConn; if (QueryList != null) { CompareQueryTimestamps comp = new CompareQueryTimestamps(); List <OMQuery> qList = FetchAllQueries(); // qList.Sort(comp); if (qList.Count >= 20) { bool check = false; foreach (OMQuery qry in qList) { if (qry.QueryString == query.QueryString) { //check if the query string is among 5 check = true; } } //if it is not among five then remove the last item from the list if (check == false) { OMQuery q = qList[qList.Count - 1]; qList.RemoveAt(qList.Count - 1); foreach (OMQuery qry1 in this.QueryList) { if (q.QueryString.Equals(qry1.QueryString)) { this.QueryList.Remove(qry1); break; } } container.Delete(q); container.Commit(); } } List <OMQuery> qListForClass = FetchQueriesForAClass(query.BaseClass); if (qListForClass != null) { qListForClass.Sort(comp); if (qListForClass.Count >= 5) { bool check = false; foreach (OMQuery qry in qListForClass) { if (qry.QueryString == query.QueryString) { //check if the query string is among 5 check = true; } } //if it is not among five then remove the last item from the list if (check == false) { OMQuery q = qListForClass[qListForClass.Count - 1]; qListForClass.RemoveAt(qListForClass.Count - 1); foreach (OMQuery qry1 in this.QueryList) { if (q.QueryString.Equals(qry1.QueryString)) { this.QueryList.Remove(qry1); break; } } container.Delete(q); container.Commit(); } } // recent queries should always be 5 for a class therefore its checked //against qListForClass. foreach (OMQuery q in qListForClass) { if (q != null) { if (q.QueryString != null) { if (q.QueryString.Equals(query.QueryString)) { //if query string is same as already in the list then remove from the list //so that same string can be added again with updated timestamp foreach (OMQuery qry1 in this.QueryList) { if (q.QueryString.Equals(qry1.QueryString)) { this.QueryList.Remove(qry1); break; } } } } } } } //add query with latest timestamp. this.QueryList.Add(query); RecentQueries temprc = this.ChkIfRecentConnIsInDb(); if (temprc != null) { temprc.Timestamp = DateTime.Now; temprc.QueryList = this.QueryList; } else { temprc = this; temprc.m_TimeOfCreation = Sharpen.Runtime.CurrentTimeMillis(); } container.Ext().Store(temprc, 5); container.Commit(); container = null; Db4oClient.CloseRecentConnectionFile(); } } catch (Exception oEx) { LoggingHelper.HandleException(oEx); container = null; Db4oClient.CloseRecentConnectionFile(); } }