HeadlinePuller can import all news articles for Fortune 50 within a date range from Yahoo Finance historical data, inserting the headline text into the headlines table of database cs6601p3 on woodyfolsom.net:3306.
Limited to 25 headline per day (with many reptitions) per Yahoo Finance REST functionality.
This commit is contained in:
@@ -8,7 +8,8 @@ import net.woodyfolsom.cs6601.p3.domain.Headline;
|
||||
public interface HeadlineDao {
|
||||
|
||||
int deleteById(int id);
|
||||
int insert(Headline player);
|
||||
int insert(Headline headline);
|
||||
int[] insertBatch(List<Headline> headlines);
|
||||
|
||||
Headline select(int id);
|
||||
List<Headline> select(String stock, Date date);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.woodyfolsom.cs6601.p3.dao;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
@@ -8,6 +9,7 @@ import java.util.List;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@@ -34,6 +36,26 @@ public class HeadlineDaoImpl implements HeadlineDao {
|
||||
return jdbcTemplate.update(INSERT_STMT, headline.getText(), headline.getDate(), headline.getStock(), headline.getDataset());
|
||||
}
|
||||
|
||||
public int[] insertBatch(final List<Headline> headlines){
|
||||
|
||||
return jdbcTemplate.batchUpdate(INSERT_STMT, new BatchPreparedStatementSetter() {
|
||||
|
||||
@Override
|
||||
public void setValues(PreparedStatement ps, int i) throws SQLException {
|
||||
Headline headline = headlines.get(i);
|
||||
ps.setString(1, headline.getText());
|
||||
ps.setDate(2, new java.sql.Date(headline.getDate().getTime()));
|
||||
ps.setString(3, headline.getStock() );
|
||||
ps.setInt(4, headline.getDataset() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return headlines.size();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Headline select(int headlineId) {
|
||||
return jdbcTemplate.queryForObject(SELECT_BY_ID_QRY,
|
||||
new RequestMapper(), headlineId);
|
||||
@@ -54,6 +76,10 @@ public class HeadlineDaoImpl implements HeadlineDao {
|
||||
@Override
|
||||
public Headline mapRow(ResultSet rs, int arg1) throws SQLException {
|
||||
Headline headline = new Headline();
|
||||
headline.setText(rs.getString("text"));
|
||||
headline.setStock(rs.getString("stock"));
|
||||
headline.setDate(rs.getDate("date"));
|
||||
headline.setDataset(rs.getInt("dataset"));
|
||||
return headline;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user