2013년 8월 27일 화요일

Spring Batch | Tasklet 옵션

Copied from : http://stackoverflow.com/questions/11119036/spring-batch-how-to-limit-the-no-of-executions-of-a-chunk

<batch:step id="mig-chain-data">
<batch:tasklet allow-start-if-complete="false" start-limit="1">
<batch:chunk commit-interval="1" reader="reader" writer="writer"></batch:chunk>
</batch:tasklet>
</batch:step>


 start-limit controls the number of times a Step may be started, not the chunk configured for this step.

From : http://www.codeproject.com/Articles/445856/Getting-Started-With-Spring-Batch-Part-Two

commit-interval 은 한번에 수행할 청크의 갯수를 지정 (processes 'N'  chunk at a time as indicated by the commit-interval)

Copied from : http://springsource.tistory.com/93
Tasklet
Tasklet 은 Step 내부의 트랜잭션 또는 반복될 수 있는 처리작업을 의미한다. 개발자들은 Tasklet 인터페이스를 직접 구현해서 사용하거나 스프링 배치가 제공하는 구현체를 사용할 수도 있다. 압축파일을 해제한다거나 특정 디렉토리를 정리하는 등의 특정 작업에는 직접 구현한 Tasklet 이 유용하다. 스프링 배치는 시스템 명령을 호출한다거나 chunk 기반(chunk-oriented) 처리를 수행할 수 있도록 좀더 일반화된 Tasklet 구현체를 제공한다. 
tasklet 엘리먼트가 제공하는 어트리뷰트는 다음과 같다.
ref : Tasklet 인터페이스를 구현한 스프링 빈의 id 를 의미한다. 커스텀 tasklet 을 사용하려면 이 어트리뷰트를 설정해 줘야 한다.
transaction-manager : Tasklet 에서 트랜젝션처리 시에 사용할 스프링 트랜젝션 매니저를 설정한다. tasklet 에서는 기본적으로 트랜잭션 처리가 가능하다. 디폴트 값은 transactionManager 이다.
allow-start-if-complete : Tasklet 의 실행이 성공했을 경우라도 스프링 배치가 이 Tasklet 을 재실행 가능한지 여부를 설정한다.

Reference : http://www.pfl-cepia.inra.fr/uploads/gdp_docs/spring-batch-2.0.pdf

Hadoop mode - 하둡 모드, 각 요소 노트

하둡은 Stand alone, Pseudo-distributed, Fully-distributed 총 3가지 모드로 설치할 수 있다.
(설치 후 설정 파일을 어떻게 설정하냐에 따라서)

Stand alone mode와 Pseudo-distributed mode의 공통점은 하나의 머신에서 실행된다는 것이다.
하지만 stand alone 모드는 tasktacker와 namenode, datanode, jobtracker 모두 하나의 JVM에서 실행된다는 것이 다르다. (Pseudo-distributed mode는 각각의 JVM에서 실행된다)
그래서 stand alone 모드에서는 데이터의 직렬화가 크게 중요한 문제는 아니다. 하지만 가상 분산 모드에서는 맵퍼와 리듀서간에 직렬화된 데이터를 주고 받으므로 직렬화가 중요하다.
(그렇다는 내용을 StackOverflow에서 봤었다)

하둡은 마스터와 슬레이브 구조로 이루어져 있는데
마스터는 Namenode, Jobtracker (추가적으로 SecondaryNamenode) 로 이루어져 있고
슬레이브는 Datanode, Tasktracker로 이루어져 있다.
마스터/슬레이브의 설정, Namenode, Datanode 설정 Job/Task tracker 설정 등 모두 하둡의 conf 폴더에서 직접 설정 해 줄 수 있다.



각 요소들의 기능
Copy From : http://amalgjose.wordpress.com/2012/12/08/making-a-pseudo-distributed-hadoop-cluster/
NameNodes
Name node is the master server of the cluster. It  doesnot store any file but knows where the blocks are stored in the child nodes and can give pointers and can re-assemble .Namenodes  comes up with  two  features  say Fsimage  and the edit log.FSImage   and edit log
Features
  1. Highly memory intensive
  2. Keeping it safe and isolated is necessary
  3. Manages the file system namespaces
DataNodes
Child nodes are attached to the main node.
Features:
  1. Data node  has  a configuration file to make itself  available in the cluster .Again they stores  data regarding storage capacity(Ex:5 out f 10 is available) of   that  particular data  node.
  2. Data nodes are independent ,since they are not pointing to any other data nodes.
  3. Manages the storage  attached to the  node.
  4. There  will be  multiple data nodes  in a cluster.
Job Tracker
  1. Schedules and assign task to the different datanodes.
  2. Work Flow
  3. Takes  the request.
  4. Assign the  task.
  5. Validate the requested work.
  6. Checks  whether  all the  data nodes  are working properly.
  7. If not, reschedule the tasks.
Task Tracker
Job Tracker and  task tracker   works   in  a master slave model. Every  datanode has got a  task tracker which  actually performs  the  task  which ever  assigned to it by the Job tracker.
Secondary Name Node
Secondaryname node  is not  a redundant  namenode but  this actually  provides  the  check pointing  and  housekeeping tasks  periodically.

2013년 8월 26일 월요일

사진-링크|하둡 맵리듀스의 전반적인 과정 설명

하둡의 맵리듀스 과정에 대한 설명을 보기 좋게 정리한 내용이 있어서
나중에 참고하고자 담아왔다.

Please refer the following url

Original: http://grepalex.com/2012/09/24/map-partition-sort-spill/
http://develop.sunshiny.co.kr/897
 

Spring EL 사용하기

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<util:properties id="mySettings" location="classpath:my.properties"/>
<context:component-scan base-package="com.my.classes" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="#{mySettings['jdbc.driver']}" />
<property name="url" value="#{mySettings['jdbc.url']}" />
<property name="username" value="#{mySettings['jdbc.user']}" />
<property name="password" value="#{mySettings['jdbc.password']}" />

</bean>
</beans>

자바에서 Spring EL을 사용해서 Annotation으로 기본 변수 값을 지정하려 하니 null 값이 반환되서 원인을 찾다보니 내가 사용할 클래스의 패키지를 스프링이 알게 해야 한다는것을 알았다.
진하게 표시된 부분을 통해서 Annotation을 찾을 수 있도록 해줬다.
java에서 사용 
  1. @Value("#{db['db.driverclassname']}")  
  2. private String defaultString;  


jsp 에서 사용 
  1. <spring:eval expression="@db['db.username']" />  


출처: http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/expressions.html
http://stackoverflow.com/questions/12977484/null-pointer-when-calling-pre-instantiated-bean-from-spring-container-with-jsf
http://devkkaok.tistory.com/90
http://whiteship.tistory.com/2201
http://tazz009.tistory.com/507

2013년 8월 25일 일요일

fieldSetMapper 사용 - 스프링 배치

플랫 파일을 읽고 쓸 때 자신이 만든 클래스에 매핑시켜 읽어 들이면 편하다.
이떄 BeanWrapperFieldSetMapper를 사용하면 편리하다.

<bean id="myDataReader"
  class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
  <property name="resource" value="file:/home/output/data/#{jobParameters['myfolder']}.txt"/>
  <property name="lineMapper">
  <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer">
<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="names" value="number,dataTime,data1,data2,data3"/>
<property name="delimiter">
<util:constant static-field="org.springframework.batch.item.file.transform.DelimitedLineTokenizer.DELIMITER_TAB"/>
<!-- 탭으로 구분 -->
</property>
</bean>
</property>
<property name="fieldSetMapper">
<bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<property name="targetType"
value="com.my.data.myDao"/>
    <!-- myDao는 파란색글씨와 똑같은 이름의 변수들을 갖고 있고 setter와 getter도 갖고있다-->
    <!-- filedSetMapper를 만들어서 사용해도 관계없다 -->
    <!--bean class="com.my.data.ReportFieldSetMapper" /-->
</bean>
</property>
  </bean>
  </property>
  </bean>
  <bean id="myDataWriter"
  class="org.springframework.batch.item.database.JdbcBatchItemWriter" scope="step">
  <property name="assertUpdates" value="true"/>
  <property name="dataSource" ref="dataSource"/>
  <property name="itemSqlParameterSourceProvider">
<bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
</property>
  <property name="sql"
  value="INSERT INTO MY_DATA_TB (MY_ID,DATA_TM,DATA_1,DATA_2,DATA_3)
  VALUES (:number,:dataTime,:data1,:data2,:data3)">
  </property>
  </bean>



참조 :http://blog.naver.com/yesql?Redirect=Log&logNo=70173668117
http://static.springsource.org/spring-batch/reference/html/readersAndWriters.html

2013년 8월 22일 목요일

Hadoop multiple mapper | reducer

하나의 하둡 잡에는 여러개의 맵퍼는 가능하지만 리듀서는 하나만 가능하다.
From : http://stackoverflow.com/questions/11122832/hadoop-mapreduce-possible-to-define-two-mappers-and-reducers-in-one-hadoop-job
You can have multiple mappers, but in one job, you can only have one reducer. And the features you need are MultipleInputMultipleOutput and GenericWritable.
Using MultipleInput, you can set the mapper and the corresponding inputFormat. Here is my post about how to use it.
Using GenericWritable, you can separate different input classes in the reducer. Here is my post about how to use it.
Using MultipleOutput, you can output different classes in the same reducer.

여러개의 리듀서를 사용하고 싶다면 잡을 연결시키면 된다. (다른 방법도 있을지도)
먼저 하둡 잡을 잘 설명한 내용이 있어서 가져와봤다.
From: http://stackoverflow.com/questions/12872590/hadoop-streaming-chaining-jobs
                            hadoopJob
                               /\
                              /  \
                             /    \
                            /      \
                           /        \
                Configuration       Execution
                     /\                 |
                    /  \                |
                   /    \   executable or script files
                  /      \
                 /        \
                /          \
  hadoopEnvironment     userEnvironment
           |                   /\
           |                  /  \
           |                 /    \ 
    $HADOOP_HOME/conf       /      \
                           /        \   
                genericOptions   streamingOptions
                      |                 |
                      |                 | 
            GenericOptionsParser StreamJob 

From : http://hadoop.apache.org/docs/current/api/org/apache/hadoop/mapred/lib/IdentityMapper.html
From: http://stackoverflow.com/questions/9749655/map-map-reduce-reduce-final-output
send the result of this job to another job, and set the mapper to IdentityMapper and the reducer to the second phase reducer that you have.
두개의 잡을 이어줄 때 IdentityMapper를 이용해서 결과값을 전달해 줄 수 있다고 한다.


참조: 하둡소개-http://www.slideshare.net/KeeyongHan/hadoop-introduction-10
맵리듀스 체이닝-http://gandhigeet.dinstudio.com/blog_1_7.html
야후 맵리듀스 예제-http://developer.yahoo.com/hadoop/tutorial/module4.html

2013년 8월 19일 월요일

ajax post - spring mvc

getJSON(http://api.jquery.com/jQuery.getJSON/)을 사용하는 것과 .ajax를 사용할 때 약간 다른 부분이 있어서 노트삼아 남겨놓는다.


1. Java Script 부분
 var inData = "data = data for sending"; 
$.ajax({
type:"POST",
url:"mypage",
//dataType : "json",
data: inData,
error: function(data) {
alert("FAIL");
},
success: function(data) {
handling data part
}
});
2. Controller 부분
@RequestMapping(value = "/mypage", method=RequestMethod.POST)
@ResponseBody
public List<Object> makeReport(HttpServletRequest req) {
logger.info("Displaying Page is AD");
string data = new String(req.getParameter("data"));
List<Object> data = (new SelectByDate().findFromByDate(data));
return data;
}

그냥 여러 군데를 참조하면서 배운것은 type을 통일시키고, url을 맵핑시키면 ajax요청은 문제없다는 것이다.
그리고 요청의 반환값은 여기서는 @ResponseBody를 이용해 Object의 리스트를 바로 넘겨줬지만 @ResponseBody없이 String 값을 넘겨줘도 된다.
여기서는 Object의 리스트를 넘겨주면 servlet 설정 파일에서 MappingJacksonHttpMessageConverter를 이용해서 JSON형식으로 변환시키도록 했다.
String 값을 바로 넘기면 JSON형식으로 String을 만들어서 넘기면 된다.
그냥 String을 넘기면 나는 주소값처럼 매핑시키려는 오류가 났는데 아직 원인과 해결 방법은 모르겠다.. ㅠ
post형식으로 요청시에 데이터를 넘길때는 '데이터이름=데이터값' 형식으로 저장한 후 HttpServletRequest를 통해 접근하는게 편하다. 여러가지 방법이 많이 있었다.
.ajax의 문법을 알아두면 나중에 요긴할 것 같다.

참조:
http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/web/bind/annotation/RequestBody.html
http://babtingdev.tistory.com/194
http://static.springsource.org/spring/docs/4.0.x/spring-framework-reference/html/jdbc.html#jdbc-JdbcTemplate
http://freesora.tistory.com/91
http://nanstrong.tistory.com/182
http://api.jquery.com/jQuery.post/
http://windvoice.tistory.com/51
http://blog.naver.com/jaeik714?Redirect=Log&logNo=140192129518

2013년 8월 14일 수요일

Javascript - 사용한것 기록중

document.getElementById('element ID').innerHTML = "";
=> clean the element like <div> and so on


console.log(var data);
=> write the variable to console


function foo(bar) {
       return bar;
}
=> this function return variable


data.sort(function(a, b){
return a.Number < b.Number ? -1 : a.Number > b.Number ? 1 : 0;
});
//데이터 정렬 오름차순
=> Array 객체 data내부의 sort 메소드를 사용,
     data 내용 a와 b비교할 때 각각의 Number란을 대소 구별 기준으로 삼았다.
참조: http://programmingsummaries.tistory.com/150


for(var i=0;i<data.length;i++)
=>for(var i in data)
=>for문의 함축적 표현 방법


자바 스크립트는 항상 call by value
함수를 변수처럼 인식.
참조: http://emflant.tistory.com/64

String class match() 메소드
string1.match(string2)
=> if it is matched return true
참조: http://blog.naver.com/mecca0515?Redirect=Log&logNo=60107858100



2013년 8월 12일 월요일

메시지 컨버터 AJAX JSON sample

메시지 컨버터는 HTTP요청 메시지 본문과 HTTP 응답 메시지 본문을
통째로 메시지로 다루는 방식
파라미터의 @RequestBody와 메소드에 부여한 @ResponseBody를 이용해 쓸 수 있다.

메시지 방식의 컨트롤러를 사용하는 방법은 두가지
1. HTTP - GET 요청 메소드 : 요청정보가 URL, 쿼리 스트링으로 제한되므로 @RequestBody 대신 @RequestParam이나 @ModelAttribute로 요청 파라미터를 전달 받음
2. HTTP - POST 요청 메소드 : HTTP 요청 본문이 제공되므로 @RequestBody를 사용할 수 있다.

JSON 기반의 AJAX를 지원하려면 컨트롤러는 결과를 JSON 포멧으로 만들어서 돌려줘야 한다.


1. Controller part
@RequestMapping(value = "/page", method=RequestMethod.GET)
        //page라고 들어오는 JSON GET 요청을 처리할 것임
@ResponseBody
//JSON으로 변환해 클라이언트로 보내기 위해
public List<MyDao> makeReport(@RequestParam("startTime") int startTime,
@RequestParam("endTime") int endTime) {
        //시작, 종료 시간을 폼에서 입력받아 get으로 넘겨받음 MyDao라는 클래스 리스트를 리턴
logger.info("Displaying Page ");
List<MyDao> data = (new SelectByDate().findByDate(startTime, endTime));
                //DB에서 날짜를 기준으로 검색해서 데이터를 가져오는 메소드 부분
return data;
               //리스트를 리턴 -> JSON message converter가 처리할 내용
}

2. servlet part
<beans:bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<beans:property name="messageConverters">
<beans:list>
<beans:bean class=
"org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<!-- 오브젝트를 JSON으로 변환시켜줄 메시지 컨버터 -->
</beans:list>
</beans:property>
</beans:bean>

3. Java Script part (page.js)
$(document).ready(
function() {
$('adpage').submit(
function() {
if (request) {
request.abort(); // abort any pending request
}

$.getJSON('adpage/', function(data) {
                                                  //make url (adpage), GET방식의 JSON요청을 보낸다
                                                 //function()은 받은 data를 처리할 부분
console.log(data);  //print data
});
});
});

4. View part
<html>
<head>
<title>Home</title>
<script type="text/javascript" src="resources/jquery-2.0.3.js"></script>
<script type="text/javascript" src="resources/page.js"></script>
</head>
<body>
<h1>
AJAX JSON Example
</h1>

<P>  The time on the server is ${serverTime}. </P>
<form action="adpage" method="get">
<P>  Start Time
<input type="text" name="startTime" value="20130728"/>
</P>
<P>  End Time
<input type="text" name="endTime" value="20130801"/>
</P>
<input id="adpage" type="submit" value="Show Result"/>
</form>

</body>
</html>

Spring MVC controller 사용

Spring MVC Controller

@Controller
public class OrderController {

private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

@RequestMapping(value = "/report", method=RequestMethod.GET)
public String adForm(Model model) {
model.addAttribute("startTime", "Start Time");
model.addAttribute("endTime", "End Time");
return "home";
}
@RequestMapping(value = "/result", method=RequestMethod.GET)
public String makeReport(@RequestParam("startTime") int startTime,
@RequestParam("endTime") int endTime, Model model) {
logger.info("Displaying Page is AD");
List<AdDao> data = (new SelectAdByDate().findFromAdByDate(startTime, endTime));
model.addAttribute("data", data);
return "result";
}

}

View
1. home.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
AJAX JSON Example
</h1>

<P>  The time on the server is ${serverTime}. </P>
<form action="result" method="get">
<P>  Start Time 
<input type="text" name="startTime" value="20130728"/>
</P>
<P>  End Time
<input type="text" name="endTime" value="20130801"/>
</P>
<input type="submit" value="result" onclick="result"/>
</form>

</body>
</html>

2. result.jsp
<!-- Use this for the 'form' tag   -->
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<%@ page session="false" %>
<html>
<head>
</head>
<body onload="loadChart(${data})">
<script type="text/javascript">
    var chart1;

    function loadChart(data) {
                 내용
    };

</script>
</body>
</html>


참조: http://snoopy81.tistory.com/314
http://blog.naver.com/PostView.nhn?blogId=fourleaf0311&logNo=140117091984&categoryNo=0&parentCategoryNo=0&viewDate=&currentPage=1&postListTopCurrentPage=1&userTopListOpen=true&userTopListCount=30&userTopListManageOpen=false&userTopListCurrentPage=1
http://springsource.tistory.com/13
http://arawn.github.io/blog/2012/03/17/at-modelattributeyi-sseuimsaeneun-mueosingo/
http://www.kunner.com/997
http://blog.daum.net/aswip/8429416

2013년 8월 11일 일요일

maven에 tomcat plugin 설정하기

From : http://www.captaindebug.com/2012/03/configuring-maven-tomcat-plugin.html#.Ugg8yeYW2Kk

Copied from Captain Debug's Blog
1. Setup a Tomcat Manager Account
$TOMCAT_HOME/conf/tomcat_users.xml
<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users>
 <role rolename="manager-gui"/>
 <role rolename="manager-script"/>
    <user username="admin" password="password" roles="manager-gui, manager-script"/>
</tomcat-users>

2. Add the manager credentials to your settings.xml
$MAVEN_HOME/conf/settings.xml
    <server>
      <id>myserver</id>
      <username>admin</username>
      <password>password</password>
    </server>

3. Add the Maven Tomcat plug in to your POM file
Your projects/pom.xml
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <version>1.1</version>
        <configuration>
            <server>myserver</server>
            <url>http://localhost:8080/manager/text</url>
        </configuration>
    </plugin>

You can now start your server and run a Maven build using the "mvn install tomcat:deploy" command. Once installed, switch to the "tomcat:redeploy" goal.

Updated Information - by kwonjae
now there is apache tomcat plugin
So you have to write the following configuration instead of the number 3.
        <plugin>
         <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat6-maven-plugin</artifactId>
         <version>2.1</version>
         <configuration>
           <server>myserver</server>
           <url>http://localhost:8080/manager/text</url> 
       </configuration>
       </plugin>
       <plugin>
         <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat7-maven-plugin</artifactId>
         <version>2.1</version>
   </plugin>
And Some goals are not yet available with the tomcat7.
You have to write on tomcat6 and your goal have to be 'tomcat6:deploy'
From tomcat plugin, not using '/manager/html' but using '/manager/text'

refer : http://tomcat.apache.org/maven-plugin-2.1/
http://stackoverflow.com/questions/11824365/deploy-with-maven-on-tomcat7
http://stackoverflow.com/questions/5410479/tomcat-maven-plugin-403-error

2013년 8월 8일 목요일

JDBC, JUnit - 테이블에서 데이터 읽어오기

NamedParameter 를 사용해서 쿼리를 하려고 하였다.
하지만 쿼리 결과를 custom class의 리스트 형태로 받으려고 하니 제대로 되지 않았다.
그래서 NamedParameterJdbcTemplate 를 사용하지 않고
JdbcTemplate를 사용해서 쿼리를 날렸다.

그래서 sql문에 ?를 사용해서 퀴리를 만들고 사용했다.
(NamedParameter를 쓴다면 ? 대신 :이름 을 사용했을 것)

InitializingBean 을 사용해서 xml에 설정한 dataSource의 세팅을 확인했다.
RowMapper를 구현한 MyMapper 클래스를 작성해서 내가 원하는 형태의 출력을 만들었다.


------------------------- 자바 소스 -------------------------
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.my.dao.MyDao;

public class SelectByDate implements InitializingBean{
private JdbcTemplate jdbcTemplate;
private String sql = "SELECT * from MY_CNT_TB WHERE TM >= ? AND TM <= ?";
@Autowired
private DataSource dataSource;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public void afterPropertiesSet() throws Exception {
// TODO Auto-generated method stub
if(dataSource==null) {
throw new BeanCreationException("Must set dataSource!");
}
}
public List<MyDao> findFromByDate(int startTime, int endTime) {
Object[] args = new Object[] {startTime,endTime};
return jdbcTemplate.query(sql, args, new MyMapper());
}

private static final class MyMapper implements RowMapper<MyDao> {
@Override
public MyDao mapRow(ResultSet rs, int rowNum) throws SQLException {
// TODO Auto-generated method stub
MyDao tempMy = new MyDao();
tempMy.setNumber(rs.getInt("NM_ID"));
tempMy.setTime(rs.getInt("TM"));
tempMy.setVal1(rs.getInt("VAL1_CNT"));
tempMy.setVal2(rs.getInt("VAL2_CNT"));
tempMy.setVal3(rs.getInt("VAL3_CNT"));
return tempMy;
}

}
}

------------------------- xml  설정파일 -------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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">

<context:property-placeholder location="./jdbc.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${jdbc.driver}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.user}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>
</beans>

jdbc.properties 파일
# Placeholders jdbc*
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/user
# use this one for a separate server process so you can inspect the results
# (or add it to system properties with -D to override at run time).
schema=
schema.script=classpath:/org/springframework/batch/core/schema-mysql.sql
jdbc.user=user
jdbc.password=


------------------------- JUnit 테스트 파일 -------------------------
import java.util.List;
import javax.sql.DataSource;
import junit.framework.TestCase;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.util.StopWatch;

import com.my.dao.MyDao;
import com.my.SelectByDate;


@Configuration(value = "./jdbc-config.xml")
public class testJdbc extends TestCase {
private final static Logger logger = Logger
.getLogger(testJdbc.class);
SelectByDate test1;
@Autowired
private DataSource dataSource;

@Before
public void setUp() {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("./jdbc-config.xml");
ctx.refresh();
dataSource = (DataSource) ctx.getBean("dataSource");
}

@Test
public void testJdbcTask() throws Exception {
StopWatch sw = new StopWatch();
test1 = new SelectByDate();
List<MyDao> result = null;
test1.setDataSource(dataSource);
sw.start();
result = test1.findFromByDate(20130728, 20130801);
assertEquals(108, result.size());
//108은 내가 직접 쿼리를 돌려 얻은 예상 값
logger.info(result.size());
sw.stop();
logger.info(">>> TIME ELAPSED:" + sw.prettyPrint());
}
}


참조 : http://stackoverflow.com/questions/16359316/namedparameterjdbctemplate-vs-jdbctemplate
http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.html#queryForObject(java.lang.String, org.springframework.jdbc.core.namedparam.SqlParameterSource, org.springframework.jdbc.core.RowMapper)
http://pirrip.tistory.com/entry/Spring-JDBC-Template-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0
http://julingks.tistory.com/entry/Spring-JDBC-support
http://loopypapa.tistory.com/entry/SQL-SELECT-%EC%A1%B0%EA%B1%B4

Spring MVC 예제 -링크

환경구축 : http://springmvc.egloos.com/429779
오류 없이 따라한 예제 : http://blog.naver.com/PostView.nhn?blogId=namoyo&logNo=110167145365&parentCategoryNo=&categoryNo=&viewDate=&isShowPopularPosts=false&from=postView
자세한 강좌 : http://blog.daum.net/openeidos/8879784
폼 사용 예제 : http://linuxism.tistory.com/456
Java config security 내용 : http://sleeplessinslc.blogspot.kr/2012/02/spring-security-stateless-cookie-based.html
Java config 내용 : http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-java

div 태그

DIV 태그는 HTML 또는 XHTML 문서에서 Division 또는 Section을 정의하는데 사용되는 태그
TABLE 등의 태그는 그 안에 TR,TD 등의 태그로 행과 열을 만들어 주는 등 구조가 복잡하지만, DIV는 단순히 블록을 지정
그룹을 묶는 태그에는 DIV 이외에도 SPAN 이라는 태그가 있으나 DIV는 Block레벨 , SPAN은 Inline 레벨
div 태그는 한줄 전체를 영역으로하고, span 태그는 태그안의 내용 만큼만을 영역으로 한다.

사용 예
< div id="Box" style="position:absolute;top:10px;left:30px;width:300px;height:300px;z-index:1;visibility:hidden;overflow:auto;background:#E6E6E6">

출처: http://knowledgenomad.tistory.com/49
http://blog.naver.com/PostView.nhn?blogId=effect73&logNo=80170141190

JUnit 개요 및 메소드 소개

JUnit
Eric GammaKent Beck1997년에 만들었다.
자바 프로그래밍 시 Unit테스트를 쉽게 해주는 프레임워크이다.

JUnit 테스트 코드를 수행하는 일반적인 방법
1. 이클립스 같은 IDE를 사용하여 수행
2. 텍스트 기반 커맨드 명령어를 사용하여 수행
3. Swing 기반 테스트 수행 프로그램을 사용하여 수행 (4.x 버젼부터 지원 안함)
4. Ant를 이용하여 수행
xUnit 이란?  어떤 언어를 막론하고, 단위 테스트를 하는데 도움을 주는 프레임워크를
  통틀어서 xUnit 혹은 xUnit 테스트 자동화 프레임워크라고 부른다.
단위 테스트(Unit Test)?    프로그래밍 소스 코드의 특정 모듈이 의도대로
    정확히 작동되는지 검증하는 절차이다.

JUnit 개념
Unit 개념
역할
Assert
테스트하려는 조건을 명시한다.
Assert()는 조건이 만족되면 그냥 지나가고, 만족되지 못하면 예외를 던진다
Test
@Test Annotation이 부여된 메소드로, 하나의 테스트를 뜻한다.
JUnit은 먼저 메소드를 포함하는 클래스의 인스턴스를 만들고, 주석 처리메소드를 찾아 호출한다
Test 클래스
@Test 메소드를 포함한 클래스이다
Suite
여러 테스트 클래스를 하나로 묶는 수단을 제공한다
Runner
테스트를 실행시킨다.
JUnit 4는 하위 호환성을 가지므로 JUnit 3의 테스트도 실행할 수 있다

assertXxx 메소드
assertXxx 메소드
사용목적
assrtArrayEqual("message", A, B)
배열 A B가 일치함을 확인한다.
assertEquals("message", A, B)
객체 A B가 일치함을 확인한다. B파라미터로 A equals()를 호출한다.
assertSame("message", A, B)
객체 A B가 같은 객체임을 확인한다. ( ==연산자사용 )
assertTrue("message", A)
조건 A가 참(true)임을 확인한다.
assertNotNull("message", A)
객체 A null이 아님을 확인한다.

테스트의 준비와 실행 그리고 정리
setUp()
테스트 대상 클래스의 메소드 구조와 상관 없이 테스트 메소드가 실행되기 전에 수행된다.
코드 내에서 사용할 리소스를 초기화 할 때 이용한다.
(테스트 대상 클래스의 객체 생성, 네트워크 연결 시작, DB 연결)
testXXX()
XXX는 테스트 대상 클래스의 메소드 이름이다.
모든 테스트 대상 메소드 이름은 test로 시작해야 한다.
메소드의 내에 assertXXX()를 이용하여 테스트 결과를 확인하는 작업을 수행한다.
tearDown()
메소드는 각각의 테스트 메소드들이 실행되고 난 다음에 호출된다.
사용한 리소스를 정리할 때 이용한다.
(테스트 대상 클래스의 객체를 제거, 네트워크 연결 종료, DB 연결 종료)

테스트의 준비와 실행 그리고 정리 주석기반 방법
메소드에 부여되는 Annotation (해당 메소드가 반드시 public이어야 한다)
@Before 
  - Annotation이 부여된 메소드는 @Test 메소드가 호출되기 직전에 실행된다.
@Test 
  - 실제 테스트를 할 대상 메소드에 작성한다.
@After 
  - Annotation이 부여된 메소드는 @Test 메소드 호출 후에 실행된다.
@Ignore
  - 해당 메소드를 실행하지 않도록 한다.
원한다면 여러 개의 @Before @After method를 정의할 수도 있지만, 이들 사이의 실행 순서를 정하는 방법은 없다.  
메소드에 부여되는 클래스 대상 Annotation (해당 메소드가 반드시 public이고 static이어야 한다.)
@BeforeClass
  - 클래스 안에 정의된 모든 @Test method들이 수행하기 한번만 호출
@AfterClass
  - 클래스 안에 정의된 모든 @Test method들이 수행된 후 한번만 수행