1 package ch.ige.edossier.web.server.dao;
2
3 import java.sql.*;
4 import java.util.ArrayList;
5 import java.util.List;
6 import ch.ige.edossier.util.DBHelper;
7 import ch.ige.edossier.web.vo.PriorityVO;
8
9
17 public class PriorityDAO
18 {
19
25 public List select( int dossierId ) throws SQLException
26 {
27 Connection con = null;
28 PreparedStatement ps = null;
29 ResultSet rs = null;
30 List list = new ArrayList();
31 PriorityVO vo = null;
32
33 try
34 {
35 con = DBHelper.getInstance().getEsolutionConnection();
36 ps = con.prepareStatement( getSelectStatement() + "where dossier_id = ? ORDER BY country_cd" );
37 ps.setInt( 1, dossierId );
38 rs = ps.executeQuery();
39
40 while( rs.next() )
41 {
42 vo = this.fillVO( rs );
43 list.add( vo );
44 }
45 }
46 finally
47 {
48 DBHelper.getInstance().close( con, ps );
49 }
50 return list;
51 }
52
53
58 public void insert( PriorityVO priorityVO ) throws Exception
59 {
60 Connection con = null;
61 PreparedStatement ps = null;
62
63 try
64 {
65 con = DBHelper.getInstance().getEsolutionConnection();
66
67 ps = con.prepareStatement(
68 "INSERT INTO edossier.priority(" +
69 "priority_id, " +
70 "dossier_id, " +
71 "country_cd, " +
72 "prio_dat ) " +
73 "VALUES(EDOSSIER.SEQ_PRIORITY_ID.nextval,?,?,?)"
74 );
75
76 ps.setInt( 1, priorityVO.getDossierId() );
77 ps.setString( 2, priorityVO.getCountryCd() );
78 ps.setDate( 3, priorityVO.getPrioDat() );
79
80 if( ps.executeUpdate() != 1 )
81 {
82 throw new SQLException();
83 }
84
85 }
86 finally
87 {
88 DBHelper.getInstance().close( con, ps );
89 }
90 }
91
92
97 public void update( PriorityVO priorityVO ) throws Exception
98 {
99 Connection con = null;
100 PreparedStatement ps = null;
101
102 try
103 {
104 con = DBHelper.getInstance().getEsolutionConnection();
105 ps = con.prepareStatement( "UPDATE edossier.priority " +
106 "SET country_cd = ?, prio_dat = ?, changed_dat = sysdate " +
107 "WHERE priority_id = ? " +
108 "AND dossier_id = ?" );
109
110 ps.setString( 1, priorityVO.getCountryCd() );
111 ps.setDate( 2, priorityVO.getPrioDat() );
112 ps.setInt( 3, priorityVO.getPriorityId() );
113 ps.setInt( 4, priorityVO.getDossierId() );
114
115 if( ps.executeUpdate() != 1 )
116 {
117 throw new SQLException();
118 }
119 }
120 finally
121 {
122 DBHelper.getInstance().close( con, ps );
123 }
124 }
125
126
132 public int delete( int priorityId ) throws SQLException
133 {
134 Connection con = null;
135 PreparedStatement ps = null;
136
137 try
138 {
139 con = DBHelper.getInstance().getEsolutionConnection();
140
141 ps = con.prepareStatement(
142 "DELETE FROM edossier.priority where priority_id = ? "
143 );
144 ps.setInt( 1, priorityId );
145
146 return ps.executeUpdate();
147 }
148 finally
149 {
150 DBHelper.getInstance().close( con, ps );
151 }
152 }
153
154
158 private String getSelectStatement()
159 {
160 return
161 ( "select priority_id, dossier_id, country_cd, prio_dat, created_dat, changed_dat " +
162 "from edossier.priority " );
163 }
164
165
171 private PriorityVO fillVO( ResultSet rs ) throws SQLException
172 {
173 PriorityVO priorityVO = new PriorityVO();
174
175 priorityVO.setPriorityId( rs.getInt( "priority_id" ) );
176 priorityVO.setDossierId( rs.getInt( "dossier_id" ) );
177 priorityVO.setCountryCd( rs.getString( "country_cd" ) );
178 priorityVO.setPrioDat( rs.getDate( "prio_dat" ) );
179 priorityVO.setCreatedDat( rs.getDate( "created_dat" ) );
180 priorityVO.setChangedDat( rs.getDate( "changed_dat" ) );
181
182 return priorityVO;
183 }
184 }
185