コード例 #1
0
 public int delete(Connection conn, JboIFace jbo) throws JxException {
   if (conn == null || jbo == null) {
     LOG.info("传入的参数为空。");
     return -1;
   }
   String tabname = jbo.getJboSet().getEntityname();
   String msql = "Delete from " + tabname + " where " + jbo.getUidName() + "=?";
   Object[] columns = new Object[] {jbo.getJxAttributes().get(jbo.getUidName())};
   JxLog jxlog = JxLogFactory.getJxLog(jbo.getJboSet().getAppname(), tabname);
   if (jxlog != null) {
     jxlog.info(jbo, "DELETE");
   }
   return execute(conn, msql, columns, new Object[] {jbo.getUidValue()});
 }
コード例 #2
0
 /**
  * 执行Insert 之前,检查数据必填项是否填写完毕。
  *
  * @param jbo
  * @return
  */
 public boolean checkValid(JboIFace jbo) throws JxException {
   if (jbo == null) {
     return false;
   }
   Map<String, JxAttribute> jxattr = jbo.getJxAttributes();
   String jboname = jbo.getJboName();
   String keyName = jbo.getUidName();
   Map<String, Object> data = jbo.getData();
   for (Map.Entry<String, JxAttribute> entry : jxattr.entrySet()) {
     String key = entry.getKey();
     if ((keyName != null && key.equalsIgnoreCase(keyName))) {
       continue;
     }
     JxAttribute attr = entry.getValue();
     if (attr == null) {
       continue;
     } else if (attr.getDefaultValue() != null) {
       if (data.get(key) == null) {
         data.put(key, attr.getDefaultValue());
       }
     } else if (attr.isRequired() && key.indexOf(".") == -1) {
       if (null == data.get(key)) {
         LOG.debug("表名.字段名(" + jboname + "." + key + ")为必填项。");
         throw new JxException(
             "必须填写:"
                 + attr.getObjectName()
                 + " : "
                 + attr.getTitle()
                 + " : "
                 + attr.getAttributeName());
       }
     }
   }
   return true;
 }
コード例 #3
0
 /**
  * 保存数据
  *
  * @param conn
  * @param jbo
  * @return
  */
 public boolean save(Connection conn, JboIFace jbo) throws JxException {
   if (conn == null || jbo == null) {
     LOG.warn("保存数据失败,conn is null or jbo is null.");
     return false;
   }
   Map<String, Object> data = jbo.getData();
   if (data == null) {
     LOG.info("没有要保存的数据");
     return false;
   }
   int res;
   if (jbo.isToBeAdd() && jbo.isToBeDel()) {
     return true;
   }
   String tableName = jbo.getJboSet().getEntityname();
   if (jbo.isToBeDel() && !jbo.isToBeAdd()) {
     if (delete(conn, jbo) > 0) {
       removeCache(tableName);
       return true;
     } else {
       return false;
     }
   }
   if (!jbo.isModify() && !jbo.isToBeAdd()) {
     return true;
   }
   String keyName = jbo.getUidName();
   if (StrUtil.isNull(keyName)) {
     throw new JxException("表" + tableName + "没有指定关键字,请与管理员联系。");
   }
   Object keyValue = data.get(keyName);
   JboSetIFace js = jbo.getJboSet();
   DataQuery dq = DBFactory.getDataQuery(js.getDbtype(), js.getDataSourceName());
   // 设定记录信息
   java.sql.Timestamp ts = DateUtil.sqlDateTime();
   JxUserInfo user = JxSession.getJxUserInfo();
   if (user != null && jbo != null) {
     jbo.setString("MODIFIER_ID", user.getUserid());
     jbo.setString("MODIFIER", user.getDisplayname());
     jbo.setObject("MODIFY_TIME", ts);
     jbo.setObject("MODIFY_DATE", ts);
     jbo.setString("CHANGEBY", user.getUserid());
     jbo.setObject("CHANGEDATE", ts);
   }
   if (dq.exist(conn, tableName, keyName, keyValue)) {
     // 更改记录,修改人、修改时间要设置为现在
     res = update(conn, jbo);
   } else {
     res = insert(conn, jbo);
   }
   if (res > 0) {
     removeCache(tableName);
     return true;
   } else {
     LOG.info("没有保存到数据," + tableName + "." + keyName + "=" + keyValue);
     return false;
   }
 }