public void Refresh() { Paper paper; using (IStatelessSession ss = sessions.OpenStatelessSession()) { using (ITransaction tx = ss.BeginTransaction()) { paper = new Paper {Color = "whtie"}; ss.Insert(paper); tx.Commit(); } } using (IStatelessSession ss = sessions.OpenStatelessSession()) { using (ITransaction tx = ss.BeginTransaction()) { var p2 = ss.Get<Paper>(paper.Id); p2.Color = "White"; ss.Update(p2); tx.Commit(); } } using (IStatelessSession ss = sessions.OpenStatelessSession()) { using (ITransaction tx = ss.BeginTransaction()) { Assert.AreEqual("whtie", paper.Color); ss.Refresh(paper); Assert.AreEqual("White", paper.Color); ss.Delete(paper); tx.Commit(); } } }
private void UpdateOldUsersSessions(AnalyticsHttpContextExtensions.AnalyticsUserChangedResult changedResult, AnalyticsSession analyticsSession, AnalyticsUser analyticsUser) { if (!changedResult.OldGuid.HasValue || analyticsUser.Guid == changedResult.OldGuid.Value) { return; } _session.Transact(session => { analyticsSession.AnalyticsUser = analyticsUser; _session.Update(analyticsSession); var oldUser = GetUser(changedResult.OldGuid.Value); if (oldUser != null && oldUser.Id != analyticsUser.Id) { // this must have been the current user, so move over their sessions var analyticsSessions = _session.QueryOver <AnalyticsSession>().Where(x => x.AnalyticsUser.Id == oldUser.Id).List(); foreach (var entity in analyticsSessions) { entity.AnalyticsUser = analyticsUser; _session.Update(entity); } _session.Delete(oldUser); } }); }
public void CreateUpdateReadDelete() { Document doc; DateTime?initVersion; using (IStatelessSession ss = sessions.OpenStatelessSession()) { ITransaction tx; using (tx = ss.BeginTransaction()) { doc = new Document("blah blah blah", "Blahs"); ss.Insert(doc); Assert.IsNotNull(doc.LastModified); initVersion = doc.LastModified; Assert.IsTrue(initVersion.HasValue); tx.Commit(); } Thread.Sleep(100); // Only to be secure that next modification have a different version using (tx = ss.BeginTransaction()) { doc.Text = "blah blah blah .... blah"; ss.Update(doc); Assert.IsTrue(doc.LastModified.HasValue); Assert.AreNotEqual(initVersion, doc.LastModified); tx.Commit(); } using (tx = ss.BeginTransaction()) { doc.Text = "blah blah blah .... blah blay"; ss.Update(doc); tx.Commit(); } var doc2 = ss.Get <Document>("Blahs"); Assert.AreEqual("Blahs", doc2.Name); Assert.AreEqual(doc.Text, doc2.Text); doc2 = (Document)ss.CreateQuery("from Document where text is not null").UniqueResult(); Assert.AreEqual("Blahs", doc2.Name); Assert.AreEqual(doc.Text, doc2.Text); doc2 = (Document)ss.CreateSQLQuery("select * from Document").AddEntity(typeof(Document)).UniqueResult(); Assert.AreEqual("Blahs", doc2.Name); Assert.AreEqual(doc.Text, doc2.Text); doc2 = ss.CreateCriteria <Document>().UniqueResult <Document>(); Assert.AreEqual("Blahs", doc2.Name); Assert.AreEqual(doc.Text, doc2.Text); doc2 = (Document)ss.CreateCriteria(typeof(Document)).UniqueResult(); Assert.AreEqual("Blahs", doc2.Name); Assert.AreEqual(doc.Text, doc2.Text); using (tx = ss.BeginTransaction()) { ss.Delete(doc); tx.Commit(); } } }
public virtual void DeleteStateless(String name) { using (IStatelessSession session = sessManager.OpenStatelessSession()) { NUnit.Framework.Assert.IsNotNull(session.Transaction); session.Delete("from Blog b where b.Name ='" + name + "'"); } }
public void Delete(object obj) { if (_isStateless) { _wrapStateless.Delete(obj); } else { _wrap.Delete(obj); } }
public virtual void DeleteStateless(int orderId) { using (IStatelessSession session = sessManager.OpenStatelessSession("db2")) { NUnit.Framework.Assert.IsNotNull(session.Transaction); var order = (Order)session.Get(typeof(Order).FullName, orderId); session.Delete(order); } }
/// <summary> /// Deletes the instance from the database using IStatelessSession. /// </summary> /// <param name="instance">The instance to be deleted from the database</param> public void DeleteStateless(object instance) { using (IStatelessSession session = GetStatelessSession()) { try { session.Delete(instance); } catch (Exception ex) { throw new DataException("Could not perform DeleteStateless for " + instance.GetType().Name, ex); } } }
/// <summary> /// Deletes all rows for the specified type using IStatelessSession. /// </summary> /// <param name="type">type on which the rows on the database should be deleted</param> public void DeleteAllStateless(Type type) { using (IStatelessSession session = GetStatelessSession()) { try { session.Delete(String.Format("from {0}", type.Name)); } catch (Exception ex) { throw new DataException("Could not perform DeleteAllStateless for " + type.Name, ex); } } }
protected override void OnExecute() { IStatelessSession statelessSession = _sessionFactory.OpenStatelessSession(); System.Collections.Generic.IList <QueuedTask> logs = statelessSession.QueryOver <QueuedTask>().Where(data => data.CompletedAt <= CurrentRequestData.Now.AddDays(-1)).List(); using (ITransaction transaction = statelessSession.BeginTransaction()) { foreach (QueuedTask log in logs) { statelessSession.Delete(log); } transaction.Commit(); } }
protected override void OnExecute() { IStatelessSession statelessSession = _sessionFactory.OpenStatelessSession(); IList <SessionData> sessionDatas = statelessSession.QueryOver <SessionData>() .Where(data => data.ExpireOn <= CurrentRequestData.Now).List(); using (ITransaction transaction = statelessSession.BeginTransaction()) { foreach (SessionData sessionData in sessionDatas) { statelessSession.Delete(sessionData); } transaction.Commit(); } }
protected override void OnExecute() { var logs = GetLogs(); while (logs.Any()) { IList <Log> currentLogs = logs; _statelessSession.Transact(session => { foreach (var log in currentLogs) { _statelessSession.Delete(log); } }); logs = GetLogs(); } }
public virtual void Delete(IEnumerable <TEntity> list, int batchSize) { if (_statelessSession == null) { throw new InvalidOperationException("stateless connection not created for batch delete"); } using (var transaction = _statelessSession.BeginTransaction()) { _statelessSession.SetBatchSize(batchSize); foreach (var entity in list) { _statelessSession.Delete(entity); } transaction.Commit(); } }
public void Stateless_GetObject_Tests() { Assert.IsNull(_session.GetObject <User>(x => x.Name == "test")); _session.Insert(new User { Name = "test" }); var user = _session.GetObject <User>(x => x.Name == "test"); Assert.IsNotNull(user); user.Name = "foo"; _session.Update(user); user = _session.GetObject <User>(x => x.Name == "foo"); Assert.IsNotNull(user); _session.Delete(user); Assert.IsNull(_session.GetObject <User>(x => x.Name == "foo")); }
public void InitId() { Paper paper; using (IStatelessSession ss = sessions.OpenStatelessSession()) { ITransaction tx; using (tx = ss.BeginTransaction()) { paper = new Paper {Color = "White"}; ss.Insert(paper); Assert.IsTrue(paper.Id != 0); tx.Commit(); } using (tx = ss.BeginTransaction()) { ss.Delete(ss.Get<Paper>(paper.Id)); tx.Commit(); } } }
/// <summary> /// Deletes given object from database. /// </summary> /// <param name="obj">Object to be deleted.</param> /// <returns>True if operation was succesful.</returns> public bool Delete(object obj) { try { using (IStatelessSession session = sessionFactory.OpenStatelessSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Delete(obj); transaction.Commit(); return(true); } } } catch (Exception e) { m_log.Error("[NHIBERNATE] issue deleting object ", e); return(false); } }
public bool bulkDelete(IList <object> coll) { try { using (IStatelessSession statelessSession = NHibernateHelper.OpenStatelessSession()) using (ITransaction transaction = statelessSession.BeginTransaction()) try { foreach (Object obj in coll) { statelessSession.Delete(obj); } transaction.Commit(); Utility.logFile(Utility.getCurrentMethodName(2) + Constant.PERSISTENCE_METHOD_SUCCESS, null, Constant.LOGTYPE_INFO); return(true); } catch (GenericADOException ex) { transaction.Rollback(); Utility.logFile(ex.Message, ex.InnerException, Constant.LOGTYPE_ERROR); return(false); } catch (Exception ex) { transaction.Rollback(); Utility.logFile(ex.Message, ex.InnerException, Constant.LOGTYPE_ERROR); return(false); } } catch (Exception ex) { Utility.logFile(ex.Message, ex.InnerException, Constant.LOGTYPE_ERROR); return(false); } }
/// <summary> /// Delete a entity. /// </summary> /// <param name="entity">a detached entity instance </param> public void Delete(object entity) { innerSession.Delete(entity); }
public void Delete(object entity) { _session.Delete(entity); }
/// <summary> /// Deletes the object. /// </summary> /// <param name="entity">The entity.</param> public void Delete(T entity) { Session.Delete(entity); }
public void Delete(string entityName, object obj) { statelessSession.Delete(entityName, obj); }
public void Delete(object entity) { EnsureWriteLock(); _session.Delete(entity); }
public int SynchroniseTableInserts(ISession sourceSession, IStatelessSession destinationSession, Func <T, bool> predicate, Synchroniser.SyncDirection syncDirection, Synchroniser.SyncType syncType) //, List<T> sourceList { int result = 0; int batchSize = 50; int numBatches = 0; List <T> sourceList; try { // get the source list -- don't use filtering if in replace mode TUFStatus.DAL.Repositories.Repository <ISession, T> sourceRepo = new TUFStatus.DAL.Repositories.Repository <ISession, T>(sourceSession); if (syncType == Synchroniser.SyncType.Replace) { // delete all records first var xa = destinationSession.BeginTransaction(); ///var metaData = destinationSession.SessionFactory.GetClassMetadata(typeof(T)) as NHibernate.Persister.Entity.AbstractEntityPersister; ///string table = metaData.TableName; ///string deleteAll = string.Format("DELETE FROM \"{0}\"", table); ///destinationSession.CreateSQLQuery(deleteAll).ExecuteUpdate(); //destinationSession.Delete("Select * from " + typeof(T)); destinationSession.Delete("from " + typeof(T)); //TUFStatus.DAL.Repositories.Repository<ISession, T> destRepo = new TUFStatus.DAL.Repositories.Repository<ISession, T>(destinationSession); //List<T> deleteList = sourceRepo.All().ToList() ; //foreach (T deleteItem in deleteList) //{ // destRepo.Delete(deleteItem); //} xa.Commit(); sourceList = sourceRepo.All().ToList(); } else { sourceList = sourceRepo.All().Where(predicate).ToList(); } // split into batch-size chunks numBatches = sourceList.Count() / batchSize; if ((sourceList.Count() % batchSize) > 0) { numBatches += 1; } for (int b = 0; b < numBatches; b++) { var xa = destinationSession.BeginTransaction(); for (int i = 0; i < batchSize; i++) { int item = (b * batchSize) + i; if (item < sourceList.Count()) { destinationSession.Insert(sourceList[(b * batchSize) + i]); //Merge result += 1; } } xa.Commit(); sourceRepo = null; } } catch (Exception ex) { ErrorHandler.Instance.HandleError(ActionLog.ActionTypes.Application, "", "There was an error syncronising inserts for " + typeof(T).ToString() + ":", ex.Message); result = -1; } return(result); }