private void Validate(Order order) { //no-op - throw exception on error. }
public void ShipOrder(Order order) { log.Info("Shipping order id = " + order.Id); }
public void Delete(Order order) { CurrentSession.Delete(order); }
public void Update(Order order) { CurrentSession.SaveOrUpdate(order); }
public int Save(Order order) { return (int) CurrentSession.Save(order); }
public void ProductDaoTests() { Assert.AreEqual(830, orderDao.GetAll().Count); Order order = new Order(); Customer customer = customerDao.Get("PICCO"); order.Customer = customer; order.ShipCity = "New York"; orderDao.Save(order); int orderId = order.Id; order = orderDao.Get(orderId); Assert.AreEqual("PICCO", order.Customer.Id); Assert.AreEqual("New York", order.ShipCity); //SessionFactoryUtils.GetSession(sessionFactory, true).Flush(); // Required trip to db to get idendity column, so data is visible int ordersCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Orders"); Assert.AreEqual(831, ordersCount); Assert.AreEqual(831, orderDao.GetAll().Count); order.ShipCity = "Sao Paulo"; orderDao.Update(order); order = orderDao.Get(orderId); Assert.AreEqual("PICCO", order.Customer.Id); Assert.AreEqual("Sao Paulo", order.ShipCity); orderDao.Delete(order); //Without flushing, nothing changes in the database: SessionFactoryUtils.GetSession(sessionFactory, true).Flush(); ordersCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Orders"); Assert.AreEqual(830, ordersCount); try { order = orderDao.Get(orderId); Assert.Fail("Should have thrown HibernateObjectRetrievalFailureException when finding order with Id = " + orderId); } catch (HibernateObjectRetrievalFailureException e) { Assert.AreEqual("Order", e.PersistentClassName); } }