@SuppressWarnings("unchecked")
 public List<MessageBundleProperty> getModifiedProperties(
     int sortOrder, int sortField, int startingIndex, int pageSize) {
   String orderBy = "asc";
   if (sortOrder == SORT_ORDER_DESCENDING) {
     orderBy = "desc";
   }
   String sortFieldName = "id";
   if (sortField == SORT_FIELD_MODULE) {
     sortFieldName = "moduleName";
   }
   if (sortField == SORT_FIELD_PROPERTY) {
     sortFieldName = "propertyName";
   }
   if (sortField == SORT_FIELD_LOCALE) {
     sortFieldName = "locale";
   }
   if (sortField == SORT_FIELD_BASENAME) {
     sortFieldName = "baseName";
   }
   org.hibernate.Query query = null;
   String queryString =
       "from MessageBundleProperty where value != null order by " + sortFieldName + " " + orderBy;
   try {
     query = getSession().createQuery(queryString);
     query.setFirstResult(startingIndex);
     query.setMaxResults(pageSize);
     return query.list();
   } catch (HibernateException e) {
     throw new RuntimeException(e.getMessage(), e);
   }
 }
  public static GroovyAwareJavassistProxyFactory buildProxyFactory(
      PersistentClass persistentClass) {
    GroovyAwareJavassistProxyFactory proxyFactory = new GroovyAwareJavassistProxyFactory();

    @SuppressWarnings("unchecked")
    Set<Class<HibernateProxy>> proxyInterfaces = new HashSet<Class<HibernateProxy>>();
    proxyInterfaces.add(HibernateProxy.class);

    final Class<?> javaClass = persistentClass.getMappedClass();
    final Property identifierProperty = persistentClass.getIdentifierProperty();
    final Method idGetterMethod =
        identifierProperty != null ? identifierProperty.getGetter(javaClass).getMethod() : null;
    final Method idSetterMethod =
        identifierProperty != null ? identifierProperty.getSetter(javaClass).getMethod() : null;
    final Type identifierType =
        persistentClass.hasEmbeddedIdentifier() ? persistentClass.getIdentifier().getType() : null;

    try {
      proxyFactory.postInstantiate(
          persistentClass.getEntityName(),
          javaClass,
          proxyInterfaces,
          idGetterMethod,
          idSetterMethod,
          identifierType instanceof CompositeType ? (CompositeType) identifierType : null);
    } catch (HibernateException e) {
      LOG.warn("Cannot instantiate proxy factory: " + e.getMessage());
      return null;
    }

    return proxyFactory;
  }
 protected int executeCountQuery(String query) {
   Integer count = null;
   try {
     count = (Integer) getSession().createQuery(query).uniqueResult();
   } catch (HibernateException e) {
     throw new RuntimeException(e.getMessage(), e);
   }
   return count.intValue();
 }
  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;
  }