Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactorings

  • Loading branch information...
commit 965e302399340546ecc8aa51af50d228d722bf26 1 parent f58eb11
Heikki Uljas authored
26 jmeter-client/src/test/jmeter/Basic.jmx
@@ -17,7 +17,7 @@
17 17 <boolProp name="LoopController.continue_forever">false</boolProp>
18 18 <intProp name="LoopController.loops">-1</intProp>
19 19 </elementProp>
20   - <stringProp name="ThreadGroup.num_threads">1</stringProp>
  20 + <stringProp name="ThreadGroup.num_threads">10</stringProp>
21 21 <stringProp name="ThreadGroup.ramp_time">10</stringProp>
22 22 <longProp name="ThreadGroup.start_time">1330871850000</longProp>
23 23 <longProp name="ThreadGroup.end_time">1330871850000</longProp>
@@ -31,7 +31,7 @@
31 31 <collectionProp name="Arguments.arguments"/>
32 32 </elementProp>
33 33 <stringProp name="HTTPSampler.domain">localhost</stringProp>
34   - <stringProp name="HTTPSampler.port"></stringProp>
  34 + <stringProp name="HTTPSampler.port">8080</stringProp>
35 35 <stringProp name="HTTPSampler.connect_timeout"></stringProp>
36 36 <stringProp name="HTTPSampler.response_timeout"></stringProp>
37 37 <stringProp name="HTTPSampler.protocol"></stringProp>
@@ -49,8 +49,8 @@
49 49 <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
50 50 <collectionProp name="Arguments.arguments"/>
51 51 </elementProp>
52   - <stringProp name="HTTPSampler.domain">localhost</stringProp>
53   - <stringProp name="HTTPSampler.port">8080</stringProp>
  52 + <stringProp name="HTTPSampler.domain"></stringProp>
  53 + <stringProp name="HTTPSampler.port"></stringProp>
54 54 <stringProp name="HTTPSampler.connect_timeout"></stringProp>
55 55 <stringProp name="HTTPSampler.response_timeout"></stringProp>
56 56 <stringProp name="HTTPSampler.protocol"></stringProp>
@@ -75,7 +75,7 @@
75 75 <stringProp name="HTTPSampler.response_timeout"></stringProp>
76 76 <stringProp name="HTTPSampler.protocol"></stringProp>
77 77 <stringProp name="HTTPSampler.contentEncoding"></stringProp>
78   - <stringProp name="HTTPSampler.path">/stock/{id}</stringProp>
  78 + <stringProp name="HTTPSampler.path">/stock/15</stringProp>
79 79 <stringProp name="HTTPSampler.method">GET</stringProp>
80 80 <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
81 81 <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
@@ -117,7 +117,9 @@
117 117 <stringProp name="filename"></stringProp>
118 118 </ResultCollector>
119 119 <hashTree/>
120   - <ResultCollector guiclass="GraphVisualizer" testclass="ResultCollector" testname="Graph Results" enabled="true">
  120 + <Summariser guiclass="SummariserGui" testclass="Summariser" testname="Generate Summary Results" enabled="true"/>
  121 + <hashTree/>
  122 + <ResultCollector guiclass="kg.apc.jmeter.vizualizers.HitsPerSecondGui" testclass="ResultCollector" testname="jp@gc - Hits per Second" enabled="true">
121 123 <boolProp name="ResultCollector.error_logging">false</boolProp>
122 124 <objProp>
123 125 <name>saveConfig</name>
@@ -147,11 +149,11 @@
147 149 </value>
148 150 </objProp>
149 151 <stringProp name="filename"></stringProp>
  152 + <longProp name="interval_grouping">100</longProp>
  153 + <boolProp name="graph_aggregated">false</boolProp>
150 154 </ResultCollector>
151 155 <hashTree/>
152   - <Summariser guiclass="SummariserGui" testclass="Summariser" testname="Generate Summary Results" enabled="true"/>
153   - <hashTree/>
154   - <ResultCollector guiclass="kg.apc.jmeter.vizualizers.HitsPerSecondGui" testclass="ResultCollector" testname="jp@gc - Hits per Second" enabled="true">
  156 + <ResultCollector guiclass="kg.apc.jmeter.vizualizers.ResponseTimesDistributionGui" testclass="ResultCollector" testname="jp@gc - Response Times Distribution" enabled="true">
155 157 <boolProp name="ResultCollector.error_logging">false</boolProp>
156 158 <objProp>
157 159 <name>saveConfig</name>
@@ -181,11 +183,11 @@
181 183 </value>
182 184 </objProp>
183 185 <stringProp name="filename"></stringProp>
184   - <longProp name="interval_grouping">1000</longProp>
  186 + <longProp name="interval_grouping">100</longProp>
185 187 <boolProp name="graph_aggregated">false</boolProp>
186 188 </ResultCollector>
187 189 <hashTree/>
188   - <ResultCollector guiclass="kg.apc.jmeter.vizualizers.ResponseTimesDistributionGui" testclass="ResultCollector" testname="jp@gc - Response Times Distribution" enabled="true">
  190 + <ResultCollector guiclass="kg.apc.jmeter.vizualizers.ResponseCodesPerSecondGui" testclass="ResultCollector" testname="jp@gc - Response Codes per Second" enabled="true">
189 191 <boolProp name="ResultCollector.error_logging">false</boolProp>
190 192 <objProp>
191 193 <name>saveConfig</name>
@@ -215,7 +217,7 @@
215 217 </value>
216 218 </objProp>
217 219 <stringProp name="filename"></stringProp>
218   - <longProp name="interval_grouping">100</longProp>
  220 + <longProp name="interval_grouping">1000</longProp>
219 221 <boolProp name="graph_aggregated">false</boolProp>
220 222 </ResultCollector>
221 223 <hashTree/>
8 stock-trade/src/main/java/com/sukyky/controller/Index.java
@@ -3,7 +3,7 @@
3 3 import com.sukyky.jamon.aspect.Jamon;
4 4 import com.sukyky.model.Stock;
5 5 import com.sukyky.model.StockView;
6   -import com.sukyky.repository.StockRepository;
  6 +import com.sukyky.repository.StockService;
7 7 import org.slf4j.Logger;
8 8 import org.slf4j.LoggerFactory;
9 9 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,16 +23,16 @@
23 23 private static final Logger logger = LoggerFactory.getLogger(Index.class);
24 24
25 25 @Autowired
26   - private StockRepository stockRepository;
  26 + private StockService stockService;
27 27
28 28 @RequestMapping("/")
29 29 public String show(Model model) {
30   - List<Stock> list = stockRepository.findAllStocks();
  30 + List<Stock> list = stockService.findAllStocks();
31 31
32 32 List<StockView> stocks = new ArrayList<StockView>();
33 33
34 34 for (Stock stock : list) {
35   - stocks.add(new StockView(stock, stockRepository));
  35 + stocks.add(new StockView(stock, stockService));
36 36 }
37 37
38 38 List<StockView> downStocks = new ArrayList<StockView>(stocks);
8 stock-trade/src/main/java/com/sukyky/controller/StockDetails.java
@@ -3,7 +3,7 @@
3 3 import com.sukyky.jamon.aspect.Jamon;
4 4 import com.sukyky.model.Stock;
5 5 import com.sukyky.model.StockView;
6   -import com.sukyky.repository.StockRepository;
  6 +import com.sukyky.repository.StockService;
7 7 import org.springframework.beans.factory.annotation.Autowired;
8 8 import org.springframework.stereotype.Controller;
9 9 import org.springframework.ui.Model;
@@ -15,12 +15,12 @@
15 15 public class StockDetails {
16 16
17 17 @Autowired
18   - private StockRepository stockRepository;
  18 + private StockService stockService;
19 19
20 20 @RequestMapping("/stock/{id}")
21 21 public String stockPage(@PathVariable("id") Long id, Model model) {
22   - Stock stock = stockRepository.getStock(id);
23   - model.addAttribute("stock", new StockView(stock, stockRepository));
  22 + Stock stock = stockService.getStock(id);
  23 + model.addAttribute("stock", new StockView(stock, stockService));
24 24 return "stockDetails";
25 25 }
26 26
8 stock-trade/src/main/java/com/sukyky/controller/Trends.java
@@ -2,7 +2,7 @@
@@ -15,14 +15,14 @@
@@ -31,7 +31,7 @@ public StockHistory monthlyTrend(@PathVariable("id") Long id) {
24 stock-trade/src/main/java/com/sukyky/model/StockView.java
... ... @@ -1,6 +1,6 @@
1 1 package com.sukyky.model;
2 2
3   -import com.sukyky.repository.StockRepository;
  3 +import com.sukyky.repository.StockService;
4 4
5 5 import java.util.Date;
6 6
@@ -11,27 +11,27 @@
11 11
12 12 public Stock stock;
13 13
14   - public StockRepository stockRepository;
  14 + public StockService stockService;
15 15
16   - public StockView(Stock stock, StockRepository stockRepository) {
  16 + public StockView(Stock stock, StockService stockService) {
17 17 this.stock = stock;
18   - this.stockRepository = stockRepository;
  18 + this.stockService = stockService;
19 19 }
20 20
21 21 public int getOpeningPrice() {
22   - return stockRepository.getOpeningPrice(stock);
  22 + return stockService.getOpeningPrice(stock);
23 23 }
24 24
25 25 public int getClosingPrice() {
26   - return stockRepository.getClosingPrice(stock);
  26 + return stockService.getClosingPrice(stock);
27 27 }
28 28
29 29 public int getLastPrice() {
30   - return stockRepository.getLastPrice(stock);
  30 + return stockService.getLastPrice(stock);
31 31 }
32 32
33 33 public Date getLastTime() {
34   - return stockRepository.getLastTime(stock);
  34 + return stockService.getLastTime(stock);
35 35 }
36 36
37 37 public int getChange() {
@@ -63,19 +63,19 @@ public String getName() {
63 63 }
64 64
65 65 public int getDailyMin() {
66   - return stockRepository.getDailyMin(stock);
  66 + return stockService.getDailyMin(stock);
67 67 }
68 68
69 69 public int getDailyMax() {
70   - return stockRepository.getDailyMax(stock);
  70 + return stockService.getDailyMax(stock);
71 71 }
72 72
73 73 public int getYearlyMin() {
74   - return stockRepository.getYearlyMin(stock);
  74 + return stockService.getYearlyMin(stock);
75 75 }
76 76
77 77 public int getYearlyMax() {
78   - return stockRepository.getYearlyMax(stock);
  78 + return stockService.getYearlyMax(stock);
79 79 }
80 80
81 81 public String getChangeDirection() {
83 stock-trade/src/main/java/com/sukyky/repository/JpaStockRepository.java
... ... @@ -0,0 +1,83 @@
  1 +package com.sukyky.repository;
  2 +
  3 +import com.sukyky.model.*;
  4 +import org.springframework.cache.annotation.Cacheable;
  5 +import org.springframework.transaction.annotation.Propagation;
  6 +import org.springframework.transaction.annotation.Transactional;
  7 +
  8 +import javax.persistence.EntityManager;
  9 +import javax.persistence.PersistenceContext;
  10 +import javax.persistence.criteria.CriteriaQuery;
  11 +import java.util.Date;
  12 +import java.util.List;
  13 +
  14 +@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
  15 +public class JpaStockRepository implements StockRepository{
  16 +
  17 + @PersistenceContext
  18 + private EntityManager em;
  19 +
  20 + public List<Stock> findAllStocks() {
  21 + CriteriaQuery<Stock> criteriaQuery = em.getCriteriaBuilder().createQuery(Stock.class);
  22 + criteriaQuery.from(Stock.class);
  23 + List<Stock> stocks = em.createQuery(criteriaQuery).getResultList();
  24 + return stocks;
  25 + }
  26 +
  27 + public Stock getStock(Long id) {
  28 + return em.find(Stock.class, id);
  29 + }
  30 +
  31 + public StockHistory findHistory(Long id, Date start, Date end) {
  32 + List<Object[]> results = em.createNativeQuery("select avg(price), date(time) from trade " +
  33 + "where stock_id = :id " +
  34 + "and time <= :start and " +
  35 + "time >= :end " +
  36 + "group by date(time) order by date(time)")
  37 + .setParameter("id", id)
  38 + .setParameter("start", start)
  39 + .setParameter("end", end)
  40 + .getResultList();
  41 + return new StockHistory(results);
  42 + }
  43 +
  44 + public Trade getLastTrade(Long id) {
  45 + List<Trade> prices = em.createQuery("select o from Trade o where o.stock.id = :stock order by o.time desc", Trade.class)
  46 + .setParameter("stock", id).setMaxResults(1).getResultList();
  47 + if (prices.isEmpty()) return null; else return prices.get(0);
  48 + }
  49 +
  50 + public Trade getLastTradeBefore(Long id, Date since) {
  51 + List<Trade> prices = em.createQuery("select o from Trade o where o.stock.id = :stock and o.time < :since order by o.time desc", Trade.class)
  52 + .setParameter("stock", id).setParameter("since", since)
  53 + .setMaxResults(1).getResultList();
  54 + if (prices.isEmpty()) return null; else return prices.get(0);
  55 + }
  56 +
  57 + public Trade getFirstTradeAfter(Long id, Date since) {
  58 + List<Trade> prices = em.createQuery("select o from Trade o where o.stock.id = :stock and o.time > :since order by o.time asc", Trade.class)
  59 + .setParameter("stock", id).setParameter("since", since)
  60 + .setMaxResults(1).getResultList();
  61 + if (prices.isEmpty()) return null; else return prices.get(0);
  62 + }
  63 +
  64 + @Cacheable("stockRepository")
  65 + public int getMin(Long id, Date start) {
  66 + Integer result = em.createQuery("select min(o.price) " +
  67 + "from Trade o " +
  68 + "where o.stock.id = :stock " +
  69 + "and o.time >= :start", Integer.class)
  70 + .setParameter("stock", id).setParameter("start", start).getSingleResult();
  71 + return result;
  72 + }
  73 +
  74 + @Cacheable("stockRepository")
  75 + public int getMax(Long id, Date start) {
  76 + Integer result = em.createQuery("select max(o.price) " +
  77 + "from Trade o " +
  78 + "where o.stock.id = :stock " +
  79 + "and o.time >= :start", Integer.class)
  80 + .setParameter("stock", id).setParameter("start", start).getSingleResult();
  81 + return result;
  82 + }
  83 +}
29 stock-trade/src/main/java/com/sukyky/repository/StockRepository.java
... ... @@ -1,32 +1,29 @@
1 1 package com.sukyky.repository;
2 2
3   -import com.sukyky.model.*;
4   -import org.joda.time.LocalDate;
  3 +import com.sukyky.model.Stock;
  4 +import com.sukyky.model.StockHistory;
  5 +import com.sukyky.model.Trade;
5 6
6 7 import java.util.Date;
7 8 import java.util.List;
8 9
  10 +/**
  11 + * @author huljas
  12 + */
9 13 public interface StockRepository {
10   -
11   - public List<Stock> findAllStocks();
  14 + List<Stock> findAllStocks();
12 15
13 16 Stock getStock(Long id);
14 17
15   - StockHistory findHistory(Long stockId, LocalDate start, LocalDate end);
16   -
17   - int getOpeningPrice(Stock stock);
18   -
19   - int getClosingPrice(Stock stock);
20   -
21   - int getLastPrice(Stock stock);
  18 + StockHistory findHistory(Long id, Date start, Date end);
22 19
23   - int getDailyMin(Stock stock);
  20 + Trade getLastTrade(Long id);
24 21
25   - int getDailyMax(Stock stock);
  22 + Trade getFirstTradeAfter(Long id, Date since);
26 23
27   - int getYearlyMin(Stock stock);
  24 + Trade getLastTradeBefore(Long id, Date since);
28 25
29   - int getYearlyMax(Stock stock);
  26 + int getMin(Long id, Date since);
30 27
31   - Date getLastTime(Stock stock);
  28 + int getMax(Long id, Date start);
32 29 }
142 stock-trade/src/main/java/com/sukyky/repository/StockRepositoryImpl.java
... ... @@ -1,142 +0,0 @@
1   -package com.sukyky.repository;
2   -
3   -import com.sukyky.model.*;
4   -import org.joda.time.LocalDate;
5   -import org.springframework.transaction.annotation.Propagation;
6   -import org.springframework.transaction.annotation.Transactional;
7   -
8   -import javax.persistence.EntityManager;
9   -import javax.persistence.PersistenceContext;
10   -import javax.persistence.criteria.CriteriaQuery;
11   -import java.util.Calendar;
12   -import java.util.Date;
13   -import java.util.List;
14   -
15   -@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
16   -public class StockRepositoryImpl implements StockRepository {
17   -
18   - @PersistenceContext
19   - private EntityManager em;
20   -
21   - public List<Stock> findAllStocks() {
22   - CriteriaQuery<Stock> criteriaQuery = em.getCriteriaBuilder().createQuery(Stock.class);
23   - criteriaQuery.from(Stock.class);
24   - List<Stock> stocks = em.createQuery(criteriaQuery).getResultList();
25   - return stocks;
26   - }
27   -
28   - public Stock getStock(Long id) {
29   - return em.find(Stock.class, id);
30   - }
31   -
32   - public StockHistory findHistory(Long stockId, LocalDate start, LocalDate end) {
33   - List<Object[]> results = em.createNativeQuery("select avg(price), date(time) from trade " +
34   - "where stock_id = :stockId " +
35   - "and time <= :start and " +
36   - "time >= :end " +
37   - "group by date(time) order by date(time)")
38   - .setParameter("stockId", stockId)
39   - .setParameter("start", start.toDateTimeAtStartOfDay().toDate())
40   - .setParameter("end", end.toDateTimeAtStartOfDay().toDate())
41   - .getResultList();
42   - return new StockHistory(results);
43   - }
44   -
45   - public int getOpeningPrice(Stock stock) {
46   - Trade last = getLastTrade(stock);
47   - Date since = new LocalDate(last.time).toDateTimeAtStartOfDay().toDate();
48   - Trade opening = getFirstTradeAfter(stock, since);
49   - return opening.price;
50   - }
51   -
52   - public int getClosingPrice(Stock stock) {
53   - Trade last = getLastTrade(stock);
54   - Date since = new LocalDate(last.time).toDateTimeAtStartOfDay().toDate();
55   - Trade closing = getLastTradeBefore(stock, since);
56   - return closing.price;
57   - }
58   -
59   - public int getLastPrice(Stock stock) {
60   - return getLastTrade(stock).price;
61   - }
62   -
63   - public int getDailyMin(Stock stock) {
64   - Trade order = getLastTrade(stock);
65   - Date start = minusDays(order.time, 1);
66   - return getMin(stock, start);
67   - }
68   -
69   - public int getDailyMax(Stock stock) {
70   - Trade order = getLastTrade(stock);
71   - Date start = minusDays(order.time, 1);
72   - return getMax(stock, start);
73   - }
74   -
75   - public int getYearlyMin(Stock stock) {
76   - Trade order = getLastTrade(stock);
77   - Date start = minusDays(order.time, 365);
78   - return getMin(stock, start);
79   - }
80   -
81   - public int getYearlyMax(Stock stock) {
82   - Trade order = getLastTrade(stock);
83   - Date start = minusDays(order.time, 365);
84   - return getMax(stock, start);
85   - }
86   -
87   - public Date getLastTime(Stock stock) {
88   - return getLastTrade(stock).time;
89   - }
90   -
91   - // Helper queries
92   -
93   - protected Trade getLastTrade(Stock stock) {
94   - List<Trade> prices = em.createQuery("select o from Trade o where o.stock = :stock order by o.time desc", Trade.class)
95   - .setParameter("stock", stock).setMaxResults(1).getResultList();
96   - if (prices.isEmpty()) return null; else return prices.get(0);
97   - }
98   -
99   - protected Trade getLastTradeBefore(Stock stock, Date since) {
100   - List<Trade> prices = em.createQuery("select o from Trade o where o.stock = :stock and o.time < :since order by o.time desc", Trade.class)
101   - .setParameter("stock", stock).setParameter("since", since)
102   - .setMaxResults(1).getResultList();
103   - if (prices.isEmpty()) return null; else return prices.get(0);
104   - }
105   -
106   - protected Trade getFirstTradeAfter(Stock stock, Date since) {
107   - List<Trade> prices = em.createQuery("select o from Trade o where o.stock = :stock and o.time > :since order by o.time asc", Trade.class)
108   - .setParameter("stock", stock).setParameter("since", since)
109   - .setMaxResults(1).getResultList();
110   - if (prices.isEmpty()) return null; else return prices.get(0);
111   - }
112   -
113   -
114   - protected int getMin(Stock stock, Date start) {
115   - Integer result = em.createQuery("select min(o.price) " +
116   - "from Trade o " +
117   - "where o.stock = :stock " +
118   - "and o.time >= :start", Integer.class)
119   - .setParameter("stock", stock).setParameter("start", start).getSingleResult();
120   - return result;
121   - }
122   -
123   - protected int getMax(Stock stock, Date start) {
124   - Integer result = em.createQuery("select max(o.price) " +
125   - "from Trade o " +
126   - "where o.stock = :stock " +
127   - "and o.time >= :start", Integer.class)
128   - .setParameter("stock", stock).setParameter("start", start).getSingleResult();
129   - return result;
130   - }
131   -
132   - public static Date minusDays(Date now, int days) {
133   - Calendar last = Calendar.getInstance();
134   - last.setTime(now);
135   - Calendar calendar = Calendar.getInstance();
136   - calendar.set(Calendar.DAY_OF_MONTH, last.get(Calendar.DAY_OF_MONTH));
137   - calendar.set(Calendar.MONTH, last.get(Calendar.MONTH));
138   - calendar.set(Calendar.YEAR, last.get(Calendar.YEAR));
139   - calendar.add(Calendar.DAY_OF_MONTH, -1*days);
140   - return calendar.getTime();
141   - }
142   -}
32 stock-trade/src/main/java/com/sukyky/repository/StockService.java
... ... @@ -0,0 +1,32 @@
  1 +package com.sukyky.repository;
  2 +
  3 +import com.sukyky.model.*;
  4 +import org.joda.time.LocalDate;
  5 +
  6 +import java.util.Date;
  7 +import java.util.List;
  8 +
  9 +public interface StockService {
  10 +
  11 + public List<Stock> findAllStocks();
  12 +
  13 + Stock getStock(Long id);
  14 +
  15 + StockHistory findHistory(Long stockId, LocalDate start, LocalDate end);
  16 +
  17 + int getOpeningPrice(Stock stock);
  18 +
  19 + int getClosingPrice(Stock stock);
  20 +
  21 + int getLastPrice(Stock stock);
  22 +
  23 + int getDailyMin(Stock stock);
  24 +
  25 + int getDailyMax(Stock stock);
  26 +
  27 + int getYearlyMin(Stock stock);
  28 +
  29 + int getYearlyMax(Stock stock);
  30 +
  31 + Date getLastTime(Stock stock);
  32 +}
94 stock-trade/src/main/java/com/sukyky/repository/StockServiceBean.java
... ... @@ -0,0 +1,94 @@
  1 +package com.sukyky.repository;
  2 +
  3 +import com.sukyky.model.Stock;
  4 +import com.sukyky.model.StockHistory;
  5 +import com.sukyky.model.Trade;
  6 +import org.joda.time.LocalDate;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Service;
  9 +import org.springframework.transaction.annotation.Propagation;
  10 +import org.springframework.transaction.annotation.Transactional;
  11 +
  12 +import javax.persistence.EntityManager;
  13 +import javax.persistence.PersistenceContext;
  14 +import javax.persistence.criteria.CriteriaQuery;
  15 +import java.util.Calendar;
  16 +import java.util.Date;
  17 +import java.util.List;
  18 +
  19 +@Service
  20 +@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
  21 +public class StockServiceBean implements StockService {
  22 +
  23 + @Autowired
  24 + private StockRepository stockRepository;
  25 +
  26 + public List<Stock> findAllStocks() {
  27 + return stockRepository.findAllStocks();
  28 + }
  29 +
  30 + public Stock getStock(Long id) {
  31 + return stockRepository.getStock(id);
  32 + }
  33 +
  34 + public StockHistory findHistory(Long id, LocalDate start, LocalDate end) {
  35 + return stockRepository.findHistory(id, start.toDateTimeAtStartOfDay().toDate(), end.toDateMidnight().toDate());
  36 + }
  37 +
  38 + public int getOpeningPrice(Stock stock) {
  39 + Trade last = stockRepository.getLastTrade(stock.id);
  40 + Date since = new LocalDate(last.time).toDateTimeAtStartOfDay().toDate();
  41 + Trade opening = stockRepository.getFirstTradeAfter(stock.id, since);
  42 + return opening.price;
  43 + }
  44 +
  45 + public int getClosingPrice(Stock stock) {
  46 + Trade last = stockRepository.getLastTrade(stock.id);
  47 + Date since = new LocalDate(last.time).toDateTimeAtStartOfDay().toDate();
  48 + Trade closing = stockRepository.getLastTradeBefore(stock.id, since);
  49 + return closing.price;
  50 + }
  51 +
  52 + public int getLastPrice(Stock stock) {
  53 + return stockRepository.getLastTrade(stock.id).price;
  54 + }
  55 +
  56 + public int getDailyMin(Stock stock) {
  57 + Trade order = stockRepository.getLastTrade(stock.id);
  58 + Date start = minusDays(order.time, 1);
  59 + return stockRepository.getMin(stock.id, start);
  60 + }
  61 +
  62 + public int getDailyMax(Stock stock) {
  63 + Trade order = stockRepository.getLastTrade(stock.id);
  64 + Date start = minusDays(order.time, 1);
  65 + return stockRepository.getMax(stock.id, start);
  66 + }
  67 +
  68 + public int getYearlyMin(Stock stock) {
  69 + Trade order = stockRepository.getLastTrade(stock.id);
  70 + Date start = minusDays(order.time, 365);
  71 + return stockRepository.getMin(stock.id, start);
  72 + }
  73 +
  74 + public int getYearlyMax(Stock stock) {
  75 + Trade order = stockRepository.getLastTrade(stock.id);
  76 + Date start = minusDays(order.time, 365);
  77 + return stockRepository.getMax(stock.id, start);
  78 + }
  79 +
  80 + public Date getLastTime(Stock stock) {
  81 + return stockRepository.getLastTrade(stock.id).time;
  82 + }
  83 +
  84 + public static Date minusDays(Date now, int days) {
  85 + Calendar last = Calendar.getInstance();
  86 + last.setTime(now);
  87 + Calendar calendar = Calendar.getInstance();
  88 + calendar.set(Calendar.DAY_OF_MONTH, last.get(Calendar.DAY_OF_MONTH));
  89 + calendar.set(Calendar.MONTH, last.get(Calendar.MONTH));
  90 + calendar.set(Calendar.YEAR, last.get(Calendar.YEAR));
  91 + calendar.add(Calendar.DAY_OF_MONTH, -1*days);
  92 + return calendar.getTime();
  93 + }
  94 +}
2  stock-trade/src/main/resources/ehcache-sukyky.xml
@@ -3,6 +3,6 @@
3 3
4 4 <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" statistics="false"/>
5 5
6   - <cache name="sampleCache1" maxElementsInMemory="10000" maxElementsOnDisk="1000" eternal="false" overflowToDisk="false" diskSpoolBufferSizeMB="20" timeToIdleSeconds="300" timeToLiveSeconds="600" memoryStoreEvictionPolicy="LFU" transactionalMode="off"/>
  6 + <cache name="stockRepository" maxElementsInMemory="1000000" eternal="true" overflowToDisk="false" memoryStoreEvictionPolicy="LFU" transactionalMode="off"/>
7 7
8 8 </ehcache>
2  stock-trade/src/main/resources/repository-context.xml
@@ -5,7 +5,7 @@
5 5
6 6 <import resource="infrastructure.xml"/>
7 7
8   - <bean id="stockRepository" class="com.sukyky.repository.StockRepositoryImpl">
  8 + <bean id="stockRepository" class="com.sukyky.repository.JpaStockRepository">
9 9 </bean>
10 10
11 11 </beans>

0 comments on commit 965e302

Please sign in to comment.
Something went wrong with that request. Please try again.