Ejemplo n.º 1
0
 @Override
 public boolean exec(MethodContext methodContext) throws MiniLangException {
   try {
     Delegator delegator = getDelegator(methodContext);
     String entityName = this.entityNameFse.expandString(methodContext.getEnvMap());
     ModelEntity modelEntity = delegator.getModelEntity(entityName);
     EntityCondition whereEntityCondition = null;
     if (this.whereCondition != null) {
       whereEntityCondition =
           this.whereCondition.createCondition(
               methodContext.getEnvMap(),
               modelEntity,
               delegator.getModelFieldTypeReader(modelEntity));
     }
     EntityCondition havingEntityCondition = null;
     if (this.havingCondition != null) {
       havingEntityCondition =
           this.havingCondition.createCondition(
               methodContext.getEnvMap(),
               modelEntity,
               delegator.getModelFieldTypeReader(modelEntity));
     }
     long count =
         delegator.findCountByCondition(
             entityName, whereEntityCondition, havingEntityCondition, null);
     this.countFma.put(methodContext.getEnvMap(), count);
   } catch (GeneralException e) {
     String errMsg = "Exception thrown while performing entity count: " + e.getMessage();
     Debug.logWarning(e, errMsg, module);
     simpleMethod.addErrorMessage(methodContext, errMsg);
     return false;
   }
   return true;
 }
Ejemplo n.º 2
0
  public static Map<String, Object> ping(DispatchContext dctx, Map<String, ?> context) {
    Delegator delegator = dctx.getDelegator();
    String message = (String) context.get("message");
    Locale locale = (Locale) context.get("locale");
    if (message == null) {
      message = "PONG";
    }

    long count = -1;
    try {
      count = delegator.findCountByCondition("SequenceValueItem", null, null, null);
    } catch (GenericEntityException e) {
      Debug.logError(e.getMessage(), module);
      return ServiceUtil.returnError(
          UtilProperties.getMessage(resource, "CommonPingDatasourceCannotConnect", locale));
    }

    if (count > 0) {
      Map<String, Object> result = ServiceUtil.returnSuccess();
      result.put("message", message);
      return result;
    } else {
      return ServiceUtil.returnError(
          UtilProperties.getMessage(resource, "CommonPingDatasourceInvalidCount", locale));
    }
  }
 public static long categoryMemberCount(GenericValue category) {
   if (category == null) return 0;
   Delegator delegator = category.getDelegator();
   long count = 0;
   try {
     count =
         delegator.findCountByCondition(
             "ProductCategoryMember",
             buildCountCondition("productCategoryId", category.getString("productCategoryId")),
             null,
             null);
   } catch (GenericEntityException e) {
     Debug.logError(e, module);
   }
   return count;
 }