Пример #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);
 }