List of usage examples for org.hibernate Session refresh
void refresh(Object object);
From source file:mx.edu.um.mateo.general.dao.impl.OrganizacionDaoHibernate.java
License:Open Source License
@Override public Organizacion actualiza(Organizacion organizacion, Usuario usuario) { Session session = currentSession(); log.debug("NombreCompleto: {}", organizacion.getNombreCompleto()); session.update(organizacion);//from w w w. ja va 2 s. c om session.flush(); if (usuario != null) { session.refresh(organizacion); actualizaUsuario: for (Empresa empresa : organizacion.getEmpresas()) { for (Almacen almacen : empresa.getAlmacenes()) { usuario.setEmpresa(empresa); usuario.setAlmacen(almacen); session.update(usuario); break actualizaUsuario; } } } session.flush(); return organizacion; }
From source file:mx.edu.um.mateo.general.dao.OrganizacionDao.java
License:Open Source License
public Organizacion crea(Organizacion organizacion, Usuario usuario) { Session session = currentSession(); session.save(organizacion);// w w w .j a v a2s . c o m Empresa empresa = new Empresa("MTZ", "MATRIZ", "MATRIZ", organizacion); session.save(empresa); Almacen almacen = new Almacen("CENTRAL", empresa); session.save(almacen); if (usuario != null) { usuario.setEmpresa(empresa); usuario.setAlmacen(almacen); session.update(usuario); } session.refresh(empresa); session.refresh(organizacion); session.flush(); return organizacion; }
From source file:net.micwin.openspace.dao.OpenSpaceHibernateDaoSupport.java
License:Open Source License
public T refresh(final T entity) { new TxBracelet<T>(sf) { @Override/*ww w . jav a 2 s.c o m*/ public T doWork(Session session, Transaction tx) { session.refresh(entity); return null; } }.execute(); return entity; }
From source file:nl.b3p.gis.viewer.ConfigClusterAction.java
License:Open Source License
public ActionForward save(ActionMapping mapping, DynaValidatorForm dynaForm, HttpServletRequest request, HttpServletResponse response) throws Exception { if (!isTokenValid(request)) { prepareMethod(dynaForm, request, EDIT, LIST); addAlternateMessage(mapping, request, TOKEN_ERROR_KEY); return getAlternateForward(mapping, request); }// w ww . j ava2 s .c o m // nieuwe default actie op delete zetten Session sess = HibernateUtil.getSessionFactory().getCurrentSession(); ActionErrors errors = dynaForm.validate(mapping, request); if (!errors.isEmpty()) { addMessages(request, errors); prepareMethod(dynaForm, request, EDIT, LIST); addAlternateMessage(mapping, request, VALIDATION_ERROR_KEY); return getAlternateForward(mapping, request); } Clusters c = getCluster(dynaForm, true); if (c == null) { prepareMethod(dynaForm, request, LIST, EDIT); addAlternateMessage(mapping, request, NOTFOUND_ERROR_KEY); return getAlternateForward(mapping, request); } populateClustersObject(dynaForm, c, request); sess.saveOrUpdate(c); sess.flush(); /* Indien we input bijvoorbeeld herformatteren oid laad het dynaForm met * de waardes uit de database. */ sess.refresh(c); populateClustersForm(c, dynaForm, request); prepareMethod(dynaForm, request, LIST, EDIT); addDefaultMessage(mapping, request, ACKNOWLEDGE_MESSAGES); return getDefaultForward(mapping, request); }
From source file:nl.phanos.testwedstrijdrunner.utils.HibernateSessionHandler.java
public void update(Object object) { Session session = null; try {/*from ww w .j a v a 2s . c o m*/ session = getSession(); session.beginTransaction(); session.refresh(object); } catch (Exception e) { e.printStackTrace(); } finally { if (session != null) { session.getTransaction().commit(); } } }
From source file:omero.cmd.graphs.ChgrpI.java
License:Open Source License
@SuppressWarnings("deprecation") public Object step(int i) throws Cancel { helper.assertStep(i);/*from w ww . ja va 2 s.com*/ try { if ((i + 1) == helper.getSteps()) { // The dataset was loaded in order to check its permissions. // Since these have been changed "in the background" (via SQL) // it's important that we refresh that object for later cmds. Session s = helper.getSession(); IObject obj = spec.load(s); s.refresh(obj); EventLogMessage elm = new EventLogMessage(this, "CHGRP", obj.getClass(), Arrays.asList(Long.valueOf(this.id))); try { helper.getServiceFactory().getContext().publishMessage(elm); } catch (Throwable t) { GraphException de = new GraphException("EventLogMessage failed."); de.initCause(t); throw de; } return null; } else { return state.execute(i); } } catch (GraphException ge) { throw helper.graphException(ge, i, id); } }
From source file:onl.netfishers.netshot.work.tasks.RunDeviceScriptTask.java
License:Open Source License
@Override public void run() { logger.debug("Starting script task for device {}.", device.getId()); this.logIt(String.format("Run script task for device %s (%s).", device.getName(), device.getMgmtAddress().getIp()), 5); Session session = Database.getSession(); try {/*w w w.ja v a 2s . c o m*/ session.beginTransaction(); session.refresh(device); if (deviceDriver == null || !deviceDriver.equals(device.getDriver())) { logger.trace("The script doesn't apply to the driver of the device."); this.logIt("The script doesn't apply to the driver of the device.", 2); this.status = Status.CANCELLED; return; } if (device.getStatus() != Device.Status.INPRODUCTION) { logger.trace("Device not INPRODUCTION, stopping the run script task."); this.logIt("The device is not enabled (not in production).", 2); this.status = Status.FAILURE; return; } device.runScript(script); this.logIt(String.format("Device logs (%d next lines):", device.getLog().size()), 3); this.log.append(device.getPlainLog()); session.update(device); session.getTransaction().commit(); this.status = Status.SUCCESS; } catch (Exception e) { session.getTransaction().rollback(); logger.error("Error while running the script.", e); this.logIt("Error while running the script: " + e.getMessage(), 3); this.logIt(String.format("Device logs (%d next lines):", device.getLog().size()), 3); this.log.append(device.getPlainLog()); this.status = Status.FAILURE; return; } finally { session.close(); } }
From source file:onl.netfishers.netshot.work.tasks.TakeSnapshotTask.java
License:Open Source License
@Override public void run() { logger.debug("Starting snapshot task for device {}.", device.getId()); this.logIt(String.format("Snapshot task for device %s (%s).", device.getName(), device.getMgmtAddress().getIp()), 5); Session session = Database.getSession(); try {/*from www . java 2s . c om*/ session.beginTransaction(); session.refresh(device); if (device.getStatus() != Device.Status.INPRODUCTION) { logger.trace("Device not INPRODUCTION, stopping the snapshot task."); this.logIt("The device is not enabled (not in production).", 2); this.status = Status.FAILURE; return; } if (!TakeSnapshotTask.checkRunningSnapshot(device.getId())) { logger.trace("Snapshot task already ongoing for this device, cancelling."); this.logIt("A snapshot task is already running for this device, cancelling this task.", 2); this.status = Status.CANCELLED; return; } device.takeSnapshot(); this.logIt(String.format("Device logs (%d next lines):", device.getLog().size()), 3); this.log.append(device.getPlainLog()); session.update(device); session.getTransaction().commit(); this.status = Status.SUCCESS; } catch (Exception e) { session.getTransaction().rollback(); logger.error("Error while taking the snapshot.", e); this.logIt("Error while taking the snapshot: " + e.getMessage(), 3); this.logIt(String.format("Device logs (%d next lines):", device.getLog().size()), 3); this.log.append(device.getPlainLog()); this.status = Status.FAILURE; return; } finally { TakeSnapshotTask.clearRunningSnapshot(device.getId()); if (automatic) { TakeSnapshotTask.clearScheduledAutoSnapshot(this.device.getId()); } session.close(); } logger.debug("Request to refresh all the groups for the device after the snapshot."); DynamicDeviceGroup.refreshAllGroups(device); try { Task checkTask = new CheckComplianceTask(device, "Check compliance after snapshot.", "Auto"); TaskManager.addTask(checkTask); } catch (Exception e) { logger.error("Error while registering the new task.", e); } }
From source file:org.dafoe.framework.builder.model.SerializableObjectFactory.java
License:Open Source License
/** * Creates a new serializable ITerminoConceptRelation from a non-serializable BinaryTCRelation. * * @param bTCR1 a non-serializable binary terminoconceptual relation * @param hSession an hibernate session//from w ww . j av a 2s .c o m * @return the new serializable terminoconceptual relation */ @SuppressWarnings("unchecked") public static ITerminoConceptRelation createTCR(MockBinaryTCRelation bTCR1, Session hSession) { Transaction dTx; ITerminoConceptRelation newTCR = null; List<ITerminoConceptRole> tcrs = null; Iterator<ITerminoConceptRole> itTcrs = null; ITerminoConceptRole tcr = null; System.out.println("binary RTC TC1 = " + bTCR1.getTc1().getLabel()); try { dTx = hSession.beginTransaction(); newTCR = new TerminoConceptRelationImpl(); tcrs = hSession.createCriteria(ITerminoConceptRole.class).list(); itTcrs = tcrs.iterator(); while (itTcrs.hasNext()) { tcr = itTcrs.next(); if (tcr.getLabel().compareTo("arg1") == 0) { newTCR.addTerminoConcept(bTCR1.getTc1(), tcr); } else if (tcr.getLabel().compareTo("arg2") == 0) { newTCR.addTerminoConcept(bTCR1.getTc2(), tcr); } } newTCR.setTypeRelation(bTCR1.getType()); newTCR.setState(bTCR1.getState()); hSession.save(newTCR); dTx.commit(); System.out.println("newRTC.getId() = " + newTCR.getId()); // ES: pour mettre jour les dpendances ... le framework devrait // le faire !! hSession.refresh(newTCR); hSession.refresh(bTCR1.getTc1()); hSession.refresh(bTCR1.getTc2()); System.out.println("Associated members: " + newTCR.getTerminoConceptRelationMembers().size()); } catch (Exception e) { e.printStackTrace(); } return newTCR; }
From source file:org.dafoe.framework.samples.hibernate.OntologicalSamples.java
License:Open Source License
public static void testCreateDeleteClasse() {//ok System.out.println("void testCreateDeleteClasse()"); Session hSession = getDafoeSession(); // create /* w w w . jav a2 s .com*/ Transaction tx = hSession.beginTransaction(); IOntology onto = new OntologyImpl(); IClass cls = new ClassImpl(); onto.setName("toto_onto_3"); onto.setNameSpace("www.toto_3"); onto.setLanguage("fr"); hSession.save(onto); cls.setLabel("toto_class_3"); cls.setState(ONTO_OBJECT_STATE.REJECTED); onto.addOntoObject(cls); hSession.save(cls); tx.commit(); hSession.refresh(onto); // delete tx = hSession.beginTransaction(); onto.removeOntoObject(cls); //hSession.delete(cls); Object obj = hSession.load(ClassImpl.class, cls.getId()); hSession.delete(obj); tx.commit(); }