Exemplo n.º 1
0
        /// <summary>
        /// Executes the SQL statment over the Data Base connected
        /// </summary>
        /// <param name="onSql">This parameter has the current SQL statment</param>
        /// <param name="onFilterList">List of filters to check</param>
        /// <param name="comparer">This parameter has all the information refering to the order criteria to add to SQL statment</param>
        /// <param name="startRowOid">This parameter has the OID necessary to start the search</param>
        /// <param name="blockSize">This parameter represents the number of instances to be returned</param>
        public override ONCollection ExecuteSql(ONSql onSql, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria orderCriteria, ONOid startRowOid, int blockSize)
        {
            AeronaveCollection lQuery = null;
            bool lWithStartRow = (startRowOid != null).TypedValue;
            long lCount = -1;
            if (!lWithStartRow)
                lCount = 0;

            IDataReader lDataReader = null;
            ONSQLConnection lOnSQLConnection = null;

            try
            {
                lDataReader = Execute(onSql) as IDataReader;

                AeronaveInstance lInstance = null;
                AeronaveInstance lAntInstance = null;
                if (lDataReader != null)
                {
                    object[] lColumns;
                    if(displaySet == null)
                        lColumns = new object[4];
                    else
                        lColumns = new object[displaySet.ElementsInData];

                    lQuery = new AeronaveCollection(OnContext);
                    bool lFoundStartRow = false;
                    while (lDataReader.Read())
                    {
                        lAntInstance = lInstance;

                        // Read Columns
                        lDataReader.GetValues(lColumns);

                        // Read Instance
                        int lIndex = 0;
                        lInstance = LoadFacet(OnContext, displaySet, lColumns, ref lIndex);

                        // Read related attributes
                        if (displaySet != null)
                            LoadRelated(OnContext, displaySet, lColumns, lIndex, lInstance);

                        if (lCount >= 0) // Add the load instance
                        {
                            if ((onFilterList == null) || (!onFilterList.InMemory))
                            {
                                // Add to the Instance list
                                lQuery.Add(lInstance);
                                lCount++;
                            }
                            else
                            {
                                ONSQLConnection lSQLConnectionOld = (ONSQLConnection) lInstance.OnContext.SqlConnection;

                                // Set another connection because it is imposible to use
                                // the same connection that is used in the DataReader
                                if (lOnSQLConnection == null)
                                    lOnSQLConnection = GetConnection();
                                lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                if (onFilterList.FilterInMemory(lInstance))
                                {
                                    // Add to the Instance list
                                    lQuery.Add(lInstance);
                                    lCount++;
                                }

                                lInstance.OnContext.SqlConnection = lSQLConnectionOld;
                            }
                        }
                        else
                        {
                            if ((orderCriteria != null) && (orderCriteria.InMemory)) // Need to load for ordering in memory after loading
                            {
                                if (lAntInstance != null)
                                {
                                    // Set another connection because it is imposible to use
                                    // the same connection that is used in the DataReader
                                    ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection;
                                    if (lOnSQLConnection == null)
                                        lOnSQLConnection = GetConnection();
                                    lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                    int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance);
                                    if (lCompare != 0)
                                    {
                                        if (lFoundStartRow)
                                            lCount = 1;
                                        else
                                            lQuery.Clear();
                                    }

                                    // Restores the old connection
                                    lInstance.OnContext.SqlConnection = lOnSQLConnectionOld;
                                }

                                if ((onFilterList == null) || (!onFilterList.InMemory))
                                {
                                    // Add to the Instance list
                                    lQuery.Add(lInstance);
                                }
                                else
                                {
                                    ONSQLConnection lSQLConnectionOld = (ONSQLConnection)lInstance.OnContext.SqlConnection;

                                    // Set another connection because it is imposible to use
                                    // the same connection that is used in the DataReader
                                    if (lOnSQLConnection == null)
                                        lOnSQLConnection = GetConnection();
                                    lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                    if (onFilterList.FilterInMemory(lInstance))
                                    {
                                        // Add to the Instance list
                                        lQuery.Add(lInstance);
                                    }
                                    else
                                        lCount--;

                                    lInstance.OnContext.SqlConnection = lSQLConnectionOld;
                                }

                                if (lInstance.Oid.Equals(startRowOid))
                                    lFoundStartRow = true;
                            }

                            else if (lInstance.Oid.Equals(startRowOid)) // Search the start row
                                lCount = 0;
                        }

                        // Stop loading
                        if ((blockSize != 0) && (lCount > blockSize))
                        {
                            if (orderCriteria == null)
                                break;
                            else
                            {
                                // Set another connection because it is imposible to use
                                // the same connection that is used in the DataReader
                                ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection;
                                if (lOnSQLConnection == null)
                                    lOnSQLConnection = GetConnection();
                                lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance);

                                // Restores the old connection
                                lInstance.OnContext.SqlConnection = lOnSQLConnectionOld;

                                if (lCompare > 0)
                                    break;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string ltraceItem = "Method: ExecuteSql, Component: AeronaveData";
              			if (e is ONSystemException)
              			{
              				ONSystemException lException = e as ONSystemException;
              				lException.addTraceInformation(ltraceItem);
              				throw lException;
                }
              		throw new ONSystemException(e, ltraceItem);
              		}
            finally
            {
                if (lOnSQLConnection != null)
                    ONDBData.CloseConnection(lOnSQLConnection);
                if (lDataReader != null)
                {
                    if (mSqlCommand != null)
                        mSqlCommand.Cancel();
                    lDataReader.Close();
                }
                Close();
                if ((onFilterList != null) && (onFilterList.InMemory) && !lWithStartRow && (lCount <= blockSize))
                    lQuery.totalNumInstances = lQuery.Count;
            }

            return lQuery;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Execution of a sql
 /// </summary>
 /// <param name="onSql">Sentence SQL to be executed</param>
 /// <param name="onFilterList">List of filters to check</param>
 /// <param name="comparer">Order Criteria that must be followed by the query</param>
 /// <param name="startRowOID">OID frontier</param>
 /// <param name="blockSize">Number of instances to be returned</param>
 public virtual ONCollection ExecuteSql(ONSql onSql, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOID, int blockSize)
 {
     return null;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Execution of a query
 /// </summary>
 /// <param name="onSql">Sentence SQL to be executed</param>
 public ONCollection ExecuteQuery(ONSql onSql)
 {
     return ExecuteSql(onSql, null, null, null, null, 0);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Executes the sentence SQL fixing the parameters needed.
        /// </summary>
        /// <param name="onSql">Sentence SQL to be executed</param>
        public object Execute(ONSql onSql)
        {
            ArrayList lSqlParameters;
            string lSql = onSql.GenerateSQL(out lSqlParameters);

            if (onSql is ONSqlScalar)
                return ExecuteScalar(lSql, lSqlParameters);
            else if (onSql is ONSqlSelect)
                return ExecuteReader(lSql, lSqlParameters);
            else if (onSql is ONSqlInsertAutoInc)
                return ExecuteInsertAutoIncScalar(lSql, lSqlParameters);
            else
                ExecuteNonQuery(lSql, lSqlParameters);

            return null;
        }
Exemplo n.º 5
0
 public virtual ONCollection ExecuteQuery(ONSql onSql, ONFilterList onFilterList, ONOrderCriteria comparer, ONOid startRowOID, int blockSize, ONInstance instance)
 {
     return null;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Execution of a query
 /// </summary>
 /// <param name="onSql">Sentence SQL to be executed</param>
 /// <param name="comparer">Order Criteria that must be followed by the query</param>
 /// <param name="startRowOID">OID frontier</param>
 /// <param name="blockSize">Number of instances to be returned</param>
 public ONCollection ExecuteQuery(ONSql onSql, ONInstance instance)
 {
     return ExecuteQuery(onSql, null, null, null, 0, instance);
 }