示例#1
0
 @Transactional(
     propagation = Propagation.REQUIRES_NEW,
     readOnly = false,
     rollbackFor = Throwable.class)
 private void removeRecursos(Flota p) {
   try {
     if (p != null && p.getId() != null) {
       Session currentSession = getSession();
       currentSession.clear();
       p = this.get(p.getId());
       if (p != null && p.getRecurso() != null) {
         for (Recurso r : p.getRecurso()) {
           r = (Recurso) currentSession.get(Recurso.class, r.getId());
           if (r != null) {
             r.setFlotas(null);
             currentSession.saveOrUpdate(r);
           }
         }
       }
     }
   } catch (Throwable t) {
     log.error(t, t);
   }
 }
示例#2
0
  @Transactional(
      propagation = Propagation.REQUIRES_NEW,
      readOnly = false,
      rollbackFor = Throwable.class)
  public boolean saveOrUpdate(Flota f) {
    boolean res = false;
    if (f == null) return res;
    try {
      log.debug("Saving " + f);
      final Set<Rol> roles = f.getRoles();
      final Set<Recurso> recurso = f.getRecurso();
      removeRecursos(f);
      removeRoles(f);
      Session currentSession = getSession();
      currentSession.clear();

      Flota entity = null;

      if (f.getId() != null && this.get(f.getId()) != null)
        entity = (Flota) currentSession.merge(f);
      else entity = f;
      if (recurso != null)
        for (Recurso r : recurso) {
          r = (Recurso) currentSession.get(Recurso.class, r.getId());
          if (r != null) {
            r.setFlotas(entity);
            currentSession.saveOrUpdate(r);
          }
        }

      if (roles != null)
        for (Rol r : roles) {
          Rol rentity = (Rol) currentSession.get(Rol.class, r.getId());
          if (rentity != null) {
            rentity.getFlotas().add(entity);
            currentSession.saveOrUpdate(rentity);
          }
        }

      currentSession.saveOrUpdate(entity);
    } catch (Throwable t) {
      log.error(t, t);
      return false;
    }
    return true;
  }
示例#3
0
  @Transactional(
      propagation = Propagation.REQUIRES_NEW,
      readOnly = false,
      rollbackFor = Throwable.class)
  public boolean delete(Flota p) {
    try {
      if (p.getId() == null || (p = this.get(p.getId())) == null) return true;

      if (!p.getRecurso().isEmpty()) return false;

      removeRoles(p);

      this.remove(p.getId());

      return true;
    } catch (Throwable t) {
      log.error(t, t);
      return false;
    }
  }