/*
   * (non-Javadoc)
   *
   * @see cn.tinder.fuego.dao.AssetsQuotaDao#delete(cn.tinder.fuego.domain.po. AssetsQuota)
   */
  @Override
  public void delete(AssetsQuota quota) {
    // TODO Auto-generated method stub
    log.debug("[DAO] Delete the DiscardPlan:" + quota.toString());

    Session session = null;
    Transaction tx = null;
    String hql = null;
    // SystemUser user = null;
    try {
      session = HibernateUtil.getSession();

      tx = session.beginTransaction();

      hql = "delete from AssetsQuota where ASSETS_NAME =? and  DUTY = ?";
      Query query = session.createQuery(hql);
      query.setString(0, quota.getAssetsName());
      query.setString(1, quota.getDuty());

      query.executeUpdate();

      tx.commit();
    } catch (RuntimeException re) {
      throw re;
    } finally {
      if (null != session) {
        session.close();
      }
    }

    log.debug("[DAO] Success!Delete the DiscardPlan:" + quota.toString());
  }
Beispiel #2
0
 public Boolean loginResult(String loginId, String password) {
   Session session = sessionFactory.openSession();
   Transaction tx = null;
   Boolean loginResult = null;
   try {
     tx = session.beginTransaction();
     Query query =
         session.createQuery("select count(*) from User where id=:id and password=:password");
     query.setString("id", loginId);
     query.setString("password", password);
     Long count = (Long) query.uniqueResult();
     if (1 == count) {
       // 중복 Id 존재
       loginResult = true;
     } else {
       loginResult = false;
     }
     tx.commit();
   } catch (HibernateException e) {
     if (tx != null) {
       tx.rollback();
       e.printStackTrace();
     }
   } finally {
     session.close();
   }
   return loginResult;
 }
  public void update(NormalDiscount normalDiscount, int normalId) {
    try {

      System.out.println("更新daoimpl");
      System.out.println("normId" + normalDiscount.getNormalId());
      String hql =
          "update NormalDiscount cu set cu.discountName=?,cu.type=?,cu.discountBase=?,cu.baseQty=?,cu.discountRate=?,cu.activity=? where cu.normalId=?";
      Session session = sessionFactory.getCurrentSession();
      Query query = session.createQuery(hql);
      query.setString(0, normalDiscount.getDiscountName());
      query.setString(1, normalDiscount.getType());
      query.setString(2, normalDiscount.getDiscountBase());
      if (normalDiscount.getBaseQty() == null) {
        query.setInteger(3, 0);
      } else {
        query.setInteger(3, normalDiscount.getBaseQty());
      }
      query.setDouble(4, normalDiscount.getDiscountRate());
      query.setString(5, normalDiscount.getActivity());
      query.setInteger(6, normalId);
      query.executeUpdate();

    } catch (HibernateException e) {
      e.printStackTrace();
    }
  }
  /**
   * @param code
   * @param parentCode
   * @param description
   * @return list of EgPartytype filtered by optional conditions
   */
  public List<EgPartytype> getPartyTypeDetailFilterBy(
      final String code, final String parentCode, final String description) {
    final StringBuffer qryStr = new StringBuffer();
    qryStr.append(
        "select distinct ptype From EgPartytype ptype where ptype.createdby is not null ");
    Query qry = getCurrentSession().createQuery(qryStr.toString());

    if (code != null && !code.equals("")) {
      qryStr.append(" and (upper(ptype.code) like :code)");
      qry = getCurrentSession().createQuery(qryStr.toString());
    }
    if (parentCode != null && !parentCode.equals("")) {
      qryStr.append(" and (upper(ptype.egPartytype.code) like :parentCode)");
      qry = getCurrentSession().createQuery(qryStr.toString());
    }
    if (description != null && !description.equals("")) {
      qryStr.append(" and (upper(ptype.description) like :description)");
      qry = getCurrentSession().createQuery(qryStr.toString());
    }

    if (code != null && !code.equals("")) {
      qry.setString("code", "%" + code.toUpperCase().trim() + "%");
    }
    if (parentCode != null && !parentCode.equals("")) {
      qry.setString("parentCode", "%" + parentCode.toUpperCase().trim() + "%");
    }
    if (description != null && !description.equals("")) {
      qry.setString("description", "%" + description.toUpperCase().trim() + "%");
    }

    return qry.list();
  }
 @Override
 public Customer getByLoginAndPassword(final String login, final String password) {
   Session session = null;
   Transaction transaction = null;
   Customer customer = null;
   try {
     session = sf.openSession();
     transaction = session.beginTransaction();
     Query query =
         session.createQuery("from Customer where login = "******":login and password = :password");
     query.setString("login", login);
     query.setString("password", PASSWORD_ENCRYPTOR.getCryptString(password));
     customer = (Customer) query.uniqueResult();
     transaction.commit();
   } catch (RuntimeException e) {
     try {
       transaction.rollback();
     } catch (RuntimeException re) {
       LOGGER.error(ROLLBACK_EXC_MSG, re);
     }
     throw e;
   } finally {
     if (session != null) {
       session.close();
     }
   }
   return customer;
 }
Beispiel #6
0
 public void updatepwd(String adminid, String adminpwd) throws Exception {
   String hql = "UPDATE Admin SET adminpwd=? WHERE adminid=?";
   Query q = super.getSession().createQuery(hql);
   q.setString(0, adminpwd);
   q.setString(1, adminid);
   q.executeUpdate();
 }
 @Override
 public Customer getByName(final String firstName, final String lastName) {
   Session session = null;
   Transaction transaction = null;
   Customer customer = null;
   try {
     session = sf.openSession();
     transaction = session.beginTransaction();
     Query query =
         session.createQuery(
             "from Customer where firstName = " + ":firstName and lastName = :lastName");
     query.setString("firstName", firstName);
     query.setString("lastName", lastName);
     customer = (Customer) query.uniqueResult();
     transaction.commit();
   } catch (RuntimeException e) {
     try {
       transaction.rollback();
     } catch (RuntimeException re) {
       LOGGER.error(ROLLBACK_EXC_MSG, re);
     }
     throw e;
   } finally {
     if (session != null) {
       session.close();
     }
   }
   return customer;
 }
  @Override
  public List getShipmentHeader(String orderId, String mailId, int index, int size) {
    Session session = getSession();
    StringBuilder sb = new StringBuilder();
    sb.append("select a.senddt,a.shipment_id,a.mail_id,f.dsc,a.prod_price,");
    sb.append("e.address,c.name,a.order_id,a.mail_price from acoapp_oms.shipment_header a");
    sb.append(" inner join iagent.orderhist b on a.order_id = b.orderid");
    sb.append(" inner join iagent.contact c on b.contactid = c.contactid");
    sb.append(" inner join iagent.address e on b.addressid = e.addressid");
    sb.append(" left join iagent.names f on b.ordertype = f.id and f.tid = 'ORDERTYPE'");
    sb.append(
        " where CAST(a.logistics_status_id as NUMBER) >= 2 and CAST(a.logistics_status_id as NUMBER) not in (5,6)");
    sb.append(" and NVL(a.RECONCIL_FLAG,0)=0 and a.account_type = 1");
    if (!"".equals(orderId)) {
      sb.append(" and a.order_id = :orderId");
    }
    if (!"".equals(mailId)) {
      sb.append(" and a.mail_id = :mailId");
    }
    Query q = session.createSQLQuery(sb.toString());
    if (!"".equals(orderId) && orderId != null) {
      q.setString("orderId", orderId);
    }
    if (!"".equals(mailId) && mailId != null) {
      q.setString("mailId", mailId);
    }
    q.setFirstResult(index);
    q.setMaxResults(size);

    return q.list();
  }
 @Override
 public Long getShipmentHeaderCount(String orderId, String mailId) {
   Session session = getSession();
   StringBuilder sb = new StringBuilder();
   sb.append("select count(a.id) from acoapp_oms.shipment_header a");
   sb.append(" inner join iagent.orderhist b on a.order_id = b.orderid");
   sb.append(" inner join iagent.contact c on b.contactid = c.contactid");
   sb.append(" inner join iagent.address e on b.addressid = e.addressid");
   sb.append(" left join iagent.names f on b.ordertype = f.id and f.tid = 'ORDERTYPE'");
   sb.append(
       " where CAST(a.logistics_status_id as NUMBER) >= 2  and NVL(a.RECONCIL_FLAG,0)=0 and a.account_type = 1");
   if (!"".equals(orderId)) {
     sb.append(" and a.order_id = :orderId");
   }
   if (!"".equals(mailId)) {
     sb.append(" and a.mail_id = :mailId");
   }
   Query q = session.createSQLQuery(sb.toString());
   if (!"".equals(orderId) && orderId != null) {
     q.setString("orderId", orderId);
   }
   if (!"".equals(mailId) && mailId != null) {
     q.setString("mailId", mailId);
   }
   return ((BigDecimal) q.uniqueResult()).longValue();
 }
Beispiel #10
0
 @Override
 public User findByNameAndPassword(String name, String password) {
   Query query = session.createQuery(BY_NAME_AND_PASSWORD_QUERY);
   query.setString("name", name);
   query.setString("password", password);
   return (User) query.uniqueResult();
 }
  public Object execute(Environment environment) throws Exception {
    Session session = environment.get(Session.class);

    Query query =
        session.createQuery(
            "select distinct hai.activityName "
                + "from "
                + HistoryActivityInstanceImpl.class.getName()
                + " as hai "
                + "where hai.historyProcessInstance.processDefinitionId = :processDefinitionId");
    query.setString("processDefinitionId", processDefinitionId);

    Map<String, Long> avgDuration = new HashMap<String, Long>();

    List<String> activityNames = query.list();
    for (String activityName : activityNames) {
      query =
          session.createQuery(
              "select avg(hai.duration) "
                  + "from "
                  + HistoryActivityInstanceImpl.class.getName()
                  + " as hai "
                  + "where hai.historyProcessInstance.processDefinitionId = :processDefinitionId "
                  + "  and hai.activityName = :activityName");
      query.setString("processDefinitionId", processDefinitionId);
      query.setString("activityName", activityName);

      Number number = (Number) query.uniqueResult();
      avgDuration.put(activityName, new Long(number.longValue()));
    }

    return avgDuration;
  }
  public void updateOwnerByFolderIdList(List<String> folderIdList, String ownerAccountId) {
    if ((ownerAccountId == null) || (ownerAccountId.isEmpty())) {
      return;
    }

    if ((folderIdList == null) || (folderIdList.size() == 0)) {
      return;
    }

    String updateQuery =
        "update" + " dm_folder" + " set" + " da_id_owner = :ownerAccountId" + " where" + " (1 = 1)";

    updateQuery = updateQuery + " and (";
    int i = 0;
    for (String folderId : folderIdList) {
      if (i > 0) {
        updateQuery = updateQuery + " or";
      }
      updateQuery = updateQuery + " (df_id = :folderId" + i + ")";
      i++;
    }
    updateQuery = updateQuery + ")";

    Query query = getSession().createSQLQuery(updateQuery);

    query.setString("ownerAccountId", ownerAccountId);
    i = 0;
    for (String folderId : folderIdList) {
      query.setString("folderId" + i, folderId);
      i++;
    }

    query.executeUpdate();
  }
Beispiel #13
0
 @Override
 public Member memberLogin(String login, String password) throws Exception {
   Session session = HibernateUtil.getSession();
   Transaction tx = null;
   Member member = null;
   try {
     String hql = "SELECT a FROM Member AS a WHERE a.login=:login AND a.password=:password";
     Query query = session.createQuery(hql);
     query.setString("login", login.trim());
     query.setString("password", password.trim());
     query.setMaxResults(1);
     tx = session.beginTransaction();
     member = (Member) query.uniqueResult();
     if (member != null && ("y").equals(member.getActivated().toLowerCase())) {
       member.setLoginTimes(Integer.valueOf(member.getLoginTimes() + 1));
       member.setLastLogin(new Date());
       session.update(member);
     }
     tx.commit();
   } catch (Exception ex) {
     if (tx != null) tx.rollback();
     logger.info("In class MemberServiceImpl:memberLogin()\n");
     ex.printStackTrace();
   } finally {
     HibernateUtil.closeSession();
   }
   return member;
 }
Beispiel #14
0
  /*
   * (non-Javadoc)
   *
   * @see cn.tinder.fuego.dao.CheckPlanDao#delete(cn.tinder.fuego.domain.po.CheckPlan )
   */
  @Override
  public void delete(CheckPlan plan) {
    // TODO Auto-generated method stub
    log.debug("[DAO] Delete the CheckPlan:" + plan.toString());

    Session session = null;
    Transaction tx = null;
    String hql = null;
    // SystemUser user = null;
    try {
      session = HibernateUtil.getSession();

      tx = session.beginTransaction();

      hql = "delete from CheckPlan where trans_id=? and dept_id=? ";
      Query query = session.createQuery(hql);
      query.setString(0, plan.getTransID());
      query.setString(1, plan.getDeptID());

      query.executeUpdate();

      tx.commit();
    } catch (RuntimeException re) {
      throw re;
    } finally {
      if (null != session) {
        session.close();
      }
    }

    log.debug("[DAO] Success!Delete the CheckPlan:" + plan.toString());
  }
  public void testCachedQuery() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Simple simple = new Simple();
    simple.setName("Simple 1");
    s.save(simple, new Long(10));
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    Query q = s.createQuery("from Simple s where s.name=?");
    q.setCacheable(true);
    q.setString(0, "Simple 1");
    assertTrue(q.list().size() == 1);
    assertTrue(q.list().size() == 1);
    assertTrue(q.list().size() == 1);
    q = s.createQuery("from Simple s where s.name=:name");
    q.setCacheable(true);
    q.setString("name", "Simple 1");
    assertTrue(q.list().size() == 1);
    simple = (Simple) q.list().get(0);

    q.setString("name", "Simple 2");
    assertTrue(q.list().size() == 0);
    assertTrue(q.list().size() == 0);
    simple.setName("Simple 2");
    assertTrue(q.list().size() == 1);
    assertTrue(q.list().size() == 1);
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    q = s.createQuery("from Simple s where s.name=:name");
    q.setString("name", "Simple 2");
    q.setCacheable(true);
    assertTrue(q.list().size() == 1);
    assertTrue(q.list().size() == 1);
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    s.update(simple, new Long(10));
    s.delete(simple);
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    q = s.createQuery("from Simple s where s.name=?");
    q.setCacheable(true);
    q.setString(0, "Simple 1");
    assertTrue(q.list().size() == 0);
    assertTrue(q.list().size() == 0);
    t.commit();
    s.close();
  }
  public boolean updateUser(User user) {

    String hql = "update User u set u.userName = ?,u.age=? where u.id = ?";
    Query query = sessionFactory.getCurrentSession().createQuery(hql);
    query.setString(0, user.getUserName());
    query.setString(1, user.getAge());
    query.setString(2, user.getId());

    return (query.executeUpdate() > 0);
  }
 public EgNumbers getEgNumberByFiscalPeriodAndVouchertype(
     final String fiscialperiodid, final String vouchertype) {
   final Query qry =
       getCurrentSession()
           .createQuery(
               "from EgNumbers egnum where egnum.fiscialperiodid=:fiscialperiodid and vouchertype=:vouchertype");
   qry.setString("fiscialperiodid", fiscialperiodid);
   qry.setString("vouchertype", vouchertype);
   return (EgNumbers) qry.uniqueResult();
 }
 @Override
 public City getByCityAndCountryCode(String city, String countryCode) {
   String sql =
       "SELECT citys.* FROM countrys LEFT JOIN citys on citys.countryid=countrys.id WHERE "
           + "countrys.countrycode=UPPER(:country) AND citys.city=:city";
   Query q = HibernateUtil.getSession().createSQLQuery(sql).addEntity(City.class);
   q.setString("country", countryCode);
   q.setString("city", city);
   return (City) q.uniqueResult();
 }
 public VWebwloEve findById(String factNo, String factCode, String yymm) {
   // TODO Auto-generated method stub
   String hql = "from VWebwloEve where id.factNo=? and id.factCode=? and id.yymm=?";
   Query query = getSession().createQuery(hql);
   query.setString(0, factNo);
   query.setString(1, factCode);
   query.setString(2, yymm);
   VWebwloEve eve = (VWebwloEve) query.uniqueResult();
   return eve;
 }
Beispiel #20
0
  @SuppressWarnings("unchecked")
  private boolean checkForCampaignIDExist(
      final Session session, final BatchCampaignAssociationModel batchCampaignAssociationModel)
      throws HibernateException {
    // Session session = null;
    List<BatchCampaignAssociationModel> list = Collections.emptyList();
    boolean campIdExist = true;
    final String campId = batchCampaignAssociationModel.getCampaignId();
    try {
      // session = sessionFactory.openSession();
      final String hql =
          "from BatchCampaignAssociationModel where campaignId =:cmpid and campaignType =:cmpType";
      // QC-1257 (change from Prelink to Targeted)
      list = session.createQuery(hql).setString("cmpid", campId).setString("cmpType", "T").list();

      if (list.size() > 0) {
        campIdExist = false;
        // session = null;
        // session = sessionFactory.openSession();
        final String uhql =
            "update BatchCampaignAssociationModel set campaignId = :cid, batchFileNo = :bfN, campaignStartDate = :csD, "
                + "campaignEndDate = :ceD, registrationStartDate = :rsD, registrationEndDate = :reD, "
                + "registrationRequired = :rReq, campaignType = :cT, commentsRequired = :cR, campaignDescription = :cD where id = :d";
        for (BatchCampaignAssociationModel b : list) {

          Query query = session.createQuery(uhql);
          query.setString("cid", batchCampaignAssociationModel.getCampaignId());
          query.setString("bfN", batchCampaignAssociationModel.getBatchFileNo());
          query.setDate("csD", batchCampaignAssociationModel.getCampaignStartDate());
          query.setDate("ceD", batchCampaignAssociationModel.getCampaignEndDate());
          query.setDate("rsD", batchCampaignAssociationModel.getRegistrationStartDate());
          query.setDate("reD", batchCampaignAssociationModel.getRegistrationEndDate());
          query.setParameter("rReq", batchCampaignAssociationModel.getRegistrationRequired());
          query.setString("cT", batchCampaignAssociationModel.getCampaignType());
          query.setParameter("cR", batchCampaignAssociationModel.getCommentsRequired());
          query.setString("cD", batchCampaignAssociationModel.getCampaignDescription());
          query.setInteger("d", b.getId());

          int rowCount = query.executeUpdate();
          LOGGER.info(
              rowCount > 0
                  ? "Update BatchCampaignAssociation table is successful with campaignid : "
                      + campId
                  : "Failed to update BatchCampaignAssociation table with campaignid : " + campId);
        }
      }
    } catch (HibernateException e) {
      LOGGER.error("Error in checking and updating campaign details with id : " + campId);
      throw e;
    } finally {
      // session.close();
      // batchCampaignAssociationModel = null;
    }
    return campIdExist;
  }
Beispiel #21
0
 public List queryByLike(String cond) throws Exception {
   List all = null;
   String hql = "From Dept As d WHERE d.dname LIKE ? OR d.loc LIKE ? OR d.business LIKE ?";
   Query query = this.session.createQuery(hql);
   query.setString(0, "%" + cond + "%");
   query.setString(1, "%" + cond + "%");
   query.setString(2, "%" + cond + "%");
   all = query.list();
   this.session.close();
   return all;
 }
  public RecepcionMx getRecepcionMxByCodUnicoMx(String codigoUnicoMx, String codLaboratorio) {
    String query =
        "select a from RecepcionMx as a inner join a.tomaMx as t where (t.codigoUnicoMx= :codigoUnicoMx or t.codigoLab = :codigoUnicoMx) "
            + "and a.labRecepcion.codigo = :codLaboratorio";

    Session session = sessionFactory.getCurrentSession();
    Query q = session.createQuery(query);
    q.setString("codigoUnicoMx", codigoUnicoMx);
    q.setString("codLaboratorio", codLaboratorio);
    return (RecepcionMx) q.uniqueResult();
  }
 public List getVerificationCode(String phoneNum, String project) {
   Session session = sessionFactory.getCurrentSession();
   String hql =
       "from VerificationCode verificationCode where verificationCode.toPhone = :toPhone"
           + " and verificationCode.site = :site";
   Query query = session.createQuery(hql);
   query.setString("toPhone", phoneNum);
   query.setString("site", project);
   List list = query.list();
   return list;
 }
 public EgActiondetails getEgActiondetailsByWorksdetailId(
     final String moduleId, final String actionType, final String moduleType) {
   final Query qry =
       getCurrentSession()
           .createQuery(
               "from EgActiondetails ad where ad.moduleid =:moduleId and ad.actiontype =:actionType and ad.moduletype=:moduleType order by lastmodifieddate");
   qry.setString("moduleId", moduleId);
   qry.setString("actionType", actionType);
   qry.setString("moduleType", moduleType);
   return (EgActiondetails) qry.uniqueResult();
 }
 public List<EgActiondetails> getEgActiondetailsFilterBy(
     final String moduleId, final ArrayList<String> actionType, final String moduleType) {
   final Query qry =
       getCurrentSession()
           .createQuery(
               "from EgActiondetails ad where ad.moduleid =:moduleId and ad.actiontype in (:actionType) and ad.moduletype=:moduleType order by lastmodifieddate");
   qry.setString("moduleId", moduleId);
   qry.setParameterList("actionType", actionType);
   qry.setString("moduleType", moduleType);
   return qry.list();
 }
 /**
  * Finds objects for an object type (like User, Group) for a ManagedSystem definition
  *
  * @param managedSystemId
  * @param objectType
  * @return
  */
 public List<ManagedSystemObjectMatch> findBySystemId(String managedSystemId, String objectType) {
   Session session = sessionFactory.getCurrentSession();
   Query qry =
       session.createQuery(
           "from org.openiam.idm.srvc.mngsys.dto.ManagedSystemObjectMatch sys "
               + " where sys.managedSys = :managedSystemId  and sys.objectType = :objectType");
   qry.setString("managedSystemId", managedSystemId);
   qry.setString("objectType", objectType);
   List<ManagedSystemObjectMatch> result = (List<ManagedSystemObjectMatch>) qry.list();
   if (result == null || result.size() == 0) return null;
   return result;
 }
Beispiel #27
0
 public boolean login(Admin admin) throws Exception {
   boolean flag = false;
   String hql = "FROM Admin AS a WHERE a.adminid=? AND a.adminpwd=?";
   Query q = super.getSession().createQuery(hql);
   q.setString(0, admin.getAdminid());
   q.setString(1, admin.getAdminpwd());
   List all = q.list();
   if (all.size() > 0) {
     flag = true;
   }
   return flag;
 }
Beispiel #28
0
 /** 引数で指定したdateとmarketTypeのレコードを取得。 */
 @SuppressWarnings("unchecked")
 public List<StockPrice> getStockPrices(String date, String marketTypeCode) {
   String strQuery =
       "FROM mylib.hibernate.entity.StockPrice sp "
           + "WHERE sp.marketTypeCode = :marketTypeCode AND sp.date = :date";
   Query query = session.createQuery(strQuery);
   query.setString("marketTypeCode", marketTypeCode);
   query.setString("date", date);
   List<StockPrice> records = (List<StockPrice>) query.list();
   if (records.size() == 0) return null;
   return records;
 }
  public void removeAllUsersInRole(String domainId, String roleId) {
    log.debug("removeUserFromRole: roleId=" + roleId);

    Session session = sessionFactory.getCurrentSession();
    Query qry =
        session.createQuery(
            "delete org.openiam.idm.srvc.role.dto.UserRole ur "
                + " where ur.roleId = :roleId and ur.serviceId = :domainId ");
    qry.setString("roleId", roleId);
    qry.setString("domainId", domainId);
    qry.executeUpdate();
  }
Beispiel #30
0
  public FacturaAlmacen cierra(FacturaAlmacen factura, Usuario usuario)
      throws NoSePuedeCerrarException, NoSePuedeCerrarEnCeroException, NoEstaAbiertaException {
    if (factura != null) {
      if (factura.getEstatus().getNombre().equals(Constantes.ABIERTA)) {
        if (usuario != null) {
          factura.setAlmacen(usuario.getAlmacen());
        }

        Date fecha = new Date();
        factura.setIva(BigDecimal.ZERO);
        factura.setTotal(BigDecimal.ZERO);
        Query query =
            currentSession().createQuery("select e from Estatus e where e.nombre = :nombre");
        query.setString("nombre", Constantes.FACTURADA);
        Estatus facturada = (Estatus) query.uniqueResult();
        for (Salida salida : factura.getSalidas()) {
          salida.setEstatus(facturada);
          salida.setFechaModificacion(fecha);
          currentSession().update(salida);
          audita(salida, usuario, Constantes.FACTURADA, fecha);
          factura.setIva(factura.getIva().add(salida.getIva()));
          factura.setTotal(factura.getTotal().add(salida.getTotal()));
        }

        for (Entrada entrada : factura.getEntradas()) {
          entrada.setEstatus(facturada);
          entrada.setFechaModificacion(fecha);
          currentSession().update(entrada);
          audita(entrada, usuario, Constantes.FACTURADA, fecha);
          factura.setIva(factura.getIva().subtract(entrada.getIva()));
          factura.setTotal(factura.getTotal().subtract(entrada.getTotal()));
        }

        query.setString("nombre", Constantes.CERRADA);
        Estatus estatus = (Estatus) query.uniqueResult();
        factura.setEstatus(estatus);
        factura.setFolio(getFolio(factura.getAlmacen()));
        factura.setFechaModificacion(fecha);

        currentSession().update(factura);

        audita(factura, usuario, Constantes.ACTUALIZAR, fecha);

        currentSession().flush();
        return factura;
      } else {
        throw new NoEstaAbiertaException("No se puede actualizar una factura que no este abierta");
      }
    } else {
      throw new NoSePuedeCerrarException("No se puede cerrar la factura pues no existe");
    }
  }