-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package streams; | ||
|
||
import java.util.Date; | ||
|
||
public class StocksPrice { | ||
|
||
private String stockSymbol; | ||
private Date tradeDate; | ||
private double openPrice; | ||
private double highPrice; | ||
|
||
public Date getTradeDate() { | ||
return tradeDate; | ||
} | ||
|
||
public double getHighPrice() { | ||
return highPrice; | ||
} | ||
|
||
public double getOpenPrice() { | ||
return openPrice; | ||
} | ||
|
||
public void setStockSymbol(String stockSymbol) { | ||
this.stockSymbol = stockSymbol; | ||
} | ||
|
||
public String getStockSymbol() { | ||
return stockSymbol; | ||
} | ||
|
||
public void setHighPrice(double highPrice) { | ||
this.highPrice = highPrice; | ||
} | ||
|
||
public void setOpenPrice(double openPrice) { | ||
this.openPrice = openPrice; | ||
} | ||
|
||
public void setTradeDate(Date tradeDate) { | ||
this.tradeDate = tradeDate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Symbol=%s;Date=%s;open price=%s ; HighPrice=%s", stockSymbol, tradeDate, openPrice, highPrice); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package streams; | ||
|
||
import org.apache.commons.dbcp2.BasicDataSource; | ||
import streams.database.TableStreamBuilder; | ||
import streams.database.Where; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class TableStreamApplication { | ||
|
||
public static void main(String... args) { | ||
|
||
BasicDataSource ds = createDataSource(); | ||
|
||
TableStreamBuilder stocksTable = TableStreamBuilder | ||
.with(ds) | ||
.build(StocksPrice.class, "stocks_price", () -> new StocksPrice()); | ||
|
||
Stream<StocksPrice> rows = stocksTable.stream(); | ||
|
||
long count = rows | ||
.filter(Where.GT("volume", 1467200)) | ||
.filter(Where.GT("open_price", 1108d)) | ||
.count(); | ||
|
||
System.out.println(count); | ||
|
||
|
||
List<StocksPrice> o = (List<StocksPrice>) stocksTable.stream() | ||
.filter(Where.GT("volume", 1467200)) | ||
.filter(Where.GT("open_price", 1108d)) | ||
.limit(2) | ||
.collect(Collectors.toList()); | ||
|
||
System.out.println(o); | ||
|
||
|
||
} | ||
|
||
private static BasicDataSource createDataSource() { | ||
BasicDataSource ds = new BasicDataSource(); | ||
ds.setDriverClassName("com.mysql.jdbc.Driver"); | ||
ds.setUrl("jdbc:mysql://localhost:3306/playground"); | ||
ds.setUsername("root"); | ||
ds.setPassword("changeme"); | ||
return ds; | ||
} | ||
|
||
} |