Package com.poscoict.glueframework.dao.jdbc
package com.poscoict.glueframework.dao.jdbc
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.EmpVOpackage 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<List> listParam = new GlueParameter<List>(); List paramList = new ArrayList(); paramList.add( "10" ); listParam.setParameter(paramList); // binding 정보 구성 (case 2) GlueParameter<Map> mapParam = new GlueParameter<Map>(); 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:
- 허 두녕
-
ClassDescription데이타베이스 CRUD(Create, Read, Update, Delete) 오퍼레이션을 추상화하여 제공하는 Data Access Object 인터페이스.데이타베이스 CRUD(Create, Read, Update, Delete) 오퍼레이션을 추상화하여 제공하는 Data Access Object 오브젝트.Spring JDBC의 JdbcTemplate 클래스를 확장하여 PageSet 기능을 제공함.GlueLazyJdbcDao.Deprecated.