// FEATURE : add query caching here internal Result <object> Query <T>(Expression <Predicate <T> > filter, int start, int count, string orderby) { if (filter == null) { return(Query(start, count)); } DateTime dt = FastDateTime.Now; _log.Debug("query : " + _view.Name); WAHBitArray ba = new WAHBitArray(); QueryVisitor qv = new QueryVisitor(QueryColumnExpression); qv.Visit(filter); var delbits = _deletedRows.GetBits(); ba = ((WAHBitArray)qv._bitmap.Pop()).AndNot(delbits); List <T> trows = null; if (_viewmanager.inTransaction()) { // query from transaction own data tran_data data = null; if (_transactions.TryGetValue(Thread.CurrentThread.ManagedThreadId, out data)) { List <T> rrows = new List <T>(); foreach (var kv in data.rows) { foreach (var r in kv.Value) { object o = FastCreateObject(_view.Schema); rrows.Add((T)_rowfiller(o, r)); } } trows = rrows.FindAll(filter.Compile()); } } var order = SortBy(orderby); _log.Debug("query bitmap done (ms) : " + FastDateTime.Now.Subtract(dt).TotalMilliseconds); dt = FastDateTime.Now; // exec query return rows return(ReturnRows <T>(ba, trows, start, count, order)); }
internal Result <object> Query(string filter, int start, int count, string orderby) { filter = filter.Trim(); if (filter == "") { return(Query(start, count, orderby)); } DateTime dt = FastDateTime.Now; _log.Debug("query : " + _view.Name); _log.Debug("query : " + filter); _log.Debug("orderby : " + orderby); WAHBitArray ba = new WAHBitArray(); var delbits = _deletedRows.GetBits(); if (filter != "") { LambdaExpression le = null; if (_lambdacache.TryGetValue(filter, out le) == false) { le = System.Linq.Dynamic.DynamicExpression.ParseLambda(_view.Schema, typeof(bool), filter, null); _lambdacache.Add(filter, le); } QueryVisitor qv = new QueryVisitor(QueryColumnExpression); qv.Visit(le.Body); ba = ((WAHBitArray)qv._bitmap.Pop()).AndNot(delbits); } else { ba = WAHBitArray.Fill(_viewData.Count()).AndNot(delbits); } var order = SortBy(orderby); _log.Debug("query bitmap done (ms) : " + FastDateTime.Now.Subtract(dt).TotalMilliseconds); dt = FastDateTime.Now; // exec query return rows return(ReturnRows <object>(ba, null, start, count, order)); }
internal int ViewDelete <T>(Expression <Predicate <T> > filter) { _log.Debug("delete : " + _view.Name); if (_isDirty == false) { WriteDirtyFile(); } QueryVisitor qv = new QueryVisitor(QueryColumnExpression); qv.Visit(filter); var delbits = _deletedRows.GetBits(); int count = qv._bitmap.Count; if (count > 0) { WAHBitArray qbits = (WAHBitArray)qv._bitmap.Pop(); _deletedRows.InPlaceOR(qbits); count = (int)qbits.CountOnes(); } _log.Debug("Deleted rows = " + count); return(count); }
internal int Count <T>(Expression <Predicate <T> > filter) { int totcount = 0; DateTime dt = FastDateTime.Now; if (filter == null) { totcount = internalCount(); } else { WAHBitArray ba = new WAHBitArray(); QueryVisitor qv = new QueryVisitor(QueryColumnExpression); qv.Visit(filter); var delbits = _deletedRows.GetBits(); ba = ((WAHBitArray)qv._bitmap.Pop()).AndNot(delbits); totcount = (int)ba.CountOnes(); } _log.Debug("Count items = " + totcount); _log.Debug("Count time (ms) : " + FastDateTime.Now.Subtract(dt).TotalMilliseconds); return(totcount); }