Source Code Cross Referenced for PersonTimesheetQuery.java in  » Project-Management » XPlanner-0.7b7 » com » technoetic » xplanner » db » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Project Management » XPlanner 0.7b7 » com.technoetic.xplanner.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.technoetic.xplanner.db;
002:
003:        import java.sql.Connection;
004:        import java.sql.PreparedStatement;
005:        import java.sql.ResultSet;
006:        import java.sql.SQLException;
007:        import java.util.Date;
008:
009:        import net.sf.hibernate.Session;
010:        import org.apache.log4j.Logger;
011:
012:        import com.technoetic.xplanner.domain.virtual.DailyTimesheetEntry;
013:        import com.technoetic.xplanner.domain.virtual.Timesheet;
014:        import com.technoetic.xplanner.domain.virtual.TimesheetEntry;
015:
016:        // todo These queries should be converted to Hibernate
017:
018:        public class PersonTimesheetQuery {
019:            private Logger log = Logger.getLogger(getClass());
020:            private static String summaryQuery = "SELECT person.name as person_name, "
021:                    + "project.id as project_id, "
022:                    + "project.name as project_name, "
023:                    + "iteration.id as iteration_id, "
024:                    + "iteration.name as iteration_name, "
025:                    + "story.id as story_id, "
026:                    + "story.name as story_name, "
027:                    + "Sum(time_entry.duration) AS total_duration "
028:                    + "FROM person, project, iteration, story, task, time_entry "
029:                    + "WHERE project.id = iteration.project_id "
030:                    + "AND iteration.id = story.iteration_id "
031:                    + "AND story.id = task.story_id "
032:                    + "AND task.id = time_entry.task_id "
033:                    + "AND (person.id = time_entry.person1_id OR person.id = time_entry.person2_id) "
034:                    + "AND "
035:                    + "  ((time_entry.report_date >= ? AND time_entry.report_date <= ? AND time_entry.start_time IS NULL) OR "
036:                    + "   (time_entry.start_time >= ? AND time_entry.start_time <= ?)) "
037:                    + "AND person.id = ? "
038:                    + "GROUP BY person.id, person.name, project.id, project.name, iteration.id,  "
039:                    + "iteration.name, story.id, story.name "
040:                    + "ORDER BY person.name, project.name, iteration.name, story.name ";
041:
042:            private static String dailyQueryByReportDate = "SELECT "
043:                    + "time_entry.report_date as report_date, "
044:                    + "Sum(time_entry.duration) AS total_duration "
045:                    + "FROM time_entry "
046:                    + "WHERE ? in (time_entry.person1_id, time_entry.person2_id) "
047:                    + "AND time_entry.start_time IS NULL "
048:                    + "AND time_entry.report_date >= ?  "
049:                    + "AND time_entry.report_date <= ? "
050:                    + "GROUP BY time_entry.report_date "
051:                    + "ORDER BY time_entry.report_date ";
052:
053:            private static String dailyQueryByStartDate = "SELECT "
054:                    + "time_entry.start_time as report_date, "
055:                    + "Sum(time_entry.duration) AS total_duration "
056:                    + "FROM time_entry "
057:                    + "WHERE ? in (time_entry.person1_id, time_entry.person2_id) "
058:                    + "AND time_entry.start_time IS NOT NULL "
059:                    + "AND time_entry.start_time >= ?  "
060:                    + "AND time_entry.start_time <= ? "
061:                    + "GROUP BY time_entry.start_time "
062:                    + "ORDER BY time_entry.start_time ";
063:
064:            private int personId;
065:            private java.util.Date endDate = new Date();
066:            private java.util.Date startDate = new Date();
067:            private final Session session;
068:
069:            public PersonTimesheetQuery(Session session) {
070:                this .session = session;
071:            }
072:
073:            public Timesheet getTimesheet() {
074:                Timesheet timesheet = new Timesheet(this .startDate,
075:                        this .endDate);
076:                try {
077:                    try {
078:                        Connection conn = session.connection();
079:                        PreparedStatement stmt = conn
080:                                .prepareStatement(summaryQuery);
081:                        stmt.setDate(1, new java.sql.Date(this .startDate
082:                                .getTime()));
083:                        stmt.setDate(2, new java.sql.Date(this .endDate
084:                                .getTime()));
085:                        stmt.setDate(3, new java.sql.Date(this .startDate
086:                                .getTime()));
087:                        stmt.setDate(4, new java.sql.Date(this .endDate
088:                                .getTime()));
089:                        stmt.setInt(5, this .personId);
090:                        ResultSet results = stmt.executeQuery();
091:                        for (boolean isRow = results.next(); isRow; isRow = results
092:                                .next()) {
093:                            TimesheetEntry time = new TimesheetEntry();
094:                            time
095:                                    .setPersonName(results
096:                                            .getString("person_name"));
097:                            time.setProjectId(results.getInt("project_id"));
098:                            time.setProjectName(results
099:                                    .getString("project_name"));
100:                            time.setIterationId(results.getInt("iteration_id"));
101:                            time.setIterationName(results
102:                                    .getString("iteration_name"));
103:                            time.setStoryId(results.getInt("story_id"));
104:                            time.setStoryName(results.getString("story_name"));
105:                            time.setTotalDuration(results
106:                                    .getDouble("total_duration"));
107:                            timesheet.addEntry(time);
108:                        }
109:                        stmt.close();
110:
111:                        doDailyQuery(conn, timesheet, dailyQueryByReportDate);
112:                        doDailyQuery(conn, timesheet, dailyQueryByStartDate);
113:                    } catch (Exception ex) {
114:                        log.error("query error", ex);
115:                    } finally {
116:                        session.connection().rollback();
117:                    }
118:                } catch (Exception ex) {
119:                    log.error("error in PersonTimesheetQuery", ex);
120:                }
121:                return timesheet;
122:            }
123:
124:            private void doDailyQuery(Connection conn, Timesheet timesheet,
125:                    String query) throws SQLException {
126:                PreparedStatement stmt = conn.prepareStatement(query);
127:                try {
128:                    stmt.setInt(1, this .personId);
129:                    stmt
130:                            .setDate(2, new java.sql.Date(this .startDate
131:                                    .getTime()));
132:                    stmt.setDate(3, new java.sql.Date(this .endDate.getTime()));
133:                    ResultSet results = stmt.executeQuery();
134:                    for (boolean isRow = results.next(); isRow; isRow = results
135:                            .next()) {
136:                        DailyTimesheetEntry time = new DailyTimesheetEntry();
137:                        time.setEntryDate(results.getDate("report_date"));
138:                        time.setTotalDuration(results
139:                                .getDouble("total_duration"));
140:                        timesheet.addDailyEntry(time);
141:                    }
142:                } finally {
143:                    stmt.close();
144:                }
145:            }
146:
147:            public void setPersonId(int personId) {
148:                this .personId = personId;
149:            }
150:
151:            public int getPersonId() {
152:                return personId;
153:            }
154:
155:            public java.util.Date getStartDate() {
156:                return startDate;
157:            }
158:
159:            public void setStartDate(java.util.Date startDate) {
160:                this .startDate = startDate;
161:            }
162:
163:            public java.util.Date getEndDate() {
164:                return endDate;
165:            }
166:
167:            public void setEndDate(java.util.Date endDate) {
168:                this.endDate = endDate;
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.