use of doitincloud.rdbcache.queries.Query in project rdbcache by rdbcache.
the class DbaseRepoImpl method find.
@Override
public boolean find(final Context context, final KvPairs pairs, final AnyKey anyKey) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("find: " + pairs.printKey() + anyKey.print());
}
String table = anyKey.getKeyInfo().getTable();
if (table == null) {
if (!kvFind(context, pairs, anyKey)) {
LOGGER.debug("find - kvFind failed: " + pairs.printKey());
return false;
} else {
LOGGER.debug("find - kvFind Ok: " + pairs.printKey());
}
AppCtx.getKeyInfoRepo().save(context, pairs, anyKey);
return true;
} else {
JdbcTemplate jdbcTemplate = AppCtx.getDbaseOps().getJdbcTemplate(context, table);
boolean allOk = true;
if (anyKey.size() == 1) {
Query query = new Query(context, jdbcTemplate, pairs, anyKey);
if (!query.ifSelectOk() || !query.executeSelect()) {
if (enableDbFallback) {
if (!kvFind(context, pairs, anyKey)) {
String msg = "find - not found fallbacked to default table: " + pairs.printKey();
LOGGER.trace(msg);
allOk = false;
} else {
String msg = "find - found fallbacked to default table Ok: " + pairs.printKey();
context.logTraceMessage(msg);
LOGGER.warn(msg);
}
} else {
LOGGER.debug("find - not found: from " + table + " " + pairs.printKey());
allOk = false;
}
} else {
LOGGER.debug("find - found Ok: from " + table + " " + pairs.printKey());
AppCtx.getKeyInfoRepo().save(context, pairs, anyKey);
}
} else {
for (int i = 0; i < anyKey.size(); i++) {
KeyInfo keyInfo = anyKey.get(i);
if (keyInfo.getQuery() != null) {
throw new ServerErrorException("query for muliple keyInfos is not supported");
}
table = keyInfo.getTable();
AnyKey newAnyKey = new AnyKey(keyInfo);
KvPair pair = pairs.getAny(i);
KvPairs newPairs = new KvPairs(pair);
Query query = new Query(context, jdbcTemplate, newPairs, newAnyKey);
if (!query.ifSelectOk() || !query.executeSelect()) {
if (enableDbFallback) {
if (!kvFind(context, newPairs, newAnyKey)) {
String msg = "find - not found fallbacked to default table: " + newPairs.printKey();
LOGGER.trace(msg);
allOk = false;
} else {
String msg = "find - found fallbacked to default table Ok: " + newPairs.printKey();
context.logTraceMessage(msg);
LOGGER.warn(msg);
}
} else {
LOGGER.debug("find - not found: from " + table + " " + newPairs.printKey());
allOk = false;
}
} else {
LOGGER.debug("find - found Ok: from " + table + " " + pairs.printKey());
AppCtx.getKeyInfoRepo().save(context, newPairs, newAnyKey);
}
}
}
return allOk;
}
}
use of doitincloud.rdbcache.queries.Query in project rdbcache by rdbcache.
the class DbaseRepoImpl method insert.
@Override
public boolean insert(final Context context, final KvPairs pairs, final AnyKey anyKey) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("insert: " + pairs.printKey() + anyKey.print());
}
String table = anyKey.getKeyInfo().getTable();
if (table == null) {
if (!kvSave(context, pairs, anyKey)) {
LOGGER.debug("insert kvSave failed: " + pairs.printKey());
return false;
} else {
AppCtx.getKeyInfoRepo().save(context, pairs, anyKey);
LOGGER.debug("inserted kvSave Ok: " + pairs.printKey());
}
} else {
JdbcTemplate jdbcTemplate = AppCtx.getDbaseOps().getJdbcTemplate(context, table);
Query query = new Query(context, jdbcTemplate, pairs, anyKey);
if (!query.ifInsertOk() || !query.executeInsert(enableDataCache, enableRedisCache)) {
if (enableDbFallback) {
if (!kvSave(context, pairs, anyKey)) {
LOGGER.debug("insert failed - fallbacked to kvSave: " + pairs.printKey());
return false;
} else {
String msg = "inserted Ok - fallbacked to kvSave: " + pairs.printKey();
context.logTraceMessage(msg);
LOGGER.warn(msg);
}
} else {
LOGGER.debug("insert failed: " + pairs.printKey());
return false;
}
} else {
AppCtx.getKeyInfoRepo().save(context, pairs, anyKey);
LOGGER.debug("insert Ok: " + pairs.getPair().getId() + pairs.printKey() + " for " + table);
}
}
return true;
}
use of doitincloud.rdbcache.queries.Query in project rdbcache by rdbcache.
the class DbaseRepoImpl method delete.
@Override
public boolean delete(final Context context, final KvPairs pairs, final AnyKey anyKey) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("delete: " + pairs.printKey() + anyKey.print());
}
String table = anyKey.getKeyInfo().getTable();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("delete: " + pairs.size() + " table: " + table);
}
if (table == null) {
if (!kvDelete(context, pairs, anyKey)) {
LOGGER.debug("delete kvDelete failed: " + pairs.printKey());
return false;
} else {
LOGGER.debug("deleted kvDelete Ok: " + pairs.printKey());
}
} else {
JdbcTemplate jdbcTemplate = AppCtx.getDbaseOps().getJdbcTemplate(context, table);
Query query = new Query(context, jdbcTemplate, pairs, anyKey);
if (!query.ifDeleteOk() || !query.executeDelete()) {
if (enableDbFallback) {
if (!kvDelete(context, pairs, anyKey)) {
LOGGER.debug("delete failed - fallback to kvDelete: " + pairs.printKey());
return false;
} else {
String msg = "delete Ok - fallbacked to kvDelete " + pairs.printKey();
context.logTraceMessage(msg);
LOGGER.warn(msg);
}
} else {
return false;
}
} else {
LOGGER.debug("deleted Ok: " + anyKey.size() + " record(s) from " + table);
}
}
return true;
}
use of doitincloud.rdbcache.queries.Query in project rdbcache by rdbcache.
the class DbaseRepoImpl method update.
@Override
public boolean update(final Context context, final KvPairs pairs, final AnyKey anyKey) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("update: " + pairs.printKey() + anyKey.print());
}
String table = anyKey.getKeyInfo().getTable();
if (table == null) {
if (!kvUpdate(context, pairs, anyKey)) {
LOGGER.debug("update kvSave failed: " + pairs.printKey());
return false;
} else {
LOGGER.debug("updated kvSave Ok: " + pairs.printKey());
}
} else {
JdbcTemplate jdbcTemplate = AppCtx.getDbaseOps().getJdbcTemplate(context, table);
Query query = new Query(context, jdbcTemplate, pairs, anyKey);
if (!query.ifUpdateOk() || !query.executeUpdate()) {
if (enableDbFallback) {
if (!kvUpdate(context, pairs, anyKey)) {
LOGGER.debug("update failed - fallback to kvSave: " + pairs.printKey());
return false;
} else {
String msg = "update Ok - fallbacked to kvSave: " + pairs.printKey();
context.logTraceMessage(msg);
LOGGER.warn(msg);
}
} else {
LOGGER.debug("update failed - " + pairs.printKey());
return false;
}
} else {
AppCtx.getKeyInfoRepo().save(context, pairs, anyKey);
LOGGER.debug("updated Ok: " + anyKey.size() + " record(s) from " + table);
}
}
return true;
}
Aggregations