Source Code Cross Referenced for PlainUserGroupAccessor.java in  » Portal » mypersonalizer » es » udc » mypersonalizer » kernel » model » repository » sql » plain » 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 » Portal » mypersonalizer » es.udc.mypersonalizer.kernel.model.repository.sql.plain 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/model/repository/sql/plain/PlainUserGroupAccessor.java,v 1.1.1.1 2004/03/25 12:08:37 fbellas Exp $
003:         * $Revision: 1.1.1.1 $
004:         * $Date: 2004/03/25 12:08:37 $
005:         *
006:         * =============================================================================
007:         *
008:         * Copyright (c) 2003, The MyPersonalizer Development Group
009:         * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at 
010:         * University Of A Coruna
011:         * All rights reserved.
012:         *
013:         * Redistribution and use in source and binary forms, with or without
014:         * modification, are permitted provided that the following conditions are met:
015:         *
016:         *  - Redistributions of source code must retain the above copyright notice, 
017:         *    this list of conditions and the following disclaimer.
018:         *
019:         *  - Redistributions in binary form must reproduce the above copyright notice,
020:         *    this list of conditions and the following disclaimer in the documentation
021:         *    and/or other materials provided with the distribution.
022:         *
023:         *  - Neither the name of the University Of A Coruna nor the names of its 
024:         *    contributors may be used to endorse or promote products derived from 
025:         *    this software without specific prior written permission.
026:         *
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
028:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
036:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037:         * POSSIBILITY OF SUCH DAMAGE.
038:         *
039:         */
040:
041:        package es.udc.mypersonalizer.kernel.model.repository.sql.plain;
042:
043:        import java.util.Collection;
044:        import java.sql.Connection;
045:
046:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserGroup;
047:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserGroupAccessor;
048:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserAlreadyExistsInGroupException;
049:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserDoesNotExistInGroupException;
050:        import es.udc.mypersonalizer.kernel.model.repository.sql.storers.UserGroupStorer;
051:        import es.udc.mypersonalizer.kernel.util.exceptions.DuplicateInstanceException;
052:        import es.udc.mypersonalizer.kernel.util.exceptions.InstanceNotFoundException;
053:        import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
054:
055:        /**
056:         * This class provides a Plain-based implementation of 
057:         * <code>UserGroupAccessor</code>. The implementation uses the 
058:         * <code>TransactionManager</code> which returns pooled connections,
059:         * and needs to rely on the storer to perform the requested operation.
060:         *
061:         * @author   Abel Iago Toral Quiroga
062:         * @author   Fernando Bellas
063:         * @since 1.0
064:         */
065:        public class PlainUserGroupAccessor implements  UserGroupAccessor {
066:
067:            private UserGroupStorer storer;
068:
069:            /** 
070:             * Creates an instance of this accessor.
071:             */
072:            public PlainUserGroupAccessor() {
073:                storer = new UserGroupStorer();
074:            }
075:
076:            public Collection findAllGroupsAssignedToUser(String loginName,
077:                    int startIndex, int count) throws InternalErrorException {
078:
079:                Transaction transaction = null;
080:
081:                try {
082:
083:                    /* Get the transaction and the associated connection. */
084:                    transaction = TransactionManager.getInstance()
085:                            .getTransaction(Transaction.TRANSACTION_SUPPORTS);
086:                    Connection connection = transaction.getConnection();
087:
088:                    /* Delegate on the storer. */
089:                    Collection userAssignedGroups = storer
090:                            .findAllGroupsAssignedToUser(connection, loginName,
091:                                    startIndex, count);
092:
093:                    /* Release transaction and return result. */
094:                    transaction.release();
095:
096:                    return userAssignedGroups;
097:
098:                } catch (InternalErrorException e) {
099:                    rollbackTransaction(transaction);
100:                    throw e;
101:                } catch (RuntimeException e) {
102:                    rollbackTransaction(transaction);
103:                    throw new InternalErrorException(e);
104:                }
105:            }
106:
107:            public Collection findAllUsersAssignedToGroup(Long groupId,
108:                    int startIndex, int count) throws InternalErrorException {
109:
110:                Transaction transaction = null;
111:
112:                try {
113:
114:                    /* Get the transaction and the associated connection. */
115:                    transaction = TransactionManager.getInstance()
116:                            .getTransaction(Transaction.TRANSACTION_SUPPORTS);
117:                    Connection connection = transaction.getConnection();
118:
119:                    /* Delegate on the storer. */
120:                    Collection groupAssignedUsers = storer
121:                            .findAllUsersAssignedToGroup(connection, groupId,
122:                                    startIndex, count);
123:
124:                    /* Release transaction and return result. */
125:                    transaction.release();
126:
127:                    return groupAssignedUsers;
128:
129:                } catch (InternalErrorException e) {
130:                    rollbackTransaction(transaction);
131:                    throw e;
132:                } catch (RuntimeException e) {
133:                    rollbackTransaction(transaction);
134:                    throw new InternalErrorException(e);
135:                }
136:            }
137:
138:            /**
139:             * This method is implemented calling 
140:             * <code>findAllGroupsAssignedToUser(startIndex = 0, count = -1)</code> 
141:             */
142:            public Collection findAllGroupsAssignedToUser(String loginName)
143:                    throws InternalErrorException {
144:
145:                return findAllGroupsAssignedToUser(loginName, 0, -1);
146:            }
147:
148:            public Collection findAllGroups(int startIndex, int count)
149:                    throws InternalErrorException {
150:
151:                Transaction transaction = null;
152:
153:                try {
154:
155:                    /* Get the transaction and the associated connection. */
156:                    transaction = TransactionManager.getInstance()
157:                            .getTransaction(Transaction.TRANSACTION_SUPPORTS);
158:                    Connection connection = transaction.getConnection();
159:
160:                    /* Delegate on the storer. */
161:                    Collection userGroups = storer.findAllGroups(connection,
162:                            startIndex, count);
163:
164:                    /* Release transaction and return result. */
165:                    transaction.release();
166:
167:                    return userGroups;
168:
169:                } catch (InternalErrorException e) {
170:                    rollbackTransaction(transaction);
171:                    throw e;
172:                } catch (RuntimeException e) {
173:                    rollbackTransaction(transaction);
174:                    throw new InternalErrorException(e);
175:                }
176:            }
177:
178:            /**
179:             * This method is implemented calling 
180:             * <code>findAllGroups(startIndex = 0, count = -1)</code> 
181:             */
182:            public Collection findAllGroups() throws InternalErrorException {
183:
184:                return findAllGroups(0, -1);
185:            }
186:
187:            public UserGroup findGroup(Long userGroupIdentifier)
188:                    throws InternalErrorException, InstanceNotFoundException {
189:
190:                Transaction transaction = null;
191:
192:                try {
193:
194:                    /* Get the transaction and the associated connection. */
195:                    transaction = TransactionManager.getInstance()
196:                            .getTransaction(Transaction.TRANSACTION_SUPPORTS);
197:                    Connection connection = transaction.getConnection();
198:
199:                    /* Delegate on the storer. */
200:                    UserGroup userGroup = storer.findGroup(connection,
201:                            userGroupIdentifier);
202:
203:                    /* Release transaction and return result. */
204:                    transaction.release();
205:
206:                    return userGroup;
207:
208:                } catch (InternalErrorException e) {
209:                    rollbackTransaction(transaction);
210:                    throw e;
211:                } catch (InstanceNotFoundException e) {
212:                    transaction.release();
213:                    throw e;
214:                } catch (RuntimeException e) {
215:                    rollbackTransaction(transaction);
216:                    throw new InternalErrorException(e);
217:                }
218:            }
219:
220:            public UserGroup findGroupByName(String userGroupName)
221:                    throws InternalErrorException, InstanceNotFoundException {
222:
223:                Transaction transaction = null;
224:
225:                try {
226:
227:                    /* Get the transaction and the associated connection. */
228:                    transaction = TransactionManager.getInstance()
229:                            .getTransaction(Transaction.TRANSACTION_SUPPORTS);
230:                    Connection connection = transaction.getConnection();
231:
232:                    /* Delegate on the storer. */
233:                    UserGroup userGroup = storer.findGroupByName(connection,
234:                            userGroupName);
235:
236:                    /* Release transaction and return result. */
237:                    transaction.release();
238:
239:                    return userGroup;
240:
241:                } catch (InternalErrorException e) {
242:                    rollbackTransaction(transaction);
243:                    throw e;
244:                } catch (InstanceNotFoundException e) {
245:                    transaction.release();
246:                    throw e;
247:                } catch (RuntimeException e) {
248:                    rollbackTransaction(transaction);
249:                    throw new InternalErrorException(e);
250:                }
251:            }
252:
253:            public void addUserToGroup(String loginName,
254:                    Long userGroupIdentifier) throws InternalErrorException,
255:                    InstanceNotFoundException,
256:                    UserAlreadyExistsInGroupException {
257:
258:                Transaction transaction = null;
259:
260:                try {
261:
262:                    /* Get the transaction and the associated connection. */
263:                    transaction = TransactionManager.getInstance()
264:                            .getTransaction(Transaction.TRANSACTION_REQUIRED);
265:                    Connection connection = transaction.getConnection();
266:
267:                    /* Delegate on the storer. */
268:                    storer.addUserToGroup(connection, loginName,
269:                            userGroupIdentifier);
270:
271:                    /* Release transaction. */
272:                    transaction.release();
273:
274:                } catch (InternalErrorException e) {
275:                    rollbackTransaction(transaction);
276:                    throw e;
277:                } catch (InstanceNotFoundException e) {
278:                    transaction.release();
279:                    throw e;
280:                } catch (UserAlreadyExistsInGroupException e) {
281:                    transaction.release();
282:                    throw e;
283:                } catch (RuntimeException e) {
284:                    rollbackTransaction(transaction);
285:                    throw new InternalErrorException(e);
286:                }
287:            }
288:
289:            public UserGroup addGroup(UserGroup userGroup)
290:                    throws InternalErrorException, DuplicateInstanceException {
291:
292:                Transaction transaction = null;
293:
294:                try {
295:
296:                    /* Get the transaction and the associated connection. */
297:                    transaction = TransactionManager.getInstance()
298:                            .getTransaction(Transaction.TRANSACTION_REQUIRED);
299:                    Connection connection = transaction.getConnection();
300:
301:                    /* Delegate on the storer. */
302:                    UserGroup newUserGroup = storer.addGroup(connection,
303:                            userGroup);
304:
305:                    /* Release transaction and return result. */
306:                    transaction.release();
307:
308:                    return newUserGroup;
309:
310:                } catch (InternalErrorException e) {
311:                    rollbackTransaction(transaction);
312:                    throw e;
313:                } catch (DuplicateInstanceException e) {
314:                    transaction.release();
315:                    throw e;
316:                } catch (RuntimeException e) {
317:                    rollbackTransaction(transaction);
318:                    throw new InternalErrorException(e);
319:                }
320:            }
321:
322:            public void removeUserFromGroup(String loginName,
323:                    Long userGroupIdentifier) throws InternalErrorException,
324:                    InstanceNotFoundException, UserDoesNotExistInGroupException {
325:
326:                Transaction transaction = null;
327:
328:                try {
329:
330:                    /* Get the transaction and the associated connection. */
331:                    transaction = TransactionManager.getInstance()
332:                            .getTransaction(Transaction.TRANSACTION_REQUIRED);
333:                    Connection connection = transaction.getConnection();
334:
335:                    /* Delegate on the storer. */
336:                    storer.removeUserFromGroup(connection, loginName,
337:                            userGroupIdentifier);
338:
339:                    /* Release transaction. */
340:                    transaction.release();
341:
342:                } catch (InternalErrorException e) {
343:                    rollbackTransaction(transaction);
344:                    throw e;
345:                } catch (InstanceNotFoundException e) {
346:                    transaction.release();
347:                    throw e;
348:                } catch (UserDoesNotExistInGroupException e) {
349:                    transaction.release();
350:                    throw e;
351:                } catch (RuntimeException e) {
352:                    rollbackTransaction(transaction);
353:                    throw new InternalErrorException(e);
354:                }
355:            }
356:
357:            public void removeGroup(Long userGroupIdentifier)
358:                    throws InternalErrorException, InstanceNotFoundException {
359:
360:                Transaction transaction = null;
361:
362:                try {
363:
364:                    /* Get the transaction and the associated connection. */
365:                    transaction = TransactionManager.getInstance()
366:                            .getTransaction(Transaction.TRANSACTION_REQUIRED);
367:                    Connection connection = transaction.getConnection();
368:
369:                    /* Delegate on the storer. */
370:                    storer.removeGroup(connection, userGroupIdentifier);
371:
372:                    /* Release transaction. */
373:                    transaction.release();
374:
375:                } catch (InternalErrorException e) {
376:                    rollbackTransaction(transaction);
377:                    throw e;
378:                } catch (InstanceNotFoundException e) {
379:                    transaction.release();
380:                    throw e;
381:                } catch (RuntimeException e) {
382:                    rollbackTransaction(transaction);
383:                    throw new InternalErrorException(e);
384:                }
385:            }
386:
387:            public void removeAllGroupAssignments(String loginName)
388:                    throws InternalErrorException {
389:
390:                Transaction transaction = null;
391:
392:                try {
393:
394:                    /* Get the transaction and the associated connection. */
395:                    transaction = TransactionManager.getInstance()
396:                            .getTransaction(Transaction.TRANSACTION_REQUIRED);
397:                    Connection connection = transaction.getConnection();
398:
399:                    /* Delegate on the storer. */
400:                    storer.removeAllGroupAssignments(connection, loginName);
401:
402:                    /* Release transaction. */
403:                    transaction.release();
404:
405:                } catch (InternalErrorException e) {
406:                    rollbackTransaction(transaction);
407:                    throw e;
408:                } catch (RuntimeException e) {
409:                    rollbackTransaction(transaction);
410:                    throw new InternalErrorException(e);
411:                }
412:            }
413:
414:            public void updateGroup(UserGroup userGroup)
415:                    throws InternalErrorException, DuplicateInstanceException,
416:                    InstanceNotFoundException {
417:
418:                Transaction transaction = null;
419:
420:                try {
421:
422:                    /* Get the transaction and the associated connection. */
423:                    transaction = TransactionManager.getInstance()
424:                            .getTransaction(Transaction.TRANSACTION_REQUIRED);
425:                    Connection connection = transaction.getConnection();
426:
427:                    /* Delegate on the storer. */
428:                    storer.updateGroup(connection, userGroup);
429:
430:                    /* Release transaction. */
431:                    transaction.release();
432:
433:                } catch (InternalErrorException e) {
434:                    rollbackTransaction(transaction);
435:                    throw e;
436:                } catch (InstanceNotFoundException e) {
437:                    transaction.release();
438:                    throw e;
439:                } catch (DuplicateInstanceException e) {
440:                    transaction.release();
441:                    throw e;
442:                } catch (RuntimeException e) {
443:                    rollbackTransaction(transaction);
444:                    throw new InternalErrorException(e);
445:                }
446:            }
447:
448:            private void rollbackTransaction(Transaction transaction)
449:                    throws InternalErrorException {
450:
451:                if (transaction != null) {
452:                    transaction.rollback();
453:                }
454:            }
455:
456:        }
w___w__w___._j__a_va__2___s.co_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.