Inheritance: IDisposable
Exemple #1
0
 public QueryResponse(int resultId, QueryResult queryResult, int millis, string warnings)
 {
     ResultId = resultId;
     QueryResult = queryResult;
     QueryTimeMillis = millis;
     Warnings = warnings;
 }
Exemple #2
0
        protected IQueryResponse[] CoreExecuteQuery(IQueryContext context, string text, IEnumerable<QueryParameter> parameters)
        {
            // Where Query result eventually resides.
            int resultId = -1;

            // For each StreamableObject in the query object, translate it to a
            // IRef object that presumably has been pre-pushed onto the server from
            // the client.

            // Evaluate the sql Query.
            var query = new SqlQuery(text);
            if (parameters != null) {
                // TODO: Download the Large-Objects and replace with a reference
            }

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var results = context.ExecuteQuery(query);
            var responses = new IQueryResponse[results.Length];
            int j = 0;

            foreach (var result in results) {
                QueryResult queryResult;
                try {
                    queryResult = new QueryResult(query, result);
                    resultId = AddResult(queryResult);
                } catch (Exception e) {
                    if (resultId != -1)
                        DisposeResult(resultId);

                    throw;
                }

                var taken = stopwatch.Elapsed;

                // Return the Query response
                responses[j] = new QueryResponse(resultId, queryResult, (int)taken.TotalMilliseconds, "");

                j++;
            }

            stopwatch.Stop();
            return responses;
        }
Exemple #3
0
        private int AddResult(QueryResult result)
        {
            result.LockRoot(-1); // -1 because lock_key not implemented

            int resultId;

            lock (resultMap) {
                resultId = ++uniqueResultId;
                resultMap[resultId] = result;
            }

            return resultId;
        }
 internal QueryResponse(int resultId, QueryResult result, int queryTime, string warnings)
 {
     ResultId = resultId;
     this.result = result;
     QueryTimeMillis = queryTime;
     Warnings = warnings;
 }
        private int AddResult(QueryResult result)
        {
            // Lock the roots of the result set.
            result.LockRoot(-1); // -1 because lock_key not implemented

            // Make a new result id
            int resultId;
            // This ensures this block can handle concurrent updates.
            lock (resultMap) {
                resultId = ++uniqueResultId;
                // Add the result to the map.
                resultMap[resultId] = result;
            }

            return resultId;
        }
        protected IQueryResponse[] CoreExecuteQuery(string text, IEnumerable<SqlQueryParameter> parameters)
        {
            // Record the Query start time
            DateTime startTime = DateTime.Now;

            // Where Query result eventually resides.
            int resultId = -1;

            // For each StreamableObject in the query object, translate it to a
            // IRef object that presumably has been pre-pushed onto the server from
            // the client.

            // Evaluate the sql Query.
            var query = new SqlQuery(text);
            if (parameters != null) {
                foreach (var parameter in parameters) {
                    var preparedParam = parameter.Value;
                    if (preparedParam is StreamableObject) {
                        var obj = (StreamableObject) preparedParam;
                        IRef objRef = CompleteStream(obj.Identifier);
                        preparedParam = objRef;
                    }
                    query.Parameters.Add(new SqlQueryParameter(parameter.Name, preparedParam));
                }
            }

            Table[] results = SqlQueryExecutor.Execute(Session.Connection, query);
            var responses = new IQueryResponse[results.Length];
            int j = 0;

            foreach (Table result in results) {
                QueryResult queryResult;
                try {
                    // Put the result in the result cache...  This will Lock this object
                    // until it is removed from the result set cache.  Returns an id that
                    // uniquely identifies this result set in future communication.
                    // NOTE: This locks the roots of the table so that its contents
                    //   may not be altered.
                    queryResult = new QueryResult(query, result);
                    resultId = AddResult(queryResult);
                } catch (Exception e) {
                    // If resultId set, then dispose the result set.
                    if (resultId != -1)
                        DisposeResult(resultId);

                    throw;
                }

                // The time it took the Query to execute.
                TimeSpan taken = DateTime.Now - startTime;

                // Return the Query response
                responses[j]  = new QueryResponse(resultId, queryResult, (int) taken.TotalMilliseconds, "");
                j++;
            }

            return responses;
        }
Exemple #7
0
        private int AddResult(QueryResult result)
        {
            int resultId;

            lock (resultMap) {
                resultId = ++uniqueResultId;
                resultMap[resultId] = result;
            }

            return resultId;
        }
Exemple #8
0
        protected IQueryResponse[] CoreExecuteQuery(IQuery context, string text, IEnumerable<QueryParameter> parameters, QueryParameterStyle parameterStyle)
        {
            // Where Query result eventually resides.
            int resultId = -1;

            // For each StreamableObject in the query object, translate it to a
            // IRef object that presumably has been pre-pushed onto the server from
            // the client.

            // Evaluate the sql Query.
            var query = new SqlQuery(text, parameterStyle);
            if (parameters != null) {
                foreach (var p in parameters) {
                    var c = p.SqlType.TypeCode;
                    switch (c) {
                        case SqlTypeCode.Blob:
                        case SqlTypeCode.Clob:
                        case SqlTypeCode.LongVarBinary:
                        case SqlTypeCode.LongVarChar:
                        case SqlTypeCode.VarBinary:
                            throw new NotImplementedException("TODO: Download the Large-Objects and replace with a reference");
                        default:
                            query.Parameters.Add(p);
                            break;
                    }
                }
            }

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var results = context.ExecuteQuery(query);
            var responses = new IQueryResponse[results.Length];
            int j = 0;

            foreach (var result in results) {
                QueryResult queryResult;
                try {
                    if (result.Type == StatementResultType.Exception)
                        throw result.Error;

                    queryResult = new QueryResult(query, result, context.AutoCommit());
                    resultId = AddResult(queryResult);
                } catch (Exception) {
                    if (resultId != -1)
                        DisposeResult(resultId);

                    throw;
                }

                var taken = stopwatch.ElapsedMilliseconds;

                // Return the Query response
                responses[j] = new QueryResponse(resultId, queryResult, (int)taken, "");

                j++;
            }

            stopwatch.Stop();
            return responses;
        }