当前位置: 首页>>代码示例>>C#>>正文


C# NHibernate.HibernateTemplate类代码示例

本文整理汇总了C#中Spring.Data.NHibernate.HibernateTemplate的典型用法代码示例。如果您正苦于以下问题:C# HibernateTemplate类的具体用法?C# HibernateTemplate怎么用?C# HibernateTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HibernateTemplate类属于Spring.Data.NHibernate命名空间,在下文中一共展示了HibernateTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getSession

 public static ISession getSession(HibernateTemplate template)
 {
     if (session == null || !session.IsConnected)
     {
         session = template.SessionFactory.OpenSession();
     }
     return session;
 }
开发者ID:DelLitt,项目名称:opmscoral,代码行数:8,代码来源:DbUtility.cs

示例2: DoInTransaction

        public object DoInTransaction(ITransactionStatus status)
        {
            Assert.IsTrue(!TransactionSynchronizationManager.HasResource(sf), "Hasn't thread session");
            Assert.IsTrue(!status.IsNewTransaction, "Is not new transaction");

            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
            Assert.IsFalse(TransactionSynchronizationManager.ActualTransactionActive);

            HibernateTemplate ht = new HibernateTemplate(sf);
            ht.TemplateFlushMode = TemplateFlushMode.Eager;
            object returnValue = ht.Execute(new HibernateDelegate(Del));
            Assert.IsTrue(TransactionSynchronizationManager.HasResource(sf), "Has thread session");
            return null;
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:14,代码来源:HibernateTransactionManagerTests.cs

示例3: UpdateObjectHibernateCallback

 public UpdateObjectHibernateCallback(HibernateTemplate template, object entity, LockMode lockMode)
 {
     this.outer = template;
     this.entity = entity;
     this.lockMode = lockMode;
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:6,代码来源:HibernateTemplate.cs

示例4: SaveOrUpdateCopyHibernateCallback

 public SaveOrUpdateCopyHibernateCallback(HibernateTemplate template, object entity)
 {
     this.outer = template;
     this.entity = entity;
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:5,代码来源:HibernateTemplate.cs

示例5: FindByNamedQueryAndValueObjectHibernateCallback

 public FindByNamedQueryAndValueObjectHibernateCallback(HibernateTemplate template, string queryName, object valueObject)
 {
     this.outer = template;
     this.queryName = queryName;
     this.valueObject = valueObject;
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:6,代码来源:HibernateTemplate.cs

示例6: LoadAllByTypeHibernateCallback

 public LoadAllByTypeHibernateCallback(HibernateTemplate template, Type entityType)
 {
     outer = template;
     this.entityType = entityType;
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:5,代码来源:HibernateTemplate.cs

示例7: TransactionWithPropagationSupportsAndInnerTransaction

        public void TransactionWithPropagationSupportsAndInnerTransaction()
        {
            IDbConnection connection = mocks.StrictMock<IDbConnection>();
            ISessionFactory sessionFactory = mocks.StrictMock<ISessionFactory>();
            ISession session1 = mocks.StrictMock<ISession>();
            ISession session2 = mocks.StrictMock<ISession>();
            ITransaction transaction = mocks.StrictMock<ITransaction>();

            Expect.Call(sessionFactory.OpenSession()).Return(session1);
            Expect.Call(session1.Connection).Return(connection);
            Expect.Call(session1.SessionFactory).Return(sessionFactory);
            Expect.Call(session1.FlushMode).Return(FlushMode.Auto).Repeat.Twice();

            session1.Flush();
            LastCall.IgnoreArguments().Repeat.Twice();
            Expect.Call(session1.Close()).Return(null);

            Expect.Call(sessionFactory.OpenSession()).Return(session2);
            Expect.Call(session2.Connection).Return(connection).Repeat.Twice();
            Expect.Call(session2.BeginTransaction(IsolationLevel.ReadCommitted)).Return(transaction);
            Expect.Call(session2.FlushMode).Return(FlushMode.Auto);
            session2.Flush();
            LastCall.IgnoreArguments();
            Expect.Call(session2.IsOpen).Return(true);


            transaction.Commit();
            LastCall.On(transaction).Repeat.Once();


            Expect.Call(session2.Close()).Return(null);

            mocks.ReplayAll();

            LocalSessionFactoryObjectStub lsfo = new LocalSessionFactoryObjectStub(sessionFactory);
            lsfo.AfterPropertiesSet();
            ISessionFactory sfProxy = (ISessionFactory)lsfo.GetObject();
            Assert.IsNotNull(sfProxy);

            HibernateTransactionManager tm = new HibernateTransactionManager(sessionFactory);
            tm.TransactionSynchronization = TransactionSynchronizationState.Always;
            
            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.PropagationBehavior = TransactionPropagation.Supports;
            TransactionTemplate tt2 = new TransactionTemplate(tm);
            tt2.PropagationBehavior = TransactionPropagation.Required;

            HibernateTemplate ht = new HibernateTemplate(sessionFactory);
            ht.TemplateFlushMode = TemplateFlushMode.Eager;
            ht.ExposeNativeSession = true;

            Assert.IsTrue(!TransactionSynchronizationManager.HasResource(sessionFactory), "Hasn't thread session");

            tt.Execute(new TransactionWithPropagationSupportsAndInnerTransactionTxCallback(tt2, sessionFactory, ht, session1, session2));

            Assert.IsTrue(!TransactionSynchronizationManager.HasResource(sessionFactory), "Hasn't thread session");
            
            mocks.ReplayAll();
            
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:60,代码来源:HibernateTransactionManagerTests.cs

示例8: TransactionWithPropagationSupportsAndInnerTransactionTxCallback

 public TransactionWithPropagationSupportsAndInnerTransactionTxCallback(TransactionTemplate tt, 
     ISessionFactory sf, HibernateTemplate ht, ISession session1, ISession session2)
 {
     this.tt = tt;
     this.sf = sf;
     this.ht = ht;
     this.session1 = session1;
     this.session2 = session2;
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:9,代码来源:HibernateTransactionManagerTests.cs

示例9: PropagationSupportsTxCallback

 public PropagationSupportsTxCallback(HibernateTemplate ht, ISession session2)
 {
     this.ht = ht;
     this.session2 = session2;
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:5,代码来源:HibernateTransactionManagerTests.cs

示例10: UpdateDatabaseSchema

        /// <summary>
        /// Execute schema update script, determined by the Configuration object
        /// used for creating the SessionFactory. A replacement for NHibernate's
        /// SchemaUpdate class, for automatically executing schema update scripts
        /// on application startup. Can also be invoked manually.
        /// </summary>
        /// <remarks>
        /// Fetch the LocalSessionFactoryObject itself rather than the exposed
        /// SessionFactory to be able to invoke this method, e.g. via
        /// <code>LocalSessionFactoryObject lsfo = (LocalSessionFactoryObject) ctx.GetObject("mySessionFactory");</code>.
        /// <p>
        /// Uses the SessionFactory that this bean generates for accessing a ADO.NET
        /// connection to perform the script.
        /// </p>
        /// </remarks>
	    public virtual void UpdateDatabaseSchema() 
        {
		    log.Info("Updating database schema for Hibernate SessionFactory");
		    HibernateTemplate hibernateTemplate = new HibernateTemplate(sessionFactory);
		    hibernateTemplate.TemplateFlushMode = TemplateFlushMode.Never;
            hibernateTemplate.Execute(
                new HibernateDelegate(delegate(ISession session)
                                          {
                                              IDbConnection con = session.Connection;
                                              Dialect dialect = Dialect.GetDialect(Configuration.Properties);
                                              DatabaseMetadata metadata = new DatabaseMetadata((DbConnection) con, dialect);
                                              string[] sql = Configuration.GenerateSchemaUpdateScript(dialect, metadata);
                                              ExecuteSchemaScript(con, sql);
                                              return null;
                                          }));
	    }
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:31,代码来源:LocalSessionFactoryObject.cs

示例11: CreateDatabaseSchema

        /// <summary>
        /// Execute schema creation script, determined by the Configuration object
        /// used for creating the SessionFactory. A replacement for NHibernate's
        /// SchemaExport class, to be invoked on application setup.
        /// </summary>
        /// <remarks>
        /// Fetch the LocalSessionFactoryObject itself rather than the exposed
        /// SessionFactory to be able to invoke this method, e.g. via
        /// <code>LocalSessionFactoryObject lsfo = (LocalSessionFactoryObject) ctx.GetObject("mySessionFactory");</code>.
        /// <p>
        /// Uses the SessionFactory that this bean generates for accessing a ADO.NET
        /// connection to perform the script.
        /// </p>
        /// </remarks>
        public void CreateDatabaseSchema()
        {
		    log.Info("Creating database schema for Hibernate SessionFactory");
		    HibernateTemplate hibernateTemplate = new HibernateTemplate(sessionFactory);
		    hibernateTemplate.Execute(
			    new HibernateDelegate(delegate (ISession session)
                {
					    IDbConnection con = session.Connection;
					    Dialect dialect = Dialect.GetDialect(Configuration.Properties);
					    string[] sql = Configuration.GenerateSchemaCreationScript(dialect);
					    ExecuteSchemaScript(con, sql);
					    return null;
    			
			    }));		
	    }
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:29,代码来源:LocalSessionFactoryObject.cs

示例12: ExceptionTranslator

        public void ExceptionTranslator()
        {
	        ISessionFactory sessionFactory = ctx["SessionFactory"] as ISessionFactory;
	        HibernateTemplate template = new HibernateTemplate(sessionFactory);
            IAdoExceptionTranslator translator = template.AdoExceptionTranslator;
	        Assert.IsNotNull(translator, "ADO.NET exception translator should not be null");
	        
	        Assert.That(translator, Is.InstanceOf(typeof(ErrorCodeExceptionTranslator)));
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:9,代码来源:TemplateTests.cs

示例13: FindHibernateCallback

 public FindHibernateCallback(HibernateTemplate template, string queryString, object[] values, IType[] types)
 {
     this.outer = template;
     this.queryString = queryString;
     this.values = values;
     this.types = types;
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:7,代码来源:HibernateTemplate.cs

示例14: FindByNamedQueryAndNamedParamHibernateCallback

 public FindByNamedQueryAndNamedParamHibernateCallback(HibernateTemplate template, string queryName, string[] paramNames, object[] values, IType[] types)
 {
     this.outer = template;
     this.queryName = queryName;
     this.paramNames = paramNames;
     this.values = values;
     this.types = types;
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:8,代码来源:HibernateTemplate.cs

示例15: FindByValueObjectHibernateCallback

 public FindByValueObjectHibernateCallback(HibernateTemplate template, string queryString, object valueObject)
 {
     this.outer = template;
     this.queryString = queryString;
     this.valueObject = valueObject;
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:6,代码来源:HibernateTemplate.cs


注:本文中的Spring.Data.NHibernate.HibernateTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。