package selling.sunshine.dao.impl;

import java.util.List;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

import selling.sunshine.dao.BaseDao;
import selling.sunshine.dao.ExpressDao;
import selling.sunshine.model.Express;
import selling.sunshine.utils.IDGenerator;
import selling.sunshine.utils.ResponseCode;
import selling.sunshine.utils.ResultData;

public class ExpressDaoImpl extends BaseDao implements ExpressDao {

    private Logger logger = LoggerFactory.getLogger(ExpressDaoImpl.class);

    private Object lock = new Object();

    @Transactional
    @Override
	public ResultData insertExpress(Express express) {
		
    	 ResultData result = new ResultData();
         synchronized (lock) {
             try {
                 express.setExpressId(IDGenerator.generate("EXP"));
                 sqlSession.insert("selling.express.insert", express);
                 result.setData(express);
             } catch (Exception e) {
                 logger.error(e.getMessage());
                 result.setResponseCode(ResponseCode.RESPONSE_ERROR);
                 result = insertExpress(express);
             } finally {
                 return result;
             }
         }
	}

	@Override
	public ResultData queryExpress(Map<String, Object> condition) {
		 ResultData result = new ResultData();
	        try {
	            List<Express> list = sqlSession.selectList("selling.express.query",condition);
	            result.setData(list);
	        } catch (Exception e) {
	            logger.error(e.getMessage());
	            result.setResponseCode(ResponseCode.RESPONSE_ERROR);
	            result.setDescription(e.getMessage());
	        } finally {
	            return result;
	        }
	}

}

@@ -40,47 +40,25 @@
 ort 
-java.util.List;%0A%0Aimport java.util.Map;%0A
+org.slf4j.Logger;
 %0Aimp
@@ -69,32 +69,39 @@
 org.slf4j.Logger
+Factory
 ;%0Aimport org.slf
@@ -94,38 +94,56 @@
 import org.s
-lf4j.LoggerFac
+pringframework.stereotype.Reposi
 tory;%0Aimport
@@ -201,17 +201,16 @@
 tional;%0A
-%0A
 import s
@@ -447,16 +447,74 @@
 tData;%0A%0A
+import java.util.List;%0Aimport java.util.Map;%0A%0A@Repository%0A
 public c
@@ -573,17 +573,16 @@
 ssDao %7B%0A
-%0A
     priv
@@ -686,24 +686,99 @@
  Object();%0A%0A
+    /**%0A     * %E6%B7%BB%E5%8A%A0%E5%BF%AB%E9%80%92%E5%8D%95%E8%AE%B0%E5%BD%95%0A     *%0A     * @param express%0A     * @return%0A     */%0A
     @Transac
@@ -790,33 +790,36 @@
 l%0A    @Override%0A
-%09
+    
 public ResultDat
@@ -857,16 +857,15 @@
 ) %7B%0A
-%09%09%0A
     
-%09
+   
  Res
@@ -899,17 +899,16 @@
 Data();%0A
- 
         
@@ -945,16 +945,14 @@
     
- 
 try %7B%0A
- 
     
@@ -1030,17 +1030,16 @@
         
- 
 sqlSessi
@@ -1076,33 +1076,32 @@
 ert%22, express);%0A
- 
                 
@@ -1130,32 +1130,68 @@
 );%0A             
+   
+sqlSession.commit();%0A            
 %7D catch (Excepti
@@ -1218,40 +1218,31 @@
     
- logger.error(e.getMessage()
+sqlSession.rollback(
 );%0A
- 
     
@@ -1303,24 +1303,69 @@
 SE_ERROR);%0A 
+               logger.error(e.getMessage());%0A
             
@@ -1409,25 +1409,24 @@
             
- 
 %7D finally %7B%0A
@@ -1421,25 +1421,24 @@
 %7D finally %7B%0A
- 
             
@@ -1456,17 +1456,16 @@
 result;%0A
- 
         
@@ -1482,16 +1482,101 @@
     
- 
 %7D%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    /**%0A     * %E6%A0%B9%E6%8D%AE%E6%9D%A1%E4%BB%B6%E6%9F%A5%E8%AF%A2%E5%BF%AB%E9%80%92%E5%88%97%E8%A1%A8%0A     *%0A     * @param condition%0A     * @return%0A     */%0A    
 @Ove
@@ -1581,17 +1581,20 @@
 verride%0A
-%09
+    
 public R
@@ -1653,10 +1653,15 @@
 ) %7B%0A
-%09%09
+       
  Res
@@ -1695,17 +1695,16 @@
 Data();%0A
-%09
         
@@ -1705,25 +1705,24 @@
       try %7B%0A
-%09
             
@@ -1788,16 +1788,17 @@
 .query%22,
+ 
 conditio
@@ -1801,17 +1801,16 @@
 ition);%0A
-%09
         
@@ -1835,17 +1835,16 @@
 (list);%0A
-%09
         
@@ -1867,17 +1867,16 @@
 on e) %7B%0A
-%09
         
@@ -1901,33 +1901,32 @@
 .getMessage());%0A
-%09
             resu
@@ -1974,17 +1974,16 @@
 ERROR);%0A
-%09
         
@@ -2025,17 +2025,16 @@
 age());%0A
-%09
         
@@ -2045,17 +2045,16 @@
 nally %7B%0A
-%09
         
@@ -2072,17 +2072,16 @@
 result;%0A
-%09
         
@@ -2086,10 +2086,12 @@
   %7D%0A
-%09%7D%0A
+    %7D
 %0A%7D%0A

optimize express dao