@Override public Object fetch(Namespace namespace, String key) { try { Object obj = jdbcTemplate.queryForObject( "select value from " + TABLE_NAME + " where name=? and key=?", new Object[] {namespace.toString(), key}, Object.class); return SerializationUtils.deserialize((byte[]) obj); } catch (IncorrectResultSizeDataAccessException e) { return null; } }
@Override public Collection<Object> fetchAll(Namespace namespace, String key) { List<Map<String, Object>> fetch; try { fetch = jdbcTemplate.queryForList( "select value as value from " + TABLE_NAME + " where name=? and key=? ", new Object[] {namespace.toString(), key}); } catch (EmptyResultDataAccessException e) { return ImmutableList.of(); } List<Object> result = Lists.newLinkedList(); for (Map<String, Object> map : fetch) { byte[] data = (byte[]) map.get("value"); Object value = SerializationUtils.deserialize(data); result.add(value); } return result; }
@Override public Multimap<String, Object> fetchAll(Namespace namespace) { List<Map<String, Object>> fetch; try { fetch = jdbcTemplate.queryForList( "select key as key, value as value from " + TABLE_NAME + " where name=? ", new Object[] {namespace.toString()}); } catch (EmptyResultDataAccessException e) { return ImmutableMultimap.of(); } Multimap<String, Object> result = ArrayListMultimap.create(); for (Map<String, Object> map : fetch) { String key = (String) map.get("key"); byte[] data = (byte[]) map.get("value"); Object value = SerializationUtils.deserialize(data); result.put(key, value); } return result; }
@Override public void put(Namespace namespace, String key, Object value) { jdbcTemplate.update( "insert into " + TABLE_NAME + " (name, key, value) values (?, ?, ?)", new Object[] {namespace.toString(), key, SerializationUtils.serialize(value)}); }
private Namespace namespace() { return Namespace.of(sessionId, taskId, "ValidationCollector", kernelContext.getId().toString()); }