コード例 #1
0
        public void SetUp()
        {
            const string sql = "select myvarchar from mytesttable where mynumeric = ? order by mybigint asc";

            var databaseConnectionFactory = SupportDatabaseService.MakeService().GetConnectionFactory("mydb");
            var connectionCache           = new ConnectionNoCacheImpl(databaseConnectionFactory, sql, null);

            var resultProperties = new Dictionary <String, Object>();

            resultProperties["myvarchar"] = typeof(string);
            var resultEventType = SupportEventAdapterService.Service.CreateAnonymousMapType("test", resultProperties);

            IDictionary <String, DBOutputTypeDesc> propertiesOut = new Dictionary <String, DBOutputTypeDesc>();

            propertiesOut["myvarchar"] = new DBOutputTypeDesc("TIME", typeof(string), null);

            _dbPollExecStrategy = new PollExecStrategyDBQuery(
                SupportEventAdapterService.Service,
                resultEventType,
                connectionCache,
                sql,
                propertiesOut,
                null,
                null);
        }
コード例 #2
0
        /// <summary>
        /// Creates the viewable for polling via database SQL query.
        /// </summary>
        /// <param name="statementId">The statement id.</param>
        /// <param name="streamNumber">is the stream number of the view</param>
        /// <param name="databaseStreamSpec">provides the SQL statement, database name and additional info</param>
        /// <param name="databaseConfigService">for getting database connection and settings</param>
        /// <param name="eventAdapterService">for generating event beans from database information</param>
        /// <param name="epStatementAgentInstanceHandle">The ep statement agent instance handle.</param>
        /// <param name="contextAttributes">The db attributes.</param>
        /// <param name="columnTypeConversionHook">The column type conversion hook.</param>
        /// <param name="outputRowConversionHook">The output row conversion hook.</param>
        /// <param name="enableAdoLogging">if set to <c>true</c> [enable JDBC logging].</param>
        /// <param name="dataCacheFactory">The data cache factory.</param>
        /// <param name="statementContext">The statement context.</param>
        /// <returns>
        /// viewable providing poll functionality
        /// </returns>
        /// <exception cref="ExprValidationException">the validation failed</exception>
        public static HistoricalEventViewable CreateDBStatementView(
            int statementId,
            int streamNumber,
            DBStatementStreamSpec databaseStreamSpec,
            DatabaseConfigService databaseConfigService,
            EventAdapterService eventAdapterService,
            EPStatementAgentInstanceHandle epStatementAgentInstanceHandle,
            IEnumerable <Attribute> contextAttributes,
            SQLColumnTypeConversion columnTypeConversionHook,
            SQLOutputRowConversion outputRowConversionHook,
            bool enableAdoLogging,
            DataCacheFactory dataCacheFactory,
            StatementContext statementContext)
        {
            // Parse the SQL for placeholders and text fragments
            var            sqlFragments = GetSqlFragments(databaseStreamSpec);
            IList <String> invocationInputParameters = new List <string>();

            foreach (var fragment in sqlFragments)
            {
                if ((fragment.IsParameter) && (fragment.Value != SAMPLE_WHERECLAUSE_PLACEHOLDER))
                {
                    invocationInputParameters.Add(fragment.Value);
                }
            }

            // Get the database information
            var databaseName = databaseStreamSpec.DatabaseName;
            var dbDriver     = GetDatabaseConnectionFactory(databaseConfigService, databaseName).Driver;
            var dbCommand    = dbDriver.CreateCommand(
                sqlFragments,
                GetMetaDataSettings(databaseConfigService, databaseName),
                contextAttributes);

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".CreateDBStatementView dbCommand=" + dbCommand);
            }

            var queryMetaData = GetQueryMetaData(
                databaseStreamSpec,
                databaseConfigService,
                dbCommand,
                contextAttributes);

            Func <SQLColumnTypeContext, Type> columnTypeConversionFunc = null;

            if (columnTypeConversionHook != null)
            {
                columnTypeConversionFunc = columnTypeConversionHook.GetColumnType;
            }

            Func <SQLOutputRowTypeContext, Type> outputRowConversionFunc = null;

            if (outputRowConversionHook != null)
            {
                outputRowConversionFunc = outputRowConversionHook.GetOutputRowType;
            }

            // Construct an event type from SQL query result metadata
            var eventType = CreateEventType(
                statementId,
                streamNumber,
                queryMetaData,
                eventAdapterService,
                databaseStreamSpec,
                columnTypeConversionFunc,
                outputRowConversionFunc);

            // Get a proper connection and data cache
            ConnectionCache connectionCache;
            DataCache       dataCache;

            try
            {
                connectionCache = databaseConfigService.GetConnectionCache(
                    databaseName, dbCommand.PseudoText, contextAttributes);
                dataCache = databaseConfigService.GetDataCache(
                    databaseName, statementContext, epStatementAgentInstanceHandle, dataCacheFactory, streamNumber);
            }
            catch (DatabaseConfigException e)
            {
                const string text = "Error obtaining cache configuration";
                Log.Error(text, e);
                throw new ExprValidationException(text + ", reason: " + e.Message, e);
            }

            var dbPollStrategy = new PollExecStrategyDBQuery(
                eventAdapterService,
                eventType,
                connectionCache,
                dbCommand.CommandText,
                queryMetaData.OutputParameters,
                columnTypeConversionHook,
                outputRowConversionHook);

            return(new DatabasePollingViewable(
                       streamNumber,
                       invocationInputParameters,
                       dbPollStrategy,
                       dataCache,
                       eventType));
        }