Source Code Cross Referenced for NotesController.java in  » Chat » claros-intouch » org » claros » intouch » notes » controllers » 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 » Chat » claros intouch » org.claros.intouch.notes.controllers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.claros.intouch.notes.controllers;
002:
003:        import java.util.List;
004:
005:        import org.claros.commons.auth.models.AuthProfile;
006:        import org.claros.commons.exception.NoPermissionException;
007:        import org.claros.intouch.common.utility.Constants;
008:        import org.claros.intouch.common.utility.Utility;
009:        import org.claros.intouch.notes.models.Note;
010:
011:        import com.jenkov.mrpersister.impl.mapping.AutoGeneratedColumnsMapper;
012:        import com.jenkov.mrpersister.itf.IGenericDao;
013:        import com.jenkov.mrpersister.itf.mapping.IObjectMappingKey;
014:        import com.jenkov.mrpersister.util.JdbcUtil;
015:
016:        /**
017:         * @author Umut Gokbayrak
018:         */
019:        public class NotesController {
020:
021:            /**
022:             * 
023:             * @param auth
024:             * @return
025:             * @throws Exception
026:             */
027:            public static List getUnfiledNotes(AuthProfile auth)
028:                    throws Exception {
029:                return getNotesByFolderId(auth, new Long(0));
030:            }
031:
032:            /**
033:             * 
034:             * @param auth
035:             * @param folderId
036:             * @return
037:             * @throws Exception
038:             */
039:            public static List getNotesByFolderId(AuthProfile auth,
040:                    Long folderId) throws Exception {
041:                IGenericDao dao = null;
042:                List notes = null;
043:                try {
044:                    dao = Utility.getDbConnection();
045:                    String username = auth.getUsername();
046:
047:                    String sql = "SELECT * FROM NOTES WHERE USERNAME=? AND FOLDER_ID = ? ORDER BY ID DESC";
048:
049:                    notes = dao.readList(Note.class, sql, new Object[] {
050:                            username, folderId });
051:                } finally {
052:                    JdbcUtil.close(dao);
053:                    dao = null;
054:                }
055:                return notes;
056:            }
057:
058:            /**
059:             * 
060:             * @param auth
061:             * @param note
062:             * @throws Exception
063:             */
064:            public static void saveNote(AuthProfile auth, Note note)
065:                    throws Exception {
066:                IGenericDao dao = null;
067:                try {
068:                    dao = Utility.getDbConnection();
069:
070:                    Long id = note.getId();
071:                    if (id == null) {
072:                        // it is an insert
073:                        IObjectMappingKey myObj = Constants.persistMan
074:                                .getObjectMappingFactory().createInstance(
075:                                        Note.class,
076:                                        new AutoGeneratedColumnsMapper(true));
077:                        dao.insert(myObj, note);
078:                    } else {
079:                        // it is an update
080:                        Note tmp = getNoteById(auth, note.getId());
081:                        if (!auth.getUsername().equals(tmp.getUsername())) {
082:                            throw new NoPermissionException();
083:                        }
084:                        dao.update(note);
085:                    }
086:                } finally {
087:                    JdbcUtil.close(dao);
088:                    dao = null;
089:                }
090:            }
091:
092:            /**
093:             * 
094:             * @param auth
095:             * @param noteId
096:             * @throws Exception
097:             */
098:            public static void deleteNote(AuthProfile auth, Long noteId)
099:                    throws Exception {
100:                Note tmp = getNoteById(auth, noteId);
101:                if (!auth.getUsername().equals(tmp.getUsername())) {
102:                    throw new NoPermissionException();
103:                }
104:
105:                IGenericDao dao = null;
106:                try {
107:                    dao = Utility.getDbConnection();
108:                    dao.deleteByPrimaryKey(Note.class, noteId);
109:                } catch (Exception e) {
110:                    // do nothing sier
111:                } finally {
112:                    JdbcUtil.close(dao);
113:                    dao = null;
114:                }
115:            }
116:
117:            /**
118:             * 
119:             * @param auth
120:             * @param folderId
121:             * @throws Exception
122:             */
123:            public static void deleteNotesByFolderId(AuthProfile auth,
124:                    Long folderId) throws Exception {
125:                if (!folderId.equals(new Long(0))) {
126:                    IGenericDao dao = null;
127:                    try {
128:                        dao = Utility.getDbConnection();
129:                        String username = auth.getUsername();
130:
131:                        String sql = "DELETE FROM NOTES WHERE USERNAME=? AND FOLDER_ID = ?";
132:
133:                        dao.executeUpdate(sql, new Object[] { username,
134:                                folderId });
135:                    } catch (Exception e) {
136:                        // do nothing sier
137:                    } finally {
138:                        JdbcUtil.close(dao);
139:                        dao = null;
140:                    }
141:                }
142:            }
143:
144:            /**
145:             * 
146:             * @param auth
147:             * @param noteId
148:             * @return
149:             * @throws Exception
150:             */
151:            public static Note getNoteById(AuthProfile auth, Long noteId)
152:                    throws Exception {
153:                IGenericDao dao = null;
154:                Note note = null;
155:                try {
156:                    dao = Utility.getDbConnection();
157:                    String username = auth.getUsername();
158:
159:                    String sql = "SELECT * FROM NOTES WHERE USERNAME=? AND ID = ?";
160:                    note = (Note) dao.read(Note.class, sql, new Object[] {
161:                            username, noteId });
162:                } finally {
163:                    JdbcUtil.close(dao);
164:                    dao = null;
165:                }
166:                return note;
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.