protected void executeJFishEntityListener(
     boolean before, JFishEvent jfishEvent, Object entities, List<DbmEntityListener> listeners) {
   if (LangUtils.isMultiple(entities)) {
     List<?> list = LangUtils.asList(entities);
     for (Object entity : list) {
       this.executeJFishEntityListenerForSingle(before, jfishEvent, entity, listeners);
     }
   } else {
     this.executeJFishEntityListenerForSingle(before, jfishEvent, entities, listeners);
   }
 }
 protected void executeJFishEntityListenerForSingle(
     boolean before, JFishEvent jfishEvent, Object entity, List<DbmEntityListener> listeners) {
   if (LangUtils.isEmpty(listeners)) return;
   if (before) {
     if (jfishEvent.getAction() == JFishEventAction.insert) {
       for (DbmEntityListener jel : listeners) {
         jel.beforeInsert(entity);
       }
     } else if (jfishEvent.getAction() == JFishEventAction.update) {
       for (DbmEntityListener jel : listeners) {
         jel.beforeUpdate(entity);
       }
     }
   } else {
     if (jfishEvent.getAction() == JFishEventAction.insert) {
       for (DbmEntityListener jel : listeners) {
         jel.afterInsert(entity);
       }
     } else if (jfishEvent.getAction() == JFishEventAction.update) {
       for (DbmEntityListener jel : listeners) {
         jel.afterUpdate(entity);
       }
     }
   }
 }
  /**
   * **** 如果使用批量处理,因为某些驱动的实现机制,比如oracle,不能根据返回值来判断是否更新成功
   *
   * @param userBatch
   * @param sql
   * @param args
   * @param es
   * @return
   */
  protected int executeJdbcUpdate(
      boolean userBatch, String sql, List<Object[]> args, JFishEventSource es) {
    int count = 0;
    if (userBatch) {
      //			int[] ups = es.getJFishJdbcTemplate().batchUpdate(sql, args);
      int batchSize = es.getDataBaseConfig().getProcessSizePerBatch();
      int[][] ups =
          es.getJFishJdbcTemplate()
              .batchUpdateWith(
                  sql, args, batchSize /*, new ParameterizedPreparedStatementSetter<Object[]>(){

				@Override
				public void setValues(PreparedStatement ps, Object[] argument) throws SQLException {
					JdbcUtils.setValues(ps, argument);
				}
				
			}*/);
      for (int[] up : ups) count += LangUtils.sum(up);
    } else {
      for (Object[] arg : args) {
        count +=
            es.getJFishJdbcTemplate().updateWith(new SimpleArgsPreparedStatementCreator(sql, arg));
      }
    }
    return count;
  }
 protected void throwIfMultiple(Object parent, Object entity) {
   if (LangUtils.isMultiple(entity)) {
     String msg =
         "element of "
             + (parent == null ? "container" : parent)
             + " can not be a multiple object, element: "
             + entity;
     throw new DbmException(msg);
   }
 }
Beispiel #5
0
  public static ModelAndView createModelAndView(String viewName, Object... models) {
    ModelAndView mv = new ModelAndView(viewName);
    //		mv.getModel().put(UrlHelper.MODEL_KEY, getUrlMeta());
    if (LangUtils.isEmpty(models)) {
      return mv;
    }

    if (models.length == 1) {
      if (Map.class.isInstance(models[0])) {
        mv.addAllObjects((Map<String, ?>) models[0]);

      } else if (DataWrapper.class.isInstance(models[0])) {
        mv.addObject(models[0]);

      } else if (ModelAttr.class.isInstance(models[0])) {
        ModelAttr attr = (ModelAttr) models[0];
        mv.addObject(attr.getName(), attr.getValue());

      } else {
        mv.addObject(models[0]);
        //				mv.addObject(JsonWrapper.wrap(models[0]));
        //				mv.addObject(SINGLE_MODEL_FLAG_KEY, true);
      }
    } else {
      /*Map<String, ?> modelMap = LangUtils.asMap(models);
      mv.addAllObjects(modelMap);*/

      for (int i = 0; i < models.length; i++) {
        if (DataWrapper.class.isInstance(models[i])) {
          mv.addObject(models[i]);

        } else if (ModelAttr.class.isInstance(models[i])) {
          ModelAttr attr = (ModelAttr) models[i];
          mv.addObject(attr.getName(), attr.getValue());

        } else {
          Object name = models[i];
          if (!String.class.isInstance(name)) {
            throw new BaseException("model key must be a string, but is : " + name);
          }
          i++;
          if (i >= models.length) {
            throw new BaseException("no value for model key : " + name);
          }
          mv.addObject(name.toString(), models[i]);
        }
      }
    }
    return mv;
  }
  public void doEvent(JFishEvent event) {
    Object entity = event.getObject();
    JFishInsertOrUpdateEvent insertOrUpdate = (JFishInsertOrUpdateEvent) event;

    int updateCount = 0;
    if (LangUtils.isMultiple(entity)) {
      Collection<Object> entities = CUtils.toCollection(entity);
      for (Object obj : entities) {
        if (obj == null) continue;
        throwIfMultiple(entities, obj);
        updateCount += this.onInnerEventWithSingle(obj, insertOrUpdate);
      }
    } else {
      updateCount = onInnerEventWithSingle(entity, insertOrUpdate);
    }
    event.setUpdateCount(updateCount);
  }