Inheritance: IDisposable
コード例 #1
0
ファイル: ServerConnector.cs プロジェクト: prepare/deveeldb
 public QueryResponse(int resultId, QueryResult queryResult, int millis, string warnings)
 {
     ResultId = resultId;
     QueryResult = queryResult;
     QueryTimeMillis = millis;
     Warnings = warnings;
 }
コード例 #2
0
ファイル: ServerConnector.cs プロジェクト: prepare/deveeldb
        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;
        }
コード例 #3
0
ファイル: ServerConnector.cs プロジェクト: prepare/deveeldb
        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;
        }
コード例 #4
0
 internal QueryResponse(int resultId, QueryResult result, int queryTime, string warnings)
 {
     ResultId = resultId;
     this.result = result;
     QueryTimeMillis = queryTime;
     Warnings = warnings;
 }
コード例 #5
0
        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;
        }
コード例 #6
0
        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;
        }
コード例 #7
0
ファイル: ServerConnector.cs プロジェクト: deveel/deveeldb
        private int AddResult(QueryResult result)
        {
            int resultId;

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

            return resultId;
        }
コード例 #8
0
ファイル: ServerConnector.cs プロジェクト: deveel/deveeldb
        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;
        }