Пример #1
0
 public DictKungFuType update(DictKungFuType model, int instPlayerId) throws Exception {
   try {
     Object[] params = null;
     int version = model.getVersion() + 1;
     StringBuffer sql = new StringBuffer("update Dict_KungFuType set ");
     sql.append("name=?,sname=?,description=?,version=? ");
     sql.append("where id=? and version=?");
     params =
         new Object[] {
           model.getName(),
           model.getSname(),
           model.getDescription(),
           version,
           model.getId(),
           model.getVersion()
         };
     int count = this.getJdbcTemplate().update(sql.toString(), params);
     if (count == 0) {
       throw new Exception("Concurrent Exception");
     } else {
       model.setVersion(version, 0);
       PlayerMemObj playerMemObj = getPlayerMemObjByPlayerId(instPlayerId);
       if (instPlayerId != 0 && isUseCach() && playerMemObj != null) {
         playerMemObj.dictKungFuTypeMap.put(model.getId(), model);
       }
     }
   } catch (Exception e) {
     throw e;
   }
   return model;
 }
Пример #2
0
 @SuppressWarnings("unchecked")
 public DictKungFuType getModel(int id, int instPlayerId) {
   try {
     PlayerMemObj playerMemObj = getPlayerMemObjByPlayerId(instPlayerId);
     if (instPlayerId != 0 && isUseCach() && playerMemObj != null) {
       DictKungFuType model = playerMemObj.dictKungFuTypeMap.get(id);
       if (model == null) {
         String sql = "select * from Dict_KungFuType where id=?";
         Object[] params = new Object[] {id};
         playerMemObj.dictKungFuTypeMap.put(
             id,
             (DictKungFuType)
                 this.getJdbcTemplate().queryForObject(sql, params, new ItemMapper()));
       } else {
         int cacheVersion = model.getVersion();
         List<Map<String, Object>> list =
             sqlHelper("select version from Dict_KungFuType where id = " + id);
         int dbVersion = (int) list.get(0).get("version");
         if (cacheVersion != dbVersion) {
           String sql = "select * from Dict_KungFuType where id=?";
           Object[] params = new Object[] {id};
           playerMemObj.dictKungFuTypeMap.put(
               id,
               (DictKungFuType)
                   this.getJdbcTemplate().queryForObject(sql, params, new ItemMapper()));
         }
       }
       model = playerMemObj.dictKungFuTypeMap.get(id);
       model.result = "";
       return model;
     } else {
       String sql = "select * from Dict_KungFuType where id=?";
       Object[] params = new Object[] {id};
       DictKungFuType model =
           (DictKungFuType) this.getJdbcTemplate().queryForObject(sql, params, new ItemMapper());
       model.result = "";
       return model;
     }
   } catch (DataAccessException e) {
     return null;
   }
 }
Пример #3
0
 private List<DictKungFuType> listCacheCommonHandler(String sql, int instPlayerId) {
   List<DictKungFuType> modelList = new ArrayList<DictKungFuType>();
   PlayerMemObj playerMemObj = getPlayerMemObjByPlayerId(instPlayerId);
   SqlRowSet rsSet = this.getJdbcTemplate().queryForRowSet(sql.toString());
   while (rsSet.next()) {
     int id = rsSet.getInt("id");
     int dbVersion = rsSet.getInt("version");
     DictKungFuType model = playerMemObj.dictKungFuTypeMap.get(id);
     if (model == null) {
       model = getModel(id, instPlayerId);
       model.result = "";
       modelList.add(model);
     } else {
       int cacheVersion = model.getVersion();
       if (cacheVersion != dbVersion) {
         model = getModel(id, instPlayerId);
       }
       model.result = "";
       modelList.add(model);
     }
   }
   return modelList;
 }
Пример #4
0
  public DictKungFuType add(final DictKungFuType model, int instPlayerId) throws Exception {
    try {
      StringBuilder strSql = new StringBuilder();
      strSql.append(" insert into Dict_KungFuType (");
      strSql.append("name,sname,description,version");
      strSql.append(" )");
      strSql.append(" values (?,?,?,?) ");

      final String sql = strSql.toString();
      KeyHolder keyHolder = new GeneratedKeyHolder();

      this.getJdbcTemplate()
          .update(
              new PreparedStatementCreator() {
                public PreparedStatement createPreparedStatement(Connection conn)
                    throws SQLException {
                  PreparedStatement ps = conn.prepareStatement(sql);
                  ps.setString(1, model.getName());
                  ps.setString(2, model.getSname());
                  ps.setString(3, model.getDescription());
                  ps.setInt(4, 0);
                  return ps;
                }
              },
              keyHolder);

      model.setId(keyHolder.getKey().intValue());
      model.setVersion(0);
      PlayerMemObj playerMemObj = getPlayerMemObjByPlayerId(instPlayerId);
      if (instPlayerId != 0 && isUseCach() && playerMemObj != null) {
        playerMemObj.dictKungFuTypeMap.put(model.getId(), model);
      }
    } catch (Exception e) {
      throw e;
    }
    return model;
  }
Пример #5
0
 public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
   DictKungFuType dictKungFuType = new DictKungFuType();
   dictKungFuType.setId(rs.getInt("id"), 0);
   dictKungFuType.setName(rs.getString("name"), 0);
   dictKungFuType.setSname(rs.getString("sname"), 0);
   dictKungFuType.setDescription(rs.getString("description"), 0);
   dictKungFuType.setVersion(rs.getInt("version"), 0);
   return dictKungFuType;
 }