Search in sources :

Example 1 with ResultSetHandler

use of com.haulmont.bali.db.ResultSetHandler in project cuba by cuba-platform.

the class ConfigStorage method loadCache.

protected void loadCache() {
    if (cache == null) {
        lock.readLock().unlock();
        lock.writeLock().lock();
        try {
            if (cache == null) {
                log.info("Loading DB-stored app properties cache");
                // Don't use transactions here because of loop possibility from EntityLog
                QueryRunner queryRunner = new QueryRunner(persistence.getDataSource());
                try {
                    cache = queryRunner.query("select NAME, VALUE_ from SYS_CONFIG", new ResultSetHandler<Map<String, String>>() {

                        @Override
                        public Map<String, String> handle(ResultSet rs) throws SQLException {
                            HashMap<String, String> map = new HashMap<>();
                            while (rs.next()) {
                                map.put(rs.getString(1), rs.getString(2));
                            }
                            return map;
                        }
                    });
                } catch (SQLException e) {
                    throw new RuntimeException("Error loading DB-stored app properties cache", e);
                }
            }
        } finally {
            lock.readLock().lock();
            lock.writeLock().unlock();
        }
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ResultSetHandler(com.haulmont.bali.db.ResultSetHandler) QueryRunner(com.haulmont.bali.db.QueryRunner)

Aggregations

QueryRunner (com.haulmont.bali.db.QueryRunner)1 ResultSetHandler (com.haulmont.bali.db.ResultSetHandler)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1