@SuppressWarnings("unchecked")
  public List<MessageBundleProperty> search(
      String searchQuery, String module, String baseName, String locale) {
    List<String> values = new ArrayList<String>();
    StringBuffer queryString = new StringBuffer("");

    try {
      if (searchQuery != null && searchQuery.length() > 0) {
        queryString.append("(defaultValue like ? OR value like ? OR propertyName = ?)");
        values.add("%" + searchQuery + "%");
        values.add("%" + searchQuery + "%");
        values.add(searchQuery);
      }
      if (module != null && module.length() > 0) {
        if (queryString.length() > 0) {
          queryString.append(" AND ");
        }
        queryString.append("moduleName = ? ");
        values.add(module);
      }
      if (baseName != null && baseName.length() > 0) {
        if (queryString.length() > 0) {
          queryString.append(" AND ");
        }
        queryString.append("baseName = ?");
        values.add(baseName);
      }
      if (locale != null && locale.length() > 0) {
        if (queryString.length() > 0) {
          queryString.append(" AND ");
        }
        queryString.append("locale = ?");
        values.add(locale);
      }

      if (queryString.length() > 0) {
        queryString.insert(0, "from MessageBundleProperty where ");
      } else {
        queryString.insert(0, "from MessageBundleProperty");
      }

      return getHibernateTemplate().find(queryString.toString(), values.toArray());

    } catch (Exception e) {
      logger.error("problem searching the message bundle data", e);
    }
    return new ArrayList<MessageBundleProperty>();
  }
 public float saldo(Conta conta, Date data) {
   StringBuffer sql = new StringBuffer();
   sql.append("select sum(l.valor * c.fator)");
   sql.append(" from LANCAMENTO l,");
   sql.append("   CATEGORIA c");
   sql.append(" where l.categoria = c.codigo");
   sql.append("  and l.conta = :conta");
   sql.append("  and l.data <= :data");
   SQLQuery query = this.session.createSQLQuery(sql.toString());
   query.setParameter("conta", conta.getConta());
   query.setParameter("data", data);
   BigDecimal saldo = (BigDecimal) query.uniqueResult();
   if (saldo != null) {
     return saldo.floatValue();
   }
   return 0f;
 }
  public int getSearchCount(String searchQuery, String module, String baseName, String locale) {
    List<String> values = new ArrayList<String>();
    List<NullableType> types = new ArrayList<NullableType>();
    StringBuffer queryString = new StringBuffer("");

    try {
      if (searchQuery != null && searchQuery.length() > 0) {
        queryString.append("(defaultValue like ? OR value like ? OR propertyName = ?)");
        values.add("%" + searchQuery + "%");
        values.add("%" + searchQuery + "%");
        values.add(searchQuery);
        types.add(Hibernate.STRING);
        types.add(Hibernate.STRING);
        types.add(Hibernate.STRING);
      }
      if (module != null && module.length() > 0) {
        if (queryString.length() > 0) {
          queryString.append(" AND ");
        }
        queryString.append("moduleName = ? ");
        values.add(module);
        types.add(Hibernate.STRING);
      }
      if (baseName != null && baseName.length() > 0) {
        if (queryString.length() > 0) {
          queryString.append(" AND ");
        }
        queryString.append("baseName = ?");
        values.add(baseName);
        types.add(Hibernate.STRING);
      }
      if (locale != null && locale.length() > 0) {
        if (queryString.length() > 0) {
          queryString.append(" AND ");
        }
        queryString.append("locale = ?");
        values.add(locale);
        types.add(Hibernate.STRING);
      }

      if (queryString.length() > 0) {
        queryString.insert(0, "select count(*) from MessageBundleProperty where ");
      } else {
        queryString.insert(0, "select count(*) from MessageBundleProperty");
      }

      Integer count = null;
      try {
        Query query = getSession().createQuery(queryString.toString());
        query.setParameters(values.toArray(), (Type[]) types.toArray(new Type[types.size()]));
        count = (Integer) query.uniqueResult();
      } catch (HibernateException e) {
        throw new RuntimeException(e.getMessage(), e);
      }
      return count.intValue();

    } catch (Exception e) {
      logger.error("problem searching the message bundle data", e);
    }
    return 0;
  }