Search in sources :

Example 6 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project opennms by OpenNMS.

the class JdbcEventdServiceManager method dataSourceSync.

/* (non-Javadoc)
     * @see org.opennms.netmgt.eventd.EventdServiceManager#dataSourceSync()
     */
/**
     * <p>dataSourceSync</p>
     */
@Override
public synchronized void dataSourceSync() {
    m_serviceMap.clear();
    new JdbcTemplate(m_dataSource).query(SQL_DB_SVC_TABLE_READ, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            m_serviceMap.put(resultSet.getString(2), resultSet.getInt(1));
        }
    });
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 7 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project opennms by OpenNMS.

the class AlarmdIT method assertEmptyAlarmTable.

private void assertEmptyAlarmTable() {
    List<String> alarmDescriptions = new LinkedList<>();
    m_jdbcTemplate.query("select alarmId, reductionKey, severity from alarms", new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            alarmDescriptions.add(String.format("Alarm[id=%s, reductionKey=%s, severity=%s]", rs.getString(1), rs.getObject(2), rs.getObject(3)));
        }
    });
    assertEquals("Found one or more alarms: " + alarmDescriptions, 0, alarmDescriptions.size());
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) LinkedList(java.util.LinkedList)

Example 8 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project ignite by apache.

the class CacheSpringPersonStore method loadCache.

/** {@inheritDoc} */
@Override
public void loadCache(final IgniteBiInClosure<Long, Person> clo, Object... args) {
    if (args == null || args.length == 0 || args[0] == null)
        throw new CacheLoaderException("Expected entry count parameter is not provided.");
    int entryCnt = (Integer) args[0];
    final AtomicInteger cnt = new AtomicInteger();
    jdbcTemplate.query("select * from PERSON limit ?", new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3));
            clo.apply(person.id, person);
            cnt.incrementAndGet();
        }
    }, entryCnt);
    System.out.println(">>> Loaded " + cnt + " values into cache.");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SQLException(java.sql.SQLException) CacheLoaderException(javax.cache.integration.CacheLoaderException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) Person(org.apache.ignite.examples.model.Person)

Example 9 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project dal by ctripcorp.

the class DaoBySqlBuilder method updateTask.

public int updateTask(GenTaskBySqlBuilder task) {
    final List<Integer> counts = new ArrayList<>();
    this.jdbcTemplate.query("SELECT 1 FROM task_auto WHERE id != ? AND project_id=? AND db_name=? AND table_name=? AND method_name=? LIMIT 1", new Object[] { task.getId(), task.getProject_id(), task.getDatabaseSetName(), task.getTable_name(), task.getMethod_name() }, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            counts.add(1);
        }
    });
    if (counts.size() > 0)
        return -1;
    return this.jdbcTemplate.update("UPDATE task_auto SET project_id=?,db_name=?, table_name=?, class_name=?,method_name=?," + "sql_style=?,crud_type=?,fields=?,where_condition=?,sql_content=?,`generated`=?," + "version=version+1,update_user_no=?,update_time=?,comment=?,scalarType=?," + "pagination=?,orderby=?,approved=?,approveMsg=?,hints=? WHERE id=? AND version = ?", task.getProject_id(), task.getDatabaseSetName(), task.getTable_name(), task.getClass_name(), task.getMethod_name(), task.getSql_style(), task.getCrud_type(), task.getFields(), task.getCondition(), task.getSql_content(), task.isGenerated(), task.getUpdate_user_no(), task.getUpdate_time(), task.getComment(), task.getScalarType(), task.isPagination(), task.getOrderby(), task.getApproved(), task.getApproveMsg(), task.getHints(), task.getId(), task.getVersion());
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 10 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project dal by ctripcorp.

the class DaoBySqlBuilder method updateAndGetTasks.

public List<GenTaskBySqlBuilder> updateAndGetTasks(int projectId) {
    final List<GenTaskBySqlBuilder> tasks = new ArrayList<>();
    this.jdbcTemplate.query(" SELECT  id, project_id, db_name,table_name,class_name,method_name,sql_style, " + " crud_type,fields,where_condition,sql_content,`generated`,version,update_user_no, " + " update_time,comment,scalarType,pagination,orderby,approved,approveMsg,hints " + " FROM task_auto  " + " WHERE project_id=? AND `generated`=FALSE", new Object[] { projectId }, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            GenTaskBySqlBuilder task = GenTaskBySqlBuilder.visitRow(rs);
            task.setGenerated(true);
            if (updateTask(task) > 0) {
                tasks.add(task);
            }
        }
    });
    return tasks;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Aggregations

RowCallbackHandler (org.springframework.jdbc.core.RowCallbackHandler)24 ResultSet (java.sql.ResultSet)23 SQLException (java.sql.SQLException)23 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)2 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)2 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)2 MockNode (org.opennms.netmgt.mock.MockNode)2 Customer (org.springframework.jdbc.Customer)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 Album (com.github.hakko.musiccabinet.domain.model.music.Album)1 AlbumInfo (com.github.hakko.musiccabinet.domain.model.music.AlbumInfo)1 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1