Exemplo n.º 1
0
        /// <summary>
        /// Adds this result set to the list of result sets being handled 
        /// through this processor.
        /// </summary>
        /// <param name="result"></param>
        /// <returns>
        /// Returns a number that unique identifies the result set.
        /// </returns>
        private int AddResultSet(ResultSetInfo 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 (resultSetMap) {
                resultId = ++uniqueResultId;
                // Add the result to the map.
                resultSetMap[resultId] = result;
            }

            return resultId;
        }
Exemplo n.º 2
0
 internal QueryResponse(int resultId, ResultSetInfo resultSetInfo, int queryTime, string warnings)
 {
     this.resultId = resultId;
     this.resultSetInfo = resultSetInfo;
     this.queryTime = queryTime;
     this.warnings = warnings;
 }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public virtual IQueryResponse[] ExecuteQuery(SqlQuery query)
        {
            CheckNotDisposed();

            // Record the Query start time
            DateTime startTime = DateTime.Now;

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

            // For each StreamableObject in the SQLQuery object, translate it to a
            // IRef object that presumably has been pre-pushed onto the server from
            // the client.
            bool blobsWereFlushed = false;
            object[] vars = query.Variables;
            if (vars != null) {
                for (int i = 0; i < vars.Length; ++i) {
                    object ob = vars[i];
                    // This is a streamable object, so convert it to a *IRef
                    if (ob != null && ob is StreamableObject) {
                        StreamableObject sObject = (StreamableObject) ob;

                        // Flush the streamable object from the cache
                        // Note that this also marks the blob as complete in the blob store.
                        IRef reference = FlushLargeObjectRefFromCache(sObject.Identifier);

                        // Set the IRef object in the Query.
                        vars[i] = reference;

                        // There are blobs in this Query that were written to the blob store.
                        blobsWereFlushed = true;
                    }
                }
            }

            // Evaluate the sql Query.
            Table[] results = SqlQueryExecutor.Execute(dbConnection, query);
            IQueryResponse[] responses = new IQueryResponse[results.Length];
            int j = 0;

            foreach (Table result in results) {
                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.
                    resultSetInfo = new ResultSetInfo(query, result);
                    resultId = AddResultSet(resultSetInfo);
                } catch (Exception e) {
                    // If resultId set, then dispose the result set.
                    if (resultId != -1)
                        DisposeResultSet(resultId);

                    // Handle the throwable during Query execution
                    throw HandleExecuteThrowable(e, query);
                }

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

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

            return responses;
        }