Source Code Cross Referenced for CMCNodeManagerImpl.java in  » Portal » Open-Portal » com » sun » portal » community » mc » impl » jdo » 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 » Open Portal » com.sun.portal.community.mc.impl.jdo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions
006:         * are met:
007:         *
008:         * - Redistributions of source code must retain the above copyright
009:         *   notice, this list of conditions and the following disclaimer.getc
010:         *
011:         * - Redistribution in binary form must reproduce the above copyright
012:         *   notice, this list of conditions and the following disclaimer in
013:         *   the documentation and/or other materials provided with the
014:         *   distribution.
015:         *
016:         * Neither the name of Sun Microsystems, Inc. or the names of
017:         * contributors may be used to endorse or promote products derived
018:         * from this software without specific prior written permission.
019:         *
020:         * This software is provided "AS IS," without a warranty of any
021:         * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022:         * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023:         * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024:         * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025:         * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026:         * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027:         * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028:         * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029:         * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030:         * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031:         * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032:         *
033:         * You acknowledge that Software is not designed, licensed or intended
034:         * any nuclear facility.
035:         */
036:        package com.sun.portal.community.mc.impl.jdo;
037:
038:        import com.sun.portal.community.mc.CMCNodeManager;
039:        import com.sun.portal.community.mc.CMCException;
040:        import com.sun.portal.community.mc.CMCPrincipal;
041:        import com.sun.portal.community.mc.CMCRolePrincipal;
042:        import com.sun.portal.community.mc.ConfigTable.ConfigKey;
043:        import com.sun.portal.community.mc.impl.jdo.CMCImpl.RoleMapper;
044:        import com.sun.portal.community.mc.impl.jdo.pc.Community;
045:        import javax.jdo.Extent;
046:        import javax.jdo.JDOException;
047:        import javax.jdo.PersistenceManager;
048:        import javax.jdo.Query;
049:        import javax.jdo.Transaction;
050:        import java.util.ArrayList;
051:        import java.util.Collection;
052:        import java.util.Collections;
053:        import java.util.HashMap;
054:        import java.util.HashSet;
055:        import java.util.Iterator;
056:        import java.util.List;
057:        import java.util.Map;
058:
059:        import java.util.Properties;
060:        import java.util.Set;
061:        import java.util.regex.Pattern;
062:
063:        public class CMCNodeManagerImpl extends CMCImpl implements 
064:                CMCNodeManager, SchemaNames {
065:            private static abstract class QueryElement {
066:                protected String queryString;
067:                protected Object[] parameters;
068:
069:                public String getQueryString() {
070:                    return queryString;
071:                }
072:
073:                public Object[] getParameters() {
074:                    return parameters;
075:                }
076:            }
077:
078:            private static class RoleUserCountQueryElement extends QueryElement {
079:                public RoleUserCountQueryElement(Set communityPrincipals,
080:                        Set rolePrincipals) {
081:                    if (communityPrincipals == null) {
082:                        throw new NullPointerException(
083:                                "null community principal set is not allowed");
084:                    }
085:                    if (rolePrincipals == null) {
086:                        throw new NullPointerException(
087:                                "null role principal set is not allowed");
088:                    }
089:                    if (communityPrincipals.size() == 0) {
090:                        throw new IllegalArgumentException(
091:                                "empty community principal set is not allowed");
092:                    }
093:
094:                    buildQuery(communityPrincipals, rolePrincipals);
095:                }
096:
097:                private void buildQuery(Set communityPrincipals,
098:                        Set rolePrincipals) {
099:                    StringBuffer q = new StringBuffer();
100:                    List parameterList = new ArrayList();
101:
102:                    q.append("select " + COMMUNITY_USER_TABLE + "."
103:                            + COMMUNITY_NAME_COLUMN + " as communityname, "
104:                            + COMMUNITY_USER_TABLE + "." + ROLE_ID_COLUMN
105:                            + " as roleid, count(distinct "
106:                            + COMMUNITY_USER_TABLE + "." + USER_NAME_COLUMN
107:                            + ") as usercount from " + COMMUNITY_USER_TABLE
108:                            + " where " + COMMUNITY_USER_TABLE + "."
109:                            + COMMUNITY_NAME_COLUMN + " in");
110:                    q.append(" ( ");
111:                    for (Iterator i = communityPrincipals.iterator(); i
112:                            .hasNext();) {
113:                        CMCPrincipal cmcp = (CMCPrincipal) i.next();
114:                        q.append("?");
115:                        parameterList.add(cmcp.getName());
116:                        if (i.hasNext()) {
117:                            q.append(", ");
118:                        }
119:                    }
120:                    q.append(" ) ");
121:
122:                    q.append(" and ");
123:                    q.append(COMMUNITY_USER_TABLE);
124:                    q.append(".");
125:                    q.append(ROLE_ID_COLUMN);
126:                    q.append(" in ( ");
127:                    for (Iterator i = rolePrincipals.iterator(); i.hasNext();) {
128:                        CMCRolePrincipal cmcrp = (CMCRolePrincipal) i.next();
129:                        q.append("?");
130:                        parameterList.add(new Integer(RoleMapper
131:                                .getIntValue(cmcrp.getName())));
132:                        if (i.hasNext()) {
133:                            q.append(", ");
134:                        }
135:                    }
136:                    q.append(" )");
137:                    q.append(" group by ");
138:                    q.append(COMMUNITY_USER_TABLE);
139:                    q.append(".");
140:                    q.append(COMMUNITY_NAME_COLUMN);
141:                    q.append(", ");
142:                    q.append(COMMUNITY_USER_TABLE);
143:                    q.append(".");
144:                    q.append(ROLE_ID_COLUMN);
145:
146:                    queryString = q.toString();
147:                    //System.out.println("queryString=" + queryString);
148:                    //System.out.println("parameterList=" + parameterList);
149:                    parameters = (Object[]) parameterList
150:                            .toArray(new Object[0]);
151:                }
152:            }
153:
154:            private static class UserCountQueryElement extends QueryElement {
155:                public UserCountQueryElement(Set communityPrincipals) {
156:                    if (communityPrincipals == null) {
157:                        throw new NullPointerException(
158:                                "null community principal set is not allowed");
159:                    }
160:                    if (communityPrincipals.size() == 0) {
161:                        throw new IllegalArgumentException(
162:                                "empty community principal set is not allowed");
163:                    }
164:
165:                    buildQuery(communityPrincipals);
166:                }
167:
168:                private void buildQuery(Set communityPrincipals) {
169:                    StringBuffer q = new StringBuffer();
170:                    List parameterList = new ArrayList();
171:
172:                    q.append("select " + COMMUNITY_USER_TABLE + "."
173:                            + COMMUNITY_NAME_COLUMN
174:                            + " as communityname, count(distinct "
175:                            + COMMUNITY_USER_TABLE + "." + USER_NAME_COLUMN
176:                            + ") as usercount from " + COMMUNITY_USER_TABLE
177:                            + " where " + COMMUNITY_USER_TABLE + "."
178:                            + COMMUNITY_NAME_COLUMN + " in");
179:                    q.append(" ( ");
180:                    for (Iterator i = communityPrincipals.iterator(); i
181:                            .hasNext();) {
182:                        CMCPrincipal cmcp = (CMCPrincipal) i.next();
183:                        q.append("?");
184:                        parameterList.add(cmcp.getName());
185:                        if (i.hasNext()) {
186:                            q.append(", ");
187:                        }
188:                    }
189:                    q.append(" ) group by ");
190:                    q.append(COMMUNITY_USER_TABLE);
191:                    q.append(".");
192:                    q.append(COMMUNITY_NAME_COLUMN);
193:
194:                    queryString = q.toString();
195:                    //System.out.println("queryString=" + queryString);
196:                    //System.out.println("parameterList=" + parameterList);
197:                    parameters = (String[]) parameterList
198:                            .toArray(new String[0]);
199:                }
200:            }
201:
202:            public static class RoleUserCount {
203:                private int roleid;
204:                private String communityname;
205:                private int usercount;
206:
207:                public int getRoleid() {
208:                    return roleid;
209:                }
210:
211:                public void setRoleid(int role) {
212:                    roleid = role;
213:                }
214:
215:                public String getCommunityname() {
216:                    return communityname;
217:                }
218:
219:                public void setCommunityname(String name) {
220:                    communityname = name;
221:                }
222:
223:                public int getUsercount() {
224:                    return usercount;
225:                }
226:
227:                public void setUsercount(int count) {
228:                    usercount = count;
229:                }
230:
231:                public String toString() {
232:                    return "{ communityname=" + getCommunityname()
233:                            + ", roleid=" + getRoleid() + ", usercount="
234:                            + getUsercount();
235:                }
236:            }
237:
238:            public static class UserCount {
239:                private String communityname;
240:                private int usercount;
241:
242:                public String getCommunityname() {
243:                    return communityname;
244:                }
245:
246:                public int getUsercount() {
247:                    return usercount;
248:                }
249:
250:                public void setCommunityname(String name) {
251:                    communityname = name;
252:                }
253:
254:                public void setUsercount(int count) {
255:                    usercount = count;
256:                }
257:
258:                public String toString() {
259:                    return "{ communityname=" + getCommunityname()
260:                            + ", usercount=" + getUsercount();
261:                }
262:            }
263:
264:            public void init(Properties p) throws CMCException {
265:                // nothing
266:            }
267:
268:            public Map getUserCounts(Set communityPrincipals)
269:                    throws CMCException {
270:                communityPrincipals = filterPrincipals(communityPrincipals);
271:                Map counts = new HashMap();
272:
273:                QueryElement qe = new UserCountQueryElement(communityPrincipals);
274:
275:                PersistenceManager pm = getPersistenceManager();
276:                Transaction tx = pm.currentTransaction();
277:
278:                try {
279:                    tx.begin();
280:
281:                    Query query = pm.newQuery("javax.jdo.query.SQL", qe
282:                            .getQueryString());
283:                    query.setResultClass(UserCount.class);
284:                    Collection results = (Collection) query.executeWithArray(qe
285:                            .getParameters());
286:
287:                    for (Iterator i = results.iterator(); i.hasNext();) {
288:                        UserCount uc = (UserCount) i.next();
289:                        CMCPrincipal cmcp = new CMCPrincipal(getType(), uc
290:                                .getCommunityname());
291:                        Integer count = new Integer(uc.getUsercount());
292:                        counts.put(cmcp, count);
293:                    }
294:
295:                    tx.commit();
296:                } catch (JDOException jdoe) {
297:                    throw new CMCException(jdoe);
298:                } finally {
299:                    if (tx.isActive()) {
300:                        tx.rollback();
301:                    }
302:                    pm.close();
303:                }
304:
305:                return counts;
306:            }
307:
308:            public Map getRoleUserCounts(Set communityPrincipals,
309:                    Set rolePrincipals) throws CMCException {
310:                communityPrincipals = filterPrincipals(communityPrincipals);
311:                Map counts = new HashMap();
312:
313:                QueryElement qe = new RoleUserCountQueryElement(
314:                        communityPrincipals, rolePrincipals);
315:
316:                PersistenceManager pm = getPersistenceManager();
317:                Transaction tx = pm.currentTransaction();
318:
319:                try {
320:                    tx.begin();
321:
322:                    Query query = pm.newQuery("javax.jdo.query.SQL", qe
323:                            .getQueryString());
324:                    query.setResultClass(RoleUserCount.class);
325:                    Collection results = (Collection) query.executeWithArray(qe
326:                            .getParameters());
327:
328:                    for (Iterator i = results.iterator(); i.hasNext();) {
329:                        RoleUserCount uc = (RoleUserCount) i.next();
330:                        //System.out.println("uc=" + uc);
331:                        CMCPrincipal cmcp = new CMCPrincipal(getType(), uc
332:                                .getCommunityname());
333:                        CMCRolePrincipal cmcrp = RoleMapper
334:                                .getCMCRolePrincipalValue(uc.getRoleid());
335:                        ConfigKey ck = new ConfigKey(cmcp, cmcrp);
336:                        Integer count = new Integer(uc.getUsercount());
337:                        counts.put(ck, count);
338:                    }
339:
340:                    tx.commit();
341:                } catch (JDOException jdoe) {
342:                    throw new CMCException(jdoe);
343:                } finally {
344:                    if (tx.isActive()) {
345:                        tx.rollback();
346:                    }
347:                    pm.close();
348:                }
349:
350:                return counts;
351:            }
352:
353:            public Set match(Pattern p, boolean nameOnly) throws CMCException {
354:                PersistenceManager pm = getPersistenceManager();
355:                Transaction tx = pm.currentTransaction();
356:
357:                Set principals = new HashSet();
358:
359:                try {
360:                    tx.begin();
361:
362:                    Extent e = pm
363:                            .getExtent(com.sun.portal.community.mc.impl.jdo.pc.Community.class);
364:                    Query q = pm.newQuery(e);
365:                    StringBuffer filterBuf = new StringBuffer(
366:                            "communityName.matches(pattern)");
367:                    if (!nameOnly) {
368:                        filterBuf.append(" || description.matches(pattern)");
369:                    }
370:                    q.setFilter(filterBuf.toString());
371:                    q.declareImports("import java.lang.String");
372:                    q.declareParameters("java.lang.String pattern");
373:                    Map parameterMap = Collections.singletonMap("pattern", p
374:                            .pattern());
375:
376:                    Collection results = (Collection) q
377:                            .executeWithMap(parameterMap);
378:
379:                    for (Iterator i = results.iterator(); i.hasNext();) {
380:                        Community c = (Community) i.next();
381:                        CMCPrincipal principal = new CMCPrincipal(getType(), c
382:                                .getCommunityName());
383:                        principals.add(principal);
384:                    }
385:
386:                    tx.commit();
387:                } catch (JDOException jdoe) {
388:                    throw new CMCException(jdoe);
389:                } finally {
390:                    if (tx.isActive()) {
391:                        tx.rollback();
392:                    }
393:                    pm.close();
394:                }
395:
396:                return principals;
397:            }
398:
399:        }
ww__w.__ja___v_a___2___s._c___om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.