コード例 #1
0
		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();
				}
			}
		}
コード例 #2
0
        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);
                }
            });
        }
コード例 #3
0
        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();
                }
            }
        }
コード例 #4
0
 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 + "'");
     }
 }
コード例 #5
0
 public void Delete(object obj)
 {
     if (_isStateless)
     {
         _wrapStateless.Delete(obj);
     }
     else
     {
         _wrap.Delete(obj);
     }
 }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
 /// <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);
         }
     }
 }
コード例 #8
0
 /// <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);
         }
     }
 }
コード例 #9
0
        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();
            }
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        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();
            }
        }
コード例 #12
0
        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();
            }
        }
コード例 #13
0
        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"));
        }
コード例 #14
0
		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();
				}
			}
		}
コード例 #15
0
        /// <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);
            }
        }
コード例 #16
0
 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);
     }
 }
コード例 #17
0
 /// <summary>
 /// Delete a entity.
 /// </summary>
 /// <param name="entity">a detached entity instance </param>
 public void Delete(object entity)
 {
     innerSession.Delete(entity);
 }
コード例 #18
0
 public void Delete(object entity)
 {
     _session.Delete(entity);
 }
コード例 #19
0
 /// <summary>
 /// Deletes the object.
 /// </summary>
 /// <param name="entity">The entity.</param>
 public void Delete(T entity)
 {
     Session.Delete(entity);
 }
コード例 #20
0
 public void Delete(string entityName, object obj)
 {
     statelessSession.Delete(entityName, obj);
 }
コード例 #21
0
 public void Delete(object entity)
 {
     EnsureWriteLock();
     _session.Delete(entity);
 }
コード例 #22
0
        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);
        }