예제 #1
0
  @SuppressWarnings("unchecked")
  @Transactional(
      propagation = Propagation.REQUIRES_NEW,
      readOnly = false,
      rollbackFor = Throwable.class)
  private void removeRoles(Flota f) {
    try {
      if (f != null && f.getId() != null) {
        Session currentSession = getSession();
        currentSession.clear();

        f = this.get(f.getId());

        final Set<Rol> roles = Collections.unmodifiableSet(f.getRoles());
        if (f != null && roles != null)
          for (Rol r : roles) {
            r = (Rol) currentSession.get(Rol.class, r.getId());
            if (r != null && r.getFlotas() != null) {
              final Set<Flota> flotas = Collections.unmodifiableSet(r.getFlotas());
              List<Flota> aBorrar = new LinkedList<Flota>();
              for (Flota fl : flotas) if (fl.getId().equals(f.getId())) aBorrar.add(fl);
              for (Flota fl : aBorrar) r.getFlotas().remove(fl);
              currentSession.saveOrUpdate(r);
            }
          }
      }
    } catch (Throwable t) {
      log.error(t, t);
    }
  }
예제 #2
0
  public static List<Rol> getByExample(Rol example) {
    List<Rol> res = new ArrayList<Rol>();
    try {
      if (example != null && example.getNombre() != null)
        res = rolHome.findByName(LogicConstants.getGenericString(example.getNombre()));
      else res = rolHome.getAll();
    } catch (Throwable t1) {
      log.error(t1, t1);
    }

    return res;
  }
예제 #3
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;
  }
예제 #4
0
  @SuppressWarnings("unchecked")
  @Transactional(
      propagation = Propagation.REQUIRES_NEW,
      readOnly = true,
      rollbackFor = Throwable.class)
  public List<Flota> getByFilter(Flota f) {
    List<Flota> res = new ArrayList<Flota>(0);
    try {
      Session currentSession = getSession();
      currentSession.clear();
      Criteria criteria =
          currentSession.createCriteria(Flota.class).add(Restrictions.eq("habilitada", true));

      if (f.getInfoAdicional() != null)
        criteria =
            criteria.add(
                Restrictions.ilike(
                    "infoAdicional", LogicConstants.getGenericString(f.getInfoAdicional())));
      if (f.getNombre() != null)
        criteria =
            criteria.add(
                Restrictions.ilike("nombre", LogicConstants.getGenericString(f.getNombre())));
      if (f.getHabilitada() != null)
        criteria = criteria.add(Restrictions.eq("habilitada", f.getHabilitada()));
      if (f.getJuegoIconos() != null)
        criteria =
            criteria.add(
                Restrictions.ilike(
                    "juegoIconos", LogicConstants.getGenericString(f.getJuegoIconos())));
      res =
          criteria
              .addOrder(Order.asc("nombre"))
              .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
              .list();

      for (Flota fl : res)
        if (fl != null) {
          if (fl.getRoles() != null) for (Rol r : fl.getRoles()) r.getId();
        }
    } catch (Throwable t) {
      log.error(t, t);
    }
    return res;
  }