Exemplo n.º 1
0
  public void setVersion(long version) {
    VersionTrackerDAOImpl vt = null;
    Query query = _em.createQuery("select v from VersionTrackerDAOImpl v");
    query.setHint("openjpa.FetchPlan.ReadLockMode", "WRITE");

    List<VersionTrackerDAOImpl> res = query.getResultList();

    if (!res.isEmpty()) vt = res.get(0);

    if (vt == null) vt = new VersionTrackerDAOImpl();

    vt.setVersion(version);
    _em.persist(vt);
  }
Exemplo n.º 2
0
  public long getNextVersion() {
    VersionTrackerDAOImpl vt = null;
    Query query = _em.createQuery("select v from VersionTrackerDAOImpl v");
    query.setHint("openjpa.FetchPlan.ReadLockMode", "WRITE");

    List<VersionTrackerDAOImpl> res = query.getResultList();

    if (!res.isEmpty()) vt = res.get(0);

    if (vt == null) {
      vt = new VersionTrackerDAOImpl();
      vt.setVersion(1);
    } else {
      vt.setVersion(vt.getVersion() + 1);
    }

    _em.persist(vt);
    return vt.getVersion();
  }