@Test public void testQueryForPojoOne() { Map<String, Object> args = new HashMap<String, Object>(); args.put("id", "123"); UserPO user = dao.queryForPojoOne(UserPO.class, args); System.out.println(user.getId()); }
@SuppressWarnings("unchecked") @Override public <T> T queryForPojoOne(Class<T> pojoType, Map<String, Object> args) throws DataAccessException { Jedis jedis = getJedis(); if (jedis != null) { try { T t = null; ORMTable ormTable = pojoType.getAnnotation(ORMTable.class); String cachedTableKey = "".equalsIgnoreCase(ormTable.cachedShortAlias()) ? ormTable.tableName() : ormTable.cachedShortAlias(); String[] cachedKeys = ormTable.cachedKey(); for (String cachedKey : cachedKeys) { String[] ks = cachedKey.split("="); Object arg = args.get(ks[0]); if (arg != null) { String key = cachedTableKey + "." + ks[1] + "." + String.valueOf(arg); T obj = null; try { obj = (T) getCache(jedis, key); } catch (ClassNotFoundException e) { logger.warn("Get from cache fail!", e); } catch (IOException e) { logger.warn("Get from cache fail!", e); } if (obj != null) { t = obj; break; } } } if (t != null) { return t; } else { t = super.queryForPojoOne(pojoType, args); if (t != null) { for (String cachedKey : cachedKeys) { String[] fk = cachedKey.split("="); try { Field f = t.getClass().getDeclaredField(fk[0]); f.setAccessible(true); String key = cachedTableKey + "." + fk[1] + "." + f.get(t); setCache(jedis, key, t); } catch (Exception e) { logger.warn("Set to cache fail!", e); } } } } return t; } finally { jedisPool.returnResource(jedis); } } else { return super.queryForPojoOne(pojoType, args); } }
RedisWeakCachedCommonDao extends DefaultCommonDao { @SuppressWarnings("unchecked") @Override public <T> T queryForPojoOne(Class<T> pojoType, Map<String, Object> args) throws DataAccessException { Jedis jedis = getJedis(); if (jedis != null) { try { T t = null; ORMTable ormTable = pojoType.getAnnotation(ORMTable.class); String cachedTableKey = "".equalsIgnoreCase(ormTable.cachedShortAlias()) ? ormTable.tableName() : ormTable.cachedShortAlias(); String[] cachedKeys = ormTable.cachedKey(); for (String cachedKey : cachedKeys) { String[] ks = cachedKey.split("="); Object arg = args.get(ks[0]); if (arg != null) { String key = cachedTableKey + "." + ks[1] + "." + String.valueOf(arg); T obj = null; try { obj = (T) getCache(jedis, key); } catch (ClassNotFoundException e) { logger.warn("Get from cache fail!", e); } catch (IOException e) { logger.warn("Get from cache fail!", e); } if (obj != null) { t = obj; break; } } } if (t != null) { return t; } else { t = super.queryForPojoOne(pojoType, args); if (t != null) { for (String cachedKey : cachedKeys) { String[] fk = cachedKey.split("="); try { Field f = t.getClass().getDeclaredField(fk[0]); f.setAccessible(true); String key = cachedTableKey + "." + fk[1] + "." + f.get(t); setCache(jedis, key, t); } catch (Exception e) { logger.warn("Set to cache fail!", e); } } } } return t; } finally { jedisPool.returnResource(jedis); } } else { return super.queryForPojoOne(pojoType, args); } } }
RedisWeakCachedCommonDao extends DefaultCommonDao { @SuppressWarnings("unchecked") @Override public <T> T queryForPojoOne(Class<T> pojoType, Map<String, Object> args) throws DataAccessException { Jedis jedis = getJedis(); if (jedis != null) { try { T t = null; ORMTable ormTable = pojoType.getAnnotation(ORMTable.class); String cachedTableKey = "".equalsIgnoreCase(ormTable.cachedShortAlias()) ? ormTable.tableName() : ormTable.cachedShortAlias(); String[] cachedKeys = ormTable.cachedKey(); for (String cachedKey : cachedKeys) { String[] ks = cachedKey.split("="); Object arg = args.get(ks[0]); if (arg != null) { String key = cachedTableKey + "." + ks[1] + "." + String.valueOf(arg); T obj = null; try { obj = (T) getCache(jedis, key); } catch (ClassNotFoundException e) { logger.warn("Get from cache fail!", e); } catch (IOException e) { logger.warn("Get from cache fail!", e); } if (obj != null) { t = obj; break; } } } if (t != null) { return t; } else { t = super.queryForPojoOne(pojoType, args); if (t != null) { for (String cachedKey : cachedKeys) { String[] fk = cachedKey.split("="); try { Field f = t.getClass().getDeclaredField(fk[0]); f.setAccessible(true); String key = cachedTableKey + "." + fk[1] + "." + f.get(t); setCache(jedis, key, t); } catch (Exception e) { logger.warn("Set to cache fail!", e); } } } } return t; } finally { jedisPool.returnResource(jedis); } } else { return super.queryForPojoOne(pojoType, args); } } RedisWeakCachedCommonDao(); }
RedisWeakCachedCommonDao extends DefaultCommonDao { @SuppressWarnings("unchecked") @Override public <T> T queryForPojoOne(Class<T> pojoType, Map<String, Object> args) throws DataAccessException { Jedis jedis = getJedis(); if (jedis != null) { try { T t = null; ORMTable ormTable = pojoType.getAnnotation(ORMTable.class); String cachedTableKey = "".equalsIgnoreCase(ormTable.cachedShortAlias()) ? ormTable.tableName() : ormTable.cachedShortAlias(); String[] cachedKeys = ormTable.cachedKey(); for (String cachedKey : cachedKeys) { String[] ks = cachedKey.split("="); Object arg = args.get(ks[0]); if (arg != null) { String key = cachedTableKey + "." + ks[1] + "." + String.valueOf(arg); T obj = null; try { obj = (T) getCache(jedis, key); } catch (ClassNotFoundException e) { logger.warn("Get from cache fail!", e); } catch (IOException e) { logger.warn("Get from cache fail!", e); } if (obj != null) { t = obj; break; } } } if (t != null) { return t; } else { t = super.queryForPojoOne(pojoType, args); if (t != null) { for (String cachedKey : cachedKeys) { String[] fk = cachedKey.split("="); try { Field f = t.getClass().getDeclaredField(fk[0]); f.setAccessible(true); String key = cachedTableKey + "." + fk[1] + "." + f.get(t); setCache(jedis, key, t); } catch (Exception e) { logger.warn("Set to cache fail!", e); } } } } return t; } finally { jedisPool.returnResource(jedis); } } else { return super.queryForPojoOne(pojoType, args); } } RedisWeakCachedCommonDao(); void setJedisPool(JedisPool jedisPool); void setCacheSeconds(int cacheSeconds); @Override int updateByLogic(Object... pojos); @Override int updateByPhysical(Object... pojos); @Override int deleteByLogic(Object... pojos); @Override int deleteByPhysical(Object... pojos); @SuppressWarnings("unchecked") @Override T queryForPojoOne(Class<T> pojoType, Map<String, Object> args); @Override List<T> queryForPojoList(Class<T> pojoType, String col, Object... args); @Override PaginationSupport<T> queryForPaginatedPojoList(
			Class<T> pojoType, Map<String, Object> args,
			RowSelection rowSelection); }
RedisWeakCachedCommonDao extends DefaultCommonDao { @SuppressWarnings("unchecked") @Override public <T> T queryForPojoOne(Class<T> pojoType, Map<String, Object> args) throws DataAccessException { Jedis jedis = getJedis(); if (jedis != null) { try { T t = null; ORMTable ormTable = pojoType.getAnnotation(ORMTable.class); String cachedTableKey = "".equalsIgnoreCase(ormTable.cachedShortAlias()) ? ormTable.tableName() : ormTable.cachedShortAlias(); String[] cachedKeys = ormTable.cachedKey(); for (String cachedKey : cachedKeys) { String[] ks = cachedKey.split("="); Object arg = args.get(ks[0]); if (arg != null) { String key = cachedTableKey + "." + ks[1] + "." + String.valueOf(arg); T obj = null; try { obj = (T) getCache(jedis, key); } catch (ClassNotFoundException e) { logger.warn("Get from cache fail!", e); } catch (IOException e) { logger.warn("Get from cache fail!", e); } if (obj != null) { t = obj; break; } } } if (t != null) { return t; } else { t = super.queryForPojoOne(pojoType, args); if (t != null) { for (String cachedKey : cachedKeys) { String[] fk = cachedKey.split("="); try { Field f = t.getClass().getDeclaredField(fk[0]); f.setAccessible(true); String key = cachedTableKey + "." + fk[1] + "." + f.get(t); setCache(jedis, key, t); } catch (Exception e) { logger.warn("Set to cache fail!", e); } } } } return t; } finally { jedisPool.returnResource(jedis); } } else { return super.queryForPojoOne(pojoType, args); } } RedisWeakCachedCommonDao(); void setJedisPool(JedisPool jedisPool); void setCacheSeconds(int cacheSeconds); @Override int updateByLogic(Object... pojos); @Override int updateByPhysical(Object... pojos); @Override int deleteByLogic(Object... pojos); @Override int deleteByPhysical(Object... pojos); @SuppressWarnings("unchecked") @Override T queryForPojoOne(Class<T> pojoType, Map<String, Object> args); @Override List<T> queryForPojoList(Class<T> pojoType, String col, Object... args); @Override PaginationSupport<T> queryForPaginatedPojoList(
			Class<T> pojoType, Map<String, Object> args,
			RowSelection rowSelection);  }