コード例 #1
0
 /**
  * 将bean对象更新进数据库
  *
  * @return 返回更新条数,-1为更新失败
  * @throws AttributeException
  * @throws InvokeException
  * @throws DbPropertyException
  * @throws SQLException
  */
 public Integer update()
     throws InvokeException, AttributeException, DbPropertyException, SQLException {
   String tableName = getMapTableName();
   List<String> keyList = super.getKeys();
   BuildSql sqlHelper = new BuildSql();
   Map<String, Object> valueMap = getMapValuesMap();
   Map<String, Object> filteMap = new HashMap<String, Object>();
   Map<String, Object> values = new HashMap<String, Object>();
   Iterator<String> it = valueMap.keySet().iterator();
   while (it.hasNext()) {
     String key = it.next();
     if (keyList.contains(key)) {
       filteMap.put(key, valueMap.get(key));
     } else {
       values.put(key, valueMap.get(key));
     }
   }
   BuildSql buildSql = new BuildSql();
   buildSql.setTableName(tableName);
   buildSql.setFilterMap(filteMap);
   buildSql.setValueMap(values);
   buildSql.BuildUpdateSql();
   DbCon db = new DbCon();
   return db.updateSql(buildSql);
 }
コード例 #2
0
 /**
  * 更新或者新增(根据主键条件判断新增或者更新)
  *
  * @return 返回更新条数,-1为更新失败
  * @throws InvokeException
  * @throws AttributeException
  * @throws DbPropertyException
  * @throws SQLException
  * @throws DynConfigException
  */
 public Integer saveOrUpdate()
     throws InvokeException, AttributeException, DbPropertyException, SQLException {
   String tableName = getMapTableName();
   Map<String, String> mappingMap = super.getMappingMap();
   List<String> keyList = super.getKeys();
   List<String> excluList = super.getExclusiveList();
   BuildSql sqlHelper = new BuildSql();
   Map<String, Object> filteMap = new HashMap<String, Object>();
   Map<String, Object> valuesMap = new HashMap<String, Object>();
   Iterator<String> it = super.getMap().keySet().iterator();
   while (it.hasNext()) {
     String fieldName = it.next();
     Object value = super.getMap().get(fieldName);
     String name = fieldName;
     if (!excluList.contains(fieldName)) { // 如果不在排除列中
       if (mappingMap.containsKey(fieldName)) { // 如果存在映射关系
         name = mappingMap.get(fieldName);
       }
       if (keyList.contains(fieldName)) {
         filteMap.put(name, value);
       } else {
         valuesMap.put(name, value);
       }
     }
   }
   BuildSql buildSql = new BuildSql();
   buildSql.setTableName(tableName);
   buildSql.BuildSaveOrUpdateSql(filteMap, valuesMap);
   DbCon db = new DbCon();
   return db.updateSql(buildSql);
 }
コード例 #3
0
 /**
  * 将Map对象插入数据库
  *
  * @throws AttributeException
  * @throws InvokeException
  * @throws SQLException
  * @throws DbPropertyException
  */
 public Integer insert()
     throws InvokeException, AttributeException, DbPropertyException, SQLException {
   List<String> keyList = this.getKeys();
   Map<String, Object> valueMap = super.getMap();
   for (String str : keyList) {
     if (super.getMap().get(str) == null) {
       super.getMap().put(str, StringUtil.getUUID());
     }
   }
   BuildSql buildSql = new BuildSql();
   String tableName = getMapTableName();
   buildSql.setValueMap(getMapValuesMap());
   buildSql.setTableName(tableName);
   buildSql.BuildInsertSql();
   DbCon db = new DbCon();
   return db.updateSql(buildSql);
 }
コード例 #4
0
 /**
  * 查询满足bean对象主键值的集合
  *
  * @return
  * @throws InvokeException
  * @throws AttributeException
  * @throws DbPropertyException
  * @throws SQLException
  */
 public List<Map<String, Object>> query()
     throws InvokeException, AttributeException, DbPropertyException, SQLException {
   String tableName = getMapTableName();
   List<String> keyList = super.getKeys();
   List<String> excluList = super.getExclusiveList();
   List<String> likeFilterCol = super.getLikeFilterCol();
   Map<String, String> mappingMap = super.getMappingMap();
   BuildSql buildSql = new BuildSql();
   List<String> colList = new ArrayList<String>();
   Map<String, Object> filteMap = new HashMap<String, Object>();
   Map<String, String> likeFilterMap = new HashMap<String, String>(); // 模糊查询对象
   Iterator<String> it = super.getMap().keySet().iterator();
   while (it.hasNext()) {
     String fieldName = it.next();
     String name = fieldName;
     Object value = super.getMap().get(fieldName);
     if (!excluList.contains(fieldName)) { // 如果不在排除列中
       if (mappingMap.containsKey(fieldName)) { // 如果存在映射关系
         name = mappingMap.get(fieldName);
       }
       //				colList.add(name) ;
       if (likeFilterCol.contains(fieldName)) {
         if (value != null) {
           likeFilterMap.put(name, StringUtil.objectToString(value));
         }
       } else if (keyList.contains(fieldName)) {
         if (value != null) {
           filteMap.put(name, value);
         }
       }
     }
   }
   if (colList.size() > 0) {
     buildSql.setColList(colList);
   }
   buildSql.setTableName(tableName);
   buildSql.setFilterMap(filteMap);
   buildSql.setLikeFilterMap(likeFilterMap);
   buildSql.setOrderList(super.getOrderList());
   buildSql.BuildQuerySql();
   DbCon db = new DbCon();
   return db.querySql(buildSql);
 }