/**
   * Tests <code>{@link CopilotProjectDAOImpl#delete(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testDelete2() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(hibernateTemplate, copilotProfile, copilotProject);

    CopilotProjectInfoType copilotProjectInfoType = TestHelper.createCopilotProjectInfoType();
    hibernateTemplate.save(copilotProjectInfoType);

    CopilotProjectInfo copilotProjectInfo = TestHelper.createCopilotProjectInfo();
    copilotProjectInfo.setCopilotProjectId(copilotProject.getId());
    copilotProjectInfo.setInfoType(copilotProjectInfoType);
    copilotProject.getProjectInfos().add(copilotProjectInfo);
    hibernateTemplate.save(copilotProject);

    instance.delete(copilotProject.getId());

    Assert.assertEquals(
        "None entity in database should exist.",
        0,
        hibernateTemplate.find("from CopilotProject").size());
    Assert.assertEquals(
        "None entity in database should exist.",
        0,
        hibernateTemplate.find("from CopilotProjectInfo").size());
  }
  @Override
  @Transactional(readOnly = true)
  public List<Ticket> searchTicketByKeyword(String keyword) {

    HibernateTemplate ht = getHibernateTemplate();

    List<Ticket> resultList = new ArrayList<Ticket>();

    List<Ticket> titleList =
        ht.find("from Ticket t where t.title like ? order by t.id desc", wildCardKeyword(keyword));
    List<Ticket> creatorList =
        ht.find(
            "from Ticket t where t.creator.username like ? order by t.id desc",
            wildCardKeyword(keyword)); // searchTicket By Creator;
    List<Ticket> assigneeList =
        ht.find(
            "from Ticket t where t.assignee.username like ? order by t.id desc",
            wildCardKeyword(keyword));
    List<Ticket> custList =
        ht.find(
            "from Ticket t where t.customer.username like ? order by t.id desc",
            wildCardKeyword(keyword)); // searchTicketByCustomer(keyword);
    // List<Ticket> noteList   = ht.find("from Ticket t where t.notes.note like ?",
    // wildCardKeyword(keyword));

    resultList.addAll(titleList);
    resultList.addAll(creatorList);
    resultList.addAll(assigneeList);
    resultList.addAll(custList);
    // resultList.addAll(noteList);

    return resultList;
  }
 /**
  * 还款时候,取消正在转让的债权
  *
  * @param loanId
  * @throws RepayException
  */
 public void cancelTransfering(String loanId) throws RepayException {
   // 取消投资下面的所有正在转让的债权
   String hql = "from TransferApply ta where ta.invest.loan.id=? and ta.status=?";
   List<TransferApply> tas = ht.find(hql, new String[] {loanId, TransferStatus.WAITCONFIRM});
   if (tas.size() > 0) {
     // 有购买了等待第三方确认的债权,所以不能还款。
     throw new RepayException("有等待第三方确认的债权转让,不能还款!");
   }
   tas = ht.find(hql, new String[] {loanId, TransferStatus.TRANSFERING});
   for (TransferApply ta : tas) {
     transferService.cancel(ta.getId());
   }
 }
Пример #4
0
  public void importarPendientes(Long sucursalId) {
    String sql = "select * from sx_clientes_log where tx_importado is null";
    JdbcTemplate template = ReplicaServices.getInstance().getJdbcTemplate(sucursalId);
    List<Map<String, Object>> rows = template.queryForList(sql);
    for (Map<String, Object> row : rows) {
      System.out.println("Importando: " + row);

      try {
        Number cliente_id = (Number) row.get("CLIENTE_ID");
        HibernateTemplate source = ReplicaServices.getInstance().getHibernateTemplate(sucursalId);
        List<Cliente> clientes =
            source.find(
                "from Cliente c "
                    + " left join fetch c.direcciones d"
                    + " left join fetch c.telefonos t"
                    + " where c.id=?",
                cliente_id.longValue());
        Cliente c = clientes.get(0);
        Services.getInstance().getHibernateTemplate().replicate(c, ReplicationMode.IGNORE);
      } catch (Exception e) {
        logger.error("Error importando cliente: " + row, e);
      }
      try {
        Number id = (Number) row.get("ID");
        String update = "UPDATE SX_CLIENTES_LOG SET TX_IMPORTADO=NOW() WHERE ID=?";
        template.update(update, new Object[] {id.longValue()});
      } catch (Exception e) {
        logger.error("Error actualizando importado: " + row);
      }
    }
  }
Пример #5
0
 public List getListFieldValueByMemberId(String memberId) {
   String sql =
       "select fieldValue from Customer customer,FieldValue fieldValue where fieldValue.userId=customer.webId and fieldValue.fieldId=99";
   sql += " and customer.uid = ?";
   List list = hibernateTemplate.find(sql, memberId);
   return list;
 }
  public BackDetail loadByNum(String num) {
    String queryString = "from  BackDetail backDetail where backDetail.code='" + num + "'";

    List<BackDetail> backDetails = hibernateTemplate.find(queryString);

    return backDetails.get(0);
  }
Пример #7
0
 @SuppressWarnings("unchecked")
 @Transactional
 @Override
 public List<LookFor> findAllLookFor() {
   List<LookFor> result = template.find("from LookFor");
   return result;
 }
  /**
   * Tests <code>{@link
   * CopilotProjectDAOImpl#update(com.topcoder.direct.services.copilot.model.IdentifiableEntity)}
   * </code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testUpdate() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(hibernateTemplate, copilotProfile, copilotProject);
    hibernateTemplate.save(copilotProject);

    copilotProject.setCompletionDate(new Date());
    copilotProject.setCustomerFeedback("test customer feedback");
    copilotProject.setCustomerRating(0.9F);
    copilotProject.setPmFeedback("test pm feedback");
    copilotProject.setPmRating(0.9F);

    CopilotProjectInfoType copilotProjectInfoType = TestHelper.createCopilotProjectInfoType();
    hibernateTemplate.save(copilotProjectInfoType);

    CopilotProjectInfo copilotProjectInfo = TestHelper.createCopilotProjectInfo();
    copilotProjectInfo.setInfoType(copilotProjectInfoType);
    copilotProject.getProjectInfos().add(copilotProjectInfo);

    instance.update(copilotProject);

    List<CopilotProject> result =
        (List<CopilotProject>)
            hibernateTemplate.find("from CopilotProject where id = ?", copilotProject.getId());

    assertCopilotProject(copilotProject, result.get(0));
  }
Пример #9
0
  public void importarClientesPendientes(final Date desde) {
    for (Long sucursal : getSucursales()) {

      JdbcTemplate sucursalTemplate = ReplicaServices.getInstance().getJdbcTemplate(sucursal);
      String sql = "select CLIENTE_ID from sx_clientes where date(creado)>=?";
      Object args[] = {new SqlParameterValue(Types.DATE, desde)};
      final List<Long> ids = sucursalTemplate.queryForList(sql, args, Long.class);
      System.out.println("Clientes: " + ids.size());
      for (Long id : ids) {
        System.out.println("Validando: " + id + " En sucursal: " + sucursal);
        Cliente c = Services.getInstance().getClientesManager().get(id);
        if (c == null) {
          System.out.println("Faltante: " + id + " importandolo...");
          HibernateTemplate target = Services.getInstance().getHibernateTemplate();
          HibernateTemplate source = ReplicaServices.getInstance().getHibernateTemplate(sucursal);
          List<Cliente> clientes =
              source.find(
                  "from Cliente c left join fetch c.credito "
                      + " left join fetch c.direcciones d"
                      + " left join fetch c.telefonos t"
                      + " where c.id=?",
                  id);
          c = clientes.get(0);
          target.replicate(c, ReplicationMode.EXCEPTION);
        }
      }
    }
  }
Пример #10
0
 @Override
 public int sizeOfAll() {
   // TODO Auto-generated method stub
   String hql = "select count(*) from Goodsinfo";
   Object o = mysqlhibernateTemplete.find(hql).listIterator().next();
   Integer count = Integer.parseInt(o == null ? "0" : o.toString());
   return count.intValue();
 }
  @SuppressWarnings("unchecked")
  public Account findByCreditCard(String creditCardNumber) {

    List<Account> accounts =
        hibernateTemplate.find("from Account a  where a.creditCardNumber = ?", creditCardNumber);
    if (accounts.isEmpty()) return null;
    return accounts.get(0);
  }
  public List<BackDetail> getBackDetailsByNum(String num) {
    // TODO Auto-generated method stub
    String queryString = "from  BackDetail backDetail where backDetail.code='" + num + "'";

    List<BackDetail> backDetails = hibernateTemplate.find(queryString);

    return backDetails;
  }
Пример #13
0
 public Authorities findByPrimaryKey(Object key) {
   if (key instanceof String) {
     String username = (String) key;
     List<?> find = hibernateTemplate.find("from Authorities where username = ?", username);
     return (Authorities) find.get(0);
   } else {
     return null;
   }
 }
Пример #14
0
 public List<FieldValue> getFieldValueListByUserIdAndRole(Integer userId, String role) {
   String sql =
       "from FieldValue fieldValue where fieldValue.userId="
           + userId
           + " and fieldValue.fieldValue LIKE '%"
           + role
           + "%'";
   return hibernateTemplate.find(sql);
 }
Пример #15
0
 public List<Integer> getIdListByUserIdAndGroup(Integer fieldId, Integer userId, Integer group) {
   String sql =
       "select value.fieldValueId from FieldValue value where value.fieldId="
           + fieldId
           + " and value.userId="
           + userId;
   sql += " and value.groupMulti=" + group;
   return hibernateTemplate.find(sql);
 }
Пример #16
0
  public void loadDetails(Object target, HibernateTemplate ht, String fkName, Object key)
      throws Exception {

    for (PropertyDescriptor pd : listProps) {
      String hsql = "from " + capitalizeFirstChar(pd.getName()) + " p where p." + fkName + " = ?";
      // System.out.println("hsql is " + hsql);
      List items = ht.find(hsql, key);
      pd.getWriteMethod().invoke(target, items);
    }
  }
Пример #17
0
 public Long getPCCount() {
   try {
     List<Long> count =
         hibernateTemplate.find(
             "select COUNT(*) from Consumable c left join c.instru i where i is null");
     return count.get(0);
   } catch (RuntimeException re) {
     throw re;
   }
 }
Пример #18
0
 public List<User> getUserNoTeachstaffenlargeinfo() {
   String hql_1 = "from Teachstaffenlargeinfo";
   List<Teachstaffenlargeinfo> teachstaffenlargeinfo = hibernateTemplate.find(hql_1);
   String hql_2 = "from User";
   List<User> userBy = hibernateTemplate.find(hql_2);
   List<User> userList = null;
   for (User u : userBy) {
     if (teachstaffenlargeinfo != null && teachstaffenlargeinfo.equals("[]")) {
       for (Teachstaffenlargeinfo t : teachstaffenlargeinfo) {
         if (u.getUserId() != t.getUserId()) {
           userList.add(u);
         }
       }
     } else {
       userList = userBy;
     }
   }
   return userList;
 }
Пример #19
0
 /** 资金池累计充值 */
 public double getPaidCapRechargeMoney(String userId) {
   String hql =
       "select sum(recharge.actualMoney) from Recharge recharge "
           + "where recharge.status =? and recharge.user.id=? and recharge.rechargeWay='cap'";
   List<Object> oos = ht.find(hql, new String[] {RechargeStatus.SUCCESS, userId});
   Object o = oos.get(0);
   if (o == null) {
     return 0;
   }
   return (Double) o;
 }
Пример #20
0
  @Test
  public void deposit() throws InsufficientPriviledgesException {
    Deposit deposit = new Deposit(admin, brh, new Date(), 10.);

    // make the deposit
    depositRepository.executeDeposit(deposit);

    // verify that the deposit has been created
    List<Deposit> deposits = t.find("from Deposit");
    assertTrue("The deposit lists should contain the new deposit.", deposits.contains(deposit));

    // verify that the saldo has been updated.
    UserProfile brh_fromdb =
        (UserProfile) t.find("from UserProfile u where u.id=?", brh.getId()).get(0);
    assertEquals(
        "The balance should be updated after the deposit.",
        22.,
        brh_fromdb.getBalance().doubleValue(),
        0.001);
  }
Пример #21
0
 @Override
 @Transactional(readOnly = false, rollbackFor = Exception.class)
 public void delete(String levelForUserId) throws UserExistInLevelException {
   // 如果有用户处于当前等级,则不能删除
   String hql = "select count(user) from User user where user.level.id = ?";
   long n = (Long) ht.find(hql, levelForUserId).get(0);
   if (n > 0) {
     throw new UserExistInLevelException();
   }
   ht.bulkUpdate("delete from LevelForUser lfu where lfu.id = ?", levelForUserId);
 }
Пример #22
0
 public List<Consumable> findByProperty(String key, Object value) {
   log.debug("finding Consumable instance with property: " + key + ", value: " + value);
   try {
     String queryString = "from Consumable as model where model." + key + "= '" + value + "'";
     List<Consumable> consumables = hibernateTemplate.find(queryString);
     return consumables;
   } catch (RuntimeException re) {
     log.error("find by property name failed", re);
     throw re;
   }
 }
Пример #23
0
  @Override
  @SuppressWarnings("unchecked")
  public List<LineaPedido> masComprados() {

    List<LineaPedido> lp =
        hibernateTemplate.find("from LineaPedido group by producto order by Sum(cantidad) desc");

    int numProductos = 10;

    if (numProductos <= lp.size()) return lp.subList(0, 10);
    else return lp.subList(0, lp.size());
  }
Пример #24
0
 /* (non-Javadoc)
  * @see cn.cas.iue.dao.ConsumableDAO#getCount()
  */
 @Override
 public Long getICCount(Integer instruId) {
   // TODO Auto-generated method stub
   try {
     List<Long> count =
         hibernateTemplate.find(
             "select COUNT(*) from Consumable c join c.instru i where i.instruId=" + instruId);
     return count.get(0);
   } catch (RuntimeException re) {
     throw re;
   }
 }
Пример #25
0
  @SuppressWarnings("unchecked")
  public List<PlaceInfo> findPlaceInfoBySqlTop(String sql, int maxResults, Object... args) {
    List<PlaceInfo> list = null;
    try {
      HibernateTemplate hibernateTemplate = getHibernateTemplate();
      //			hibernateTemplate.setMaxResults(maxResults);
      list = hibernateTemplate.find(sql, args);
    } catch (Exception e) {

    }
    return list;
  }
  /**
   * Tests <code>{@link CopilotProjectDAOImpl#delete(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testDelete1() throws CopilotDAOException {

    CopilotProfile copilotProfile1 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject1 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile1, copilotProject1);
    hibernateTemplate.save(copilotProject1);

    CopilotProfile copilotProfile2 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject2 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile2, copilotProject2);
    hibernateTemplate.save(copilotProject2);

    instance.delete(copilotProject1.getId());

    List<CopilotProject> result =
        hibernateTemplate.find("from CopilotProject where id = ?", copilotProject1.getId());

    Assert.assertEquals(
        "One entity in database should still exist.",
        1,
        hibernateTemplate.find("from CopilotProject").size());
    Assert.assertEquals("Entity was not deleted.", 0, result.size());

    instance.delete(copilotProject2.getId());

    result = hibernateTemplate.find("from CopilotProject where id = ?", copilotProject2.getId());

    Assert.assertEquals(
        "None entity in database should exist.",
        0,
        hibernateTemplate.find("from CopilotProject").size());
    Assert.assertEquals("Entity was not deleted.", 0, result.size());
  }
Пример #27
0
 /**
  * Importa un cliente
  *
  * @param clave
  * @param source
  */
 public void importarCliente(String clave, Long sucursalId) {
   HibernateTemplate target = Services.getInstance().getHibernateTemplate();
   HibernateTemplate source = ReplicaServices.getInstance().getHibernateTemplate(sucursalId);
   List<Cliente> clientes =
       source.find(
           "from Cliente c left join fetch c.credito "
               + " left join fetch c.direcciones d"
               + " left join fetch c.telefonos t"
               + " where c.clave=?",
           clave);
   Cliente c = clientes.get(0);
   target.replicate(c, ReplicationMode.EXCEPTION);
 }
Пример #28
0
  @Override
  @SuppressWarnings("unchecked")
  @Transactional(readOnly = true)
  public List<Company> findAll() throws DaoException {
    List<Company> companies;

    try {
      companies = (List<Company>) hibernateTemplate.find("from Company order by name");
    } catch (DataAccessException e) {
      throw new DaoException("Error while calling findAll()", e);
    }

    return companies;
  }
Пример #29
0
  // 通过HQL语句 "select count(*) from table_name" 获取记录总数
  public int getRecordCount(final String HQL) {
    /*List list = ht.executeFind(
    	new HibernateCallback() {
    		public List doInHibernate(Session s) throws HibernateException, SQLException {
    			List result = s.createQuery(HQL).list();
    			return result;
    		}
    	}
    );*/
    List result = ht.find(HQL);
    int recordCount = ((Number) result.iterator().next()).intValue();

    // System.out.println("++++++++recordCount="+recordCount);
    return recordCount;
  }
  /**
   * Tests <code>{@link
   * CopilotProjectDAOImpl#create(com.topcoder.direct.services.copilot.model.IdentifiableEntity)}
   * </code> method.
   *
   * @throws com.topcoder.direct.services.copilot.dao.CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testCreate1() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(hibernateTemplate, copilotProfile, copilotProject);

    instance.create(copilotProject);

    List<CopilotProject> result =
        (List<CopilotProject>)
            hibernateTemplate.find("from CopilotProject where id = ?", copilotProject.getId());

    assertCopilotProject(copilotProject, result.get(0));
  }