GetDbProvider() public static method

Gets the Spring IDbProvider given the ISessionFactory.
The matching is performed by comparing the assembly qualified name string of the hibernate Driver.ConnectionType to those in the DbProviderFactory definitions. No connections are created in performing this comparison.
If DbProviderFactory's ApplicaitonContext is not /// an instance of IConfigurableApplicaitonContext.
public static GetDbProvider ( ISessionFactory sessionFactory ) : IDbProvider
sessionFactory ISessionFactory The session factory.
return IDbProvider
        /// <summary>
        /// Invoked by an <see cref="Spring.Objects.Factory.IObjectFactory"/>
        /// after it has injected all of an object's dependencies.
        /// </summary>
        /// <remarks>
        /// <p>
        /// This method allows the object instance to perform the kind of
        /// initialization only possible when all of it's dependencies have
        /// been injected (set), and to throw an appropriate exception in the
        /// event of misconfiguration.
        /// </p>
        /// <p>
        /// Please do consult the class level documentation for the
        /// <see cref="Spring.Objects.Factory.IObjectFactory"/> interface for a
        /// description of exactly <i>when</i> this method is invoked. In
        /// particular, it is worth noting that the
        /// <see cref="Spring.Objects.Factory.IObjectFactoryAware"/>
        /// and <see cref="Spring.Context.IApplicationContextAware"/>
        /// callbacks will have been invoked <i>prior</i> to this method being
        /// called.
        /// </p>
        /// </remarks>
        /// <exception cref="System.ArgumentException">
        /// In the event of misconfiguration (such as the failure to set a
        /// required property) or if initialization fails.
        /// </exception>
        public void AfterPropertiesSet()
        {
            if (SessionFactory == null)
            {
                throw new ArgumentException("sessionFactory is required");
            }
            if (this.entityInterceptor is string && this.objectFactory == null)
            {
                throw new ArgumentException("objectFactory is required for entityInterceptorBeanName");
            }

            // Try to derive a DbProvider given the SessionFactory.
            if (this.autodetectDbProvider && DbProvider == null)
            {
                IDbProvider sfDbProvider = SessionFactoryUtils.GetDbProvider(SessionFactory);
                if (sfDbProvider != null)
                {
                    // Use the SessionFactory's DataSource for exposing transactions to ADO.NET code.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Derived DbProvider [" + sfDbProvider.DbMetadata.ProductName +
                                 "] of Hibernate SessionFactory for HibernateTransactionManager");
                    }
                    DbProvider = sfDbProvider;
                }
                else
                {
                    log.Info("Could not auto detect DbProvider from SessionFactory configuration");
                }
            }
        }
Beispiel #2
0
        public void DbProviderTranslation()
        {
            ISessionFactory sf         = ctx["SessionFactory"] as ISessionFactory;
            IDbProvider     dbProvider = SessionFactoryUtils.GetDbProvider(sf);

            Assert.That(dbProvider.DbMetadata.ProductName, Does.Contain("Microsoft SQL Server"));
        }
Beispiel #3
0
        public void DbProviderTranslation()
        {
            ISessionFactory sf         = ctx["SessionFactory"] as ISessionFactory;
            IDbProvider     dbProvider = SessionFactoryUtils.GetDbProvider(sf);

            Assert.IsTrue(dbProvider.DbMetadata.ProductName.Contains("Microsoft SQL Server, provider"));
            Assert.IsTrue(dbProvider.DbMetadata.ProductName.Contains("in framework .NET"));
        }
        public void DbProviderTransalation()
        {
            ISessionFactory sf         = ctx["SessionFactory"] as ISessionFactory;
            IDbProvider     dbProvider = SessionFactoryUtils.GetDbProvider(sf);

#if NET_2_0
            Assert.AreEqual("Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0",
                            dbProvider.DbMetadata.ProductName);
#else
            Assert.AreEqual("Microsoft SQL Server, provider V1.0.5000.0 in framework .NET V1.1",
                            dbProvider.DbMetadata.ProductName);
#endif
        }
        public void SessionFactoryUtilsWithGetDbProvider()
        {
            ISessionFactoryImplementor sessionFactory = A.Fake <ISessionFactoryImplementor>();

            DriverBase driver = A.Fake <DriverBase>();

            A.CallTo(() => driver.CreateCommand()).Returns(new SqlCommand());

            IConnectionProvider cp = A.Fake <IConnectionProvider>();

            A.CallTo(() => cp.Driver).Returns(driver);

            A.CallTo(() => sessionFactory.ConnectionProvider).Returns(cp);

            IDbProvider provider = SessionFactoryUtils.GetDbProvider(sessionFactory);

            Assert.AreEqual(typeof(SqlCommand), provider.DbMetadata.CommandType);
        }
Beispiel #6
0
        public void SessionFactoryUtilsWithGetDbProvider()
        {
            MockRepository             mockery        = new MockRepository();
            ISessionFactoryImplementor sessionFactory = (ISessionFactoryImplementor)mockery.CreateMultiMock(typeof(ISessionFactory), typeof(ISessionFactoryImplementor));

            IDriver driver = (IDriver)mockery.DynamicMock(typeof(IDriver));

            Expect.Call(driver.CreateCommand()).Repeat.AtLeastOnce().Return(new SqlCommand());

            IConnectionProvider cp = (IConnectionProvider)mockery.DynamicMock(typeof(IConnectionProvider));

            Expect.Call(cp.Driver).Repeat.AtLeastOnce().Return(driver);

            Expect.Call(sessionFactory.ConnectionProvider).Repeat.AtLeastOnce().Return(cp);

            mockery.ReplayAll();
            IDbProvider provider = SessionFactoryUtils.GetDbProvider(sessionFactory);

            Assert.AreEqual(typeof(SqlCommand), provider.DbMetadata.CommandType);

            mockery.VerifyAll();
        }