本文整理汇总了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;
}
示例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;
}
示例3: UpdateObjectHibernateCallback
public UpdateObjectHibernateCallback(HibernateTemplate template, object entity, LockMode lockMode)
{
this.outer = template;
this.entity = entity;
this.lockMode = lockMode;
}
示例4: SaveOrUpdateCopyHibernateCallback
public SaveOrUpdateCopyHibernateCallback(HibernateTemplate template, object entity)
{
this.outer = template;
this.entity = entity;
}
示例5: FindByNamedQueryAndValueObjectHibernateCallback
public FindByNamedQueryAndValueObjectHibernateCallback(HibernateTemplate template, string queryName, object valueObject)
{
this.outer = template;
this.queryName = queryName;
this.valueObject = valueObject;
}
示例6: LoadAllByTypeHibernateCallback
public LoadAllByTypeHibernateCallback(HibernateTemplate template, Type entityType)
{
outer = template;
this.entityType = entityType;
}
示例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();
}
示例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;
}
示例9: PropagationSupportsTxCallback
public PropagationSupportsTxCallback(HibernateTemplate ht, ISession session2)
{
this.ht = ht;
this.session2 = session2;
}
示例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)));
}
示例13: FindHibernateCallback
public FindHibernateCallback(HibernateTemplate template, string queryString, object[] values, IType[] types)
{
this.outer = template;
this.queryString = queryString;
this.values = values;
this.types = types;
}
示例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;
}
示例15: FindByValueObjectHibernateCallback
public FindByValueObjectHibernateCallback(HibernateTemplate template, string queryString, object valueObject)
{
this.outer = template;
this.queryString = queryString;
this.valueObject = valueObject;
}