/** @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();
 }
  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#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;
  }
 private Criteria buildInactiveJpaCriteria(Class clazz) {
   Criteria criteria = new Criteria(clazz.getName());
   criteria.eq(KRADPropertyConstants.ACTIVE, false);
   return criteria;
 }