Source Code Cross Referenced for AdministratorManagerDbImpl.java in  » Database-DBMS » myoodb-2.2.1 » org » myoodb » objects » 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 » Database DBMS » myoodb 2.2.1 » org.myoodb.objects 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        ///////////////////////////////////////////////////////////////////////////////
002:        //
003:        //   Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004:        //
005:        //                          All Rights Reserved
006:        //
007:        //   This program is free software; you can redistribute it and/or modify
008:        //   it under the terms of the GNU General Public License and GNU Library
009:        //   General Public License as published by the Free Software Foundation;
010:        //   either version 2, or (at your option) any later version.
011:        //
012:        //   This program is distributed in the hope that it will be useful,
013:        //   but WITHOUT ANY WARRANTY; without even the implied warranty of
014:        //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015:        //   GNU General Public License and GNU Library General Public License
016:        //   for more details.
017:        //
018:        //   You should have received a copy of the GNU General Public License
019:        //   and GNU Library General Public License along with this program; if
020:        //   not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021:        //   MA 02139, USA.
022:        //
023:        ///////////////////////////////////////////////////////////////////////////////
024:        package org.myoodb.objects;
025:
026:        import org.myoodb.*;
027:        import org.myoodb.core.*;
028:
029:        public class AdministratorManagerDbImpl extends
030:                org.myoodb.collectable.CollectableDbImpl implements 
031:                AdministratorManager {
032:            public static String ADMINISTRATOR_USERNAME = "admin";
033:            public static String ADMINISTRATOR_PASSWORD = "admin";
034:
035:            private static boolean isAdministrator(String name) {
036:                return name.equals(ADMINISTRATOR_USERNAME);
037:            }
038:
039:            public AdministratorManagerDbImpl() {
040:            }
041:
042:            private User internalGetUser(String username) {
043:                User user = null;
044:
045:                try {
046:                    user = MyOodbManager.getTheManager().getUserManager()
047:                            .getUser(username);
048:                } catch (Exception e) {
049:                    throw new org.myoodb.exception.PermissionException(
050:                            "Get User", e);
051:                }
052:
053:                return user;
054:            }
055:
056:            private synchronized void internalCreateUser(String username,
057:                    String password) {
058:                if (isAdministrator(invokedBy()) == false) {
059:                    throw new org.myoodb.exception.PermissionException(
060:                            "Only the Administrator can create users");
061:                } else if (isAdministrator(username) == true) {
062:                    throw new org.myoodb.exception.PermissionException(
063:                            "Administrator already exists");
064:                }
065:
066:                try {
067:                    MyOodbManager.getTheManager().getUserManager().newUser(
068:                            username, password);
069:                } catch (Exception e) {
070:                    throw new org.myoodb.exception.PermissionException(
071:                            "Create User", e);
072:                }
073:            }
074:
075:            private synchronized void internalDeleteUser(String username) {
076:                if (isAdministrator(invokedBy()) == false) {
077:                    throw new org.myoodb.exception.PermissionException(
078:                            "Only the Administrator can delete users");
079:                } else if (isAdministrator(username) == true) {
080:                    throw new org.myoodb.exception.PermissionException(
081:                            "Administrator user cannot be deleted");
082:                }
083:
084:                try {
085:                    MyOodbManager.getTheManager().getUserManager().removeUser(
086:                            username);
087:                } catch (Exception e) {
088:                    throw new org.myoodb.exception.PermissionException(
089:                            "Delete User", e);
090:                }
091:            }
092:
093:            public boolean internalBreakUserLocks(String username) {
094:                boolean success = true;
095:                User self = internalGetUser(username);
096:
097:                java.util.Iterator iter = MyOodbManager.getTheManager()
098:                        .getTransactionManager().getTransactions().iterator();
099:                while (iter.hasNext()) {
100:                    AbstractTransaction tx = (AbstractTransaction) iter.next();
101:
102:                    if (tx.getStatus() < AbstractTransaction.STATUS_COMMITING) {
103:                        User owner = tx.getOwner();
104:
105:                        if ((owner == null) || (owner.equals(self) == false)) {
106:                            continue;
107:                        }
108:
109:                        try {
110:                            tx.abort();
111:
112:                            MyOodbManager.getTheManager()
113:                                    .getTransactionManager()
114:                                    .notifyWaitingTransactions();
115:                        } catch (Exception e) {
116:                            success = false;
117:                        } finally {
118:                            MyOodbManager.getTheManager()
119:                                    .getTransactionManager()
120:                                    .notifyWaitingTransactions();
121:                        }
122:
123:                        try {
124:                            MyOodbManager.getTheManager()
125:                                    .getTransactionManager().deleteTransaction(
126:                                            tx.getClient().getThread(), tx);
127:                        } catch (Exception e) {
128:                            success = false;
129:                        }
130:                    }
131:                }
132:
133:                return success;
134:            }
135:
136:            private boolean internalIsUserPassword(String username,
137:                    String password) {
138:                User user = null;
139:
140:                try {
141:                    user = MyOodbManager.getTheManager().getUserManager()
142:                            .getUser(username);
143:                } catch (Exception e) {
144:                    throw new org.myoodb.exception.PermissionException(
145:                            "Is User Password", e);
146:                }
147:
148:                return user.getPassword().equals(password);
149:            }
150:
151:            public void createUser(String username, String password) {
152:                if (isExplicitLock() == true) {
153:                    throw new org.myoodb.exception.PermissionException(
154:                            "Cannot preform operation within a transaction");
155:                }
156:
157:                internalCreateUser(username, password);
158:            }
159:
160:            public void deleteUser(String username) {
161:                if (isExplicitLock() == true) {
162:                    throw new org.myoodb.exception.PermissionException(
163:                            "Cannot preform operation within a transaction");
164:                }
165:
166:                internalDeleteUser(username);
167:            }
168:
169:            public boolean breakUserLocks(String username) {
170:                if (isExplicitLock() == true) {
171:                    throw new org.myoodb.exception.PermissionException(
172:                            "Cannot preform operation within a transaction");
173:                }
174:
175:                return internalBreakUserLocks(username);
176:            }
177:
178:            public boolean isUserPassword(String username, String password) {
179:                return internalIsUserPassword(username, password);
180:            }
181:
182:            public void verifyDatabase() {
183:                try {
184:                    org.myoodb.core.MyOodbManager.getTheManager()
185:                            .getStoreManager().verifyDatabase();
186:                } catch (RuntimeException e) {
187:                    throw e;
188:                } catch (Exception e) {
189:                    e.printStackTrace();
190:                }
191:            }
192:
193:            public boolean isVerifyingDatabase() {
194:                return org.myoodb.core.MyOodbManager.getTheManager()
195:                        .getStoreManager().isVerifyingDatabase();
196:            }
197:
198:            public void defragDatabase() {
199:                try {
200:                    org.myoodb.core.MyOodbManager.getTheManager()
201:                            .getStoreManager().defragDatabase();
202:                } catch (RuntimeException e) {
203:                    throw e;
204:                } catch (Exception e) {
205:                    e.printStackTrace();
206:                }
207:            }
208:
209:            public boolean isDefraggingDatabase() {
210:                return org.myoodb.core.MyOodbManager.getTheManager()
211:                        .getStoreManager().isDefraggingDatabase();
212:            }
213:
214:            public void backupDatabase(String location) {
215:                try {
216:                    org.myoodb.core.MyOodbManager.getTheManager()
217:                            .getStoreManager().backupDatabase(location);
218:                } catch (RuntimeException e) {
219:                    throw e;
220:                } catch (Exception e) {
221:                    e.printStackTrace();
222:                }
223:            }
224:
225:            public boolean isBackingUpDatabase() {
226:                return org.myoodb.core.MyOodbManager.getTheManager()
227:                        .getStoreManager().isBackingUpDatabase();
228:            }
229:
230:            public void restoreDatabase(String location) {
231:                try {
232:                    org.myoodb.core.MyOodbManager.getTheManager()
233:                            .getStoreManager().restoreDatabase(location);
234:                } catch (RuntimeException e) {
235:                    throw e;
236:                } catch (Exception e) {
237:                    e.printStackTrace();
238:                }
239:            }
240:
241:            public boolean isRestoringDatabase() {
242:                return org.myoodb.core.MyOodbManager.getTheManager()
243:                        .getStoreManager().isRestoringDatabase();
244:            }
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.