Java Code Examples for org.springframework.jdbc.core.RowCallbackHandler

The following examples show how to use org.springframework.jdbc.core.RowCallbackHandler. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: super-cloudops   Source File: WorkerNodeRegistory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get {@link WorkerNode} by node host
 * 
 * @param host
 * @param port
 * @return
 */
public WorkerNode getWorkerNodeByHostPort(String host, String port) {
	final WorkerNode workerNode = new WorkerNode();
	String querySql = "select * from WORKER_NODE where HOST_NAME = ? AND PORT = ? ";
	jdbcTemplate.query(querySql, new String[] { host, port }, new RowCallbackHandler() {
		@Override
		public void processRow(ResultSet rs) throws SQLException {
			workerNode.setId(rs.getLong("ID"));
			workerNode.setHostName(rs.getString("HOST_NAME"));
			workerNode.setPort(rs.getString("PORT"));
			workerNode.setType(rs.getInt("TYPE"));
			workerNode.setLaunchDateDate(rs.getDate("LAUNCH_DATE"));
			workerNode.setModified(rs.getDate("MODIFIED"));
			workerNode.setCreated(rs.getDate("CREATED"));
		}
	});
	return workerNode;
}
 
Example 2
Source Project: ecp-uid   Source File: WorkerNodeDAO.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get {@link WorkerNode} by node host
 * 
 * @param host
 * @param port
 * @return
 */
public WorkerNode getWorkerNodeByHostPort(String host, String port) {
    final WorkerNode workerNode = new WorkerNode();
    String querySql = "select * from WORKER_NODE where HOST_NAME = ? AND PORT = ? ";
    this.jdbcTemplate.query(querySql, new String[] {host, port}, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs)
            throws SQLException {
            workerNode.setId(rs.getLong("ID"));
            workerNode.setHostName(rs.getString("HOST_NAME"));
            workerNode.setPort(rs.getString("PORT"));
            workerNode.setType(rs.getInt("TYPE"));
            workerNode.setLaunchDateDate(rs.getDate("LAUNCH_DATE"));
            workerNode.setModified(rs.getDate("MODIFIED"));
            workerNode.setCreated(rs.getDate("CREATED"));
        }
    });
    return workerNode;
}
 
Example 3
Source Project: ecp-uid   Source File: MessageDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<Message> select(String[] ids) {
    List<Message> list = new ArrayList<Message>(ids.length);
    jdbcTemplate.query(String.format(SQL_SELECT, String.join(",", ids)), new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs)
            throws SQLException {
            Message queue = new Message();
            queue.setId(rs.getString("id"));
            queue.setSubject(rs.getString("subject"));
            queue.setPublishTime(rs.getLong("publish_time"));
            queue.setContent(rs.getString("content"));
            list.add(queue);
        }
    });
    return list;
}
 
Example 4
Source Project: hauth-java   Source File: DomainDaoImpl.java    License: MIT License 6 votes vote down vote up
@Override
public DomainEntity getDomainDetails(String domainId) {
    DomainEntity domainEntity = new DomainEntity();
    jdbcTemplate.query(SqlDefine.sys_rdbms_084, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            domainEntity.setDomain_id(domainId);
            domainEntity.setDomain_desc(resultSet.getString("domain_desc"));
            domainEntity.setDomain_status_desc(resultSet.getString("domain_status_desc"));
            domainEntity.setMaintance_date(resultSet.getString("maintance_date"));
            domainEntity.setCreate_user_id(resultSet.getString("create_user_id"));
            domainEntity.setDomain_modify_user(resultSet.getString("domain_modify_user"));
            domainEntity.setDomain_modify_date(resultSet.getString("domain_modify_date"));
        }
    }, domainId);
    return domainEntity;
}
 
Example 5
Source Project: Books-Management-System   Source File: BookDao.java    License: Apache License 2.0 6 votes vote down vote up
public Book getBook(Long bookId){
    final Book book =new Book();
    jdbcTemplate.query(GET_BOOK_SQL, new Object[]{bookId}, new RowCallbackHandler() {
        public void processRow(ResultSet resultSet) throws SQLException {
                book.setAuthor(resultSet.getString("author"));
                book.setBookId(resultSet.getLong("book_id"));
                book.setClassId(resultSet.getInt("class_id"));
                book.setIntroduction(resultSet.getString("introduction"));
                book.setIsbn(resultSet.getString("isbn"));
                book.setLanguage(resultSet.getString("language"));
                book.setName(resultSet.getString("name"));
                book.setPressmark(resultSet.getInt("pressmark"));
                book.setPubdate(resultSet.getDate("pubdate"));
                book.setPrice(resultSet.getBigDecimal("price"));
                book.setState(resultSet.getInt("state"));
                book.setPublish(resultSet.getString("publish"));
        }

    });
    return book;
}
 
Example 6
Source Project: Books-Management-System   Source File: LendDao.java    License: Apache License 2.0 6 votes vote down vote up
public ArrayList<Lend> lendList(){
    final ArrayList<Lend> list=new ArrayList<Lend>();

    jdbcTemplate.query(LEND_LIST_SQL, new RowCallbackHandler() {
        public void processRow(ResultSet resultSet) throws SQLException {
            resultSet.beforeFirst();
            while (resultSet.next()){
                Lend lend=new Lend();
                lend.setBackDate(resultSet.getDate("back_date"));
                lend.setBookId(resultSet.getLong("book_id"));
                lend.setLendDate(resultSet.getDate("lend_date"));
                lend.setReaderId(resultSet.getInt("reader_id"));
                lend.setSernum(resultSet.getLong("sernum"));
                list.add(lend);
            }
        }
    });
    return list;
}
 
Example 7
Source Project: Books-Management-System   Source File: LendDao.java    License: Apache License 2.0 6 votes vote down vote up
public ArrayList<Lend> myLendList(int readerId){
    final ArrayList<Lend> list=new ArrayList<Lend>();

    jdbcTemplate.query(MY_LEND_LIST_SQL, new Object[]{readerId},new RowCallbackHandler() {
        public void processRow(ResultSet resultSet) throws SQLException {
            resultSet.beforeFirst();
            while (resultSet.next()){
                Lend lend=new Lend();
                lend.setBackDate(resultSet.getDate("back_date"));
                lend.setBookId(resultSet.getLong("book_id"));
                lend.setLendDate(resultSet.getDate("lend_date"));
                lend.setReaderId(resultSet.getInt("reader_id"));
                lend.setSernum(resultSet.getLong("sernum"));
                list.add(lend);
            }
        }
    });
    return list;

}
 
Example 8
@Test
public void testQueryWithRowCallbackHandlerNoParameters() throws SQLException {
	given(resultSet.next()).willReturn(true, false);
	given(resultSet.getInt("id")).willReturn(1);
	given(resultSet.getString("forename")).willReturn("rod");

	final List<Customer> customers = new LinkedList<Customer>();
	namedParameterTemplate.query(SELECT_NO_PARAMETERS, 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_NO_PARAMETERS);
	verify(preparedStatement).close();
	verify(connection).close();
}
 
Example 9
Source Project: effectivejava   Source File: JdbcBeanDefinitionReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Load bean definitions from the database via the given SQL string.
 * @param sql SQL query to use for loading bean definitions.
 * The first three columns must be bean name, property name and value.
 * Any join and any other columns are permitted: e.g.
 * {@code SELECT BEAN_NAME, PROPERTY, VALUE FROM CONFIG WHERE CONFIG.APP_ID = 1}
 * It's also possible to perform a join. Column names are not significant --
 * only the ordering of these first three columns.
 */
public void loadBeanDefinitions(String sql) {
	Assert.notNull(this.jdbcTemplate, "Not fully configured - specify DataSource or JdbcTemplate");
	final Properties props = new Properties();
	this.jdbcTemplate.query(sql, new RowCallbackHandler() {
		@Override
		public void processRow(ResultSet rs) throws SQLException {
			String beanName = rs.getString(1);
			String property = rs.getString(2);
			String value = rs.getString(3);
			// Make a properties entry by combining bean name and property.
			props.setProperty(beanName + "." + property, value);
		}
	});
	this.propReader.registerBeanDefinitions(props);
}
 
Example 10
/**
 * Load bean definitions from the database via the given SQL string.
 * @param sql SQL query to use for loading bean definitions.
 * The first three columns must be bean name, property name and value.
 * Any join and any other columns are permitted: e.g.
 * {@code SELECT BEAN_NAME, PROPERTY, VALUE FROM CONFIG WHERE CONFIG.APP_ID = 1}
 * It's also possible to perform a join. Column names are not significant --
 * only the ordering of these first three columns.
 */
public void loadBeanDefinitions(String sql) {
	Assert.notNull(this.jdbcTemplate, "Not fully configured - specify DataSource or JdbcTemplate");
	final Properties props = new Properties();
	this.jdbcTemplate.query(sql, new RowCallbackHandler() {
		@Override
		public void processRow(ResultSet rs) throws SQLException {
			String beanName = rs.getString(1);
			String property = rs.getString(2);
			String value = rs.getString(3);
			// Make a properties entry by combining bean name and property.
			props.setProperty(beanName + "." + property, value);
		}
	});
	this.propReader.registerBeanDefinitions(props);
}
 
Example 11
@Test
public void testQueryWithRowCallbackHandlerNoParameters() throws SQLException {
	given(resultSet.next()).willReturn(true, false);
	given(resultSet.getInt("id")).willReturn(1);
	given(resultSet.getString("forename")).willReturn("rod");

	final List<Customer> customers = new LinkedList<Customer>();
	namedParameterTemplate.query(SELECT_NO_PARAMETERS, 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_NO_PARAMETERS);
	verify(preparedStatement).close();
	verify(connection).close();
}
 
Example 12
Source Project: ignite   Source File: CacheSpringPersonStore.java    License: Apache License 2.0 6 votes vote down vote up
/** {@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.");
}
 
Example 13
Source Project: score   Source File: ExecutionQueueRepositoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Map<Long, Payload> findPayloadByExecutionIds(Long... ids) {
    String qMarks = StringUtils.repeat("?", ",", ids.length);
    String sqlStat = QUERY_PAYLOAD_BY_EXECUTION_IDS.replace(":IDS", qMarks);

    final Map<Long, Payload> result = new HashMap<>();
    findPayloadByExecutionIdsJdbcTemplate.query(sqlStat, ids, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            result.put(
                    resultSet.getLong(1),
                    new Payload(resultSet.getBytes("payload"))
            );
        }
    });

    return result;
}
 
Example 14
Source Project: spring-boot   Source File: StartApplication.java    License: MIT License 5 votes vote down vote up
void startLargeResultSet() {

        // if large data, it may prompts java.lang.OutOfMemoryError: Java heap space
        /*List<Book> list = bookRepository.findAll();

        for (Book book : list) {
            //process it
        }*/

        // try RowCallbackHandler for large data
        jdbcTemplate.query("select * from books", new RowCallbackHandler() {
            public void processRow(ResultSet resultSet) throws SQLException {
                while (resultSet.next()) {
                    String name = resultSet.getString("Name");
                    // process it
                }
            }
        });

    }
 
Example 15
Source Project: ecp-uid   Source File: SegmentServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
private IdSegment updateId(String bizTag)
    throws Exception {
    String querySql = "select step, max_id, last_update_time, current_update_time from id_segment where biz_tag=?";
    String updateSql = "update id_segment set max_id=?, last_update_time=?, current_update_time=now() where biz_tag=? and max_id=?";
    final IdSegment currentSegment = new IdSegment();
    this.jdbcTemplate.query(querySql, new String[] {bizTag}, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs)
            throws SQLException {
            Long step = null;
            Long currentMaxId = null;
            step = rs.getLong("step");
            currentMaxId = rs.getLong("max_id");
            Date lastUpdateTime = new Date();
            if (rs.getTimestamp("last_update_time") != null) {
                lastUpdateTime = (java.util.Date)rs.getTimestamp("last_update_time");
            }
            Date currentUpdateTime = new Date();
            if (rs.getTimestamp("current_update_time") != null) {
                currentUpdateTime = (java.util.Date)rs.getTimestamp("current_update_time");
            }
            currentSegment.setStep(step);
            currentSegment.setMaxId(currentMaxId);
            currentSegment.setLastUpdateTime(lastUpdateTime);
            currentSegment.setCurrentUpdateTime(currentUpdateTime);
        }
    });
    Long newMaxId = currentSegment.getMaxId() + currentSegment.getStep();
    int row = this.jdbcTemplate.update(updateSql, new Object[] {newMaxId, currentSegment.getCurrentUpdateTime(), bizTag, currentSegment.getMaxId()});
    if (row == 1) {
        IdSegment newSegment = new IdSegment();
        newSegment.setStep(currentSegment.getStep());
        newSegment.setMaxId(newMaxId);
        return newSegment;
    } else {
        // 递归,直至更新成功
        return updateId(bizTag);
    }
}
 
Example 16
@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<Customer>();
	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();
}
 
Example 17
Source Project: hauth-java   Source File: RoleResourceDaoImpl.java    License: MIT License 5 votes vote down vote up
private Set<String> getAll(String roleId) {
    Set<String> set = new HashSet<>();
    jdbcTemplate.query(SqlDefine.sys_rdbms_100, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            set.add(resultSet.getString("res_id"));
        }
    }, roleId);
    return set;
}
 
Example 18
Source Project: hauth-java   Source File: UserResourceDaoImpl.java    License: MIT License 5 votes vote down vote up
@Override
public Set<String> findAll(String userId) {
    Set<String> set = new HashSet<>();
    jdbcTemplate.query(SqlDefine.sys_rdbms_115, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            set.add(resultSet.getString("res_id"));
        }
    }, userId);
    return set;
}
 
Example 19
Source Project: hauth-java   Source File: RoleDaoImpl.java    License: MIT License 5 votes vote down vote up
@Override
public RoleEntity getDetails(String roleId) {
    RoleEntity roleEntity = new RoleEntity();
    jdbcTemplate.query(SqlDefine.sys_rdbms_208, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            roleEntity.setDomain_id(resultSet.getString("domain_id"));
            roleEntity.setRole_id(resultSet.getString("role_id"));
            roleEntity.setCode_number(resultSet.getString("code_number"));
            roleEntity.setRole_name(resultSet.getString("role_name"));
            roleEntity.setDomain_desc(resultSet.getString("domain_desc"));
        }
    }, roleId);
    return roleEntity;
}
 
Example 20
Source Project: Books-Management-System   Source File: ReaderInfoDao.java    License: Apache License 2.0 5 votes vote down vote up
public ReaderInfo findReaderInfoByReaderId(int readerId){
    final ReaderInfo reader=new ReaderInfo();
    jdbcTemplate.query(GET_READER_INFO_SQL, new Object[]{readerId}, new RowCallbackHandler() {
        public void processRow(ResultSet resultSet) throws SQLException {
            reader.setAddress(resultSet.getString("address"));
            reader.setBirth(resultSet.getDate("birth"));
            reader.setName(resultSet.getString("name"));
            reader.setReaderId(resultSet.getInt("reader_id"));
            reader.setSex(resultSet.getString("sex"));
            reader.setTelcode(resultSet.getString("telcode"));
        }
    });
    return reader;
}
 
Example 21
Source Project: Books-Management-System   Source File: BookDao.java    License: Apache License 2.0 5 votes vote down vote up
public ArrayList<Book> queryBook(String sw){
    String swcx="%"+sw+"%";
    final ArrayList<Book> books=new ArrayList<Book>();
    jdbcTemplate.query(QUERY_BOOK_SQL, new Object[]{swcx,swcx}, new RowCallbackHandler() {
        public void processRow(ResultSet resultSet) throws SQLException {
            resultSet.beforeFirst();
            while (resultSet.next()){
                Book book =new Book();
                book.setAuthor(resultSet.getString("author"));
                book.setBookId(resultSet.getLong("book_id"));
                book.setClassId(resultSet.getInt("class_id"));
                book.setIntroduction(resultSet.getString("introduction"));
                book.setIsbn(resultSet.getString("isbn"));
                book.setLanguage(resultSet.getString("language"));
                book.setName(resultSet.getString("name"));
                book.setPressmark(resultSet.getInt("pressmark"));
                book.setPubdate(resultSet.getDate("pubdate"));
                book.setPrice(resultSet.getBigDecimal("price"));
                book.setState(resultSet.getInt("state"));
                book.setPublish(resultSet.getString("publish"));
                books.add(book);
            }

        }
    });
    return books;
}
 
Example 22
Source Project: Books-Management-System   Source File: BookDao.java    License: Apache License 2.0 5 votes vote down vote up
public ArrayList<Book> getAllBooks(){
    final ArrayList<Book> books=new ArrayList<Book>();

    jdbcTemplate.query(QUERY_ALL_BOOKS_SQL, new RowCallbackHandler() {
        public void processRow(ResultSet resultSet) throws SQLException {
            resultSet.beforeFirst();
                while (resultSet.next()){
                    Book book =new Book();
                    book.setPrice(resultSet.getBigDecimal("price"));
                    book.setState(resultSet.getInt("state"));
                    book.setPublish(resultSet.getString("publish"));
                    book.setPubdate(resultSet.getDate("pubdate"));
                    book.setName(resultSet.getString("name"));
                    book.setIsbn(resultSet.getString("isbn"));
                    book.setClassId(resultSet.getInt("class_id"));
                    book.setBookId(resultSet.getLong("book_id"));
                    book.setAuthor(resultSet.getString("author"));
                    book.setIntroduction(resultSet.getString("introduction"));
                    book.setPressmark(resultSet.getInt("pressmark"));
                    book.setLanguage(resultSet.getString("language"));
                    books.add(book);
                }
        }
    });
    return books;

}
 
Example 23
Source Project: Books-Management-System   Source File: ReaderCardDao.java    License: Apache License 2.0 5 votes vote down vote up
public ReaderCard findReaderByReaderId(int userId){
    final ReaderCard readerCard=new ReaderCard();
    jdbcTemplate.query(FIND_READER_BY_USERID, new Object[]{userId},
            //匿名类实现的回调函数
            new RowCallbackHandler() {
                public void processRow(ResultSet resultSet) throws SQLException {
                    readerCard.setReaderId(resultSet.getInt("reader_id"));
                    readerCard.setPasswd(resultSet.getString("passwd"));
                    readerCard.setName(resultSet.getString("name"));
                    readerCard.setCardState(resultSet.getInt("card_state"));
                }
            });
    return readerCard;
}
 
Example 24
Source Project: teiid-spring-boot   Source File: TestExample.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    template.query("select name, status from virt.Pet", new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs) throws SQLException {
            assertEquals("doggie", rs.getString(1));
        }
    });
}
 
Example 25
Source Project: teiid-spring-boot   Source File: WebController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping("/count")
public String count() {
    StringBuilder sb = new StringBuilder();
    JdbcTemplate template = new JdbcTemplate(dataSource);
    template.query("select count(*) from customer", new Object[] {}, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs) throws SQLException {
            //System.out.println(rs.getInt(1) + ":" + rs.getString(2));
            sb.append(rs.getObject(1));
        }
    });
    return sb.toString();
}
 
Example 26
Source Project: batch-scheduler   Source File: RoleResourceDaoImpl.java    License: MIT License 5 votes vote down vote up
private Set<String> getAll(String roleId) {
    Set<String> set = new HashSet<>();
    jdbcTemplate.query(sqlText.getSql("sys100"), new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            set.add(resultSet.getString("res_id"));
        }
    }, roleId);
    return set;
}
 
Example 27
Source Project: messaging   Source File: JobExecutionListener.java    License: Apache License 2.0 5 votes vote down vote up
@EventListener(JobExecutionEvent.class)
public void job(JobExecutionEvent executionEvent) {
 log.info("jobExecutionEvent: "
  + executionEvent.getJobExecution().toString());
 jdbcTemplate.query("select * from CONTACT", (RowCallbackHandler) rs -> log
  .info(String.format("id=%s, full_name=%s, email=%s, valid_email=%s",
   rs.getLong("id"), rs.getString("full_name"), rs.getString("email"),
   rs.getBoolean("valid_email"))));
}
 
Example 28
@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<Customer>();
	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();
}
 
Example 29
@Override
public List<LockException> getCombinations()
{
    final String sql = "select distinct datasetid, periodid from lockexception";

    final List<LockException> lockExceptions = new ArrayList<>();

    jdbcTemplate.query( sql, new RowCallbackHandler()
    {
        @Override
        public void processRow( ResultSet rs ) throws SQLException
        {
            int dataSetId = rs.getInt( 1 );
            int periodId = rs.getInt( 2 );

            LockException lockException = new LockException();
            Period period = periodService.getPeriod( periodId );
            DataSet dataSet = dataSetStore.get( dataSetId );

            lockException.setDataSet( dataSet );
            lockException.setPeriod( period );

            lockExceptions.add( lockException );
        }
    } );

    return lockExceptions;
}
 
Example 30
private void writeCompleteness( String sql, CompleteDataSetRegistrations completeDataSetRegistrations )
{
    final Calendar calendar = PeriodType.getCalendar();

    completeDataSetRegistrations.open();

    jdbcTemplate.query( sql, new RowCallbackHandler()
    {
        @Override
        public void processRow( ResultSet rs ) throws SQLException
        {
            CompleteDataSetRegistration completeDataSetRegistration = completeDataSetRegistrations.getCompleteDataSetRegistrationInstance();
            PeriodType pt = PeriodType.getPeriodTypeByName( rs.getString( "ptname" ) );

            completeDataSetRegistration.open();
            completeDataSetRegistration.setDataSet( rs.getString( "dsid" ) );
            completeDataSetRegistration.setPeriod( pt.createPeriod( rs.getDate( "pestart" ), calendar ).getIsoDate() );
            completeDataSetRegistration.setOrganisationUnit( rs.getString( "ouid" ) );
            completeDataSetRegistration.setAttributeOptionCombo( rs.getString( "aocid" ) );
            completeDataSetRegistration.setDate( removeTime( rs.getString( "date" ) ) );
            completeDataSetRegistration.setStoredBy( rs.getString( "storedby" ) );
            completeDataSetRegistration.setLastUpdatedBy( rs.getString( "lastupdatedby" ) );
            completeDataSetRegistration.setLastUpdated( removeTime( rs.getString( "lastupdated" ) ) );
            completeDataSetRegistration.setCompleted( rs.getBoolean( "iscompleted" ) );
            completeDataSetRegistration.close();
        }
    } );
    completeDataSetRegistrations.close();
}