Ejemplo n.º 1
0
  private Criteria buildJpaCriteria(Class clazz, Map<String, ?> fieldValues) {
    Criteria criteria = new Criteria(clazz.getName());
    for (Iterator i = fieldValues.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry<String, ?> e = (Map.Entry<String, ?>) i.next();

      String key = e.getKey();
      Object value = e.getValue();
      String alias = "";
      String[] keySplit = key.split("\\.");
      if (keySplit.length > 1) {
        alias = keySplit[keySplit.length - 2];
        String variableKey = keySplit[keySplit.length - 1];
        for (int j = 0; j < keySplit.length - 1; j++) {
          if (criteria.getAliasIndex(keySplit[j]) == -1) {
            criteria.join(keySplit[j], keySplit[j], false, true);
          }
        }
        key = "__JPA_ALIAS[['" + alias + "']]__." + variableKey;
      }
      if (value == null) {
        continue;
      } else if (value instanceof Collection) {
        criteria.in(key, (Collection) value);
      } else {
        criteria.eq(key, value);
      }
    }
    return criteria;
  }
 /** @see org.kuali.rice.krad.dao.MaintenanceDocumentDao#deleteLocks(java.lang.String) */
 public void deleteLocks(String documentNumber) {
   Criteria criteria = new Criteria(MaintenanceLock.class.getName());
   criteria.eq("documentNumber", documentNumber);
   new QueryByCriteria(entityManager, criteria, QueryByCriteriaType.DELETE)
       .toQuery()
       .executeUpdate();
 }
Ejemplo n.º 3
0
 /**
  * This is the default impl that comes with Kuali - uses OJB.
  *
  * @see org.kuali.rice.krad.dao.BusinessObjectDao#countMatching(java.lang.Class, java.util.Map,
  *     java.util.Map)
  */
 public int countMatching(
     Class clazz, Map<String, ?> positiveFieldValues, Map<String, ?> negativeFieldValues) {
   Criteria criteria = buildJpaCriteria(clazz, positiveFieldValues);
   criteria.and(buildNegativeJpaCriteria(clazz, negativeFieldValues));
   return ((Long) new QueryByCriteria(entityManager, criteria).toCountQuery().getSingleResult())
       .intValue();
 }
Ejemplo n.º 4
0
  private Criteria buildNegativeJpaCriteria(Class clazz, Map negativeFieldValues) {
    Criteria criteria = new Criteria(clazz.getName());
    for (Iterator i = negativeFieldValues.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry e = (Map.Entry) i.next();

      String key = (String) e.getKey();
      Object value = e.getValue();
      if (value instanceof Collection) {
        criteria.notIn(key, (List) value);
      } else {
        criteria.ne(key, value);
      }
    }

    return criteria;
  }
 /**
  * Applies the search results limit to the search criteria for this BO (JPA)
  *
  * @param businessObjectClass BO class to search on / get limit for
  * @param criteria search criteria
  */
 public static void applySearchResultsLimit(
     Class businessObjectClass,
     org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria criteria) {
   Integer limit = getSearchResultsLimit(businessObjectClass, null);
   if (limit != null) {
     criteria.setSearchLimit(limit);
   }
 }
  /**
   * @see org.kuali.rice.krad.dao.MaintenanceDocumentDao#getLockingDocumentNumber(java.lang.String,
   *     java.lang.String)
   */
  public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) {
    String lockingDocNumber = "";

    // build the query criteria
    Criteria criteria = new Criteria(MaintenanceLock.class.getName());
    criteria.eq("lockingRepresentation", lockingRepresentation);

    // if a docHeaderId is specified, then it will be excluded from the
    // locking representation test.
    if (StringUtils.isNotBlank(documentNumber)) {
      criteria.ne(KRADPropertyConstants.DOCUMENT_NUMBER, documentNumber);
    }

    // attempt to retrieve a document based off this criteria
    MaintenanceLock maintenanceLock =
        (MaintenanceLock) new QueryByCriteria(entityManager, criteria).toQuery().getSingleResult();

    // if a document was found, then there's already one out there pending,
    // and we consider it 'locked' and we return the docnumber.
    if (maintenanceLock != null) {
      lockingDocNumber = maintenanceLock.getDocumentNumber();
    }
    return lockingDocNumber;
  }
Ejemplo n.º 7
0
 private Criteria buildInactiveJpaCriteria(Class clazz) {
   Criteria criteria = new Criteria(clazz.getName());
   criteria.eq(KRADPropertyConstants.ACTIVE, false);
   return criteria;
 }
Ejemplo n.º 8
0
 /**
  * This is the default impl that comes with Kuali - uses OJB.
  *
  * @see org.kuali.rice.krad.dao.BusinessObjectDao#findMatching(java.lang.Class, java.util.Map)
  */
 public <T extends BusinessObject> Collection<T> findMatchingOrderBy(
     Class<T> clazz, Map<String, ?> fieldValues, String sortField, boolean sortAscending) {
   Criteria criteria = buildJpaCriteria(clazz, fieldValues);
   criteria.orderBy(sortField, sortAscending);
   return (Collection<T>) new QueryByCriteria(entityManager, criteria).toQuery().getResultList();
 }
Ejemplo n.º 9
0
 /**
  * @see org.kuali.rice.krad.dao.BusinessObjectDao#findMatchingActive(java.lang.Class,
  *     java.util.Map)
  */
 public <T extends BusinessObject> Collection<T> findMatchingActive(
     Class<T> clazz, Map<String, ?> fieldValues) {
   Criteria criteria = buildJpaCriteria(clazz, fieldValues);
   criteria.and(buildActiveJpaCriteria(clazz));
   return (Collection<T>) new QueryByCriteria(entityManager, criteria).toQuery().getResultList();
 }
Ejemplo n.º 10
0
 /**
  * @see org.kuali.rice.krad.dao.BusinessObjectDao#findAllActiveOrderBy(java.lang.Class,
  *     java.lang.String, boolean)
  */
 public <T extends BusinessObject> Collection<T> findAllActiveOrderBy(
     Class<T> clazz, String sortField, boolean sortAscending) {
   Criteria criteria = buildActiveJpaCriteria(clazz);
   criteria.orderBy(sortField, sortAscending);
   return (Collection<T>) new QueryByCriteria(entityManager, criteria).toQuery().getResultList();
 }