Source Code Cross Referenced for NoteHelper.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) 


01:        package com.technoetic.xplanner.db;
02:
03:        import com.technoetic.xplanner.domain.*;
04:        import com.technoetic.xplanner.file.File;
05:        import net.sf.hibernate.Hibernate;
06:        import net.sf.hibernate.HibernateException;
07:        import net.sf.hibernate.Session;
08:        import net.sf.hibernate.type.NullableType;
09:
10:        import java.util.Arrays;
11:        import java.util.Iterator;
12:        import java.util.List;
13:
14:        /**
15:         * User: Mateusz Prokopowicz
16:         * Date: Dec 16, 2004
17:         * Time: 2:10:17 PM
18:         */
19:        public class NoteHelper {
20:            //FIXME: Externalize all these query in the Note.xml mapping file
21:            //DEBT: Turn this into a NoteRepository that is spring loaded. No more static entry point. A session is passed in at construction time.
22:            static final String SELECT_NOTES_FILE_IS_ATTACHED_TO = "select note from Note note where note.file.id= ?";
23:            static final String FILE_DELETE_QUERY = "from file in "
24:                    + File.class + " where file.id= ?";
25:            static final String NOTE_DELETE_QUERY = "from note in "
26:                    + Note.class + " where note.id = ?";
27:            static final String SELECT_NOTE_ATTACHED_TO = "select note from Note note where note.attachedToId = ?";
28:            static final String SELECT_ATTACHED_TO_ID = "SELECT t.id, s.id, i.id, p.id FROM "
29:                    + Project.class.getName()
30:                    + " as p left join p.iterations as i left join i.userStories as s left join s.tasks as t"
31:                    + " WHERE  p.id = ? or i.id = ? or s.id = ? or t.id = ? order by i.id, s.id, t.id";
32:            static final String NOTE_DELETION_QUERY = "from note in "
33:                    + Note.class + " where note.attachedToId = ?";
34:
35:            static final Class[] DELETE_ORDER = { Task.class, UserStory.class,
36:                    Iteration.class, Project.class };
37:
38:            public static int deleteNote(Note note, Session session)
39:                    throws HibernateException {
40:                if (note.getFile() != null) {
41:                    List noteList = session.find(
42:                            SELECT_NOTES_FILE_IS_ATTACHED_TO, new Integer(note
43:                                    .getFile().getId()), Hibernate.INTEGER);
44:                    if (noteList != null && noteList.size() == 1) {
45:                        session.delete(FILE_DELETE_QUERY, new Integer(
46:                                ((Note) noteList.get(0)).getFile().getId()),
47:                                Hibernate.INTEGER);
48:                    }
49:                }
50:                return session.delete(NOTE_DELETE_QUERY, new Integer(note
51:                        .getId()), Hibernate.INTEGER);
52:            }
53:
54:            public static int deleteNotesFor(NoteAttachable obj, Session session)
55:                    throws HibernateException {
56:                return deleteNotesFor(obj.getClass(), obj.getId(), session);
57:            }
58:
59:            public static int deleteNotesFor(Class clazz, int objectId,
60:                    Session session) throws HibernateException {
61:                Integer[] ids = new Integer[4];
62:                Arrays.fill(ids, new Integer(objectId));
63:                NullableType[] types = new NullableType[4];
64:                Arrays.fill(types, Hibernate.INTEGER);
65:                Iterator objIt = session.iterate(SELECT_ATTACHED_TO_ID, ids,
66:                        types);
67:                Object[] oldRow = new Object[4];
68:                Arrays.fill(oldRow, new Integer(-1));
69:                int retVal = 0;
70:                while (objIt.hasNext()) {
71:                    Object[] row = (Object[]) objIt.next();
72:                    for (int i = 0; i <= Arrays.asList(DELETE_ORDER).indexOf(
73:                            clazz); i++) {
74:                        if (row[i] != null && !row[i].equals(oldRow[i])) {
75:                            List noteList = session.find(
76:                                    SELECT_NOTE_ATTACHED_TO, row[i],
77:                                    Hibernate.INTEGER);
78:                            for (Iterator noteIt = noteList.iterator(); noteIt
79:                                    .hasNext();) {
80:                                deleteNote((Note) noteIt.next(), session);
81:                            }
82:                        }
83:                    }
84:                    oldRow = row;
85:                }
86:                return retVal;
87:            }
88:
89:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.