/// <summary>
        /// Returns a new cache implementation for this database.
        /// </summary>
        /// <param name="databaseName">the name of the database to return a new cache implementation for for</param>
        /// <param name="epStatementAgentInstanceHandle">is the statements-own handle for use in registering callbacks with services</param>
        /// <returns>cache implementation</returns>
        /// <throws>  DatabaseConfigException is thrown to indicate database configuration errors </throws>
        public virtual DataCache GetDataCache(String databaseName, EPStatementAgentInstanceHandle epStatementAgentInstanceHandle)
        {
            ConfigurationDBRef config;

            if (!_mapDatabaseRef.TryGetValue(databaseName, out config))
            {
                throw new DatabaseConfigException("Cannot locate configuration information for database '" + databaseName + "'");
            }

            ConfigurationDataCache dataCacheDesc = config.DataCacheDesc;

            return(DataCacheFactory.GetDataCache(dataCacheDesc, epStatementAgentInstanceHandle, _schedulingService, _scheduleBucket));
        }
示例#2
0
        public void TestGetCache()
        {
            var dataCacheFactory = new DataCacheFactory();

            Assert.That(_databaseServiceImpl.GetDataCache("name1", null, null, dataCacheFactory, 0), Is.InstanceOf <DataCacheNullImpl>());

            var lru = (DataCacheLRUImpl)_databaseServiceImpl.GetDataCache("name2", null, null, dataCacheFactory, 0);

            Assert.AreEqual(10000, lru.CacheSize);

            var exp = (DataCacheExpiringImpl)_databaseServiceImpl.GetDataCache("name3", null, null, dataCacheFactory, 0);

            Assert.AreEqual(1000, exp.MaxAgeMSec);
            Assert.AreEqual(3000, exp.PurgeIntervalMSec);
        }
示例#3
0
        public void TestGetCache()
        {
            var statementContext = SupportStatementContextFactory.MakeContext();

            var dataCacheFactory = new DataCacheFactory();

            Assert.That(_databaseServiceImpl.GetDataCache("name1", null, null, dataCacheFactory, 0), Is.InstanceOf <DataCacheNullImpl>());

            var lru = (DataCacheLRUImpl)_databaseServiceImpl.GetDataCache("name2", statementContext, null, dataCacheFactory, 0);

            Assert.AreEqual(10000, lru.CacheSize);

            var exp = (DataCacheExpiringImpl)_databaseServiceImpl.GetDataCache("name3", statementContext, null, dataCacheFactory, 0);

            Assert.AreEqual(1.0d, exp.MaxAgeSec);
            Assert.AreEqual(3.0d, exp.PurgeIntervalSec);
        }
示例#4
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));
        }