Search Results for 'iBatis'

14 POSTS

  1. 2007.08.13 iBatis 예제 책보고 따라하기
  2. 2007.08.13 강력한 ORM iBatis 그 유래는?

iBatis 예제 책보고 따라하기

Posted 2007. 8. 13. 21:18

어떤것이든지 일단 프로그램 돌려보고 화면이나 결과가 나와야 할 맛이 난다.
iBatis In Action 책에 나오는 첫번째 세상에서 가장 간단한 예제 따라서 코딩해봤다.
클래스 패스에 넣은 jar는 ibatis-2.3.0.677.jar, mysql-connector-java-5.0.6-bin.jar 두개뿐이다.

실행의 편이성을 위해 패키지 지정 안했다.
==================== Main.java ========================
public class Main {

 /**
  * @param args
  */
 public static void main(String[] args)throws Exception {
  // TODO Auto-generated method stub
  SqlMapClient sqlMap;

        String resource = "sqlMapConfig.xml";

        Reader reader = Resources.getResourceAsReader(resource);
        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
        Map<String,String> map = new HashMap<String, String>();
        map.put("firstName","uncle");
        map.put("lastName","joe");
        map.put("updateName","Mark");
        map.put("actorId",(String)sqlMap.queryForObject("selectMaxActorId"));
         
       
        List list = sqlMap.queryForList("getActor", map);//(List)map.get("FIRST_NAME");
       
        System.out.println("Selected " + list.size() + " records."+map);
       
        int ii = sqlMap.update("updateUser", map);
        System.out.println("updateUser::::"+ii);
        //sqlMap.insert("insertUser", map);
        //System.out.println("ddddddd::"+se.);
       
        //sqlMap.queryForMap("getActor", map, "ACTOR");//  .queryForList("getActor", map);//(List)map.get("FIRST_NAME");
       
        list = sqlMap.queryForList("getAllActor", map);//(List)map.get("FIRST_NAME");
       
        System.out.println("Selected " + list.size() + " records.");
        for(int i=0;i<list.size();i++) {
         System.out.println(":::"+list.get(i));
        }   
 }

=============== sqlMapConfig.xml ===============
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
==> 이것도 옵션
<settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true"
maxRequests="32" maxSessions="10" maxTransactions="5" useStatementNamespaces="false"
/>
<!--Type aliases allow you to use a shorter name for long fully qualified class names. -->
<typeAlias alias="order" type="testdomain.Order"/>
<!--Configure a datasource to use with this SQL Map using SimpleDataSource.
Notice the use of the properties from the above resource -->
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost:3306/test"/>
<property name="JDBC.Username" value="loginUser"/>
<property name="JDBC.Password" value="usrPassword"/>
<!--OPTIONAL PROPERTIES BELOW -->
<!-- property name="Pool.MaximumActiveConnections" value="10"/>
<property name="Pool.MaximumIdleConnections" value="5"/>
<property name="Pool.MaximumCheckoutTime" value="120000"/>
<property name="Pool.TimeToWait" value="10000"/>
<property name="Pool.PingQuery" value="select * from dual"/>
<property name="Pool.PingEnabled" value="false"/>
<property name="Pool.PingConnectionsOlderThan" value="0"/>
<property name="Pool.PingConnectionsNotUsedFor" value="0"/-->
</dataSource>
</transactionManager>
<!--Identify all SQL Map XML files to be loaded by this SQL map. Notice the paths
are relative to the classpath. For now, we only have one… -->
<sqlMap resource="sqlMap.xml" />

</sqlMapConfig>

======================= sqlMap.xml ===================

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap>

<select id="getActor" resultClass="hashmap">
 select * from ACTOR
 where FIRST_NAME = #firstName#
     AND LAST_NAME  = #lastName#
</select>

<select id="getAllActor" resultClass="hashmap">
 select * from ACTOR
 where LAST_NAME  = #updateName#
</select>

<select id="selectMaxActorId" resultClass="int">
 select MAX(ACTOR_ID) AS ACTOR_ID from ACTOR
 where  FIRST_NAME = #firstName#
</select>


<insert id="insertUser">
 INSERT INTO ACTOR (FIRST_NAME, LAST_NAME)
 VALUES (
  #firstName#, #lastName#
 )
</insert>

<update id="updateUser">
 UPDATE ACTOR
 SET LAST_NAME = #updateName#
 WHERE ACTOR_ID = #actorId#
</update>

</sqlMap>


=============================
요렇게 해놓구 eclipse에서 실행했는데....


=================== 결과 ===================
Selected 12 records.{lastName=joe, updateName=Mark, actorId=null, firstName=uncle}
updateUser::::0
Selected 2 records.
:::{first_name=uncle, last_update=2007-07-27 19:59:46.0, actor_id=213, last_name=Mark}
:::{first_name=uncle, last_update=2007-07-27 20:01:24.0, actor_id=214, last_name=Mark}

요렇게 나온다....






강력한 ORM iBatis 그 유래는?

Posted 2007. 8. 13. 21:03
iBatis.. 그 뜻이 뭘까?


Clinton Begin이라는 사람에 의해 2001년에 시작된 프로젝트.
원래는 암호 관련 소프트웨어 개발에 초점을 맞춘 프로젝트였다. iBATIS에 의한 첫 산출물은 Secrets라는 이름의 툴이다.

그러다가 2002년 초반에 마이크로소프트가 .NET이 J2EE에 비해 10배 빠르고 4배 생산성이 좋다는 논문을 발표했는데, 이에 iBATIS 팀은 (역자주: 열받아서..) 같은해 7월 1일 JPetStore 1.0을 릴리스했다. 그럼으로해서 자바가 .NET보다 생산성뿐 아니라 아키텍처면에서도 이점이 있음을 보여줬다.

그런데, JPetStore가 아주 재밌는 persistene layer를 사용했는데, 이것이 오픈소스 진영의 관심을 끈 것이다. 그후 관련된 질문과 요구가 Data Mapper(SQL Maps)와 DAO라는 두개의 프레임워크로 구성된 새로운 관점에 집중한 iBATIS 프로젝트의 전이를 가져온 것이다.

ibatis는 원래 암호 관련 프로젝트로 시작되었음을 알려주는 이름이다. 즉 “internet”과 “abatis”의 합성어인데,, abatis는 적의 공격을 방어하기 위한 장애물이라는 뜻이니,,, 인터넷를 지키는데 쓰는 암호를 의미하는 것이다.

출처 http://pxforever.egloos.com/1022231

헐 이럴수가...이사람 클린턴 비긴(클린턴이 비겼다고?)이 지은책 iBatis in Action으로 공부하면서 누가 만든건지도 모르다니... 근데 관련 책이 너무 없다.



« PREV : 1 : 2 : 3 : 4 : 5 : NEXT »