Permalink
Browse files

DAO layer added.

  • Loading branch information...
1 parent c4e23fc commit a3e218d8dd10fedf9daf2a629340ff694bc31cb8 @arunk16 committed Dec 13, 2010
@@ -0,0 +1,16 @@
+package com.mycompany.webapp.stock.dao;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.appfuse.dao.GenericDao;
+import com.mycompany.webapp.stock.domain.Stock;
+
+public abstract interface StockDAO extends GenericDao<Stock, Serializable>{
+
+ public abstract List<Stock> getStockQuotes();
+
+ public abstract void saveStockQuote(Stock stock);
+
+
+}
@@ -0,0 +1,29 @@
+package com.mycompany.webapp.stock.dao.hibernate;
+
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.appfuse.dao.hibernate.GenericDaoHibernate;
+
+import com.mycompany.webapp.stock.dao.StockDAO;
+import com.mycompany.webapp.stock.domain.Stock;
+
+public class StockDAOHibernate extends GenericDaoHibernate<Stock, Serializable> implements StockDAO{
+
+ public StockDAOHibernate(Class<Stock> persistentClass) {
+ super(persistentClass);
+ // TODO Auto-generated constructor stub
+ }
+
+ public List<Stock> getStockQuotes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void saveStockQuote(Stock stock) {
+ // TODO Auto-generated method stub
+ getHibernateTemplate().saveOrUpdate(stock);
+ }
+
+}
@@ -1,12 +1,19 @@
package com.mycompany.webapp.stock.manager;
import java.io.Serializable;
+import java.util.List;
import org.appfuse.service.GenericManager;
import com.mycompany.webapp.stock.domain.Stock;
public abstract interface StockManager extends GenericManager<Stock, Serializable>{
+
+ public abstract Stock saveStockQuote(Stock stock);
+
+ public abstract List<Stock> getStockQuotes();
+
+ //public abstract void setStockDAO();
}
@@ -0,0 +1,25 @@
+package com.mycompany.webapp.stock.manager;
+
+import java.io.Serializable;
+import java.util.List;
+
+
+import org.appfuse.service.impl.GenericManagerImpl;
+
+import com.mycompany.webapp.stock.domain.Stock;
+
+public class StockManagerImpl extends GenericManagerImpl<Stock, Serializable> implements StockManager{
+
+
+
+ public List<Stock> getStockQuotes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Stock saveStockQuote(Stock stock) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
@@ -0,0 +1,22 @@
+package com.mycompany.webapp.stock.service;
+
+import java.util.List;
+
+import com.mycompany.webapp.stock.common.vo.StockPriceVO;
+import com.mycompany.webapp.stock.exceptions.InvalidTickerException;
+import com.mycompany.webapp.stock.exceptions.StockServiceException;
+
+/**
+ * Main interface to deal with real time stock quote calls
+ * from web layer as well as stock quotes from data store.
+ *
+ * @author arun
+ *
+ */
+public abstract interface StockService {
+
+ StockPriceVO getQuote(String tickerSymbol) throws InvalidTickerException,StockServiceException;
+
+ List<StockPriceVO> showAllQuotesFromDataStore();
+
+}
@@ -0,0 +1,22 @@
+package com.mycompany.webapp.stock.service;
+
+import java.util.List;
+
+import com.mycompany.webapp.stock.common.vo.StockPriceVO;
+import com.mycompany.webapp.stock.exceptions.InvalidTickerException;
+import com.mycompany.webapp.stock.exceptions.StockServiceException;
+
+public class StockServiceImpl implements StockService {
+
+ public StockPriceVO getQuote(String tickerSymbol)
+ throws InvalidTickerException, StockServiceException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<StockPriceVO> showAllQuotesFromDataStore() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
@@ -0,0 +1,42 @@
+package com.mycompany.webapp.stock.dao.hibernate;
+
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.mycompany.webapp.stock.dao.StockDAO;
+import com.mycompany.webapp.stock.domain.Stock;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath*:applicationContext-test.xml" })
+@Transactional
+public class StockDAOHibernateTest {
+
+ private Logger log = Logger.getLogger(StockDAOHibernateTest.class);
+
+ @Autowired
+ private StockDAO stockDAO;
+
+ @Test
+ public void testSaveAndGet(){
+ final String tickerSymbol = "CHHH";
+ final Double quote = new Double(17.80);
+ Stock stock = new Stock();
+ stock.setStockTicker(tickerSymbol);
+ stock.setCreatedDate(new Date());
+ stock.setLastUpdatedDate(new Date());
+ stock.setQuotePrice(quote);
+ //save the stock quote
+ stockDAO.save(stock);
+
+ }
+
+
+
+}
@@ -0,0 +1,9 @@
+package com.mycompany.webapp.stock.service;
+
+import junit.framework.TestCase;
+
+public class StockServiceImplTest {
+
+
+
+}
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ! Generated by Celerio, a Jaxio tool. http://www.jaxio.com/
+-->
+<beans default-lazy-init="true"
+ xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ <!-- The core application context -->
+ <import resource="classpath*:applicationContext.xml"/>
+ <!-- Simulate part of the web application context -->
+ <context:component-scan base-package="com.mycompany"/>
+</beans>

0 comments on commit a3e218d

Please sign in to comment.