Search in sources :

Example 11 with RowCallbackHandler

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

the class DaoByTableViewSp method updateAndGetAllTasks.

public List<GenTaskByTableViewSp> updateAndGetAllTasks(int projectId) {
    final List<GenTaskByTableViewSp> tasks = new ArrayList<>();
    this.jdbcTemplate.query("SELECT id, project_id,db_name,table_names,view_names,sp_names,prefix,suffix,cud_by_sp," + "pagination,`generated`,version,update_user_no,update_time,comment," + "sql_style,api_list,approved,approveMsg FROM task_table WHERE project_id=?", new Object[] { projectId }, new RowCallbackHandler() {

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

Example 12 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project dhis2-core by dhis2.

the class HibernateOrganisationUnitStore method getOrganisationUnitDataSetAssocationMap.

@Override
public Map<String, Set<String>> getOrganisationUnitDataSetAssocationMap() {
    final String sql = "select ds.uid as ds_uid, ou.uid as ou_uid from datasetsource d " + "left join organisationunit ou on ou.organisationunitid=d.sourceid " + "left join dataset ds on ds.datasetid=d.datasetid";
    final SetMap<String, String> map = new SetMap<>();
    jdbcTemplate.query(sql, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            String dataSetId = rs.getString("ds_uid");
            String organisationUnitId = rs.getString("ou_uid");
            map.putValue(organisationUnitId, dataSetId);
        }
    });
    return map;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) SetMap(org.hisp.dhis.common.SetMap)

Example 13 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project musiccabinet by hakko.

the class JdbcLibraryPresenceDao method getFiles.

@Override
public Set<File> getFiles(String directory) {
    String sql = "select d.path, f.filename, f.modified, f.size from library.file f" + " inner join library.directory d on f.directory_id = d.id" + " where d.path = ?";
    final Set<File> files = new HashSet<>();
    jdbcTemplate.query(sql, new Object[] { directory }, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            String directory = rs.getString(1);
            String filename = rs.getString(2);
            DateTime modified = new DateTime(rs.getTimestamp(3).getTime());
            int size = rs.getInt(4);
            files.add(new File(directory, filename, modified, size));
        }
    });
    return files;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) File(com.github.hakko.musiccabinet.domain.model.library.File) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet)

Example 14 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project musiccabinet by hakko.

the class JdbcTagDao method getCorrectedTags.

@Override
public Map<String, String> getCorrectedTags() {
    String sql = "select t.tag_name, tc.tag_name from music.tag t" + " inner join music.tag tc on t.corrected_id = tc.id";
    final Map<String, String> correctedTags = new HashMap<>();
    jdbcTemplate.query(sql, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            correctedTags.put(rs.getString(1), rs.getString(2));
        }
    });
    return correctedTags;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 15 with RowCallbackHandler

use of org.springframework.jdbc.core.RowCallbackHandler in project spring-framework by spring-projects.

the class NamedParameterJdbcTemplateTests method testQueryWithRowCallbackHandler.

@Test
public void testQueryWithRowCallbackHandler() throws SQLException {
    given(resultSet.next()).willReturn(true, false);
    given(resultSet.getInt("id")).willReturn(1);
    given(resultSet.getString("forename")).willReturn("rod");
    params.put("id", new SqlParameterValue(Types.DECIMAL, 1));
    params.put("country", "UK");
    final List<Customer> customers = new LinkedList<>();
    namedParameterTemplate.query(SELECT_NAMED_PARAMETERS, params, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            Customer cust = new Customer();
            cust.setId(rs.getInt(COLUMN_NAMES[0]));
            cust.setForename(rs.getString(COLUMN_NAMES[1]));
            customers.add(cust);
        }
    });
    assertEquals(1, customers.size());
    assertTrue("Customer id was assigned correctly", customers.get(0).getId() == 1);
    assertTrue("Customer forename was assigned correctly", customers.get(0).getForename().equals("rod"));
    verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS_PARSED);
    verify(preparedStatement).setObject(1, 1, Types.DECIMAL);
    verify(preparedStatement).setString(2, "UK");
    verify(preparedStatement).close();
    verify(connection).close();
}
Also used : SqlParameterValue(org.springframework.jdbc.core.SqlParameterValue) Customer(org.springframework.jdbc.Customer) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) LinkedList(java.util.LinkedList) Test(org.junit.Test)

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