use of com.rdbcache.helpers.Context in project rdbcache by rdbcache.
the class QueryTest method insertTest.
@Test
public void insertTest() {
try {
Context context = new Context();
KvPairs pairs = new KvPairs();
String json = "{\n" + " \"email\" : \"sam@example.com\",\n" + " \"name\" : \"Sam W.\",\n" + " \"dob\" : \"1975-08-12\"\n" + " }";
Map<String, Object> map1 = Utils.toMap(json);
KvPair pair = new KvPair("*", map1);
pairs.setPair(pair);
AnyKey anyKey = new AnyKey();
KeyInfo keyInfo = new KeyInfo();
keyInfo.setExpire("100");
keyInfo.setTable("user_table");
anyKey.setKeyInfo(keyInfo);
Query query = new Query(context, jdbcTemplate, pairs, anyKey);
assertTrue(query.ifInsertOk());
assertTrue(query.executeInsert(false, false));
// System.out.println(Utils.toJsonMap(pairs));
Map<String, Object> map2 = pair.getData();
assertEquals("4", map2.get("id"));
map2.remove("id");
assertEquals(map1, map2);
} catch (Exception e) {
e.printStackTrace();
fail(e.getCause().getMessage());
}
}
use of com.rdbcache.helpers.Context in project rdbcache by rdbcache.
the class QueryTest method deleteTest.
@Test
public void deleteTest() {
try {
Context context = new Context();
KvPairs pairs = new KvPairs();
AnyKey anyKey = new AnyKey();
KeyInfo keyInfo = new KeyInfo();
keyInfo.setExpire("100");
keyInfo.setTable("user_table");
String json1 = "{\"table\":\"user_table\",\"conditions\":{\"id\":{\"=\":[\"3\"]}}}";
QueryInfo queryInfo1 = Utils.toPojo(Utils.toMap(json1), QueryInfo.class);
keyInfo.setQuery(queryInfo1);
anyKey.setKeyInfo(keyInfo);
Query query = new Query(context, jdbcTemplate, pairs, anyKey);
assertTrue(query.ifSelectOk());
assertTrue(query.executeSelect());
// System.out.println(Utils.toJsonMap(pairs));
assertEquals(1, pairs.size());
String key = pairs.getPair().getId();
KvPair pair = new KvPair(key);
pairs.setPair(pair);
KeyInfo keyInfo2 = new KeyInfo();
keyInfo2.setExpire("100");
keyInfo2.setTable("user_table");
keyInfo2.setClause("id = ?");
keyInfo2.setParams(Arrays.asList("3"));
anyKey.setKeyInfo(keyInfo2);
query = new Query(context, jdbcTemplate, pairs, anyKey);
assertTrue(query.ifDeleteOk());
assertTrue(query.executeDelete());
pairs.clear();
query = new Query(context, jdbcTemplate, pairs, anyKey);
assertTrue(query.ifSelectOk());
assertFalse(query.executeSelect());
assertEquals(0, pairs.size());
} catch (Exception e) {
e.printStackTrace();
fail(e.getCause().getMessage());
}
}
Aggregations