Source Code Cross Referenced for OrganizationPersistenceImpl.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portal » service » persistence » 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 » liferay portal 4.4.2 » com.liferay.portal.service.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
0003:         *
0004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
0005:         * of this software and associated documentation files (the "Software"), to deal
0006:         * in the Software without restriction, including without limitation the rights
0007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008:         * copies of the Software, and to permit persons to whom the Software is
0009:         * furnished to do so, subject to the following conditions:
0010:         *
0011:         * The above copyright notice and this permission notice shall be included in
0012:         * all copies or substantial portions of the Software.
0013:         *
0014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0020:         * SOFTWARE.
0021:         */package com.liferay.portal.service.persistence;
0022:
0023:        import com.liferay.portal.NoSuchOrganizationException;
0024:        import com.liferay.portal.SystemException;
0025:        import com.liferay.portal.kernel.dao.DynamicQuery;
0026:        import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
0027:        import com.liferay.portal.kernel.util.GetterUtil;
0028:        import com.liferay.portal.kernel.util.OrderByComparator;
0029:        import com.liferay.portal.kernel.util.StringMaker;
0030:        import com.liferay.portal.kernel.util.StringPool;
0031:        import com.liferay.portal.kernel.util.Validator;
0032:        import com.liferay.portal.model.ModelListener;
0033:        import com.liferay.portal.model.Organization;
0034:        import com.liferay.portal.model.impl.OrganizationImpl;
0035:        import com.liferay.portal.model.impl.OrganizationModelImpl;
0036:        import com.liferay.portal.spring.hibernate.FinderCache;
0037:        import com.liferay.portal.spring.hibernate.HibernateUtil;
0038:        import com.liferay.portal.util.PropsUtil;
0039:
0040:        import com.liferay.util.dao.hibernate.QueryPos;
0041:        import com.liferay.util.dao.hibernate.QueryUtil;
0042:
0043:        import org.apache.commons.logging.Log;
0044:        import org.apache.commons.logging.LogFactory;
0045:
0046:        import org.hibernate.Hibernate;
0047:        import org.hibernate.Query;
0048:        import org.hibernate.SQLQuery;
0049:        import org.hibernate.Session;
0050:
0051:        import org.springframework.dao.DataAccessException;
0052:
0053:        import org.springframework.jdbc.core.SqlParameter;
0054:        import org.springframework.jdbc.object.MappingSqlQuery;
0055:        import org.springframework.jdbc.object.SqlUpdate;
0056:
0057:        import java.sql.ResultSet;
0058:        import java.sql.SQLException;
0059:        import java.sql.Types;
0060:
0061:        import java.util.Collections;
0062:        import java.util.Iterator;
0063:        import java.util.List;
0064:
0065:        /**
0066:         * <a href="OrganizationPersistenceImpl.java.html"><b><i>View Source</i></b></a>
0067:         *
0068:         * @author Brian Wing Shun Chan
0069:         *
0070:         */
0071:        public class OrganizationPersistenceImpl extends BasePersistence
0072:                implements  OrganizationPersistence {
0073:            public Organization create(long organizationId) {
0074:                Organization organization = new OrganizationImpl();
0075:
0076:                organization.setNew(true);
0077:                organization.setPrimaryKey(organizationId);
0078:
0079:                return organization;
0080:            }
0081:
0082:            public Organization remove(long organizationId)
0083:                    throws NoSuchOrganizationException, SystemException {
0084:                Session session = null;
0085:
0086:                try {
0087:                    session = openSession();
0088:
0089:                    Organization organization = (Organization) session.get(
0090:                            OrganizationImpl.class, new Long(organizationId));
0091:
0092:                    if (organization == null) {
0093:                        if (_log.isWarnEnabled()) {
0094:                            _log
0095:                                    .warn("No Organization exists with the primary key "
0096:                                            + organizationId);
0097:                        }
0098:
0099:                        throw new NoSuchOrganizationException(
0100:                                "No Organization exists with the primary key "
0101:                                        + organizationId);
0102:                    }
0103:
0104:                    return remove(organization);
0105:                } catch (NoSuchOrganizationException nsee) {
0106:                    throw nsee;
0107:                } catch (Exception e) {
0108:                    throw HibernateUtil.processException(e);
0109:                } finally {
0110:                    closeSession(session);
0111:                }
0112:            }
0113:
0114:            public Organization remove(Organization organization)
0115:                    throws SystemException {
0116:                ModelListener listener = _getListener();
0117:
0118:                if (listener != null) {
0119:                    listener.onBeforeRemove(organization);
0120:                }
0121:
0122:                organization = removeImpl(organization);
0123:
0124:                if (listener != null) {
0125:                    listener.onAfterRemove(organization);
0126:                }
0127:
0128:                return organization;
0129:            }
0130:
0131:            protected Organization removeImpl(Organization organization)
0132:                    throws SystemException {
0133:                try {
0134:                    clearGroups.clear(organization.getPrimaryKey());
0135:                } catch (Exception e) {
0136:                    throw HibernateUtil.processException(e);
0137:                } finally {
0138:                    FinderCache.clearCache("Groups_Orgs");
0139:                }
0140:
0141:                try {
0142:                    clearUsers.clear(organization.getPrimaryKey());
0143:                } catch (Exception e) {
0144:                    throw HibernateUtil.processException(e);
0145:                } finally {
0146:                    FinderCache.clearCache("Users_Orgs");
0147:                }
0148:
0149:                Session session = null;
0150:
0151:                try {
0152:                    session = openSession();
0153:
0154:                    session.delete(organization);
0155:
0156:                    session.flush();
0157:
0158:                    return organization;
0159:                } catch (Exception e) {
0160:                    throw HibernateUtil.processException(e);
0161:                } finally {
0162:                    closeSession(session);
0163:
0164:                    FinderCache.clearCache(Organization.class.getName());
0165:                }
0166:            }
0167:
0168:            public Organization update(Organization organization)
0169:                    throws SystemException {
0170:                return update(organization, false);
0171:            }
0172:
0173:            public Organization update(Organization organization, boolean merge)
0174:                    throws SystemException {
0175:                ModelListener listener = _getListener();
0176:
0177:                boolean isNew = organization.isNew();
0178:
0179:                if (listener != null) {
0180:                    if (isNew) {
0181:                        listener.onBeforeCreate(organization);
0182:                    } else {
0183:                        listener.onBeforeUpdate(organization);
0184:                    }
0185:                }
0186:
0187:                organization = updateImpl(organization, merge);
0188:
0189:                if (listener != null) {
0190:                    if (isNew) {
0191:                        listener.onAfterCreate(organization);
0192:                    } else {
0193:                        listener.onAfterUpdate(organization);
0194:                    }
0195:                }
0196:
0197:                return organization;
0198:            }
0199:
0200:            public Organization updateImpl(
0201:                    com.liferay.portal.model.Organization organization,
0202:                    boolean merge) throws SystemException {
0203:                FinderCache.clearCache("Groups_Orgs");
0204:                FinderCache.clearCache("Users_Orgs");
0205:
0206:                Session session = null;
0207:
0208:                try {
0209:                    session = openSession();
0210:
0211:                    if (merge) {
0212:                        session.merge(organization);
0213:                    } else {
0214:                        if (organization.isNew()) {
0215:                            session.save(organization);
0216:                        }
0217:                    }
0218:
0219:                    session.flush();
0220:
0221:                    organization.setNew(false);
0222:
0223:                    return organization;
0224:                } catch (Exception e) {
0225:                    throw HibernateUtil.processException(e);
0226:                } finally {
0227:                    closeSession(session);
0228:
0229:                    FinderCache.clearCache(Organization.class.getName());
0230:                }
0231:            }
0232:
0233:            public Organization findByPrimaryKey(long organizationId)
0234:                    throws NoSuchOrganizationException, SystemException {
0235:                Organization organization = fetchByPrimaryKey(organizationId);
0236:
0237:                if (organization == null) {
0238:                    if (_log.isWarnEnabled()) {
0239:                        _log
0240:                                .warn("No Organization exists with the primary key "
0241:                                        + organizationId);
0242:                    }
0243:
0244:                    throw new NoSuchOrganizationException(
0245:                            "No Organization exists with the primary key "
0246:                                    + organizationId);
0247:                }
0248:
0249:                return organization;
0250:            }
0251:
0252:            public Organization fetchByPrimaryKey(long organizationId)
0253:                    throws SystemException {
0254:                Session session = null;
0255:
0256:                try {
0257:                    session = openSession();
0258:
0259:                    return (Organization) session.get(OrganizationImpl.class,
0260:                            new Long(organizationId));
0261:                } catch (Exception e) {
0262:                    throw HibernateUtil.processException(e);
0263:                } finally {
0264:                    closeSession(session);
0265:                }
0266:            }
0267:
0268:            public List findByCompanyId(long companyId) throws SystemException {
0269:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
0270:                String finderClassName = Organization.class.getName();
0271:                String finderMethodName = "findByCompanyId";
0272:                String[] finderParams = new String[] { Long.class.getName() };
0273:                Object[] finderArgs = new Object[] { new Long(companyId) };
0274:
0275:                Object result = null;
0276:
0277:                if (finderClassNameCacheEnabled) {
0278:                    result = FinderCache.getResult(finderClassName,
0279:                            finderMethodName, finderParams, finderArgs,
0280:                            getSessionFactory());
0281:                }
0282:
0283:                if (result == null) {
0284:                    Session session = null;
0285:
0286:                    try {
0287:                        session = openSession();
0288:
0289:                        StringMaker query = new StringMaker();
0290:
0291:                        query
0292:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
0293:
0294:                        query.append("companyId = ?");
0295:
0296:                        query.append(" ");
0297:
0298:                        query.append("ORDER BY ");
0299:
0300:                        query.append("name ASC");
0301:
0302:                        Query q = session.createQuery(query.toString());
0303:
0304:                        int queryPos = 0;
0305:
0306:                        q.setLong(queryPos++, companyId);
0307:
0308:                        List list = q.list();
0309:
0310:                        FinderCache.putResult(finderClassNameCacheEnabled,
0311:                                finderClassName, finderMethodName,
0312:                                finderParams, finderArgs, list);
0313:
0314:                        return list;
0315:                    } catch (Exception e) {
0316:                        throw HibernateUtil.processException(e);
0317:                    } finally {
0318:                        closeSession(session);
0319:                    }
0320:                } else {
0321:                    return (List) result;
0322:                }
0323:            }
0324:
0325:            public List findByCompanyId(long companyId, int begin, int end)
0326:                    throws SystemException {
0327:                return findByCompanyId(companyId, begin, end, null);
0328:            }
0329:
0330:            public List findByCompanyId(long companyId, int begin, int end,
0331:                    OrderByComparator obc) throws SystemException {
0332:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
0333:                String finderClassName = Organization.class.getName();
0334:                String finderMethodName = "findByCompanyId";
0335:                String[] finderParams = new String[] { Long.class.getName(),
0336:
0337:                "java.lang.Integer", "java.lang.Integer",
0338:                        "com.liferay.portal.kernel.util.OrderByComparator" };
0339:                Object[] finderArgs = new Object[] { new Long(companyId),
0340:
0341:                String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0342:
0343:                Object result = null;
0344:
0345:                if (finderClassNameCacheEnabled) {
0346:                    result = FinderCache.getResult(finderClassName,
0347:                            finderMethodName, finderParams, finderArgs,
0348:                            getSessionFactory());
0349:                }
0350:
0351:                if (result == null) {
0352:                    Session session = null;
0353:
0354:                    try {
0355:                        session = openSession();
0356:
0357:                        StringMaker query = new StringMaker();
0358:
0359:                        query
0360:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
0361:
0362:                        query.append("companyId = ?");
0363:
0364:                        query.append(" ");
0365:
0366:                        if (obc != null) {
0367:                            query.append("ORDER BY ");
0368:                            query.append(obc.getOrderBy());
0369:                        }
0370:
0371:                        else {
0372:                            query.append("ORDER BY ");
0373:
0374:                            query.append("name ASC");
0375:                        }
0376:
0377:                        Query q = session.createQuery(query.toString());
0378:
0379:                        int queryPos = 0;
0380:
0381:                        q.setLong(queryPos++, companyId);
0382:
0383:                        List list = QueryUtil.list(q, getDialect(), begin, end);
0384:
0385:                        FinderCache.putResult(finderClassNameCacheEnabled,
0386:                                finderClassName, finderMethodName,
0387:                                finderParams, finderArgs, list);
0388:
0389:                        return list;
0390:                    } catch (Exception e) {
0391:                        throw HibernateUtil.processException(e);
0392:                    } finally {
0393:                        closeSession(session);
0394:                    }
0395:                } else {
0396:                    return (List) result;
0397:                }
0398:            }
0399:
0400:            public Organization findByCompanyId_First(long companyId,
0401:                    OrderByComparator obc) throws NoSuchOrganizationException,
0402:                    SystemException {
0403:                List list = findByCompanyId(companyId, 0, 1, obc);
0404:
0405:                if (list.size() == 0) {
0406:                    StringMaker msg = new StringMaker();
0407:
0408:                    msg.append("No Organization exists with the key {");
0409:
0410:                    msg.append("companyId=" + companyId);
0411:
0412:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0413:
0414:                    throw new NoSuchOrganizationException(msg.toString());
0415:                } else {
0416:                    return (Organization) list.get(0);
0417:                }
0418:            }
0419:
0420:            public Organization findByCompanyId_Last(long companyId,
0421:                    OrderByComparator obc) throws NoSuchOrganizationException,
0422:                    SystemException {
0423:                int count = countByCompanyId(companyId);
0424:
0425:                List list = findByCompanyId(companyId, count - 1, count, obc);
0426:
0427:                if (list.size() == 0) {
0428:                    StringMaker msg = new StringMaker();
0429:
0430:                    msg.append("No Organization exists with the key {");
0431:
0432:                    msg.append("companyId=" + companyId);
0433:
0434:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0435:
0436:                    throw new NoSuchOrganizationException(msg.toString());
0437:                } else {
0438:                    return (Organization) list.get(0);
0439:                }
0440:            }
0441:
0442:            public Organization[] findByCompanyId_PrevAndNext(
0443:                    long organizationId, long companyId, OrderByComparator obc)
0444:                    throws NoSuchOrganizationException, SystemException {
0445:                Organization organization = findByPrimaryKey(organizationId);
0446:
0447:                int count = countByCompanyId(companyId);
0448:
0449:                Session session = null;
0450:
0451:                try {
0452:                    session = openSession();
0453:
0454:                    StringMaker query = new StringMaker();
0455:
0456:                    query
0457:                            .append("FROM com.liferay.portal.model.Organization WHERE ");
0458:
0459:                    query.append("companyId = ?");
0460:
0461:                    query.append(" ");
0462:
0463:                    if (obc != null) {
0464:                        query.append("ORDER BY ");
0465:                        query.append(obc.getOrderBy());
0466:                    }
0467:
0468:                    else {
0469:                        query.append("ORDER BY ");
0470:
0471:                        query.append("name ASC");
0472:                    }
0473:
0474:                    Query q = session.createQuery(query.toString());
0475:
0476:                    int queryPos = 0;
0477:
0478:                    q.setLong(queryPos++, companyId);
0479:
0480:                    Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0481:                            organization);
0482:
0483:                    Organization[] array = new OrganizationImpl[3];
0484:
0485:                    array[0] = (Organization) objArray[0];
0486:                    array[1] = (Organization) objArray[1];
0487:                    array[2] = (Organization) objArray[2];
0488:
0489:                    return array;
0490:                } catch (Exception e) {
0491:                    throw HibernateUtil.processException(e);
0492:                } finally {
0493:                    closeSession(session);
0494:                }
0495:            }
0496:
0497:            public List findByLocations(long companyId) throws SystemException {
0498:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
0499:                String finderClassName = Organization.class.getName();
0500:                String finderMethodName = "findByLocations";
0501:                String[] finderParams = new String[] { Long.class.getName() };
0502:                Object[] finderArgs = new Object[] { new Long(companyId) };
0503:
0504:                Object result = null;
0505:
0506:                if (finderClassNameCacheEnabled) {
0507:                    result = FinderCache.getResult(finderClassName,
0508:                            finderMethodName, finderParams, finderArgs,
0509:                            getSessionFactory());
0510:                }
0511:
0512:                if (result == null) {
0513:                    Session session = null;
0514:
0515:                    try {
0516:                        session = openSession();
0517:
0518:                        StringMaker query = new StringMaker();
0519:
0520:                        query
0521:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
0522:
0523:                        query.append("companyId = ?");
0524:
0525:                        query.append(" AND parentOrganizationId != 0 ");
0526:
0527:                        query.append("ORDER BY ");
0528:
0529:                        query.append("name ASC");
0530:
0531:                        Query q = session.createQuery(query.toString());
0532:
0533:                        int queryPos = 0;
0534:
0535:                        q.setLong(queryPos++, companyId);
0536:
0537:                        List list = q.list();
0538:
0539:                        FinderCache.putResult(finderClassNameCacheEnabled,
0540:                                finderClassName, finderMethodName,
0541:                                finderParams, finderArgs, list);
0542:
0543:                        return list;
0544:                    } catch (Exception e) {
0545:                        throw HibernateUtil.processException(e);
0546:                    } finally {
0547:                        closeSession(session);
0548:                    }
0549:                } else {
0550:                    return (List) result;
0551:                }
0552:            }
0553:
0554:            public List findByLocations(long companyId, int begin, int end)
0555:                    throws SystemException {
0556:                return findByLocations(companyId, begin, end, null);
0557:            }
0558:
0559:            public List findByLocations(long companyId, int begin, int end,
0560:                    OrderByComparator obc) throws SystemException {
0561:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
0562:                String finderClassName = Organization.class.getName();
0563:                String finderMethodName = "findByLocations";
0564:                String[] finderParams = new String[] { Long.class.getName(),
0565:
0566:                "java.lang.Integer", "java.lang.Integer",
0567:                        "com.liferay.portal.kernel.util.OrderByComparator" };
0568:                Object[] finderArgs = new Object[] { new Long(companyId),
0569:
0570:                String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0571:
0572:                Object result = null;
0573:
0574:                if (finderClassNameCacheEnabled) {
0575:                    result = FinderCache.getResult(finderClassName,
0576:                            finderMethodName, finderParams, finderArgs,
0577:                            getSessionFactory());
0578:                }
0579:
0580:                if (result == null) {
0581:                    Session session = null;
0582:
0583:                    try {
0584:                        session = openSession();
0585:
0586:                        StringMaker query = new StringMaker();
0587:
0588:                        query
0589:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
0590:
0591:                        query.append("companyId = ?");
0592:
0593:                        query.append(" AND parentOrganizationId != 0 ");
0594:
0595:                        if (obc != null) {
0596:                            query.append("ORDER BY ");
0597:                            query.append(obc.getOrderBy());
0598:                        }
0599:
0600:                        else {
0601:                            query.append("ORDER BY ");
0602:
0603:                            query.append("name ASC");
0604:                        }
0605:
0606:                        Query q = session.createQuery(query.toString());
0607:
0608:                        int queryPos = 0;
0609:
0610:                        q.setLong(queryPos++, companyId);
0611:
0612:                        List list = QueryUtil.list(q, getDialect(), begin, end);
0613:
0614:                        FinderCache.putResult(finderClassNameCacheEnabled,
0615:                                finderClassName, finderMethodName,
0616:                                finderParams, finderArgs, list);
0617:
0618:                        return list;
0619:                    } catch (Exception e) {
0620:                        throw HibernateUtil.processException(e);
0621:                    } finally {
0622:                        closeSession(session);
0623:                    }
0624:                } else {
0625:                    return (List) result;
0626:                }
0627:            }
0628:
0629:            public Organization findByLocations_First(long companyId,
0630:                    OrderByComparator obc) throws NoSuchOrganizationException,
0631:                    SystemException {
0632:                List list = findByLocations(companyId, 0, 1, obc);
0633:
0634:                if (list.size() == 0) {
0635:                    StringMaker msg = new StringMaker();
0636:
0637:                    msg.append("No Organization exists with the key {");
0638:
0639:                    msg.append("companyId=" + companyId);
0640:
0641:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0642:
0643:                    throw new NoSuchOrganizationException(msg.toString());
0644:                } else {
0645:                    return (Organization) list.get(0);
0646:                }
0647:            }
0648:
0649:            public Organization findByLocations_Last(long companyId,
0650:                    OrderByComparator obc) throws NoSuchOrganizationException,
0651:                    SystemException {
0652:                int count = countByLocations(companyId);
0653:
0654:                List list = findByLocations(companyId, count - 1, count, obc);
0655:
0656:                if (list.size() == 0) {
0657:                    StringMaker msg = new StringMaker();
0658:
0659:                    msg.append("No Organization exists with the key {");
0660:
0661:                    msg.append("companyId=" + companyId);
0662:
0663:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0664:
0665:                    throw new NoSuchOrganizationException(msg.toString());
0666:                } else {
0667:                    return (Organization) list.get(0);
0668:                }
0669:            }
0670:
0671:            public Organization[] findByLocations_PrevAndNext(
0672:                    long organizationId, long companyId, OrderByComparator obc)
0673:                    throws NoSuchOrganizationException, SystemException {
0674:                Organization organization = findByPrimaryKey(organizationId);
0675:
0676:                int count = countByLocations(companyId);
0677:
0678:                Session session = null;
0679:
0680:                try {
0681:                    session = openSession();
0682:
0683:                    StringMaker query = new StringMaker();
0684:
0685:                    query
0686:                            .append("FROM com.liferay.portal.model.Organization WHERE ");
0687:
0688:                    query.append("companyId = ?");
0689:
0690:                    query.append(" AND parentOrganizationId != 0 ");
0691:
0692:                    if (obc != null) {
0693:                        query.append("ORDER BY ");
0694:                        query.append(obc.getOrderBy());
0695:                    }
0696:
0697:                    else {
0698:                        query.append("ORDER BY ");
0699:
0700:                        query.append("name ASC");
0701:                    }
0702:
0703:                    Query q = session.createQuery(query.toString());
0704:
0705:                    int queryPos = 0;
0706:
0707:                    q.setLong(queryPos++, companyId);
0708:
0709:                    Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0710:                            organization);
0711:
0712:                    Organization[] array = new OrganizationImpl[3];
0713:
0714:                    array[0] = (Organization) objArray[0];
0715:                    array[1] = (Organization) objArray[1];
0716:                    array[2] = (Organization) objArray[2];
0717:
0718:                    return array;
0719:                } catch (Exception e) {
0720:                    throw HibernateUtil.processException(e);
0721:                } finally {
0722:                    closeSession(session);
0723:                }
0724:            }
0725:
0726:            public List findByC_P(long companyId, long parentOrganizationId)
0727:                    throws SystemException {
0728:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
0729:                String finderClassName = Organization.class.getName();
0730:                String finderMethodName = "findByC_P";
0731:                String[] finderParams = new String[] { Long.class.getName(),
0732:                        Long.class.getName() };
0733:                Object[] finderArgs = new Object[] { new Long(companyId),
0734:                        new Long(parentOrganizationId) };
0735:
0736:                Object result = null;
0737:
0738:                if (finderClassNameCacheEnabled) {
0739:                    result = FinderCache.getResult(finderClassName,
0740:                            finderMethodName, finderParams, finderArgs,
0741:                            getSessionFactory());
0742:                }
0743:
0744:                if (result == null) {
0745:                    Session session = null;
0746:
0747:                    try {
0748:                        session = openSession();
0749:
0750:                        StringMaker query = new StringMaker();
0751:
0752:                        query
0753:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
0754:
0755:                        query.append("companyId = ?");
0756:
0757:                        query.append(" AND ");
0758:
0759:                        query.append("parentOrganizationId = ?");
0760:
0761:                        query.append(" ");
0762:
0763:                        query.append("ORDER BY ");
0764:
0765:                        query.append("name ASC");
0766:
0767:                        Query q = session.createQuery(query.toString());
0768:
0769:                        int queryPos = 0;
0770:
0771:                        q.setLong(queryPos++, companyId);
0772:
0773:                        q.setLong(queryPos++, parentOrganizationId);
0774:
0775:                        List list = q.list();
0776:
0777:                        FinderCache.putResult(finderClassNameCacheEnabled,
0778:                                finderClassName, finderMethodName,
0779:                                finderParams, finderArgs, list);
0780:
0781:                        return list;
0782:                    } catch (Exception e) {
0783:                        throw HibernateUtil.processException(e);
0784:                    } finally {
0785:                        closeSession(session);
0786:                    }
0787:                } else {
0788:                    return (List) result;
0789:                }
0790:            }
0791:
0792:            public List findByC_P(long companyId, long parentOrganizationId,
0793:                    int begin, int end) throws SystemException {
0794:                return findByC_P(companyId, parentOrganizationId, begin, end,
0795:                        null);
0796:            }
0797:
0798:            public List findByC_P(long companyId, long parentOrganizationId,
0799:                    int begin, int end, OrderByComparator obc)
0800:                    throws SystemException {
0801:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
0802:                String finderClassName = Organization.class.getName();
0803:                String finderMethodName = "findByC_P";
0804:                String[] finderParams = new String[] { Long.class.getName(),
0805:                        Long.class.getName(),
0806:
0807:                        "java.lang.Integer", "java.lang.Integer",
0808:                        "com.liferay.portal.kernel.util.OrderByComparator" };
0809:                Object[] finderArgs = new Object[] { new Long(companyId),
0810:                        new Long(parentOrganizationId),
0811:
0812:                        String.valueOf(begin), String.valueOf(end),
0813:                        String.valueOf(obc) };
0814:
0815:                Object result = null;
0816:
0817:                if (finderClassNameCacheEnabled) {
0818:                    result = FinderCache.getResult(finderClassName,
0819:                            finderMethodName, finderParams, finderArgs,
0820:                            getSessionFactory());
0821:                }
0822:
0823:                if (result == null) {
0824:                    Session session = null;
0825:
0826:                    try {
0827:                        session = openSession();
0828:
0829:                        StringMaker query = new StringMaker();
0830:
0831:                        query
0832:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
0833:
0834:                        query.append("companyId = ?");
0835:
0836:                        query.append(" AND ");
0837:
0838:                        query.append("parentOrganizationId = ?");
0839:
0840:                        query.append(" ");
0841:
0842:                        if (obc != null) {
0843:                            query.append("ORDER BY ");
0844:                            query.append(obc.getOrderBy());
0845:                        }
0846:
0847:                        else {
0848:                            query.append("ORDER BY ");
0849:
0850:                            query.append("name ASC");
0851:                        }
0852:
0853:                        Query q = session.createQuery(query.toString());
0854:
0855:                        int queryPos = 0;
0856:
0857:                        q.setLong(queryPos++, companyId);
0858:
0859:                        q.setLong(queryPos++, parentOrganizationId);
0860:
0861:                        List list = QueryUtil.list(q, getDialect(), begin, end);
0862:
0863:                        FinderCache.putResult(finderClassNameCacheEnabled,
0864:                                finderClassName, finderMethodName,
0865:                                finderParams, finderArgs, list);
0866:
0867:                        return list;
0868:                    } catch (Exception e) {
0869:                        throw HibernateUtil.processException(e);
0870:                    } finally {
0871:                        closeSession(session);
0872:                    }
0873:                } else {
0874:                    return (List) result;
0875:                }
0876:            }
0877:
0878:            public Organization findByC_P_First(long companyId,
0879:                    long parentOrganizationId, OrderByComparator obc)
0880:                    throws NoSuchOrganizationException, SystemException {
0881:                List list = findByC_P(companyId, parentOrganizationId, 0, 1,
0882:                        obc);
0883:
0884:                if (list.size() == 0) {
0885:                    StringMaker msg = new StringMaker();
0886:
0887:                    msg.append("No Organization exists with the key {");
0888:
0889:                    msg.append("companyId=" + companyId);
0890:
0891:                    msg.append(", ");
0892:                    msg.append("parentOrganizationId=" + parentOrganizationId);
0893:
0894:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0895:
0896:                    throw new NoSuchOrganizationException(msg.toString());
0897:                } else {
0898:                    return (Organization) list.get(0);
0899:                }
0900:            }
0901:
0902:            public Organization findByC_P_Last(long companyId,
0903:                    long parentOrganizationId, OrderByComparator obc)
0904:                    throws NoSuchOrganizationException, SystemException {
0905:                int count = countByC_P(companyId, parentOrganizationId);
0906:
0907:                List list = findByC_P(companyId, parentOrganizationId,
0908:                        count - 1, count, obc);
0909:
0910:                if (list.size() == 0) {
0911:                    StringMaker msg = new StringMaker();
0912:
0913:                    msg.append("No Organization exists with the key {");
0914:
0915:                    msg.append("companyId=" + companyId);
0916:
0917:                    msg.append(", ");
0918:                    msg.append("parentOrganizationId=" + parentOrganizationId);
0919:
0920:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0921:
0922:                    throw new NoSuchOrganizationException(msg.toString());
0923:                } else {
0924:                    return (Organization) list.get(0);
0925:                }
0926:            }
0927:
0928:            public Organization[] findByC_P_PrevAndNext(long organizationId,
0929:                    long companyId, long parentOrganizationId,
0930:                    OrderByComparator obc) throws NoSuchOrganizationException,
0931:                    SystemException {
0932:                Organization organization = findByPrimaryKey(organizationId);
0933:
0934:                int count = countByC_P(companyId, parentOrganizationId);
0935:
0936:                Session session = null;
0937:
0938:                try {
0939:                    session = openSession();
0940:
0941:                    StringMaker query = new StringMaker();
0942:
0943:                    query
0944:                            .append("FROM com.liferay.portal.model.Organization WHERE ");
0945:
0946:                    query.append("companyId = ?");
0947:
0948:                    query.append(" AND ");
0949:
0950:                    query.append("parentOrganizationId = ?");
0951:
0952:                    query.append(" ");
0953:
0954:                    if (obc != null) {
0955:                        query.append("ORDER BY ");
0956:                        query.append(obc.getOrderBy());
0957:                    }
0958:
0959:                    else {
0960:                        query.append("ORDER BY ");
0961:
0962:                        query.append("name ASC");
0963:                    }
0964:
0965:                    Query q = session.createQuery(query.toString());
0966:
0967:                    int queryPos = 0;
0968:
0969:                    q.setLong(queryPos++, companyId);
0970:
0971:                    q.setLong(queryPos++, parentOrganizationId);
0972:
0973:                    Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0974:                            organization);
0975:
0976:                    Organization[] array = new OrganizationImpl[3];
0977:
0978:                    array[0] = (Organization) objArray[0];
0979:                    array[1] = (Organization) objArray[1];
0980:                    array[2] = (Organization) objArray[2];
0981:
0982:                    return array;
0983:                } catch (Exception e) {
0984:                    throw HibernateUtil.processException(e);
0985:                } finally {
0986:                    closeSession(session);
0987:                }
0988:            }
0989:
0990:            public Organization findByC_N(long companyId, String name)
0991:                    throws NoSuchOrganizationException, SystemException {
0992:                Organization organization = fetchByC_N(companyId, name);
0993:
0994:                if (organization == null) {
0995:                    StringMaker msg = new StringMaker();
0996:
0997:                    msg.append("No Organization exists with the key {");
0998:
0999:                    msg.append("companyId=" + companyId);
1000:
1001:                    msg.append(", ");
1002:                    msg.append("name=" + name);
1003:
1004:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1005:
1006:                    if (_log.isWarnEnabled()) {
1007:                        _log.warn(msg.toString());
1008:                    }
1009:
1010:                    throw new NoSuchOrganizationException(msg.toString());
1011:                }
1012:
1013:                return organization;
1014:            }
1015:
1016:            public Organization fetchByC_N(long companyId, String name)
1017:                    throws SystemException {
1018:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1019:                String finderClassName = Organization.class.getName();
1020:                String finderMethodName = "fetchByC_N";
1021:                String[] finderParams = new String[] { Long.class.getName(),
1022:                        String.class.getName() };
1023:                Object[] finderArgs = new Object[] { new Long(companyId), name };
1024:
1025:                Object result = null;
1026:
1027:                if (finderClassNameCacheEnabled) {
1028:                    result = FinderCache.getResult(finderClassName,
1029:                            finderMethodName, finderParams, finderArgs,
1030:                            getSessionFactory());
1031:                }
1032:
1033:                if (result == null) {
1034:                    Session session = null;
1035:
1036:                    try {
1037:                        session = openSession();
1038:
1039:                        StringMaker query = new StringMaker();
1040:
1041:                        query
1042:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
1043:
1044:                        query.append("companyId = ?");
1045:
1046:                        query.append(" AND ");
1047:
1048:                        if (name == null) {
1049:                            query.append("name IS NULL");
1050:                        } else {
1051:                            query.append("name = ?");
1052:                        }
1053:
1054:                        query.append(" ");
1055:
1056:                        query.append("ORDER BY ");
1057:
1058:                        query.append("name ASC");
1059:
1060:                        Query q = session.createQuery(query.toString());
1061:
1062:                        int queryPos = 0;
1063:
1064:                        q.setLong(queryPos++, companyId);
1065:
1066:                        if (name != null) {
1067:                            q.setString(queryPos++, name);
1068:                        }
1069:
1070:                        List list = q.list();
1071:
1072:                        FinderCache.putResult(finderClassNameCacheEnabled,
1073:                                finderClassName, finderMethodName,
1074:                                finderParams, finderArgs, list);
1075:
1076:                        if (list.size() == 0) {
1077:                            return null;
1078:                        } else {
1079:                            return (Organization) list.get(0);
1080:                        }
1081:                    } catch (Exception e) {
1082:                        throw HibernateUtil.processException(e);
1083:                    } finally {
1084:                        closeSession(session);
1085:                    }
1086:                } else {
1087:                    List list = (List) result;
1088:
1089:                    if (list.size() == 0) {
1090:                        return null;
1091:                    } else {
1092:                        return (Organization) list.get(0);
1093:                    }
1094:                }
1095:            }
1096:
1097:            public List findWithDynamicQuery(
1098:                    DynamicQueryInitializer queryInitializer)
1099:                    throws SystemException {
1100:                Session session = null;
1101:
1102:                try {
1103:                    session = openSession();
1104:
1105:                    DynamicQuery query = queryInitializer.initialize(session);
1106:
1107:                    return query.list();
1108:                } catch (Exception e) {
1109:                    throw HibernateUtil.processException(e);
1110:                } finally {
1111:                    closeSession(session);
1112:                }
1113:            }
1114:
1115:            public List findWithDynamicQuery(
1116:                    DynamicQueryInitializer queryInitializer, int begin, int end)
1117:                    throws SystemException {
1118:                Session session = null;
1119:
1120:                try {
1121:                    session = openSession();
1122:
1123:                    DynamicQuery query = queryInitializer.initialize(session);
1124:
1125:                    query.setLimit(begin, end);
1126:
1127:                    return query.list();
1128:                } catch (Exception e) {
1129:                    throw HibernateUtil.processException(e);
1130:                } finally {
1131:                    closeSession(session);
1132:                }
1133:            }
1134:
1135:            public List findAll() throws SystemException {
1136:                return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1137:            }
1138:
1139:            public List findAll(int begin, int end) throws SystemException {
1140:                return findAll(begin, end, null);
1141:            }
1142:
1143:            public List findAll(int begin, int end, OrderByComparator obc)
1144:                    throws SystemException {
1145:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1146:                String finderClassName = Organization.class.getName();
1147:                String finderMethodName = "findAll";
1148:                String[] finderParams = new String[] { "java.lang.Integer",
1149:                        "java.lang.Integer",
1150:                        "com.liferay.portal.kernel.util.OrderByComparator" };
1151:                Object[] finderArgs = new Object[] { String.valueOf(begin),
1152:                        String.valueOf(end), String.valueOf(obc) };
1153:
1154:                Object result = null;
1155:
1156:                if (finderClassNameCacheEnabled) {
1157:                    result = FinderCache.getResult(finderClassName,
1158:                            finderMethodName, finderParams, finderArgs,
1159:                            getSessionFactory());
1160:                }
1161:
1162:                if (result == null) {
1163:                    Session session = null;
1164:
1165:                    try {
1166:                        session = openSession();
1167:
1168:                        StringMaker query = new StringMaker();
1169:
1170:                        query
1171:                                .append("FROM com.liferay.portal.model.Organization ");
1172:
1173:                        if (obc != null) {
1174:                            query.append("ORDER BY ");
1175:                            query.append(obc.getOrderBy());
1176:                        }
1177:
1178:                        else {
1179:                            query.append("ORDER BY ");
1180:
1181:                            query.append("name ASC");
1182:                        }
1183:
1184:                        Query q = session.createQuery(query.toString());
1185:
1186:                        List list = QueryUtil.list(q, getDialect(), begin, end);
1187:
1188:                        if (obc == null) {
1189:                            Collections.sort(list);
1190:                        }
1191:
1192:                        FinderCache.putResult(finderClassNameCacheEnabled,
1193:                                finderClassName, finderMethodName,
1194:                                finderParams, finderArgs, list);
1195:
1196:                        return list;
1197:                    } catch (Exception e) {
1198:                        throw HibernateUtil.processException(e);
1199:                    } finally {
1200:                        closeSession(session);
1201:                    }
1202:                } else {
1203:                    return (List) result;
1204:                }
1205:            }
1206:
1207:            public void removeByCompanyId(long companyId)
1208:                    throws SystemException {
1209:                Iterator itr = findByCompanyId(companyId).iterator();
1210:
1211:                while (itr.hasNext()) {
1212:                    Organization organization = (Organization) itr.next();
1213:
1214:                    remove(organization);
1215:                }
1216:            }
1217:
1218:            public void removeByLocations(long companyId)
1219:                    throws SystemException {
1220:                Iterator itr = findByLocations(companyId).iterator();
1221:
1222:                while (itr.hasNext()) {
1223:                    Organization organization = (Organization) itr.next();
1224:
1225:                    remove(organization);
1226:                }
1227:            }
1228:
1229:            public void removeByC_P(long companyId, long parentOrganizationId)
1230:                    throws SystemException {
1231:                Iterator itr = findByC_P(companyId, parentOrganizationId)
1232:                        .iterator();
1233:
1234:                while (itr.hasNext()) {
1235:                    Organization organization = (Organization) itr.next();
1236:
1237:                    remove(organization);
1238:                }
1239:            }
1240:
1241:            public void removeByC_N(long companyId, String name)
1242:                    throws NoSuchOrganizationException, SystemException {
1243:                Organization organization = findByC_N(companyId, name);
1244:
1245:                remove(organization);
1246:            }
1247:
1248:            public void removeAll() throws SystemException {
1249:                Iterator itr = findAll().iterator();
1250:
1251:                while (itr.hasNext()) {
1252:                    remove((Organization) itr.next());
1253:                }
1254:            }
1255:
1256:            public int countByCompanyId(long companyId) throws SystemException {
1257:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1258:                String finderClassName = Organization.class.getName();
1259:                String finderMethodName = "countByCompanyId";
1260:                String[] finderParams = new String[] { Long.class.getName() };
1261:                Object[] finderArgs = new Object[] { new Long(companyId) };
1262:
1263:                Object result = null;
1264:
1265:                if (finderClassNameCacheEnabled) {
1266:                    result = FinderCache.getResult(finderClassName,
1267:                            finderMethodName, finderParams, finderArgs,
1268:                            getSessionFactory());
1269:                }
1270:
1271:                if (result == null) {
1272:                    Session session = null;
1273:
1274:                    try {
1275:                        session = openSession();
1276:
1277:                        StringMaker query = new StringMaker();
1278:
1279:                        query.append("SELECT COUNT(*) ");
1280:                        query
1281:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
1282:
1283:                        query.append("companyId = ?");
1284:
1285:                        query.append(" ");
1286:
1287:                        Query q = session.createQuery(query.toString());
1288:
1289:                        int queryPos = 0;
1290:
1291:                        q.setLong(queryPos++, companyId);
1292:
1293:                        Long count = null;
1294:
1295:                        Iterator itr = q.list().iterator();
1296:
1297:                        if (itr.hasNext()) {
1298:                            count = (Long) itr.next();
1299:                        }
1300:
1301:                        if (count == null) {
1302:                            count = new Long(0);
1303:                        }
1304:
1305:                        FinderCache.putResult(finderClassNameCacheEnabled,
1306:                                finderClassName, finderMethodName,
1307:                                finderParams, finderArgs, count);
1308:
1309:                        return count.intValue();
1310:                    } catch (Exception e) {
1311:                        throw HibernateUtil.processException(e);
1312:                    } finally {
1313:                        closeSession(session);
1314:                    }
1315:                } else {
1316:                    return ((Long) result).intValue();
1317:                }
1318:            }
1319:
1320:            public int countByLocations(long companyId) throws SystemException {
1321:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1322:                String finderClassName = Organization.class.getName();
1323:                String finderMethodName = "countByLocations";
1324:                String[] finderParams = new String[] { Long.class.getName() };
1325:                Object[] finderArgs = new Object[] { new Long(companyId) };
1326:
1327:                Object result = null;
1328:
1329:                if (finderClassNameCacheEnabled) {
1330:                    result = FinderCache.getResult(finderClassName,
1331:                            finderMethodName, finderParams, finderArgs,
1332:                            getSessionFactory());
1333:                }
1334:
1335:                if (result == null) {
1336:                    Session session = null;
1337:
1338:                    try {
1339:                        session = openSession();
1340:
1341:                        StringMaker query = new StringMaker();
1342:
1343:                        query.append("SELECT COUNT(*) ");
1344:                        query
1345:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
1346:
1347:                        query.append("companyId = ?");
1348:
1349:                        query.append(" AND parentOrganizationId != 0 ");
1350:
1351:                        Query q = session.createQuery(query.toString());
1352:
1353:                        int queryPos = 0;
1354:
1355:                        q.setLong(queryPos++, companyId);
1356:
1357:                        Long count = null;
1358:
1359:                        Iterator itr = q.list().iterator();
1360:
1361:                        if (itr.hasNext()) {
1362:                            count = (Long) itr.next();
1363:                        }
1364:
1365:                        if (count == null) {
1366:                            count = new Long(0);
1367:                        }
1368:
1369:                        FinderCache.putResult(finderClassNameCacheEnabled,
1370:                                finderClassName, finderMethodName,
1371:                                finderParams, finderArgs, count);
1372:
1373:                        return count.intValue();
1374:                    } catch (Exception e) {
1375:                        throw HibernateUtil.processException(e);
1376:                    } finally {
1377:                        closeSession(session);
1378:                    }
1379:                } else {
1380:                    return ((Long) result).intValue();
1381:                }
1382:            }
1383:
1384:            public int countByC_P(long companyId, long parentOrganizationId)
1385:                    throws SystemException {
1386:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1387:                String finderClassName = Organization.class.getName();
1388:                String finderMethodName = "countByC_P";
1389:                String[] finderParams = new String[] { Long.class.getName(),
1390:                        Long.class.getName() };
1391:                Object[] finderArgs = new Object[] { new Long(companyId),
1392:                        new Long(parentOrganizationId) };
1393:
1394:                Object result = null;
1395:
1396:                if (finderClassNameCacheEnabled) {
1397:                    result = FinderCache.getResult(finderClassName,
1398:                            finderMethodName, finderParams, finderArgs,
1399:                            getSessionFactory());
1400:                }
1401:
1402:                if (result == null) {
1403:                    Session session = null;
1404:
1405:                    try {
1406:                        session = openSession();
1407:
1408:                        StringMaker query = new StringMaker();
1409:
1410:                        query.append("SELECT COUNT(*) ");
1411:                        query
1412:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
1413:
1414:                        query.append("companyId = ?");
1415:
1416:                        query.append(" AND ");
1417:
1418:                        query.append("parentOrganizationId = ?");
1419:
1420:                        query.append(" ");
1421:
1422:                        Query q = session.createQuery(query.toString());
1423:
1424:                        int queryPos = 0;
1425:
1426:                        q.setLong(queryPos++, companyId);
1427:
1428:                        q.setLong(queryPos++, parentOrganizationId);
1429:
1430:                        Long count = null;
1431:
1432:                        Iterator itr = q.list().iterator();
1433:
1434:                        if (itr.hasNext()) {
1435:                            count = (Long) itr.next();
1436:                        }
1437:
1438:                        if (count == null) {
1439:                            count = new Long(0);
1440:                        }
1441:
1442:                        FinderCache.putResult(finderClassNameCacheEnabled,
1443:                                finderClassName, finderMethodName,
1444:                                finderParams, finderArgs, count);
1445:
1446:                        return count.intValue();
1447:                    } catch (Exception e) {
1448:                        throw HibernateUtil.processException(e);
1449:                    } finally {
1450:                        closeSession(session);
1451:                    }
1452:                } else {
1453:                    return ((Long) result).intValue();
1454:                }
1455:            }
1456:
1457:            public int countByC_N(long companyId, String name)
1458:                    throws SystemException {
1459:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1460:                String finderClassName = Organization.class.getName();
1461:                String finderMethodName = "countByC_N";
1462:                String[] finderParams = new String[] { Long.class.getName(),
1463:                        String.class.getName() };
1464:                Object[] finderArgs = new Object[] { new Long(companyId), name };
1465:
1466:                Object result = null;
1467:
1468:                if (finderClassNameCacheEnabled) {
1469:                    result = FinderCache.getResult(finderClassName,
1470:                            finderMethodName, finderParams, finderArgs,
1471:                            getSessionFactory());
1472:                }
1473:
1474:                if (result == null) {
1475:                    Session session = null;
1476:
1477:                    try {
1478:                        session = openSession();
1479:
1480:                        StringMaker query = new StringMaker();
1481:
1482:                        query.append("SELECT COUNT(*) ");
1483:                        query
1484:                                .append("FROM com.liferay.portal.model.Organization WHERE ");
1485:
1486:                        query.append("companyId = ?");
1487:
1488:                        query.append(" AND ");
1489:
1490:                        if (name == null) {
1491:                            query.append("name IS NULL");
1492:                        } else {
1493:                            query.append("name = ?");
1494:                        }
1495:
1496:                        query.append(" ");
1497:
1498:                        Query q = session.createQuery(query.toString());
1499:
1500:                        int queryPos = 0;
1501:
1502:                        q.setLong(queryPos++, companyId);
1503:
1504:                        if (name != null) {
1505:                            q.setString(queryPos++, name);
1506:                        }
1507:
1508:                        Long count = null;
1509:
1510:                        Iterator itr = q.list().iterator();
1511:
1512:                        if (itr.hasNext()) {
1513:                            count = (Long) itr.next();
1514:                        }
1515:
1516:                        if (count == null) {
1517:                            count = new Long(0);
1518:                        }
1519:
1520:                        FinderCache.putResult(finderClassNameCacheEnabled,
1521:                                finderClassName, finderMethodName,
1522:                                finderParams, finderArgs, count);
1523:
1524:                        return count.intValue();
1525:                    } catch (Exception e) {
1526:                        throw HibernateUtil.processException(e);
1527:                    } finally {
1528:                        closeSession(session);
1529:                    }
1530:                } else {
1531:                    return ((Long) result).intValue();
1532:                }
1533:            }
1534:
1535:            public int countAll() throws SystemException {
1536:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1537:                String finderClassName = Organization.class.getName();
1538:                String finderMethodName = "countAll";
1539:                String[] finderParams = new String[] {};
1540:                Object[] finderArgs = new Object[] {};
1541:
1542:                Object result = null;
1543:
1544:                if (finderClassNameCacheEnabled) {
1545:                    result = FinderCache.getResult(finderClassName,
1546:                            finderMethodName, finderParams, finderArgs,
1547:                            getSessionFactory());
1548:                }
1549:
1550:                if (result == null) {
1551:                    Session session = null;
1552:
1553:                    try {
1554:                        session = openSession();
1555:
1556:                        Query q = session
1557:                                .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.Organization");
1558:
1559:                        Long count = null;
1560:
1561:                        Iterator itr = q.list().iterator();
1562:
1563:                        if (itr.hasNext()) {
1564:                            count = (Long) itr.next();
1565:                        }
1566:
1567:                        if (count == null) {
1568:                            count = new Long(0);
1569:                        }
1570:
1571:                        FinderCache.putResult(finderClassNameCacheEnabled,
1572:                                finderClassName, finderMethodName,
1573:                                finderParams, finderArgs, count);
1574:
1575:                        return count.intValue();
1576:                    } catch (Exception e) {
1577:                        throw HibernateUtil.processException(e);
1578:                    } finally {
1579:                        closeSession(session);
1580:                    }
1581:                } else {
1582:                    return ((Long) result).intValue();
1583:                }
1584:            }
1585:
1586:            public List getGroups(long pk) throws NoSuchOrganizationException,
1587:                    SystemException {
1588:                return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1589:            }
1590:
1591:            public List getGroups(long pk, int begin, int end)
1592:                    throws NoSuchOrganizationException, SystemException {
1593:                return getGroups(pk, begin, end, null);
1594:            }
1595:
1596:            public List getGroups(long pk, int begin, int end,
1597:                    OrderByComparator obc) throws NoSuchOrganizationException,
1598:                    SystemException {
1599:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1600:                String finderClassName = "Groups_Orgs";
1601:                String finderMethodName = "getGroups";
1602:                String[] finderParams = new String[] { Long.class.getName(),
1603:                        "java.lang.Integer", "java.lang.Integer",
1604:                        "com.liferay.portal.kernel.util.OrderByComparator" };
1605:                Object[] finderArgs = new Object[] { new Long(pk),
1606:                        String.valueOf(begin), String.valueOf(end),
1607:                        String.valueOf(obc) };
1608:
1609:                Object result = null;
1610:
1611:                if (finderClassNameCacheEnabled) {
1612:                    result = FinderCache.getResult(finderClassName,
1613:                            finderMethodName, finderParams, finderArgs,
1614:                            getSessionFactory());
1615:                }
1616:
1617:                if (result == null) {
1618:                    Session session = null;
1619:
1620:                    try {
1621:                        session = HibernateUtil.openSession();
1622:
1623:                        StringMaker sm = new StringMaker();
1624:
1625:                        sm.append(_SQL_GETGROUPS);
1626:
1627:                        if (obc != null) {
1628:                            sm.append("ORDER BY ");
1629:                            sm.append(obc.getOrderBy());
1630:                        }
1631:
1632:                        else {
1633:                            sm.append("ORDER BY ");
1634:
1635:                            sm.append("Group_.name ASC");
1636:                        }
1637:
1638:                        String sql = sm.toString();
1639:
1640:                        SQLQuery q = session.createSQLQuery(sql);
1641:
1642:                        q.addEntity("Group_",
1643:                                com.liferay.portal.model.impl.GroupImpl.class);
1644:
1645:                        QueryPos qPos = QueryPos.getInstance(q);
1646:
1647:                        qPos.add(pk);
1648:
1649:                        List list = QueryUtil.list(q, getDialect(), begin, end);
1650:
1651:                        FinderCache.putResult(finderClassNameCacheEnabled,
1652:                                finderClassName, finderMethodName,
1653:                                finderParams, finderArgs, list);
1654:
1655:                        return list;
1656:                    } catch (Exception e) {
1657:                        throw new SystemException(e);
1658:                    } finally {
1659:                        closeSession(session);
1660:                    }
1661:                } else {
1662:                    return (List) result;
1663:                }
1664:            }
1665:
1666:            public int getGroupsSize(long pk) throws SystemException {
1667:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1668:                String finderClassName = "Groups_Orgs";
1669:                String finderMethodName = "getGroupsSize";
1670:                String[] finderParams = new String[] { Long.class.getName() };
1671:                Object[] finderArgs = new Object[] { new Long(pk) };
1672:
1673:                Object result = null;
1674:
1675:                if (finderClassNameCacheEnabled) {
1676:                    result = FinderCache.getResult(finderClassName,
1677:                            finderMethodName, finderParams, finderArgs,
1678:                            getSessionFactory());
1679:                }
1680:
1681:                if (result == null) {
1682:                    Session session = null;
1683:
1684:                    try {
1685:                        session = openSession();
1686:
1687:                        SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1688:
1689:                        q.addScalar(HibernateUtil.getCountColumnName(),
1690:                                Hibernate.LONG);
1691:
1692:                        QueryPos qPos = QueryPos.getInstance(q);
1693:
1694:                        qPos.add(pk);
1695:
1696:                        Long count = null;
1697:
1698:                        Iterator itr = q.list().iterator();
1699:
1700:                        if (itr.hasNext()) {
1701:                            count = (Long) itr.next();
1702:                        }
1703:
1704:                        if (count == null) {
1705:                            count = new Long(0);
1706:                        }
1707:
1708:                        FinderCache.putResult(finderClassNameCacheEnabled,
1709:                                finderClassName, finderMethodName,
1710:                                finderParams, finderArgs, count);
1711:
1712:                        return count.intValue();
1713:                    } catch (Exception e) {
1714:                        throw HibernateUtil.processException(e);
1715:                    } finally {
1716:                        closeSession(session);
1717:                    }
1718:                } else {
1719:                    return ((Long) result).intValue();
1720:                }
1721:            }
1722:
1723:            public boolean containsGroup(long pk, long groupPK)
1724:                    throws SystemException {
1725:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1726:                String finderClassName = "Groups_Orgs";
1727:                String finderMethodName = "containsGroups";
1728:                String[] finderParams = new String[] { Long.class.getName(),
1729:
1730:                Long.class.getName() };
1731:                Object[] finderArgs = new Object[] { new Long(pk),
1732:                        new Long(groupPK) };
1733:
1734:                Object result = null;
1735:
1736:                if (finderClassNameCacheEnabled) {
1737:                    result = FinderCache.getResult(finderClassName,
1738:                            finderMethodName, finderParams, finderArgs,
1739:                            getSessionFactory());
1740:                }
1741:
1742:                if (result == null) {
1743:                    try {
1744:                        Boolean value = Boolean.valueOf(containsGroup.contains(
1745:                                pk, groupPK));
1746:
1747:                        FinderCache.putResult(finderClassNameCacheEnabled,
1748:                                finderClassName, finderMethodName,
1749:                                finderParams, finderArgs, value);
1750:
1751:                        return value.booleanValue();
1752:                    } catch (DataAccessException dae) {
1753:                        throw new SystemException(dae);
1754:                    }
1755:                } else {
1756:                    return ((Boolean) result).booleanValue();
1757:                }
1758:            }
1759:
1760:            public boolean containsGroups(long pk) throws SystemException {
1761:                if (getGroupsSize(pk) > 0) {
1762:                    return true;
1763:                } else {
1764:                    return false;
1765:                }
1766:            }
1767:
1768:            public void addGroup(long pk, long groupPK)
1769:                    throws NoSuchOrganizationException,
1770:                    com.liferay.portal.NoSuchGroupException, SystemException {
1771:                try {
1772:                    addGroup.add(pk, groupPK);
1773:                } catch (DataAccessException dae) {
1774:                    throw new SystemException(dae);
1775:                } finally {
1776:                    FinderCache.clearCache("Groups_Orgs");
1777:                }
1778:            }
1779:
1780:            public void addGroup(long pk, com.liferay.portal.model.Group group)
1781:                    throws NoSuchOrganizationException,
1782:                    com.liferay.portal.NoSuchGroupException, SystemException {
1783:                try {
1784:                    addGroup.add(pk, group.getPrimaryKey());
1785:                } catch (DataAccessException dae) {
1786:                    throw new SystemException(dae);
1787:                } finally {
1788:                    FinderCache.clearCache("Groups_Orgs");
1789:                }
1790:            }
1791:
1792:            public void addGroups(long pk, long[] groupPKs)
1793:                    throws NoSuchOrganizationException,
1794:                    com.liferay.portal.NoSuchGroupException, SystemException {
1795:                try {
1796:                    for (int i = 0; i < groupPKs.length; i++) {
1797:                        addGroup.add(pk, groupPKs[i]);
1798:                    }
1799:                } catch (DataAccessException dae) {
1800:                    throw new SystemException(dae);
1801:                } finally {
1802:                    FinderCache.clearCache("Groups_Orgs");
1803:                }
1804:            }
1805:
1806:            public void addGroups(long pk, List groups)
1807:                    throws NoSuchOrganizationException,
1808:                    com.liferay.portal.NoSuchGroupException, SystemException {
1809:                try {
1810:                    for (int i = 0; i < groups.size(); i++) {
1811:                        com.liferay.portal.model.Group group = (com.liferay.portal.model.Group) groups
1812:                                .get(i);
1813:
1814:                        addGroup.add(pk, group.getPrimaryKey());
1815:                    }
1816:                } catch (DataAccessException dae) {
1817:                    throw new SystemException(dae);
1818:                } finally {
1819:                    FinderCache.clearCache("Groups_Orgs");
1820:                }
1821:            }
1822:
1823:            public void clearGroups(long pk)
1824:                    throws NoSuchOrganizationException, SystemException {
1825:                try {
1826:                    clearGroups.clear(pk);
1827:                } catch (DataAccessException dae) {
1828:                    throw new SystemException(dae);
1829:                } finally {
1830:                    FinderCache.clearCache("Groups_Orgs");
1831:                }
1832:            }
1833:
1834:            public void removeGroup(long pk, long groupPK)
1835:                    throws NoSuchOrganizationException,
1836:                    com.liferay.portal.NoSuchGroupException, SystemException {
1837:                try {
1838:                    removeGroup.remove(pk, groupPK);
1839:                } catch (DataAccessException dae) {
1840:                    throw new SystemException(dae);
1841:                } finally {
1842:                    FinderCache.clearCache("Groups_Orgs");
1843:                }
1844:            }
1845:
1846:            public void removeGroup(long pk,
1847:                    com.liferay.portal.model.Group group)
1848:                    throws NoSuchOrganizationException,
1849:                    com.liferay.portal.NoSuchGroupException, SystemException {
1850:                try {
1851:                    removeGroup.remove(pk, group.getPrimaryKey());
1852:                } catch (DataAccessException dae) {
1853:                    throw new SystemException(dae);
1854:                } finally {
1855:                    FinderCache.clearCache("Groups_Orgs");
1856:                }
1857:            }
1858:
1859:            public void removeGroups(long pk, long[] groupPKs)
1860:                    throws NoSuchOrganizationException,
1861:                    com.liferay.portal.NoSuchGroupException, SystemException {
1862:                try {
1863:                    for (int i = 0; i < groupPKs.length; i++) {
1864:                        removeGroup.remove(pk, groupPKs[i]);
1865:                    }
1866:                } catch (DataAccessException dae) {
1867:                    throw new SystemException(dae);
1868:                } finally {
1869:                    FinderCache.clearCache("Groups_Orgs");
1870:                }
1871:            }
1872:
1873:            public void removeGroups(long pk, List groups)
1874:                    throws NoSuchOrganizationException,
1875:                    com.liferay.portal.NoSuchGroupException, SystemException {
1876:                try {
1877:                    for (int i = 0; i < groups.size(); i++) {
1878:                        com.liferay.portal.model.Group group = (com.liferay.portal.model.Group) groups
1879:                                .get(i);
1880:
1881:                        removeGroup.remove(pk, group.getPrimaryKey());
1882:                    }
1883:                } catch (DataAccessException dae) {
1884:                    throw new SystemException(dae);
1885:                } finally {
1886:                    FinderCache.clearCache("Groups_Orgs");
1887:                }
1888:            }
1889:
1890:            public void setGroups(long pk, long[] groupPKs)
1891:                    throws NoSuchOrganizationException,
1892:                    com.liferay.portal.NoSuchGroupException, SystemException {
1893:                try {
1894:                    clearGroups.clear(pk);
1895:
1896:                    for (int i = 0; i < groupPKs.length; i++) {
1897:                        addGroup.add(pk, groupPKs[i]);
1898:                    }
1899:                } catch (DataAccessException dae) {
1900:                    throw new SystemException(dae);
1901:                } finally {
1902:                    FinderCache.clearCache("Groups_Orgs");
1903:                }
1904:            }
1905:
1906:            public void setGroups(long pk, List groups)
1907:                    throws NoSuchOrganizationException,
1908:                    com.liferay.portal.NoSuchGroupException, SystemException {
1909:                try {
1910:                    clearGroups.clear(pk);
1911:
1912:                    for (int i = 0; i < groups.size(); i++) {
1913:                        com.liferay.portal.model.Group group = (com.liferay.portal.model.Group) groups
1914:                                .get(i);
1915:
1916:                        addGroup.add(pk, group.getPrimaryKey());
1917:                    }
1918:                } catch (DataAccessException dae) {
1919:                    throw new SystemException(dae);
1920:                } finally {
1921:                    FinderCache.clearCache("Groups_Orgs");
1922:                }
1923:            }
1924:
1925:            public List getUsers(long pk) throws NoSuchOrganizationException,
1926:                    SystemException {
1927:                return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1928:            }
1929:
1930:            public List getUsers(long pk, int begin, int end)
1931:                    throws NoSuchOrganizationException, SystemException {
1932:                return getUsers(pk, begin, end, null);
1933:            }
1934:
1935:            public List getUsers(long pk, int begin, int end,
1936:                    OrderByComparator obc) throws NoSuchOrganizationException,
1937:                    SystemException {
1938:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_USERS_ORGS;
1939:                String finderClassName = "Users_Orgs";
1940:                String finderMethodName = "getUsers";
1941:                String[] finderParams = new String[] { Long.class.getName(),
1942:                        "java.lang.Integer", "java.lang.Integer",
1943:                        "com.liferay.portal.kernel.util.OrderByComparator" };
1944:                Object[] finderArgs = new Object[] { new Long(pk),
1945:                        String.valueOf(begin), String.valueOf(end),
1946:                        String.valueOf(obc) };
1947:
1948:                Object result = null;
1949:
1950:                if (finderClassNameCacheEnabled) {
1951:                    result = FinderCache.getResult(finderClassName,
1952:                            finderMethodName, finderParams, finderArgs,
1953:                            getSessionFactory());
1954:                }
1955:
1956:                if (result == null) {
1957:                    Session session = null;
1958:
1959:                    try {
1960:                        session = HibernateUtil.openSession();
1961:
1962:                        StringMaker sm = new StringMaker();
1963:
1964:                        sm.append(_SQL_GETUSERS);
1965:
1966:                        if (obc != null) {
1967:                            sm.append("ORDER BY ");
1968:                            sm.append(obc.getOrderBy());
1969:                        }
1970:
1971:                        String sql = sm.toString();
1972:
1973:                        SQLQuery q = session.createSQLQuery(sql);
1974:
1975:                        q.addEntity("User_",
1976:                                com.liferay.portal.model.impl.UserImpl.class);
1977:
1978:                        QueryPos qPos = QueryPos.getInstance(q);
1979:
1980:                        qPos.add(pk);
1981:
1982:                        List list = QueryUtil.list(q, getDialect(), begin, end);
1983:
1984:                        FinderCache.putResult(finderClassNameCacheEnabled,
1985:                                finderClassName, finderMethodName,
1986:                                finderParams, finderArgs, list);
1987:
1988:                        return list;
1989:                    } catch (Exception e) {
1990:                        throw new SystemException(e);
1991:                    } finally {
1992:                        closeSession(session);
1993:                    }
1994:                } else {
1995:                    return (List) result;
1996:                }
1997:            }
1998:
1999:            public int getUsersSize(long pk) throws SystemException {
2000:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_USERS_ORGS;
2001:                String finderClassName = "Users_Orgs";
2002:                String finderMethodName = "getUsersSize";
2003:                String[] finderParams = new String[] { Long.class.getName() };
2004:                Object[] finderArgs = new Object[] { new Long(pk) };
2005:
2006:                Object result = null;
2007:
2008:                if (finderClassNameCacheEnabled) {
2009:                    result = FinderCache.getResult(finderClassName,
2010:                            finderMethodName, finderParams, finderArgs,
2011:                            getSessionFactory());
2012:                }
2013:
2014:                if (result == null) {
2015:                    Session session = null;
2016:
2017:                    try {
2018:                        session = openSession();
2019:
2020:                        SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2021:
2022:                        q.addScalar(HibernateUtil.getCountColumnName(),
2023:                                Hibernate.LONG);
2024:
2025:                        QueryPos qPos = QueryPos.getInstance(q);
2026:
2027:                        qPos.add(pk);
2028:
2029:                        Long count = null;
2030:
2031:                        Iterator itr = q.list().iterator();
2032:
2033:                        if (itr.hasNext()) {
2034:                            count = (Long) itr.next();
2035:                        }
2036:
2037:                        if (count == null) {
2038:                            count = new Long(0);
2039:                        }
2040:
2041:                        FinderCache.putResult(finderClassNameCacheEnabled,
2042:                                finderClassName, finderMethodName,
2043:                                finderParams, finderArgs, count);
2044:
2045:                        return count.intValue();
2046:                    } catch (Exception e) {
2047:                        throw HibernateUtil.processException(e);
2048:                    } finally {
2049:                        closeSession(session);
2050:                    }
2051:                } else {
2052:                    return ((Long) result).intValue();
2053:                }
2054:            }
2055:
2056:            public boolean containsUser(long pk, long userPK)
2057:                    throws SystemException {
2058:                boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_USERS_ORGS;
2059:                String finderClassName = "Users_Orgs";
2060:                String finderMethodName = "containsUsers";
2061:                String[] finderParams = new String[] { Long.class.getName(),
2062:
2063:                Long.class.getName() };
2064:                Object[] finderArgs = new Object[] { new Long(pk),
2065:                        new Long(userPK) };
2066:
2067:                Object result = null;
2068:
2069:                if (finderClassNameCacheEnabled) {
2070:                    result = FinderCache.getResult(finderClassName,
2071:                            finderMethodName, finderParams, finderArgs,
2072:                            getSessionFactory());
2073:                }
2074:
2075:                if (result == null) {
2076:                    try {
2077:                        Boolean value = Boolean.valueOf(containsUser.contains(
2078:                                pk, userPK));
2079:
2080:                        FinderCache.putResult(finderClassNameCacheEnabled,
2081:                                finderClassName, finderMethodName,
2082:                                finderParams, finderArgs, value);
2083:
2084:                        return value.booleanValue();
2085:                    } catch (DataAccessException dae) {
2086:                        throw new SystemException(dae);
2087:                    }
2088:                } else {
2089:                    return ((Boolean) result).booleanValue();
2090:                }
2091:            }
2092:
2093:            public boolean containsUsers(long pk) throws SystemException {
2094:                if (getUsersSize(pk) > 0) {
2095:                    return true;
2096:                } else {
2097:                    return false;
2098:                }
2099:            }
2100:
2101:            public void addUser(long pk, long userPK)
2102:                    throws NoSuchOrganizationException,
2103:                    com.liferay.portal.NoSuchUserException, SystemException {
2104:                try {
2105:                    addUser.add(pk, userPK);
2106:                } catch (DataAccessException dae) {
2107:                    throw new SystemException(dae);
2108:                } finally {
2109:                    FinderCache.clearCache("Users_Orgs");
2110:                }
2111:            }
2112:
2113:            public void addUser(long pk, com.liferay.portal.model.User user)
2114:                    throws NoSuchOrganizationException,
2115:                    com.liferay.portal.NoSuchUserException, SystemException {
2116:                try {
2117:                    addUser.add(pk, user.getPrimaryKey());
2118:                } catch (DataAccessException dae) {
2119:                    throw new SystemException(dae);
2120:                } finally {
2121:                    FinderCache.clearCache("Users_Orgs");
2122:                }
2123:            }
2124:
2125:            public void addUsers(long pk, long[] userPKs)
2126:                    throws NoSuchOrganizationException,
2127:                    com.liferay.portal.NoSuchUserException, SystemException {
2128:                try {
2129:                    for (int i = 0; i < userPKs.length; i++) {
2130:                        addUser.add(pk, userPKs[i]);
2131:                    }
2132:                } catch (DataAccessException dae) {
2133:                    throw new SystemException(dae);
2134:                } finally {
2135:                    FinderCache.clearCache("Users_Orgs");
2136:                }
2137:            }
2138:
2139:            public void addUsers(long pk, List users)
2140:                    throws NoSuchOrganizationException,
2141:                    com.liferay.portal.NoSuchUserException, SystemException {
2142:                try {
2143:                    for (int i = 0; i < users.size(); i++) {
2144:                        com.liferay.portal.model.User user = (com.liferay.portal.model.User) users
2145:                                .get(i);
2146:
2147:                        addUser.add(pk, user.getPrimaryKey());
2148:                    }
2149:                } catch (DataAccessException dae) {
2150:                    throw new SystemException(dae);
2151:                } finally {
2152:                    FinderCache.clearCache("Users_Orgs");
2153:                }
2154:            }
2155:
2156:            public void clearUsers(long pk) throws NoSuchOrganizationException,
2157:                    SystemException {
2158:                try {
2159:                    clearUsers.clear(pk);
2160:                } catch (DataAccessException dae) {
2161:                    throw new SystemException(dae);
2162:                } finally {
2163:                    FinderCache.clearCache("Users_Orgs");
2164:                }
2165:            }
2166:
2167:            public void removeUser(long pk, long userPK)
2168:                    throws NoSuchOrganizationException,
2169:                    com.liferay.portal.NoSuchUserException, SystemException {
2170:                try {
2171:                    removeUser.remove(pk, userPK);
2172:                } catch (DataAccessException dae) {
2173:                    throw new SystemException(dae);
2174:                } finally {
2175:                    FinderCache.clearCache("Users_Orgs");
2176:                }
2177:            }
2178:
2179:            public void removeUser(long pk, com.liferay.portal.model.User user)
2180:                    throws NoSuchOrganizationException,
2181:                    com.liferay.portal.NoSuchUserException, SystemException {
2182:                try {
2183:                    removeUser.remove(pk, user.getPrimaryKey());
2184:                } catch (DataAccessException dae) {
2185:                    throw new SystemException(dae);
2186:                } finally {
2187:                    FinderCache.clearCache("Users_Orgs");
2188:                }
2189:            }
2190:
2191:            public void removeUsers(long pk, long[] userPKs)
2192:                    throws NoSuchOrganizationException,
2193:                    com.liferay.portal.NoSuchUserException, SystemException {
2194:                try {
2195:                    for (int i = 0; i < userPKs.length; i++) {
2196:                        removeUser.remove(pk, userPKs[i]);
2197:                    }
2198:                } catch (DataAccessException dae) {
2199:                    throw new SystemException(dae);
2200:                } finally {
2201:                    FinderCache.clearCache("Users_Orgs");
2202:                }
2203:            }
2204:
2205:            public void removeUsers(long pk, List users)
2206:                    throws NoSuchOrganizationException,
2207:                    com.liferay.portal.NoSuchUserException, SystemException {
2208:                try {
2209:                    for (int i = 0; i < users.size(); i++) {
2210:                        com.liferay.portal.model.User user = (com.liferay.portal.model.User) users
2211:                                .get(i);
2212:
2213:                        removeUser.remove(pk, user.getPrimaryKey());
2214:                    }
2215:                } catch (DataAccessException dae) {
2216:                    throw new SystemException(dae);
2217:                } finally {
2218:                    FinderCache.clearCache("Users_Orgs");
2219:                }
2220:            }
2221:
2222:            public void setUsers(long pk, long[] userPKs)
2223:                    throws NoSuchOrganizationException,
2224:                    com.liferay.portal.NoSuchUserException, SystemException {
2225:                try {
2226:                    clearUsers.clear(pk);
2227:
2228:                    for (int i = 0; i < userPKs.length; i++) {
2229:                        addUser.add(pk, userPKs[i]);
2230:                    }
2231:                } catch (DataAccessException dae) {
2232:                    throw new SystemException(dae);
2233:                } finally {
2234:                    FinderCache.clearCache("Users_Orgs");
2235:                }
2236:            }
2237:
2238:            public void setUsers(long pk, List users)
2239:                    throws NoSuchOrganizationException,
2240:                    com.liferay.portal.NoSuchUserException, SystemException {
2241:                try {
2242:                    clearUsers.clear(pk);
2243:
2244:                    for (int i = 0; i < users.size(); i++) {
2245:                        com.liferay.portal.model.User user = (com.liferay.portal.model.User) users
2246:                                .get(i);
2247:
2248:                        addUser.add(pk, user.getPrimaryKey());
2249:                    }
2250:                } catch (DataAccessException dae) {
2251:                    throw new SystemException(dae);
2252:                } finally {
2253:                    FinderCache.clearCache("Users_Orgs");
2254:                }
2255:            }
2256:
2257:            protected void initDao() {
2258:                containsGroup = new ContainsGroup(this );
2259:
2260:                addGroup = new AddGroup(this );
2261:                clearGroups = new ClearGroups(this );
2262:                removeGroup = new RemoveGroup(this );
2263:
2264:                containsUser = new ContainsUser(this );
2265:
2266:                addUser = new AddUser(this );
2267:                clearUsers = new ClearUsers(this );
2268:                removeUser = new RemoveUser(this );
2269:            }
2270:
2271:            protected ContainsGroup containsGroup;
2272:            protected AddGroup addGroup;
2273:            protected ClearGroups clearGroups;
2274:            protected RemoveGroup removeGroup;
2275:            protected ContainsUser containsUser;
2276:            protected AddUser addUser;
2277:            protected ClearUsers clearUsers;
2278:            protected RemoveUser removeUser;
2279:
2280:            protected class ContainsGroup extends MappingSqlQuery {
2281:                protected ContainsGroup(
2282:                        OrganizationPersistenceImpl persistenceImpl) {
2283:                    super (persistenceImpl.getDataSource(), _SQL_CONTAINSGROUP);
2284:
2285:                    declareParameter(new SqlParameter(Types.BIGINT));
2286:                    declareParameter(new SqlParameter(Types.BIGINT));
2287:
2288:                    compile();
2289:                }
2290:
2291:                protected Object mapRow(ResultSet rs, int rowNumber)
2292:                        throws SQLException {
2293:                    return new Integer(rs.getInt("COUNT_VALUE"));
2294:                }
2295:
2296:                protected boolean contains(long organizationId, long groupId) {
2297:                    List results = execute(new Object[] {
2298:                            new Long(organizationId), new Long(groupId) });
2299:
2300:                    if (results.size() > 0) {
2301:                        Integer count = (Integer) results.get(0);
2302:
2303:                        if (count.intValue() > 0) {
2304:                            return true;
2305:                        }
2306:                    }
2307:
2308:                    return false;
2309:                }
2310:            }
2311:
2312:            protected class AddGroup extends SqlUpdate {
2313:                protected AddGroup(OrganizationPersistenceImpl persistenceImpl) {
2314:                    super (persistenceImpl.getDataSource(),
2315:                            "INSERT INTO Groups_Orgs (organizationId, groupId) VALUES (?, ?)");
2316:
2317:                    _persistenceImpl = persistenceImpl;
2318:
2319:                    declareParameter(new SqlParameter(Types.BIGINT));
2320:                    declareParameter(new SqlParameter(Types.BIGINT));
2321:
2322:                    compile();
2323:                }
2324:
2325:                protected void add(long organizationId, long groupId) {
2326:                    if (!_persistenceImpl.containsGroup.contains(
2327:                            organizationId, groupId)) {
2328:                        update(new Object[] { new Long(organizationId),
2329:                                new Long(groupId) });
2330:                    }
2331:                }
2332:
2333:                private OrganizationPersistenceImpl _persistenceImpl;
2334:            }
2335:
2336:            protected class ClearGroups extends SqlUpdate {
2337:                protected ClearGroups(
2338:                        OrganizationPersistenceImpl persistenceImpl) {
2339:                    super (persistenceImpl.getDataSource(),
2340:                            "DELETE FROM Groups_Orgs WHERE organizationId = ?");
2341:
2342:                    declareParameter(new SqlParameter(Types.BIGINT));
2343:
2344:                    compile();
2345:                }
2346:
2347:                protected void clear(long organizationId) {
2348:                    update(new Object[] { new Long(organizationId) });
2349:                }
2350:            }
2351:
2352:            protected class RemoveGroup extends SqlUpdate {
2353:                protected RemoveGroup(
2354:                        OrganizationPersistenceImpl persistenceImpl) {
2355:                    super (persistenceImpl.getDataSource(),
2356:                            "DELETE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?");
2357:
2358:                    declareParameter(new SqlParameter(Types.BIGINT));
2359:                    declareParameter(new SqlParameter(Types.BIGINT));
2360:
2361:                    compile();
2362:                }
2363:
2364:                protected void remove(long organizationId, long groupId) {
2365:                    update(new Object[] { new Long(organizationId),
2366:                            new Long(groupId) });
2367:                }
2368:            }
2369:
2370:            protected class ContainsUser extends MappingSqlQuery {
2371:                protected ContainsUser(
2372:                        OrganizationPersistenceImpl persistenceImpl) {
2373:                    super (persistenceImpl.getDataSource(), _SQL_CONTAINSUSER);
2374:
2375:                    declareParameter(new SqlParameter(Types.BIGINT));
2376:                    declareParameter(new SqlParameter(Types.BIGINT));
2377:
2378:                    compile();
2379:                }
2380:
2381:                protected Object mapRow(ResultSet rs, int rowNumber)
2382:                        throws SQLException {
2383:                    return new Integer(rs.getInt("COUNT_VALUE"));
2384:                }
2385:
2386:                protected boolean contains(long organizationId, long userId) {
2387:                    List results = execute(new Object[] {
2388:                            new Long(organizationId), new Long(userId) });
2389:
2390:                    if (results.size() > 0) {
2391:                        Integer count = (Integer) results.get(0);
2392:
2393:                        if (count.intValue() > 0) {
2394:                            return true;
2395:                        }
2396:                    }
2397:
2398:                    return false;
2399:                }
2400:            }
2401:
2402:            protected class AddUser extends SqlUpdate {
2403:                protected AddUser(OrganizationPersistenceImpl persistenceImpl) {
2404:                    super (persistenceImpl.getDataSource(),
2405:                            "INSERT INTO Users_Orgs (organizationId, userId) VALUES (?, ?)");
2406:
2407:                    _persistenceImpl = persistenceImpl;
2408:
2409:                    declareParameter(new SqlParameter(Types.BIGINT));
2410:                    declareParameter(new SqlParameter(Types.BIGINT));
2411:
2412:                    compile();
2413:                }
2414:
2415:                protected void add(long organizationId, long userId) {
2416:                    if (!_persistenceImpl.containsUser.contains(organizationId,
2417:                            userId)) {
2418:                        update(new Object[] { new Long(organizationId),
2419:                                new Long(userId) });
2420:                    }
2421:                }
2422:
2423:                private OrganizationPersistenceImpl _persistenceImpl;
2424:            }
2425:
2426:            protected class ClearUsers extends SqlUpdate {
2427:                protected ClearUsers(OrganizationPersistenceImpl persistenceImpl) {
2428:                    super (persistenceImpl.getDataSource(),
2429:                            "DELETE FROM Users_Orgs WHERE organizationId = ?");
2430:
2431:                    declareParameter(new SqlParameter(Types.BIGINT));
2432:
2433:                    compile();
2434:                }
2435:
2436:                protected void clear(long organizationId) {
2437:                    update(new Object[] { new Long(organizationId) });
2438:                }
2439:            }
2440:
2441:            protected class RemoveUser extends SqlUpdate {
2442:                protected RemoveUser(OrganizationPersistenceImpl persistenceImpl) {
2443:                    super (persistenceImpl.getDataSource(),
2444:                            "DELETE FROM Users_Orgs WHERE organizationId = ? AND userId = ?");
2445:
2446:                    declareParameter(new SqlParameter(Types.BIGINT));
2447:                    declareParameter(new SqlParameter(Types.BIGINT));
2448:
2449:                    compile();
2450:                }
2451:
2452:                protected void remove(long organizationId, long userId) {
2453:                    update(new Object[] { new Long(organizationId),
2454:                            new Long(userId) });
2455:                }
2456:            }
2457:
2458:            private static ModelListener _getListener() {
2459:                if (Validator.isNotNull(_LISTENER)) {
2460:                    try {
2461:                        return (ModelListener) Class.forName(_LISTENER)
2462:                                .newInstance();
2463:                    } catch (Exception e) {
2464:                        _log.error(e);
2465:                    }
2466:                }
2467:
2468:                return null;
2469:            }
2470:
2471:            private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Orgs ON (Groups_Orgs.groupId = Group_.groupId) WHERE (Groups_Orgs.organizationId = ?)";
2472:            private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ?";
2473:            private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?";
2474:            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Orgs ON (Users_Orgs.userId = User_.userId) WHERE (Users_Orgs.organizationId = ?)";
2475:            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ?";
2476:            private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ? AND userId = ?";
2477:            private static final String _LISTENER = GetterUtil
2478:                    .getString(PropsUtil
2479:                            .get("value.object.listener.com.liferay.portal.model.Organization"));
2480:            private static Log _log = LogFactory
2481:                    .getLog(OrganizationPersistenceImpl.class);
2482:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.