Example usage for org.hibernate Session refresh

List of usage examples for org.hibernate Session refresh

Introduction

In this page you can find the example usage for org.hibernate Session refresh.

Prototype

void refresh(Object object);

Source Link

Document

Re-read the state of the given instance from the underlying database.

Usage

From source file:edu.ku.brc.specify.treeutils.HibernateTreeDataServiceImpl.java

License:Open Source License

public synchronized void refresh(final Object... objects) {
    Session session = getNewSession(objects);
    try {/*from  w  w  w. j a v  a2  s .c  o  m*/
        for (Object o : objects) {
            session.refresh(o);
        }

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(HibernateTreeDataServiceImpl.class, ex);
        log.error(ex);
    } finally {
        session.close();
    }
}

From source file:edu.utah.further.ds.impl.executor.db.hibernate.criteria.HibernateResultListRefresher.java

License:Apache License

@Override
public boolean process(final ChainRequest request) {
    if (log.isDebugEnabled()) {
        log.debug("Re-reading entity state by calling refresh");
    }/*from  w  w w  .j a v a 2  s. c  o  m*/

    final List<?> results = request.getAttribute(QUERY_RESULT);
    Validate.notNull(results, "Expected query results");
    final HibernateExecReq executionReq = new HibernateExecReq(request);
    final SessionFactory sessionFactory = executionReq.getSessionFactory();
    Validate.notNull(sessionFactory, "SessionFactory required to re-read entity state");

    final Session session = sessionFactory.getCurrentSession();
    for (final Object result : results) {
        if (log.isTraceEnabled()) {
            log.trace("Before refreshing " + result);
        }

        session.refresh(result);

        if (log.isTraceEnabled()) {
            log.trace("After refreshing " + result);
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("All entities refreshed");
    }

    return false;
}

From source file:es.emergya.bbdd.dao.HistoricoGPSHome.java

License:Open Source License

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public HistoricoGPS lastGPSForRecurso(Recurso r) {
    if (r == null)
        return null;

    try {//from w w  w.  j av a  2 s. c  o  m

        Session currentSession = getSession();
        currentSession.flush();
        currentSession.refresh(r);
        if (r.getHistoricoGps() != null) {
            r.getHistoricoGps().getPosX();
            return r.getHistoricoGps();
        }
    } catch (Throwable t) {
    }

    return lastGPSForRecurso(r.getIdentificador());
}

From source file:es.emergya.bbdd.dao.RecursoHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public List<Recurso> getAll(Usuario u) {
    List<Recurso> res = new ArrayList<Recurso>();
    try {//from w w w  .  ja  v a  2  s .  co m
        Session currentSession = getSession();
        currentSession.clear();

        final Calendar calenar = Calendar.getInstance();
        calenar.add(Calendar.MINUTE, -LogicConstants.getInt("AVL_TIMEOUT", 30));
        Date fecha = calenar.getTime();

        String sql = "select this_.* from recursos this_ "
                + "inner join flotas flota2_ on this_.flota_x_flota=flota2_.x_flota "
                + "inner join ROLES_X_FLOTAS roles15_ on flota2_.x_flota=roles15_.X_FLOTA "
                + "inner join roles rol3_ on roles15_.X_ROL=rol3_.x_rol "
                + "inner join usuarios usuario4_ on rol3_.x_rol=usuario4_.fk_roles "
                + "inner join historico_gps historico1_ on this_.fk_historico_gps=historico1_.x_historico "
                + "where this_.habilitado=true " + "and historico1_.marca_temporal>=:DATE ";

        if (u != null && u.getId() != null) {
            sql += "and usuario4_.x_usuarios=:ID";
        }
        Query criteria = currentSession.createSQLQuery(sql).addEntity(Recurso.class).setTimestamp("DATE", fecha)
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        if (u != null && u.getId() != null) {
            criteria = criteria.setLong("ID", u.getId());
        }

        log.trace("Cogemos los recursos visibles: " + criteria.toString() + " " + fecha);

        res = criteria.list();

        if (log.isTraceEnabled()) {
            log.trace("Recursos que mostramos finalmente:");
            for (Recurso s : res) {
                log.trace(s);
            }
        }
        for (Recurso uniqueResult : res) {
            if (uniqueResult != null) {
                if (uniqueResult.getEstadoEurocop() != null) {
                    uniqueResult.getEstadoEurocop().getId();
                }
                if (uniqueResult.getFlotas() != null) {
                    uniqueResult.setFlotas(
                            (Flota) currentSession.get(Flota.class, uniqueResult.getFlotas().getId()));
                    currentSession.refresh(uniqueResult.getFlotas());
                }
                if (uniqueResult.getPatrullas() != null) {
                    uniqueResult.setPatrullas(
                            (Patrulla) currentSession.get(Patrulla.class, uniqueResult.getPatrullas().getId()));
                    uniqueResult.getPatrullas().getId();
                }
            }
        }

    } catch (Throwable t) {
        log.error("Mostrando los recursos visibles", t);
    }

    return res;
}

From source file:es.uvigo.ei.sing.gc.view.models.committee.classifiers.ClassifiersViewModel.java

License:Open Source License

@Command("deleteClassifier")
public void deleteClassifier(@BindingParam("classifier") final ClassifierBuilderMetaData classifier) {
    this.dataLostNotification("Delete Classifier", String.format(
            "Deleting this classifier will provoke data deletion. Are you sure you want to delete the %s classifier?",
            classifier.getName()), CommitteeStatus.EXPERIMENT_EXECUTION, CommitteeStatus.EVALUATOR,
            new Runnable() {
                @Override//from w ww  .  j a v a2s  .c o m
                public void run() {
                    final Session session = HibernateUtil.currentSession();
                    final Committee committee = ClassifiersViewModel.this.getCommittee();

                    session.refresh(classifier);
                    committee.getClassifiers().remove(classifier);
                    session.delete(classifier);
                    session.update(committee);

                    BindUtils.postNotifyChange(null, null, ClassifiersViewModel.this, "classifiers");
                    ClassifiersViewModel.this.updateExecutions();
                }
            }, null, new Runnable() {
                @Override
                public void run() {
                    Messagebox.show(
                            String.format("Are you sure you want to delete the %s classifier?",
                                    classifier.getName()),
                            "Delete Classifier", Messagebox.YES | Messagebox.NO, Messagebox.EXCLAMATION,
                            new EventListener<Event>() {
                                @Override
                                public void onEvent(Event event) throws Exception {
                                    if (((Integer) event.getData()).intValue() == Messagebox.YES) {
                                        final Session session = HibernateUtil.currentSession();
                                        final Committee committee = ClassifiersViewModel.this.getCommittee();

                                        session.refresh(classifier);
                                        committee.getClassifiers().remove(classifier);
                                        session.delete(classifier);
                                        session.update(committee);

                                        BindUtils.postNotifyChange(null, null, ClassifiersViewModel.this,
                                                "classifiers");
                                        ClassifiersViewModel.this.updateExecutions();
                                    }
                                }
                            });
                };
            });
}

From source file:eu.interedition.text.Text.java

License:Apache License

public Text write(Session session, Reader contents, long contentLength) throws IOException {
    Text text = (Text) session.merge(this);

    final TextDigestingFilterReader digestingFilterReader = new TextDigestingFilterReader(
            new BufferedReader(contents));
    text.setLength(contentLength);//from   ww  w  .j a va2s.  com
    text.setContent(Hibernate.getLobCreator(session).createClob(digestingFilterReader, contentLength));

    session.flush();
    session.refresh(text);

    text.setDigest(digestingFilterReader.digest());

    return text;
}

From source file:eu.interedition.text.Text.java

License:Apache License

public static Text create(Session session, Annotation layer, Text.Type type) {
    Text text = new Text();
    text.setLayer(layer);/*from   w ww  .  ja  v  a  2s . com*/
    text.setType(type);
    text.setContent(Hibernate.getLobCreator(session).createClob(""));
    text.setLength(0);

    text = (Text) session.merge(text);
    session.flush();
    session.refresh(text);

    text.setDigest(NULL_DIGEST);
    return text;
}

From source file:eu.ist_phosphorus.harmony.idb.database.TransactionManager.java

License:Open Source License

private void refreshObjects(Session sess) {
    if (refreshObjects != null) {
        for (Object o : refreshObjects) {
            sess.refresh(o);
        }/*from   w w  w.j a v a2 s. c o  m*/
    }
}

From source file:gr.interamerican.bo2.impl.open.hibernate.refreshmodes.FastGetAndRefresh.java

License:Open Source License

public Object get(Session session, Serializable id, Class<?> persistentClass) {
    Object o = session.get(persistentClass, id);
    session.refresh(o);
    return o;//from  ww  w.  jav  a 2 s.c om
}

From source file:gr.interamerican.bo2.impl.open.hibernate.refreshmodes.GetAndRefresh.java

License:Open Source License

public Object get(Session session, Serializable id, Class<?> persistentClass) {
    Object o = session.get(persistentClass, id);
    if (o != null) {
        session.refresh(o);
    }/*from ww  w .j  a va 2  s .  com*/
    return o;
}