Search in sources :

Example 21 with ServerErrorException

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");
}
Also used : ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 22 with ServerErrorException

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");
}
Also used : ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 23 with ServerErrorException

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");
}
Also used : ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 24 with ServerErrorException

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;
}
Also used : KvPair(doitincloud.rdbcache.models.KvPair) KeyInfo(doitincloud.rdbcache.models.KeyInfo) ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) StopWatch(doitincloud.rdbcache.models.StopWatch)

Example 25 with ServerErrorException

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;
}
Also used : ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) ServerErrorException(doitincloud.commons.exceptions.ServerErrorException) StopWatch(doitincloud.rdbcache.models.StopWatch)

Aggregations

ServerErrorException (doitincloud.commons.exceptions.ServerErrorException)29 StopWatch (doitincloud.rdbcache.models.StopWatch)12 KeyInfo (doitincloud.rdbcache.models.KeyInfo)9 KvPair (doitincloud.rdbcache.models.KvPair)9 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)5 AnyKey (doitincloud.rdbcache.supports.AnyKey)4 KvPairs (doitincloud.rdbcache.supports.KvPairs)4 SQLException (java.sql.SQLException)4 Query (doitincloud.rdbcache.queries.Query)1 Context (doitincloud.rdbcache.supports.Context)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 EventListener (org.springframework.context.event.EventListener)1 PreparedStatementCreator (org.springframework.jdbc.core.PreparedStatementCreator)1 GeneratedKeyHolder (org.springframework.jdbc.support.GeneratedKeyHolder)1 KeyHolder (org.springframework.jdbc.support.KeyHolder)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1