List of usage examples for org.hibernate Session evict
void evict(Object object);
From source file:com.redhat.rhn.domain.server.test.GuestBuilder.java
License:Open Source License
private void save() { Session session = VirtualInstanceFactory.getSession(); guestDAO.saveVirtualInstance(guest); session.flush();/* w ww .ja v a2 s . com*/ session.evict(guest); if (guest.isRegisteredGuest()) { session.evict(guest.getGuestSystem()); } if (guest.getHostSystem() != null) { session.evict(guest.getHostSystem()); } isSaveRequired = false; }
From source file:com.redhat.rhn.domain.server.test.HostBuilder.java
License:Open Source License
/** * This is the final step in building or compiling a host. The host and its guests (if * there are any) will be persisted, flushed, and evicted from the current hibernate * session./*from ww w . ja v a 2 s .c o m*/ * * <br/><br/> * * The builder does not maintain a reference to a host once it is built; so, calling * <code>build</code> successive times will simply return <code>null</code>. One of the * <i>create</i> methods must be called before every invocation of this method. * * @return The built host whose state will have persisted and synhronized with the * database. The host and its guests will have been removed from the hibernate session * cache. */ public Server build() { if (host == null) { return null; } Server compiledHost; Session session = HibernateFactory.getSession(); session.flush(); session.evict(host); for (Iterator iterator = host.getGuests().iterator(); iterator.hasNext();) { session.evict(iterator.next()); } compiledHost = host; host = null; return compiledHost; }
From source file:com.redhat.rhn.domain.server.test.VirtualInstanceFactoryTest.java
License:Open Source License
private void flushAndEvictGuest(VirtualInstance guest) { Session session = VirtualInstanceFactory.getSession(); flushAndEvict(guest);/*from w ww . j ava 2s .c o m*/ if (guest.isRegisteredGuest()) { session.evict(guest.getGuestSystem()); } if (guest.getHostSystem() != null) { session.evict(guest.getHostSystem()); } }
From source file:com.redhat.rhn.testing.RhnBaseTestCase.java
License:Open Source License
protected void flushAndEvict(Object obj) throws HibernateException { Session session = HibernateFactory.getSession(); session.flush();// w w w . j av a2 s . co m session.evict(obj); }
From source file:com.redhat.rhn.testing.TestUtils.java
License:Open Source License
/** * Util to flush and evict an object from the Hibernate Session * @param obj to flush// ww w .j a va 2s. c om * @throws HibernateException if something bad happens */ public static void flushAndEvict(Object obj) throws HibernateException { Session session = HibernateFactory.getSession(); session.flush(); session.evict(obj); }
From source file:com.thesett.catalogue.impl.standalone.UndoableCatalogueManagerServiceImpl.java
License:Apache License
/** {@inheritDoc} */ public void updateEntityInstance(EntityInstance element) { // Create an undo operation for the entity update. Session session = HibernateUtil.getCurrentSession(); EntityInstance instanceToUpdate = retrieveEntityInstance(element.getComponentType(), element.getOpaqueId()); session.evict(instanceToUpdate); Undoable undoOperation = new UndoModifyEntity(instanceToUpdate.getOpaqueId(), instanceToUpdate); // Modify the entity. catalogueManagerService.updateEntityInstance(element); // Post the undo operation onto the undo stack. undoStack.offer(undoOperation);/*from w ww .ja v a2 s.c o m*/ }
From source file:com.thesett.catalogue.impl.standalone.UndoableCatalogueManagerServiceImpl.java
License:Apache License
/** {@inheritDoc} */ public void deleteEntityInstance(EntityType entityType, InternalId id) { // Get a detached instance of the entity to delete, in order that it may be later recreated. Session session = HibernateUtil.getCurrentSession(); EntityInstance instanceToDelete = retrieveEntityInstance(entityType, id); session.evict(instanceToDelete); // Delete the entity. catalogueManagerService.deleteEntityInstance(entityType, id); // Create an undo operation for the entity deletion. Undoable undoOperation = new UndoDeleteEntity(instanceToDelete.getOpaqueId(), instanceToDelete); // Post the undo operation onto the undo stack. undoStack.offer(undoOperation);/* www .ja va 2 s.com*/ }
From source file:com.tm.spring.dao.EmpDAOImpl.java
@Override public boolean empUpdate(int id, Employee emp) { Session session = sessionFactory.openSession(); Transaction t = session.beginTransaction(); Employee e = (Employee) session.load(Employee.class, id); session.evict(e); e = emp;// www . ja v a2 s. co m session.update(e); t.commit(); session.close(); return true; }
From source file:com.trailmagic.image.util.FixDimensions.java
License:Open Source License
public void fixDimensions(final String ownerName, final String rollName) { m_hibernateTemplate.execute(new HibernateCallback() { public Object doInHibernate(Session session) { try { User owner = userRepository.getByScreenName(ownerName); ImageGroup roll = imageGroupRepository.getRollByOwnerAndName(owner, rollName); for (ImageFrame frame : roll.getFrames()) { Image image = frame.getImage(); for (ImageManifestation mf : image.getManifestations()) { HeavyImageManifestation heavyMf = m_imageManifestationFactory.getHeavyById(mf.getId()); BufferedImage bi = ImageIO.read(heavyMf.getData().getBinaryStream()); mf.setHeight(bi.getHeight()); mf.setWidth(bi.getWidth()); session.evict(heavyMf); }//from ww w.j a va 2 s . c om } } catch (Exception e) { s_log.error("Error fixing permissions", e); } return null; } }); }
From source file:com.trailmagic.image.util.ReplaceImageManifestation.java
License:Open Source License
/** * THIS MUST BE PUBLIC in order for interceptors to run. GRRRR. **///from www .ja v a 2 s . co m public void replaceManifestation(Long manifestationId, String filename, Integer width, Integer height) { try { Session session = SessionFactoryUtils.getSession(sessionFactory, false); HeavyImageManifestation manifest = imfFactory.getHeavyById(manifestationId.longValue()); // s_log.info("Got manifestation id " + manifest.getId()); File srcFile = new File(filename); s_log.info("Importing " + srcFile.getPath()); if (srcFile.length() > Integer.MAX_VALUE) { s_log.info("File is too big...skipping " + srcFile.getPath()); throw new RuntimeException("File too big"); } FileInputStream fis = new FileInputStream(srcFile); manifest.setData(Hibernate.createBlob(fis)); manifest.setWidth(width.intValue()); manifest.setHeight(height.intValue()); session.saveOrUpdate(manifest); s_log.info("ImageManifestation saved: " + manifest.getName() + " (" + manifest.getId() + ")" + "...flushing session and evicting manifestation."); synchronized (session) { session.flush(); session.evict(manifest); } fis.close(); SessionFactoryUtils.releaseSession(session, sessionFactory); s_log.info("Finished importing " + srcFile.getPath()); } catch (Exception e) { s_log.error("Error: " + e.getMessage(), e); throw new RuntimeException("Error", e); } }