Source Code Cross Referenced for SqlGroupStore.java in  » Groupware » lucane » org » lucane » server » store » sql » 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 » Groupware » lucane » org.lucane.server.store.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Lucane - a collaborative platform
003:         * Copyright (C) 2003  Vincent Fiack <vfiack@mail15.com>
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:        package org.lucane.server.store.sql;
020:
021:        import java.util.*;
022:        import java.sql.*;
023:
024:        import org.lucane.server.*;
025:        import org.lucane.common.concepts.*;
026:        import org.lucane.server.database.*;
027:        import org.lucane.server.store.*;
028:
029:        public class SqlGroupStore extends GroupStore {
030:            private static final String TABLENAME = "groups";
031:            protected static final String GROUPLINKS = "groupLinks";
032:            protected static final String PLUGINLINKS = "pluginLinks";
033:            protected static final String SERVICELINKS = "serviceLinks";
034:            protected static final String USERLINKS = "userLinks";
035:
036:            private DatabaseAbstractionLayer layer;
037:            private Store store;
038:
039:            public SqlGroupStore(Store store) throws Exception {
040:                this .layer = Server.getInstance().getDBLayer();
041:                this .store = store;
042:
043:                if (!layer.hasTable(TABLENAME)) {
044:                    String dbDescription = "jar:file:///"
045:                            + Server.getInstance().getWorkingDirectory()
046:                            + "lib/lucane-server-" + Server.VERSION + ".jar!/"
047:                            + "db-sqlstore.xml";
048:
049:                    layer.getTableCreator().createFromXml(dbDescription);
050:                }
051:            }
052:
053:            //-- interface
054:
055:            /**
056:             * Does the store has any data ?
057:             * 
058:             * @return true if the store is already created
059:             */
060:            public boolean isInitialized() throws Exception {
061:                return getAllGroups().hasNext();
062:            }
063:
064:            public void storeGroup(GroupConcept group) throws SQLException {
065:                Connection c = layer.getConnection();
066:                PreparedStatement insert;
067:                Iterator i;
068:
069:                //store group          
070:                insert = c.prepareStatement("INSERT INTO " + TABLENAME
071:                        + " VALUES(?, ?)");
072:                insert.setString(1, group.getName());
073:                insert.setString(2, group.getDescription());
074:                insert.execute();
075:                insert.close();
076:
077:                //store group links
078:                i = group.getParents();
079:                while (i.hasNext()) {
080:                    GroupConcept parent = (GroupConcept) i.next();
081:                    insert = c.prepareStatement("INSERT INTO " + GROUPLINKS
082:                            + " VALUES(?, ?)");
083:                    insert.setString(1, parent.getName());
084:                    insert.setString(2, group.getName());
085:                    insert.execute();
086:                    insert.close();
087:                }
088:
089:                //store user links
090:                i = group.getUsers();
091:                while (i.hasNext()) {
092:                    UserConcept user = (UserConcept) i.next();
093:                    insert = c.prepareStatement("INSERT INTO " + USERLINKS
094:                            + " VALUES(?, ?)");
095:                    insert.setString(1, group.getName());
096:                    insert.setString(2, user.getName());
097:                    insert.execute();
098:                    insert.close();
099:                }
100:
101:                //store services links
102:                i = group.getServices();
103:                while (i.hasNext()) {
104:                    ServiceConcept service = (ServiceConcept) i.next();
105:                    insert = c.prepareStatement("INSERT INTO " + SERVICELINKS
106:                            + " VALUES(?, ?)");
107:                    insert.setString(1, group.getName());
108:                    insert.setString(2, service.getName());
109:                    insert.execute();
110:                    insert.close();
111:                }
112:
113:                //store plugins links
114:                i = group.getPlugins();
115:                while (i.hasNext()) {
116:                    PluginConcept plugin = (PluginConcept) i.next();
117:                    insert = c.prepareStatement("INSERT INTO " + PLUGINLINKS
118:                            + " VALUES(?, ?)");
119:                    insert.setString(1, group.getName());
120:                    insert.setString(2, plugin.getName());
121:                    insert.execute();
122:                    insert.close();
123:                }
124:
125:                c.close();
126:            }
127:
128:            public void updateGroup(GroupConcept group) throws SQLException {
129:                removeGroupOnly(group);
130:                storeGroup(group);
131:            }
132:
133:            public void removeGroup(GroupConcept group) throws SQLException {
134:                //-- delete basic infos	
135:                removeGroupOnly(group);
136:
137:                Connection c = layer.getConnection();
138:
139:                //delete group links
140:                PreparedStatement delete = c.prepareStatement("DELETE FROM "
141:                        + GROUPLINKS + " WHERE parent=? OR child=?");
142:                delete.setString(1, group.getName());
143:                delete.setString(2, group.getName());
144:                delete.execute();
145:
146:                delete.close();
147:                c.close();
148:            }
149:
150:            public GroupConcept getGroup(String name) throws Exception {
151:                GroupConcept group = null;
152:
153:                Connection c = layer.getConnection();
154:                PreparedStatement select = c.prepareStatement("SELECT * FROM "
155:                        + TABLENAME + " WHERE name=?");
156:                select.setString(1, name);
157:                ResultSet rs = select.executeQuery();
158:
159:                if (rs.next()) {
160:                    name = rs.getString(1);
161:                    String description = rs.getString(2);
162:
163:                    group = new GroupConcept(name);
164:                    group.setDescription(description);
165:                    setGroupLinks(c, group);
166:                    setUserLinks(c, group);
167:                    setPluginLinks(c, group);
168:                    setServiceLinks(c, group);
169:                }
170:
171:                rs.close();
172:                select.close();
173:                c.close();
174:
175:                return group;
176:            }
177:
178:            public Iterator getAllGroups() throws Exception {
179:                ArrayList all = new ArrayList();
180:
181:                Connection c = layer.getConnection();
182:                PreparedStatement select = c.prepareStatement("SELECT * FROM "
183:                        + TABLENAME);
184:                ResultSet rs = select.executeQuery();
185:
186:                while (rs.next()) {
187:                    String name = rs.getString(1);
188:                    String description = rs.getString(2);
189:
190:                    GroupConcept group = new GroupConcept(name);
191:                    group.setDescription(description);
192:                    setGroupLinks(c, group);
193:                    setUserLinks(c, group);
194:                    setPluginLinks(c, group);
195:                    setServiceLinks(c, group);
196:                    all.add(group);
197:                }
198:
199:                rs.close();
200:                select.close();
201:                c.close();
202:
203:                return all.iterator();
204:            }
205:
206:            //-- private methods
207:
208:            private void setServiceLinks(Connection c, GroupConcept group)
209:                    throws Exception {
210:                PreparedStatement select = c
211:                        .prepareStatement("SELECT service FROM " + SERVICELINKS
212:                                + " WHERE groupName=?");
213:                select.setString(1, group.getName());
214:                ResultSet rs = select.executeQuery();
215:
216:                while (rs.next()) {
217:                    String name = rs.getString(1);
218:                    ServiceConcept service = store.getServiceStore()
219:                            .getService(name);
220:                    group.addService(service);
221:                }
222:
223:                rs.close();
224:                select.close();
225:            }
226:
227:            private void setPluginLinks(Connection c, GroupConcept group)
228:                    throws Exception {
229:                PreparedStatement select = c
230:                        .prepareStatement("SELECT plugin FROM " + PLUGINLINKS
231:                                + " WHERE groupName=?");
232:                select.setString(1, group.getName());
233:                ResultSet rs = select.executeQuery();
234:
235:                while (rs.next()) {
236:                    String name = rs.getString(1);
237:                    PluginConcept plugin = store.getPluginStore().getPlugin(
238:                            name);
239:                    group.addPlugin(plugin);
240:                }
241:
242:                rs.close();
243:                select.close();
244:            }
245:
246:            private void setUserLinks(Connection c, GroupConcept group)
247:                    throws Exception {
248:                PreparedStatement select = c
249:                        .prepareStatement("SELECT userName FROM " + USERLINKS
250:                                + " WHERE groupName=?");
251:                select.setString(1, group.getName());
252:                ResultSet rs = select.executeQuery();
253:
254:                while (rs.next()) {
255:                    String name = rs.getString(1);
256:                    UserConcept user = store.getUserStore().getUser(name);
257:                    group.addUser(user);
258:                }
259:
260:                rs.close();
261:                select.close();
262:            }
263:
264:            private void setGroupLinks(Connection c, GroupConcept group)
265:                    throws Exception {
266:                PreparedStatement select = c
267:                        .prepareStatement("SELECT parent FROM " + GROUPLINKS
268:                                + " WHERE child=?");
269:                select.setString(1, group.getName());
270:                ResultSet rs = select.executeQuery();
271:
272:                while (rs.next()) {
273:                    String name = rs.getString(1);
274:                    GroupConcept parent = store.getGroupStore().getGroup(name);
275:                    group.addParent(parent);
276:                }
277:
278:                rs.close();
279:                select.close();
280:            }
281:
282:            private void removeGroupOnly(GroupConcept group)
283:                    throws SQLException {
284:                Connection c = layer.getConnection();
285:                PreparedStatement delete;
286:
287:                //delete group
288:                delete = c.prepareStatement("DELETE FROM " + TABLENAME
289:                        + " WHERE name=?");
290:                delete.setString(1, group.getName());
291:                delete.execute();
292:                delete.close();
293:
294:                //delete group links
295:                delete = c.prepareStatement("DELETE FROM " + GROUPLINKS
296:                        + " WHERE child=?");
297:                delete.setString(1, group.getName());
298:                delete.execute();
299:                delete.close();
300:
301:                //delete user links
302:                delete = c.prepareStatement("DELETE FROM " + USERLINKS
303:                        + " WHERE groupName=?");
304:                delete.setString(1, group.getName());
305:                delete.execute();
306:                delete.close();
307:
308:                //delete services links
309:                delete = c.prepareStatement("DELETE FROM " + SERVICELINKS
310:                        + " WHERE groupName=?");
311:                delete.setString(1, group.getName());
312:                delete.execute();
313:                delete.close();
314:
315:                //delete plugins links
316:                delete = c.prepareStatement("DELETE FROM " + PLUGINLINKS
317:                        + " WHERE groupName=?");
318:                delete.setString(1, group.getName());
319:                delete.execute();
320:                delete.close();
321:
322:                c.close();
323:            }
324:
325:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.