private IObjectContainer OpenDatabase()
        {
            if (File.Exists(DatabaseFile))
            {
                File.Delete(DatabaseFile);
            }
            IObjectContainer   container = Db4oFactory.OpenFile(DatabaseFile);
            NativeQueryHandler handler   = ((ObjectContainerBase)container).GetNativeQueryHandler();

            handler.QueryExecution           += OnQueryExecution;
            handler.QueryOptimizationFailure += OnQueryOptimizationFailure;
            return(container);
        }
Пример #2
0
        private void ExpectFailure(string expression, Predicate predicate)
        {
            _failures.Clear();

            Db().Configure().OptimizeNativeQueries(true);

            NativeQueryHandler handler = Stream().GetNativeQueryHandler();

            handler.QueryOptimizationFailure += new QueryOptimizationFailureHandler(OnOptimizationFailure);
            try
            {
                Db().Query(predicate);
                Assert.AreEqual(1, _failures.Count, Join(_failures));
                Assert.AreEqual("Unsupported expression: " + expression, _failures[0].Message);
            }
            finally
            {
                handler.QueryOptimizationFailure -= new QueryOptimizationFailureHandler(OnOptimizationFailure);
            }
        }
        private void AssertPredicate(int expectedId, string predicateCode, string predicateTypeName)
        {
            Assembly assembly = EmitAssemblyAndLoad(predicateTypeName + ".dll", predicateCode);

            Predicate predicate = (Predicate)System.Activator.CreateInstance(assembly.GetType(predicateTypeName));

            Db().Configure().OptimizeNativeQueries(true);

            NativeQueryHandler handler = GetNativeQueryHandler(Db());

            handler.QueryExecution += OnQueryExecution;
            try
            {
                IObjectSet os = Db().Query(predicate);
                Assert.AreEqual(1, os.Count);
                Assert.AreEqual(expectedId, ((Author)os.Next()).Id);
            }
            finally
            {
                handler.QueryExecution -= OnQueryExecution;
            }
        }
Пример #4
0
		public NativeQueryHandler GetNativeQueryHandler()
		{
			lock (_lock)
			{
				if (null == _nativeQueryHandler)
				{
					_nativeQueryHandler = new NativeQueryHandler(this);
				}
				return _nativeQueryHandler;
			}
		}