Ejemplo n.º 1
0
  @Override
  public String execute() throws Exception {
    String name = this.getRequest().getParameter("name");
    String value = this.getRequest().getParameter("value");
    String type = this.getRequest().getParameter("type");
    String policy = this.getRequest().getParameter("policy");
    String enable = this.getRequest().getParameter("enable");

    Session session = SessionFactorySingle.getSessionFactory().openSession();
    session.beginTransaction();

    Criteria criteria = session.createCriteria(TypeDeviceFilter.class);
    criteria.add(Restrictions.eq("id", Integer.valueOf(type)));
    List<TypeDeviceFilter> typeDeviceFilters_array = criteria.list();
    TypeDeviceFilter typeDeviceFilter = typeDeviceFilters_array.get(0);

    criteria = session.createCriteria(DeviceFilter.class);
    criteria.add(Restrictions.eq("name", name));
    List<DeviceFilter> deviceFilters = (List<DeviceFilter>) criteria.list();

    DeviceFilter deviceFilter;
    if (deviceFilters.size() > 0) {
      deviceFilter = deviceFilters.get(0);
      deviceFilter.setName(name);
      deviceFilter.setValue(value);
      deviceFilter.setType(typeDeviceFilter);
      deviceFilter.setPolicy(Boolean.valueOf(policy));
      deviceFilter.setEnable(Boolean.valueOf(enable));
    } else {
      deviceFilter = new DeviceFilter(name, value, typeDeviceFilter, Boolean.valueOf(policy));
    }

    session.save(deviceFilter);
    session.getTransaction().commit();

    criteria = session.createCriteria(TroubleList.class);
    criteria.add(Restrictions.eq("name", "main"));
    TroubleList troubleList = (TroubleList) criteria.list().get(0);
    troubleList.getFilters().add(deviceFilter);

    session.beginTransaction();

    session.save(troubleList);
    session.getTransaction().commit();

    session.flush();
    session.close();

    ManagerMainDeviceFilter.getInstance().addNewDeviceInputFilter(deviceFilter);

    return null;
  }
Ejemplo n.º 2
0
 private Criteria createCriteria() throws HibernateException {
   Session session = HibernateUtils.getSessionFactory().openSession();
   Criteria criteria = session.createCriteria(Emprestimo.class, "c");
   criteria.createAlias("c.bemMaterial", "bema");
   criteria.createAlias("bema.categoria", "cate");
   criteria.createAlias("cate.usuario", "u");
   criteria.add(Restrictions.eq("u.id", getUsrLogado().getId()));
   return criteria;
 }
  public String execute() throws Exception {

    org.hibernate.classic.Session hibsession = HibernateUtil.getSessionFactory().openSession();
    Criteria crit = hibsession.createCriteria(Batch.class);
    ArrayList<Batch> batchList = (ArrayList<Batch>) crit.list();

    setBatchList(batchList);
    // Map session = ActionContext.getContext().getSession();

    return SUCCESS;
  }
Ejemplo n.º 4
0
 @Override
 @SuppressWarnings("unchecked")
 public List<Poem> queryAll() {
   Session session = sessionFactory.openSession();
   Criteria criteria = session.createCriteria(Poem.class);
   List<Poem> list = criteria.list();
   for (Poem poem : list) {
     Hibernate.initialize(poem.getAuthor());
   }
   session.close();
   return list;
 }
Ejemplo n.º 5
0
  @Test
  private void testALWAYSFlushMode() {

    Session session = sessionFactory.getCurrentSession();
    session.setFlushMode(FlushMode.ALWAYS);
    session.beginTransaction();
    incomesEntity =
        (IncomesEntity) session.createCriteria("incomesEntity").setMaxResults(1).uniqueResult();
    incomesEntity.setSum(100);
    session.getTransaction().commit();
    Assert.assertNotNull(session);
  }
Ejemplo n.º 6
0
 @SuppressWarnings("unchecked")
 @Override
 public List<Poem> queryByTitle(String title) {
   Session session = sessionFactory.openSession();
   Criteria criteria = session.createCriteria(Poem.class);
   criteria.add(Restrictions.like("title", "%" + title + "%"));
   List<Poem> list = criteria.list();
   for (Poem poem : list) {
     Hibernate.initialize(poem.getAuthor());
   }
   session.close();
   return list;
 }
  public void testExcludingQBE() throws Exception {
    deleteData();
    initData();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Componentizable master = getMaster("hibernate", null, "ope%");
    Criteria crit = s.createCriteria(Componentizable.class);
    Example ex = Example.create(master).enableLike().excludeProperty("component.subComponent");
    crit.add(ex);
    List result = crit.list();
    assertNotNull(result);
    assertEquals(3, result.size());

    master = getMaster("hibernate", "ORM tool", "fake stuff");
    crit = s.createCriteria(Componentizable.class);
    ex = Example.create(master).enableLike().excludeProperty("component.subComponent.subName1");
    crit.add(ex);
    result = crit.list();
    assertNotNull(result);
    assertEquals(1, result.size());
    t.commit();
    s.close();
  }
  public void testJunctionNotExpressionQBE() throws Exception {
    deleteData();
    initData();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Componentizable master = getMaster("hibernate", null, "ope%");
    Criteria crit = s.createCriteria(Componentizable.class);
    Example ex = Example.create(master).enableLike();

    crit.add(Expression.or(Expression.not(ex), ex));

    List result = crit.list();
    assertNotNull(result);
    assertEquals(2, result.size());
    t.commit();
    s.close();
  }
Ejemplo n.º 9
0
 public boolean existId(Integer tokenId) throws DAOException {
   Session session = null;
   try {
     session = getSession();
     Criteria criteria = session.createCriteria(Token.class);
     criteria.add(Restrictions.eq("tokenId", tokenId));
     criteria.setProjection(Projections.rowCount());
     Number result = (Number) criteria.uniqueResult();
     int total = result.intValue();
     return total > 0;
   } catch (Exception e) {
     throw new DAOException(e);
   } finally {
     if (session != null) {
       session.close();
     }
   }
 }
  // ADD A EMPLOYEE BANK DETAILS IN tblempbank
  @Override
  public int addEmployeeBank(EmployeeBank employeebank)
      throws HibernateException, ConstraintViolationException {
    Session session = SessionFactoryUtil.getSessionFactory().openSession();
    int status = 0;
    try {
      session.beginTransaction();
      java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());

      Criteria criteria = session.createCriteria(EmployeeBank.class);
      criteria.add(Restrictions.eq("organizationId", employeebank.getOrganizationId()));
      criteria.add(
          Restrictions.eq("employee", new Employee(employeebank.getEmployee().getEmployeeId())));
      criteria.add(Restrictions.eq("bank", new Bank(employeebank.getBank().getBankId())));
      if (criteria.list().size() == 0) {
        employeebank.setInsertDate(date.toString());
        employeebank.setUpdateDate(date.toString());
        session.save(employeebank);
        status = 1;
      } else {
        Iterator<EmployeeBank> iterator = criteria.list().iterator();
        while (iterator.hasNext()) {
          EmployeeBank empbank = iterator.next();
          if (empbank.getDeleteFlag() == true) {
            empbank.setDeleteFlag(false);
            empbank.setInsertDate(date.toString());
            empbank.setUpdateDate(date.toString());
            session.update(empbank);
            status = 1;
          } else {
            return 5;
          }
        }
      }

    } catch (Exception e) {
      e.printStackTrace();

    } finally {
      session.getTransaction().commit();
      session.close();
    }
    return status;
  }
Ejemplo n.º 11
0
  private Criteria criteria(Session session, Token search) {
    Criteria criteria = session.createCriteria(Token.class);

    {
      Integer tokenId = search.getTokenId();
      if (tokenId != null) {
        criteria.add(Restrictions.eq("tokenId", tokenId));
      }
    }

    {
      String value = search.getValue();
      if (value != null && !value.isEmpty()) {
        criteria.add(Restrictions.like("value", value));
      }
    }

    return criteria;
  }
 // GET A SINGLE RECORD by employeeId
 @Override
 public List<EmployeeBank> getEmployeeBankById(int employeeId, int organizationId)
     throws HibernateException, ConstraintViolationException {
   Session session = SessionFactoryUtil.getSessionFactory().openSession();
   try {
     session.beginTransaction();
     Criteria criteria = session.createCriteria(EmployeeBank.class);
     criteria.add(Restrictions.eq("employee", new Employee(employeeId)));
     criteria.add(Restrictions.eq("organizationId", organizationId));
     criteria.add(Restrictions.eq("deleteFlag", false));
     return (List<EmployeeBank>) criteria.list();
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     session.getTransaction().commit();
     session.close();
   }
 }
 // GET ALL RECORDS FROM tblempbank
 @SuppressWarnings("unchecked")
 @Override
 public List<EmployeeBank> getAllBankDetails(int organizationId)
     throws HibernateException, ConstraintViolationException {
   Session session = SessionFactoryUtil.getSessionFactory().openSession();
   try {
     session.beginTransaction();
     Criteria criteria = session.createCriteria(EmployeeBank.class);
     criteria.add(Restrictions.eq("organizationId", organizationId));
     criteria.add(Restrictions.eq("deleteFlag", false));
     return criteria.list();
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     session.getTransaction().commit();
     session.close();
   }
 }
Ejemplo n.º 14
0
  public String execute() {
    try {

      sess = hsf.createSession();
      Criteria crit = sess.createCriteria(Site.class);

      if (!getKeyword().equalsIgnoreCase("")) {
        String keywordQuery = "%" + getKeyword() + "%";

        crit.add(
            Expression.disjunction()
                .add(Expression.like("name", keywordQuery).ignoreCase())
                .add(Expression.like("description", keywordQuery).ignoreCase())
                .add(Expression.like("title", keywordQuery).ignoreCase())
                .add(Expression.like("url_branding", keywordQuery).ignoreCase())
                .add(Expression.like("site_url", keywordQuery).ignoreCase())
                .add(Expression.like("admin_email", keywordQuery).ignoreCase())
                .add(Expression.like("notify_email", keywordQuery).ignoreCase())
                .add(Expression.like("notify_from", keywordQuery).ignoreCase())
                .add(Expression.like("notify_message", keywordQuery).ignoreCase()));
      }

      sites = crit.list();
      //			sess.flush();
      hsf.endSession(sess);
    } catch (HibernateException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      try {
        hsf.closeSession(sess);
      } catch (HibernateException e1) {
        e1.printStackTrace();
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
    }

    return SUCCESS;
  }
  // UPDATE A EMPLOYEE BANK DETAILS IN tblempbank
  @Override
  public int updateEmployeeBank(EmployeeBank employeebank)
      throws HibernateException, ConstraintViolationException {
    Session session = SessionFactoryUtil.getSessionFactory().openSession();
    int status = 0;
    try {
      session.beginTransaction();
      java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());
      EmployeeBank empbank = getEmployeeBankId(employeebank.getEmpbankId());

      Criteria criteria = session.createCriteria(EmployeeBank.class);
      criteria.add(Restrictions.eq("organizationId", employeebank.getOrganizationId()));
      criteria.add(
          Restrictions.eq("employee", new Employee(empbank.getEmployee().getEmployeeId())));
      criteria.add(
          Restrictions.ne("employee", new Employee(employeebank.getEmployee().getEmployeeId())));
      criteria.add(Restrictions.eq("bank", new Bank(employeebank.getBank().getBankId())));

      if ((empbank != null) && (criteria.list().size() == 0)) {
        employeebank.setInsertBy(empbank.getInsertBy());
        employeebank.setInsertDate(empbank.getInsertDate());
        employeebank.setUpdateDate(date.toString());
        session.update(employeebank);
        status = 1;
      } else {
        return 5;
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      session.getTransaction().commit();
      session.close();
    }
    return status;
  }
 public <T> Criteria getCriteria(Class<T> clazz) {
   Session sess = getSession();
   return sess.createCriteria(clazz);
 }
Ejemplo n.º 17
0
 public static List<Horario> retornarTodosOsHorarios() {
   session = (Session) PreparaSessao.pegarSessao();
   List<Horario> horarios = session.createCriteria(Horario.class).list();
   // session.close();
   return horarios;
 }
Ejemplo n.º 18
0
  public String execute() {
    try {

      sess = hsf.createSession();
      Criteria crit = sess.createCriteria(Category.class);

      categoryDescriptor = (Descriptor) pm.getById(Descriptor.class, getDescriptor_id());
      parentCategory = (Category) pm.getById(Category.class, getIparentcode());

      if (!getId().equalsIgnoreCase("")) {
        crit.add(Expression.like("id", "%" + getId() + "%"));
      }
      if (!getCode().equalsIgnoreCase("")) {
        crit.add(Expression.like("code", "%" + getCode() + "%"));
      }
      if (!getDescription().equalsIgnoreCase("")) {
        crit.add(Expression.like("description", "%" + getDescription() + "%"));
      }
      if (!getUrl_category_image().equalsIgnoreCase("")) {
        crit.add(Expression.like("url_category_image", "%" + getUrl_category_image() + "%"));
      }

      if (!getDescriptor_id().equalsIgnoreCase("")) {
        crit.add(Expression.like("categoryDescriptor.id", "%" + getDescriptor_id() + "%"));
      }
      if (!getIparentcode().equalsIgnoreCase("")) {
        crit.add(Expression.like("parentCategory.id", "%" + getIparentcode() + "%"));
      }

      if (getActiveFlag() != -1) {
        crit.add(Expression.eq("logInformation.activeFlag", new Integer(getActiveFlag())));
      }

      resultRows = crit.list().size();

      maxPage = resultRows / maxRowPerPage;
      if (resultRows % maxRowPerPage == 0) maxPage = maxPage - 1;

      categories =
          crit.addOrder(Order.asc(orderBy))
              .setFirstResult(currPage * maxRowPerPage)
              .setMaxResults(maxRowPerPage)
              .list();

      prevPage = currPage - 1;
      nextPage = currPage + 1;
      page = currPage + 1;

      hsf.endSession(sess);
      return SUCCESS;

    } catch (HibernateException e) {
      return ERROR;
    } catch (SQLException e) {
      return ERROR;
    } finally {
      try {
        hsf.closeSession(sess);
      } catch (HibernateException e1) {
        return ERROR;
      } catch (SQLException e1) {
        return ERROR;
      }
    }
  }
Ejemplo n.º 19
0
 public static <T> Number getCount(Session session, Class<T> imageClass) {
   Criteria criteria = session.createCriteria(imageClass);
   criteria.setProjection(Projections.rowCount());
   return (Number) criteria.uniqueResult();
 }