@SuppressWarnings("rawtypes") public List LoadList(List<Long> p_pids) { if (p_pids == null) return null; final List<Long> pids = new ArrayList<Long>(p_pids.size()); for (Number obj : p_pids) { pids.add(obj.longValue()); } String cache = this.CacheRegion(); List<POJO> prjs = new ArrayList<POJO>(pids.size()) { { for (int i = 0; i < pids.size(); i++) add(null); } }; List<Long> no_cache_ids = new ArrayList<Long>(); for (int i = 0; i < pids.size(); i++) { long pid = pids.get(i); POJO obj = (POJO) CacheManager.get(cache, pid); if (obj != null) prjs.set(i, obj); else { no_cache_ids.add(pid); } } if (no_cache_ids.size() > 0) { List<? extends POJO> no_cache_prjs = BatchGet(no_cache_ids); if (no_cache_prjs != null) for (POJO obj : no_cache_prjs) { prjs.set(pids.indexOf(obj.getId()), obj); } } no_cache_ids = null; // Check Users if (prjs != null && IsAutoLoadUser()) { List<Long> no_cache_userids = new ArrayList<Long>(); String user_cache = User.INSTANCE.CacheRegion(); for (POJO pojo : prjs) { if (pojo == null) continue; long userid = pojo.GetAutoLoadUser(); if (userid > 0 && !no_cache_userids.contains(userid)) { POJO user = (POJO) CacheManager.get(user_cache, userid); if (user == null) { no_cache_userids.add(userid); } } } if (no_cache_userids.size() > 0) User.INSTANCE.BatchGet(no_cache_userids); no_cache_userids = null; } return prjs; }
public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (!getClass().equals(obj.getClass())) { return false; } POJO wb = (POJO) obj; return wb.getId() == getId(); }
private static long _InsertObject(POJO obj) { Map<String, Object> pojo_bean = obj.ListInsertableFields(); String[] fields = pojo_bean.keySet().toArray(new String[pojo_bean.size()]); StringBuilder sql = new StringBuilder("INSERT INTO "); sql.append(obj.TableName()); sql.append('('); for (int i = 0; i < fields.length; i++) { if (i > 0) sql.append(','); sql.append(fields[i]); } sql.append(") VALUES("); for (int i = 0; i < fields.length; i++) { if (i > 0) sql.append(','); sql.append('?'); } sql.append(')'); PreparedStatement ps = null; ResultSet rs = null; try { ps = QueryHelper.getConnection() .prepareStatement(sql.toString(), PreparedStatement.RETURN_GENERATED_KEYS); for (int i = 0; i < fields.length; i++) { ps.setObject(i + 1, pojo_bean.get(fields[i])); } ps.executeUpdate(); rs = ps.getGeneratedKeys(); return rs.next() ? rs.getLong(1) : -1; } catch (SQLException e) { throw new DBException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(ps); sql = null; fields = null; pojo_bean = null; } }