1   /*** $Id: QBEEmployeeTO.java,v 1.1.1.1 2004/05/18 10:50:21 mochoa Exp $ */
2   
3   package cmd_dao.sample.common.hibernate.employee;
4   //dao
5   import org.j2ee.dao.AbstractHibernateDAOAction;
6   //dto
7   import cmd_dao.sample.common.dto.EmployeeTO;
8   
9   /***
10  * Last modified $Date: 2004/05/18 10:50:21 $
11  * @version $Revision: 1.1.1.1 $
12  * @author Hibernate Action Generator
13  * This class is concrete implementation for an action using Hibernate.
14  * 
15  * Based on an example of book Code Notes for J2EE, Edited by GREGORY BRILL,
16  * e-ISBN 0-679-64727-9
17  * Automated generated code, DO NOT EDIT
18  */
19  public class QBEEmployeeTO extends AbstractHibernateDAOAction {
20      
21        private EmployeeTO employeeTO  = null;
22      
23      /***
24        * Default constructor, calls to the super class given the kind
25        * of action to be implement.
26        */
27        public QBEEmployeeTO() { 
28          super(AbstractHibernateDAOAction.HQL_QUERY);
29        }
30      
31      
32      /***
33        * Class constructor setting the DTO.
34        * First calls to the default contructor to set the operation
35        * then set the private instance with the given DTO.
36        * @param dto for this action
37        */
38        public QBEEmployeeTO(EmployeeTO dto) {
39          this();
40          this.employeeTO = dto;
41        }
42      
43      
44      /***
45        * getter method for the private attribute
46        */
47        public EmployeeTO getEmployeeTO() { 
48          return this.employeeTO; 
49        }
50      
51      /***
52        * getter method for the private attribute
53        */
54        public Object getTO() { 
55          return this.employeeTO; 
56        }
57      
58      /***
59        * setter method for the private attribute
60        */
61        public void setEmployeeTO(EmployeeTO dto) {
62          this.employeeTO = dto;
63        }
64      
65      /***
66        * setter method for the private attribute
67        */
68        public void setTO(Object dto) {
69          this.employeeTO = (EmployeeTO)dto;
70        }
71      
72      
73      /***
74        * private attribute to know if the query found the object
75        */
76        private boolean found = false;
77  
78      /***
79        * ArrayList to store the query result
80        */
81        private java.util.List result = null;
82  
83      /***
84        * ArrayList filled at execution time with the binding parameters values of the where condition
85        */
86        private java.util.ArrayList parameters = new java.util.ArrayList();
87  
88      /***
89        * ArrayList filled at execution time with the binding parameters names of the where condition
90        */
91        private java.util.ArrayList names = new java.util.ArrayList();
92  
93      /***
94        * Order by condition for the query.
95        */
96        private String orderBy = "";
97  
98      /***
99        * static query string using HQL sintax, do not require dynamic computation 
100       * to know the HQL syntax for finding the object throw his primary key
101       */
102       private static final String sql_stmt="from cmd_dao.sample.common.dto.EmployeeTO as EmployeeTO";
103     /***
104       * Return true if the object was found.
105       * otherwise false
106       */
107       public boolean isFound() {
108         if (result==null)
109           return false;
110         else
111           return !result.isEmpty();
112       }
113     
114     
115     /***
116       * setter method for the private attribute
117       */
118       public void setOrderBy(String newOrderBy) {
119         this.orderBy = newOrderBy;
120       }
121     
122     /***
123       * getter method for the private attribute
124       */
125       public String getOrderBy() {
126         return this.orderBy;
127       }
128     
129     
130     /***
131       * Return the HQL query string used by Hibernate to find the
132       * object.
133       * Test for every property into the DTO instance,
134       * for values not equal to null generate the where condition to test for
135       * like if its String or = for other types.
136       */
137       public String getHQL() {
138         StringBuffer whereCondition = new StringBuffer(" where ");
139         
140         if (this.employeeTO.getComm()!=null) {
141           whereCondition.append("comm = :comm and ");
142           parameters.add(this.employeeTO.getComm());
143           names.add("comm");
144         }
145         
146         if (this.employeeTO.getDeptNo()!=null) {
147           whereCondition.append("deptNo = :deptNo and ");
148           parameters.add(this.employeeTO.getDeptNo());
149           names.add("deptNo");
150         }
151         
152         if (this.employeeTO.getHireDate()!=null) {
153           whereCondition.append("hireDate = :hireDate and ");
154           parameters.add(this.employeeTO.getHireDate());
155           names.add("hireDate");
156         }
157         
158         if (this.employeeTO.getJob()!=null) {
159           whereCondition.append("job like :job and ");
160           parameters.add(this.employeeTO.getJob());
161           names.add("job");
162         }
163         
164         if (this.employeeTO.getManager()!=null) {
165           whereCondition.append("manager = :manager and ");
166           parameters.add(this.employeeTO.getManager());
167           names.add("manager");
168         }
169         
170         if (this.employeeTO.getName()!=null) {
171           whereCondition.append("name like :name and ");
172           parameters.add(this.employeeTO.getName());
173           names.add("name");
174         }
175         
176         if (this.employeeTO.getSalary()!=null) {
177           whereCondition.append("salary = :salary and ");
178           parameters.add(this.employeeTO.getSalary());
179           names.add("salary");
180         }
181         
182         String whereStr = whereCondition.toString();
183         if (names.size()==0)
184           return this.sql_stmt+"order by "+orderBy; // No where condition applied
185         else // Return the orginal query plus the where string removing last and
186           return this.sql_stmt+whereStr.substring(0,whereStr.length()-4)+"order by "+orderBy;
187       }
188     
189     
190     /***
191       * After the execution of the HQL query by the Action processor
192       * this method is called to process the hibernate result.
193       * For this implementation, It stores the result into the private attribute.
194       */
195       public void handleResults(java.util.List rs) {
196         if (rs!=null)
197           result = rs;
198       }
199     
200     
201     /***
202       * getter method for the private attribute
203       */
204       public java.util.List getResult() { 
205         return this.result; 
206       }
207     
208     
209     /***
210       * This method is called from DAOHibernateActionProcessorImpl
211       * They must return the parameters for the operation to be called.
212       * For insert/delete/update operations it only needs the transfer object
213       * For Load operation it needs the transfer object and primary key.
214       * @return an array of objects.
215       */
216       public Object[] getParameters() {
217         return parameters.toArray(); 
218       }
219     
220     
221     /***
222       * Return the names of the parameters used into the HQL query
223       */
224       public String[] getNamesForParams() { 
225         return (String [])names.toArray(new String[names.size()]);
226       }
227       
228     }
229     
230     
This page was automatically generated by Maven