當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。