Ejemplo n.º 1
0
 public Task<Statement> GetStatementAsync(ISession session, Cql cql)
 {
     if (cql.QueryOptions.NoPrepare)
     {
         // Use a SimpleStatement if we're not supposed to prepare
         Statement statement = new SimpleStatement(cql.Statement, cql.Arguments);
         SetStatementProperties(statement, cql);
         return TaskHelper.ToTask(statement);
     }
     return _statementCache
         .GetOrAdd(cql.Statement, session.PrepareAsync)
         .Continue(t =>
         {
             if (_statementCache.Count > MaxPreparedStatementsThreshold)
             {
                 Logger.Warning(String.Format("The prepared statement cache contains {0} queries. Use parameter markers for queries. You can configure this warning threshold using MappingConfiguration.SetMaxStatementPreparedThreshold() method.", _statementCache.Count));
             }
             Statement boundStatement = t.Result.Bind(cql.Arguments);
             SetStatementProperties(boundStatement, cql);
             return boundStatement;
         });
 }
Ejemplo n.º 2
0
 public Statement GetStatement(ISession session, Cql cql)
 {
     // Just use async version's result
     return GetStatementAsync(session, cql).Result;
 }
Ejemplo n.º 3
0
 private void SetStatementProperties(IStatement stmt, Cql cql)
 {
     cql.QueryOptions.CopyOptionsToStatement(stmt);
     stmt.SetAutoPage(cql.AutoPage);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Prepends the CQL statement specified with "DELETE FROM tablename " for a POCO of Type T.
        /// </summary>
        public void PrependDelete <T>(Cql cql)
        {
            PocoData pocoData = _pocoDataFactory.GetPocoData <T>();

            cql.SetStatement(string.Format("DELETE FROM {0} {1}", pocoData.TableName, cql.Statement));
        }
 public Statement GetStatement(ISession session, Cql cql)
 {
     // Just use async version's result
     return(GetStatementAsync(session, cql).Result);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Prepends the CQL statement specified with "UPDATE tablename " for a POCO of Type T.
        /// </summary>
        public void PrependUpdate <T>(Cql cql)
        {
            var pocoData = _pocoDataFactory.GetPocoData <T>();

            cql.SetStatement(string.Format("UPDATE {0} {1}", Escape(pocoData.TableName, pocoData), cql.Statement));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Prepends the CQL statement specified with "DELETE FROM tablename " for a POCO of Type T.
        /// </summary>
        public void PrependDelete <T>(Cql cql)
        {
            var pocoData = _pocoDataFactory.GetPocoData <T>();

            cql.SetStatement($"DELETE FROM {CqlGenerator.CqlIdentifierHelper.EscapeTableNameIfNecessary(pocoData, pocoData.KeyspaceName, pocoData.TableName)} {cql.Statement}");
        }
 private void SetStatementProperties(IStatement stmt, Cql cql)
 {
     cql.QueryOptions.CopyOptionsToStatement(stmt);
     stmt.SetAutoPage(cql.AutoPage);
 }
Ejemplo n.º 9
0
        public async void FetchAsync_Pocos_WithCqlAndOptions()
        {
            List <PlainUser> users = await CqlClient.FetchAsync <PlainUser>(Cql.New("SELECT * FROM users").WithOptions(opt => opt.SetConsistencyLevel(ConsistencyLevel.Quorum)));

            users.ShouldAllBeEquivalentTo(TestDataHelper.Users, opt => opt.AccountForTimestampAccuracy());
        }
Ejemplo n.º 10
0
        public void Fetch_Pocos_WithCqlAndOptions()
        {
            List <PlainUser> users = CqlClient.Fetch <PlainUser>(Cql.New("SELECT * FROM users").WithOptions(opt => opt.DoNotPrepare()));

            users.ShouldAllBeEquivalentTo(TestDataHelper.Users, opt => opt.AccountForTimestampAccuracy());
        }
 public Task <TransactionByIdReadModel> GetAsync(Guid transactionId)
 {
     return(this.connection.Mapper.FirstOrDefaultAsync <TransactionByIdReadModel>(Cql
                                                                                  .New("WHERE transaction_id = ?", transactionId)
                                                                                  .WithOptions(opt => opt.SetConsistencyLevel(this.settings.TransactionsReadConsistencyLevel))));
 }
Ejemplo n.º 12
0
 public Statement GetStatement(Cql cql)
 {
     // Just use async version's result
     return(GetStatementAsync(cql).Result);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Update an inventory item
        /// </summary>
        /// <param name="oItem"></param>
        /// <returns></returns>
        public async Task <ResultModel <item> > UpdateInventoryAsync(item oItem)
        {
            //update item
            var updateItem = Cql.New(
                $"SET status = {ItemStatus.reserved.ToString()} , date_updated = {TimeUuid.NewId(DateTime.Now)}"
                + $" WHERE business_unit={oItem.businessUnit} and location={oItem.location} and upc={oItem.upc}"
                + $" and identifier_value = {oItem.identifierValue} and identifier_type= {oItem.identifierType}");


            var updateItemByIdentifer = Cql.New(
                $" SET status = {ItemStatus.reserved.ToString()} , date_updated = {TimeUuid.NewId(DateTime.Now)}"
                + $" WHERE business_unit={oItem.businessUnit}"
                + $" and identifier_value = {oItem.identifierValue} and identifier_type= {oItem.identifierType}");

            item item = new item
            {
                businessUnit    = oItem.businessUnit,
                location        = oItem.location,
                upc             = oItem.upc,
                identifierValue = oItem.identifierValue,
                identifierType  = oItem.identifierType,
                serialNumber    = oItem.serialNumber,
                receiptId       = oItem.receiptId,
                status          = ItemStatus.reserved.ToString(),
                dateCreated     = TimeUuid.NewId(),
                dateUpdated     = TimeUuid.NewId(),
                itemAttributes  = null
            };

            //insert item history
            itemHistory itemHist = new itemHistory
            {
                businessUnit    = oItem.businessUnit,
                location        = oItem.location,
                upc             = oItem.upc,
                histItemId      = Guid.NewGuid(),
                identifierValue = oItem.identifierValue,
                identifierType  = oItem.identifierType,
                serialNumber    = oItem.serialNumber,
                receiptId       = oItem.receiptId,
                status          = ItemStatus.reserved.ToString(),
                dateCreated     = TimeUuid.NewId(),
                dateUpdated     = TimeUuid.NewId(),
                itemAttributes  = null
            };

            //insert itembyIdentifier
            itemByIdentifier itemById = new itemByIdentifier
            {
                businessUnit    = oItem.businessUnit,
                location        = oItem.location,
                upc             = oItem.upc,
                identifierValue = oItem.identifierValue,
                identifierType  = oItem.identifierType,
                serialNumber    = oItem.serialNumber,
                receiptId       = oItem.receiptId,
                status          = ItemStatus.reserved.ToString(),
                dateCreated     = TimeUuid.NewId(),
                dateUpdated     = TimeUuid.NewId(),
                itemAttributes  = null
            };

            var batch = mapper.CreateBatch(BatchType.Logged);

            batch.Insert <item>(item);
            batch.Insert <itemHistory>(itemHist);
            batch.Insert <itemByIdentifier>(itemById);
            batch.WithOptions(ac => ac.SetConsistencyLevel(ConsistencyLevel.Quorum));
            await mapper.ExecuteAsync(batch);

            return(new ResultModel <item>
            {
                resultContent = oItem,
                resultCode = ResultStatus.success
            });
        }
Ejemplo n.º 14
0
        public async Task <ICursor <T> > GetCursorAsync <T>(Guid signalId, List <long> start, List <long> count, List <long> decimationFactor = null)
        {
            myCoreService = CoreService.GetInstance();
            var signal = await myCoreService.GetOneByIdAsync(signalId);

            int sampleCount = (int)signal.NumberOfSamples;
            int indexStart  = (int)start.LastOrDefault();
            int getNumber   = (int)count.LastOrDefault();

            List <IPage <SEPayload> > listIPage = new List <IPage <SEPayload> >();

            if (decimationFactor == null)
            {
                decimationFactor = new List <long>();
                for (int i = 0; i < start.Count; i++)
                {
                    decimationFactor.Add(1);
                }
            }

            int factor = (int)decimationFactor[decimationFactor.Count() - 1];
            //from the second lowest rank find each line to read
            long lineCount = 1;

            //how many lines to read
            for (int i = 0; i < count.Count - 1; i++)
            {
                lineCount = lineCount * count[i];
            }
            List <long> lineCursor  = new List <long>(start.Count - 1);
            List <long> lineCounter = new List <long>(start.Count - 1);

            //the line cursor has every but last rank of the start point, point to the start line
            lineCursor.AddRange(start.Where((v, i) => i < start.Count - 1));
            lineCounter.AddRange(count.Where((v, i) => i < count.Count - 1));
            List <long> dimPage = new List <long>();

            List <long> indexes = new List <long>();

            for (int line = 0; line < lineCount; line++)
            {
                #region
                Byte[] pagingState = null;
                string dimension   = DimensionsToText(lineCursor);
                //计算index
                if (factor < sampleCount)
                {
                    var lastPoint  = (factor * getNumber + indexStart) - factor;
                    var lastIndex  = lastPoint / sampleCount + 1;
                    var firstIndex = indexStart / sampleCount;
                    for (int i = firstIndex; i < lastIndex; i++)
                    {
                        indexes.Add(i);
                    }
                }
                else
                {
                    int coordinate = 0;
                    int variable   = 0;
                    //每个点取一次比较
                    for (int i = 0; i < getNumber; i++)
                    {
                        coordinate = indexStart + i * factor;
                        variable   = coordinate / sampleCount;
                        indexes.Add(variable);
                    }
                }
                //

                Cql cql = Cql.New("SELECT * FROM sepayload where parentid=? and dimensions=? and indexes in ? ", signalId, dimension, indexes);
                IPage <SEPayload> ipagePartialList = (await mapper.FetchPageAsync <SEPayload>(cql.WithOptions(opt => opt.SetPageSize(pagesize).SetPagingState(pagingState))));
                //  Debug.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")+ "   getPAge");
                if (ipagePartialList.Count == 0)
                {
                    throw new Exception(ErrorMessages.DataNotFoundError);
                }
                listIPage.Add(ipagePartialList);
                while (ipagePartialList.PagingState != null)
                {
                    pagingState      = ipagePartialList.PagingState;
                    ipagePartialList = (await mapper.FetchPageAsync <SEPayload>(cql.WithOptions(opt => opt.SetPageSize(pagesize).SetPagingState(pagingState))));
                    if (ipagePartialList.Count() > 0)
                    {
                        listIPage.Add(ipagePartialList);
                    }
                }
                long dimPageCount = listIPage.Count() - dimPage.Sum();
                dimPage.Add(dimPageCount);

                /***************************************/
                #endregion
                for (var rankIndex = lineCursor.Count - 1; rankIndex >= 0; rankIndex--)
                {
                    //try read next line
                    lineCounter[rankIndex] -= 1;
                    if (lineCounter[rankIndex] == 0)
                    {
                        lineCounter[rankIndex] = count[rankIndex];
                        lineCursor[rankIndex]  = start[rankIndex];
                    }
                    else
                    {
                        //move this rank forward
                        lineCursor[rankIndex] += decimationFactor[rankIndex];
                        break;
                    }
                }
            }
            Cursor <T> jdbccursor = new Cursor <T>(listIPage, start.LastOrDefault(), count, dimPage, sampleCount, decimationFactor.LastOrDefault());
            return(jdbccursor);
        }
Ejemplo n.º 15
0
 public async Task DeleteDataAsync(Guid signalId)
 {
     Cql cql = Cql.New("where parentid=? ", signalId);
     await mapper.DeleteAsync <SEPayload>(cql);
 }