Skip navigation links

Package com.poscoict.glueframework.dao.jdbc

dao package for jdbc.

See: Description

Package com.poscoict.glueframework.dao.jdbc Description

dao package for jdbc. Glue Data Access Object(DAO).

DAO class´Â applicationContext.xml¿¡ Á¤ÀǵȴÙ.

 1. applicationContext.xml 
 <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
     <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
     <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:ORCL"/>
     <property name="username" value="scott"/>
     <property name="password" value="tiger"/>
     <property name="defaultAutoCommit" value="false"/>
 </bean>
 <bean id="dao" class="com.poscoict.glueframework.dao.jdbc.GlueJdbcDao">
     <property name="dataSource" ref="dataSource"/>
     <property name="queryManager" ref="queryManager"/>
 </bean>
 <bean id="queryManager" class="com.poscoict.glueframework.dao.manager.GlueQueryManagerImpl">
     <constructor-arg><ref local="cacheManager"/></constructor-arg>
     <constructor-arg><ref local="queryLoader"/></constructor-arg>
 </bean>
 <bean id="cacheManager" class="com.poscoict.glueframework.cache.jcs.GlueJCSCacheManager"/>
 <bean id="queryLoader" class="com.poscoict.glueframework.dao.manager.GlueQueryLoader">
     <property name="rootPath" value="query"/>
 </bean>
 
 2. query/{name}-query.glue_sql 
 <?xml version="1.0" encoding="UTF-8"?>
 <queryMap desc="sample01">
      <query id="sample01.emp.select" desc="EMP Á¶È¸" resultType="" >
           <![CDATA[
 select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO
 from EMP
 where DEPTNO=?
          ]]>
      </query>
      <query id="sample01.emp.update" desc="EMP ¼öÁ¤" resultType="" >
          <![CDATA[
 update emp
 set sal=?, ename=?
 where empno=?
          ]]>
      </query>
      <query id="sample01.emp.delete" desc="EMP »èÁ¦" resultType="" >
          <![CDATA[
 delete from emp
 where empno=?
          ]]>
      </query>
      <query id="sample01.emp.insert" desc="EMP µî·Ï" resultType="" >
          <![CDATA[
 insert into emp(empno, ename, sal, deptno)
 values(?, ?, ?, ?)
          ]]>
      </query>
      <query id="sample02.emp.select" desc="EMP Á¶È¸" resultType="" isNamed="true">
          <![CDATA[
 select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO
 from EMP
 where DEPTNO=:deptno
          ]]>
      </query>
      <query id="sample02.emp.update" desc="EMP ¼öÁ¤" resultType="" isNamed="true">
          <![CDATA[
 update emp
 set sal=:sal, ename=:ename
 where empno=:empno
          ]]>
      </query>
      <query id="sample02.emp.delete" desc="EMP »èÁ¦" resultType="" isNamed="true">
          <![CDATA[
 delete from emp
 where empno=:empno
          ]]>
      </query>
      <query id="sample02.emp.insert" desc="EMP µî·Ï" resultType="" isNamed="true">
          <![CDATA[
 insert into emp(empno, ename, sal, deptno)
 values(:empno, :ename, :sal, :deptno)
          ]]>
      </query>
      <query id="sample03.emp.select" desc="EMP Á¶È¸" resultType="sample.vo.EmpVO" isNamed="false">
          <![CDATA[
 select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO
 from EMP
 where DEPTNO=?
          ]]>
      </query>
      <query id="sample04.emp.select" desc="EMP Á¶È¸" resultType="sample.vo.EmpVO" isNamed="true">
          <![CDATA[
 select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO
 from EMP
 where DEPTNO=:deptno
          ]]>
      </query>
 </queryMap>
 
 3. vo(returnType) : sample.vo.EmpVO 
 package sample.vo;
 import java.sql.Date;
 public class EmpVO {
     private Number empno;
     private String ename;
     private String job;
     private Number mgr;
     private Date hiredate;
     private Number sal;
     private Number comm;
     private Number deptno;
 
     public Number getEmpno() {
         return empno;
     }
     public void setEmpno(Number empno) {
         this.empno = empno;
     }
     public String getEname() {
         return ename;
     }
     public void setEname(String ename) {
         this.ename = ename;
     }
     public String getJob() {
         return job;
     }
     public void setJob(String job) {
        this.job = job;
     }
     public Number getMgr() {
         return mgr;
     }
     public void setMgr(Number mgr) {
         this.mgr = mgr;
     }
     public Date getHiredate() {
         return hiredate;
     }
     public void setHiredate(Date hiredate) {
         this.hiredate = hiredate;
     }
     public Number getSal() {
         return sal;
     }
     public void setSal(Number sal) {
         this.sal = sal;
     }
     public Number getComm() {
         return comm;
     }
     public void setComm(Number comm) {
         this.comm = comm;
     }
     public Number getDeptno() {
         return deptno;
     }
     public void setDeptno(Number deptno) {
         this.deptno = deptno;
     }
 }
 
 4. java(custom activity) code 
 // dao °¡Á®¿À±â. 
 GlueGenericDao dao = this.getDao("dao");
 // binding Á¤º¸ ±¸¼º (case 1)
 GlueParameter listParam = new GlueParameter();
 List paramList = new ArrayList();
 paramList.add( "10" );
 listParam.setParameter(paramList);
 
 // binding Á¤º¸ ±¸¼º (case 2)
 GlueParameter mapParam = new GlueParameter();
 Map paramMap = new HashMap();
 paramMap.put("deptno", "10");
 mapParam.setParameter(paramMap);
 
 // Á¶È¸ ½ÇÇà
 List rowSet1 = dao.find("sample01.emp.select", listParam);
 List rowSet2 = dao.find("sample02.emp.select", mapParam);
 List rowSet3 = dao.find("sample03.emp.select", listParam);
 List rowSet4 = dao.find("sample04.emp.select", mapParam);
 
 5. °á°ú Ãâ·Â 
 for(java.util.Map row : rowSet1){
     System.out.println(row.get("EMPNO")+"/"+row.get("ENAME"));
 }
 for(java.util.Map row : rowSet2){
     System.out.println(row.get("EMPNO")+"/"+row.get("ENAME"));
 }
 for(sample.vo.EmpVO row : rowSet3){
     System.out.println(row.getEmpno()+"/"+row.getEname());
 }
 for(sample.vo.EmpVO row : rowSet4){
     System.out.println(row.getEmpno()+"/"+row.getEname());
 }
 
Since:
2013. 5. 10.
Version:
1.0.0
Author:
Ç㠵γç
Skip navigation links

Copyright © 2013–2019 POSCO ICT. All rights reserved.