use of doitincloud.commons.exceptions.ServerErrorException in project rdbcache by rdbcache.
the class DbaseOps method fetchTableColumns.
// get table columns info
//
public Map<String, Object> fetchTableColumns(Context context) {
if (databaseType.equals("mysql")) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
JdbcTemplate jdbcTemplate = AppCtx.getJdbcTemplate();
fetchMysqlTableColumns(context, jdbcTemplate, map);
JdbcTemplate systemJdbcTemplate = AppCtx.getSystemJdbcTemplate();
if (systemJdbcTemplate != jdbcTemplate) {
fetchMysqlTableColumns(context, systemJdbcTemplate, map);
}
return map;
}
if (databaseType.equals("h2")) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
JdbcTemplate jdbcTemplate = AppCtx.getJdbcTemplate();
fetchH2TableColumns(context, jdbcTemplate, map);
JdbcTemplate systemJdbcTemplate = AppCtx.getSystemJdbcTemplate();
if (systemJdbcTemplate != jdbcTemplate) {
fetchH2TableColumns(context, systemJdbcTemplate, map);
}
return map;
}
throw new ServerErrorException("database type not supported");
}
use of doitincloud.commons.exceptions.ServerErrorException in project rdbcache by rdbcache.
the class DbaseOps method fetchTableMap.
// get list of tables from mysql
//
public Map<String, Object> fetchTableMap(Context context) {
if (databaseType.equals("mysql")) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
JdbcTemplate jdbcTemplate = AppCtx.getJdbcTemplate();
fetchMysqlTableMap(context, jdbcTemplate, map, "data");
JdbcTemplate systemJdbcTemplate = AppCtx.getSystemJdbcTemplate();
if (systemJdbcTemplate != jdbcTemplate) {
fetchMysqlTableMap(context, systemJdbcTemplate, map, "system");
}
return map;
}
if (databaseType.equals("h2")) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
JdbcTemplate jdbcTemplate = AppCtx.getJdbcTemplate();
fetchH2TableMap(context, jdbcTemplate, map, "data");
JdbcTemplate systemJdbcTemplate = AppCtx.getSystemJdbcTemplate();
if (systemJdbcTemplate != jdbcTemplate) {
fetchH2TableMap(context, systemJdbcTemplate, map, "sysem");
}
return map;
}
throw new ServerErrorException("database type not supported");
}
use of doitincloud.commons.exceptions.ServerErrorException in project rdbcache by rdbcache.
the class DbaseOps method fetchTableUniqueIndexes.
// get table => unique indexes info
//
public Map<String, Object> fetchTableUniqueIndexes(Context context) {
if (databaseType.equals("mysql")) {
Map<String, Object> map = new LinkedHashMap<>();
JdbcTemplate jdbcTemplate = AppCtx.getJdbcTemplate();
fetchMysqlTableUniqueIndexes(context, jdbcTemplate, map);
JdbcTemplate systemJdbcTemplate = AppCtx.getSystemJdbcTemplate();
if (systemJdbcTemplate != jdbcTemplate) {
fetchMysqlTableUniqueIndexes(context, systemJdbcTemplate, map);
}
return map;
}
if (databaseType.equals("h2")) {
Map<String, Object> map = new LinkedHashMap<>();
JdbcTemplate jdbcTemplate = AppCtx.getJdbcTemplate();
fetchH2TableUniqueIndexes(context, jdbcTemplate, map);
JdbcTemplate systemJdbcTemplate = AppCtx.getSystemJdbcTemplate();
if (systemJdbcTemplate != jdbcTemplate) {
fetchH2TableUniqueIndexes(context, systemJdbcTemplate, map);
}
return map;
}
throw new ServerErrorException("database type not supported");
}
use of doitincloud.commons.exceptions.ServerErrorException in project rdbcache by rdbcache.
the class RedisRepoImpl method findAndSave.
@Override
public boolean findAndSave(final Context context, final KvPairs pairs, final AnyKey anyKey) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("findAndSave pairs(" + pairs.size() + "): " + pairs.printKey() + "anyKey(" + anyKey.size() + "): " + anyKey.printTable());
}
boolean allOk = true;
for (int i = 0; i < pairs.size(); i++) {
KvPair pair = pairs.get(i);
String key = pair.getId();
String type = pair.getType();
String hashKey = hdataPrefix + "::" + type + ":" + key;
KeyInfo keyInfo = anyKey.getAny(i);
Map<String, Object> map = pair.getData();
Map<String, Object> fmap = null;
if (enableDataCache) {
fmap = AppCtx.getCacheOps().getData(pair.getIdType());
if (fmap != null && fmap.size() > 0) {
LOGGER.debug("findAndSave - found from cache " + key);
}
AppCtx.getCacheOps().putData(pair, keyInfo);
}
StopWatch stopWatch = null;
if (fmap == null) {
try {
stopWatch = context.startStopWatch("redis", "hashOps.entries");
fmap = hashOps.entries(hashKey);
if (stopWatch != null)
stopWatch.stopNow();
if (fmap != null && fmap.size() > 0) {
LOGGER.debug("findAndSave - found from redis " + key);
}
} catch (Exception e) {
if (stopWatch != null)
stopWatch.stopNow();
String msg = e.getCause().getMessage();
LOGGER.error(msg);
e.printStackTrace();
throw new ServerErrorException(context, msg);
}
}
pair.setData(fmap);
try {
stopWatch = context.startStopWatch("redis", "hashOps.putAll");
hashOps.putAll(hashKey, map);
if (stopWatch != null)
stopWatch.stopNow();
LOGGER.debug("findAndSave - save " + key);
} catch (Exception e) {
if (stopWatch != null)
stopWatch.stopNow();
if (enableDataCache) {
AppCtx.getCacheOps().removeData(pair.getIdType());
}
allOk = false;
String msg = e.getCause().getMessage();
LOGGER.error(msg);
e.printStackTrace();
}
if (allOk) {
allOk = fmap != null && fmap.size() > 0;
}
}
if (LOGGER.isTraceEnabled())
LOGGER.trace("findAndSave returns " + allOk);
return allOk;
}
use of doitincloud.commons.exceptions.ServerErrorException in project rdbcache by rdbcache.
the class RedisRepoImpl method save.
@Override
public boolean save(final Context context, final KvPair pair, final KeyInfo keyInfo) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("save: " + pair.printKey() + " " + keyInfo.toString());
}
boolean savedAll = true;
String key = pair.getId();
String type = pair.getType();
String hashKey = hdataPrefix + "::" + type + ":" + key;
Map<String, Object> map = pair.getData();
if (enableDataCache) {
AppCtx.getCacheOps().putData(pair, keyInfo);
}
StopWatch stopWatch = context.startStopWatch("redis", "hashOps.putAll");
try {
hashOps.putAll(hashKey, map);
if (stopWatch != null)
stopWatch.stopNow();
LOGGER.debug("save to redis for " + key);
} catch (Exception e) {
if (stopWatch != null)
stopWatch.stopNow();
if (enableDataCache) {
AppCtx.getCacheOps().removeData(pair.getIdType());
}
savedAll = false;
String msg = e.getCause().getMessage();
LOGGER.error(msg);
context.logTraceMessage(msg);
e.printStackTrace();
if (context.isSync()) {
throw new ServerErrorException(context, msg);
}
}
if (LOGGER.isTraceEnabled())
LOGGER.trace("save returns " + savedAll);
return savedAll;
}
Aggregations