Пример #1
0
        public ICollectionReader ExecuteReader(string queryText, ICollection<IParameter> parameters)
        {
            if (string.IsNullOrEmpty(queryText))
                throw new ArgumentNullException("queryText can not be null or empty string");
            if (typeof(T) == typeof(IJSONDocument) || typeof(T) == typeof(JSONDocument))
            {
                Type type;
                if (!JsonDocumentUtil.IsSupportedParameterType(parameters, out type))
                {
                    throw new ArgumentException(string.Format("Type {0} is not supported on Collection<JSONDocument>", type), "parameters");
                }
            }

            Query query = new Query();
            query.QueryText = queryText;
            query.Parameters = parameters.Cast<IParameter>().ToList();

            ReadQueryOperation readQueryOperation = new ReadQueryOperation();
            readQueryOperation.Database = _database.DatabaseName;
            readQueryOperation.Collection = _collectionName;
            readQueryOperation.Query = query;


            ReadQueryResponse readQueryResponse = (ReadQueryResponse)_database.ExecutionMapper.ExecuteReader(readQueryOperation);
            if (!readQueryResponse.IsSuccessfull)
            {
                if (readQueryResponse.ErrorParams != null && readQueryResponse.ErrorParams.Length > 0)
                    throw new Exception(string.Format("Operation failed Error: " + Common.ErrorHandling.ErrorMessages.GetErrorMessage(readQueryResponse.ErrorCode, readQueryResponse.ErrorParams)));
                throw new Exception("Operation failed Error: " + Common.ErrorHandling.ErrorMessages.GetErrorMessage(readQueryResponse.ErrorCode));
            }

            CollectionReader reader = new CollectionReader((DataChunk)readQueryResponse.DataChunk, _database.ExecutionMapper, _database.DatabaseName, _collectionName);
            return reader;
        }
Пример #2
0
        public long ExecuteNonQuery(string queryText, ICollection<IParameter> parameters)
        {
            if (string.IsNullOrEmpty(queryText))
                throw new ArgumentNullException("queryText can not be null or empty string");

            if (typeof(T) == typeof(IJSONDocument) || typeof(T) == typeof(JSONDocument))
            {
                Type type;
                if (!JsonDocumentUtil.IsSupportedParameterType(parameters, out type))
                {
                    throw new ArgumentException(string.Format("Type {0} is not supported on Collection<JSONDocument>", type), "parameters");
                }
            }

            Query query = new Query();
            query.QueryText = queryText;
            query.Parameters = (List<IParameter>)parameters;

            WriteQueryOperation writeQueryOperation = new WriteQueryOperation();
            writeQueryOperation.Database = _database.DatabaseName;
            writeQueryOperation.Collection = _collectionName;
            writeQueryOperation.Query = query;
            var writeQueryResponse = _database.ExecutionMapper.ExecuteNonQuery(writeQueryOperation);

            if (writeQueryResponse.IsSuccessfull)
            {
                return writeQueryResponse.AffectedDocuments;
            }

            if (writeQueryResponse.ErrorParams != null && writeQueryResponse.ErrorParams.Length > 0)
                throw new Exception(string.Format("Operation failed Error :" + Common.ErrorHandling.ErrorMessages.GetErrorMessage(writeQueryResponse.ErrorCode, writeQueryResponse.ErrorParams)));

            throw new Exception("Operation failed Error: " +
                Common.ErrorHandling.ErrorMessages.GetErrorMessage(writeQueryResponse.ErrorCode));
        }
Пример #3
0
        public object ExecuteScalar(string queryText, ICollection<IParameter> parameters)
        {
            if (string.IsNullOrEmpty(queryText))
                throw new ArgumentNullException("queryText can not be null or empty string");

            if (typeof(T) == typeof(IJSONDocument) || typeof(T) == typeof(JSONDocument))
            {
                Type type;
                if (!JsonDocumentUtil.IsSupportedParameterType(parameters, out type))
                {
                    throw new ArgumentException(string.Format("Type {0} is not supported on Collection<JSONDocument>", type), "parameters");
                }
            }

            Query query = new Query();
            query.QueryText = queryText;
            query.Parameters = parameters.Cast<IParameter>().ToList();

            ReadQueryOperation readQueryOperation = new ReadQueryOperation();
            readQueryOperation.Database = _database.DatabaseName;
            readQueryOperation.Collection = _collectionName;
            readQueryOperation.Query = query;

            return _database.ExecutionMapper.ExecuteScalar(readQueryOperation);
        }