Example usage for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS

List of usage examples for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS.

Prototype

String CLOSE_PARENTHESIS

To view the source code for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS.

Click Source Link

Usage

From source file:com.liferay.portlet.wiki.service.impl.WikiPageServiceImpl.java

License:Open Source License

protected String exportToRSS(long companyId, String name, String description, String type, double version,
        String displayStyle, String feedURL, String entryURL, List<WikiPage> pages, boolean diff, Locale locale)
        throws SystemException {

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setFeedType(RSSUtil.getFeedType(type, version));
    syndFeed.setTitle(name);/*from   w w  w  . ja  v  a 2  s .  c  om*/
    syndFeed.setLink(feedURL);
    syndFeed.setDescription(description);

    List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();

    syndFeed.setEntries(syndEntries);

    WikiPage latestPage = null;

    StringBundler link = new StringBundler(7);

    for (WikiPage page : pages) {
        String author = HtmlUtil.escape(PortalUtil.getUserName(page.getUserId(), page.getUserName()));

        String title = page.getTitle() + StringPool.SPACE + page.getVersion();

        if (page.isMinorEdit()) {
            title += StringPool.SPACE + StringPool.OPEN_PARENTHESIS + LanguageUtil.get(locale, "minor-edit")
                    + StringPool.CLOSE_PARENTHESIS;
        }

        link.setIndex(0);

        link.append(entryURL);
        link.append(StringPool.AMPERSAND);
        link.append(HttpUtil.encodeURL(page.getTitle()));

        SyndEntry syndEntry = new SyndEntryImpl();

        syndEntry.setAuthor(author);
        syndEntry.setTitle(title);
        syndEntry.setPublishedDate(page.getCreateDate());
        syndEntry.setUpdatedDate(page.getModifiedDate());

        SyndContent syndContent = new SyndContentImpl();

        syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

        if (diff) {
            if (latestPage != null) {
                link.append(StringPool.QUESTION);
                link.append(PortalUtil.getPortletNamespace(PortletKeys.WIKI));
                link.append("version=");
                link.append(page.getVersion());

                String value = getPageDiff(companyId, latestPage, page, locale);

                syndContent.setValue(value);

                syndEntry.setDescription(syndContent);

                syndEntries.add(syndEntry);
            }
        } else {
            String value = null;

            if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
                value = StringUtil.shorten(HtmlUtil.extractText(page.getContent()),
                        PropsValues.WIKI_RSS_ABSTRACT_LENGTH, StringPool.BLANK);
            } else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
                value = StringPool.BLANK;
            } else {
                value = page.getContent();
            }

            syndContent.setValue(value);

            syndEntry.setDescription(syndContent);

            syndEntries.add(syndEntry);
        }

        syndEntry.setLink(link.toString());
        syndEntry.setUri(syndEntry.getLink());

        latestPage = page;
    }

    try {
        return RSSUtil.export(syndFeed);
    } catch (FeedException fe) {
        throw new SystemException(fe);
    }
}

From source file:com.liferay.privatemessaging.service.persistence.impl.UserThreadPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, UserThread> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*from   ww  w.j  a v a 2s .c om*/

    Map<Serializable, UserThread> map = new HashMap<Serializable, UserThread>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        UserThread userThread = fetchByPrimaryKey(primaryKey);

        if (userThread != null) {
            map.put(primaryKey, userThread);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        UserThread userThread = (UserThread) EntityCacheUtil.getResult(UserThreadModelImpl.ENTITY_CACHE_ENABLED,
                UserThreadImpl.class, primaryKey);

        if (userThread == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, userThread);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_USERTHREAD_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (UserThread userThread : (List<UserThread>) q.list()) {
            map.put(userThread.getPrimaryKeyObj(), userThread);

            cacheResult(userThread);

            uncachedPrimaryKeys.remove(userThread.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(UserThreadModelImpl.ENTITY_CACHE_ENABLED, UserThreadImpl.class,
                    primaryKey, _nullUserThread);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.projects.dashboard.business.unit.service.persistence.impl.BusinessUnitPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, BusinessUnit> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from www  .  j av a2  s  . com

    Map<Serializable, BusinessUnit> map = new HashMap<Serializable, BusinessUnit>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        BusinessUnit businessUnit = fetchByPrimaryKey(primaryKey);

        if (businessUnit != null) {
            map.put(primaryKey, businessUnit);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Serializable serializable = entityCache.getResult(BusinessUnitModelImpl.ENTITY_CACHE_ENABLED,
                BusinessUnitImpl.class, primaryKey);

        if (serializable != nullModel) {
            if (serializable == null) {
                if (uncachedPrimaryKeys == null) {
                    uncachedPrimaryKeys = new HashSet<Serializable>();
                }

                uncachedPrimaryKeys.add(primaryKey);
            } else {
                map.put(primaryKey, (BusinessUnit) serializable);
            }
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_BUSINESSUNIT_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (BusinessUnit businessUnit : (List<BusinessUnit>) q.list()) {
            map.put(businessUnit.getPrimaryKeyObj(), businessUnit);

            cacheResult(businessUnit);

            uncachedPrimaryKeys.remove(businessUnit.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(BusinessUnitModelImpl.ENTITY_CACHE_ENABLED, BusinessUnitImpl.class,
                    primaryKey, nullModel);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.projects.dashboard.business.unit.service.persistence.impl.ProjectBUPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, ProjectBU> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//  w  w w  .  jav a 2 s  .c om

    Map<Serializable, ProjectBU> map = new HashMap<Serializable, ProjectBU>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        ProjectBU projectBU = fetchByPrimaryKey(primaryKey);

        if (projectBU != null) {
            map.put(primaryKey, projectBU);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Serializable serializable = entityCache.getResult(ProjectBUModelImpl.ENTITY_CACHE_ENABLED,
                ProjectBUImpl.class, primaryKey);

        if (serializable != nullModel) {
            if (serializable == null) {
                if (uncachedPrimaryKeys == null) {
                    uncachedPrimaryKeys = new HashSet<Serializable>();
                }

                uncachedPrimaryKeys.add(primaryKey);
            } else {
                map.put(primaryKey, (ProjectBU) serializable);
            }
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_PROJECTBU_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (ProjectBU projectBU : (List<ProjectBU>) q.list()) {
            map.put(projectBU.getPrimaryKeyObj(), projectBU);

            cacheResult(projectBU);

            uncachedPrimaryKeys.remove(projectBU.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(ProjectBUModelImpl.ENTITY_CACHE_ENABLED, ProjectBUImpl.class, primaryKey,
                    nullModel);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.projects.dashboard.problem.service.persistence.impl.ProblemPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, Problem> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*  w  w w.j a va2 s  . c o m*/

    Map<Serializable, Problem> map = new HashMap<Serializable, Problem>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        Problem problem = fetchByPrimaryKey(primaryKey);

        if (problem != null) {
            map.put(primaryKey, problem);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Serializable serializable = entityCache.getResult(ProblemModelImpl.ENTITY_CACHE_ENABLED,
                ProblemImpl.class, primaryKey);

        if (serializable != nullModel) {
            if (serializable == null) {
                if (uncachedPrimaryKeys == null) {
                    uncachedPrimaryKeys = new HashSet<Serializable>();
                }

                uncachedPrimaryKeys.add(primaryKey);
            } else {
                map.put(primaryKey, (Problem) serializable);
            }
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_PROBLEM_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (Problem problem : (List<Problem>) q.list()) {
            map.put(problem.getPrimaryKeyObj(), problem);

            cacheResult(problem);

            uncachedPrimaryKeys.remove(problem.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(ProblemModelImpl.ENTITY_CACHE_ENABLED, ProblemImpl.class, primaryKey,
                    nullModel);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.pushnotifications.service.persistence.impl.PushNotificationsDevicePersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, PushNotificationsDevice> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*ww  w. java  2  s .  co m*/

    Map<Serializable, PushNotificationsDevice> map = new HashMap<Serializable, PushNotificationsDevice>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        PushNotificationsDevice pushNotificationsDevice = fetchByPrimaryKey(primaryKey);

        if (pushNotificationsDevice != null) {
            map.put(primaryKey, pushNotificationsDevice);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        PushNotificationsDevice pushNotificationsDevice = (PushNotificationsDevice) EntityCacheUtil.getResult(
                PushNotificationsDeviceModelImpl.ENTITY_CACHE_ENABLED, PushNotificationsDeviceImpl.class,
                primaryKey);

        if (pushNotificationsDevice == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, pushNotificationsDevice);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_PUSHNOTIFICATIONSDEVICE_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (PushNotificationsDevice pushNotificationsDevice : (List<PushNotificationsDevice>) q.list()) {
            map.put(pushNotificationsDevice.getPrimaryKeyObj(), pushNotificationsDevice);

            cacheResult(pushNotificationsDevice);

            uncachedPrimaryKeys.remove(pushNotificationsDevice.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(PushNotificationsDeviceModelImpl.ENTITY_CACHE_ENABLED,
                    PushNotificationsDeviceImpl.class, primaryKey, _nullPushNotificationsDevice);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.pushnotifications.service.persistence.impl.PushNotificationsEntryPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, PushNotificationsEntry> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from   w  w  w.j  a  v  a2s  .c o m

    Map<Serializable, PushNotificationsEntry> map = new HashMap<Serializable, PushNotificationsEntry>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        PushNotificationsEntry pushNotificationsEntry = fetchByPrimaryKey(primaryKey);

        if (pushNotificationsEntry != null) {
            map.put(primaryKey, pushNotificationsEntry);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        PushNotificationsEntry pushNotificationsEntry = (PushNotificationsEntry) EntityCacheUtil.getResult(
                PushNotificationsEntryModelImpl.ENTITY_CACHE_ENABLED, PushNotificationsEntryImpl.class,
                primaryKey);

        if (pushNotificationsEntry == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, pushNotificationsEntry);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_PUSHNOTIFICATIONSENTRY_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (PushNotificationsEntry pushNotificationsEntry : (List<PushNotificationsEntry>) q.list()) {
            map.put(pushNotificationsEntry.getPrimaryKeyObj(), pushNotificationsEntry);

            cacheResult(pushNotificationsEntry);

            uncachedPrimaryKeys.remove(pushNotificationsEntry.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            EntityCacheUtil.putResult(PushNotificationsEntryModelImpl.ENTITY_CACHE_ENABLED,
                    PushNotificationsEntryImpl.class, primaryKey, _nullPushNotificationsEntry);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.recommend.service.persistence.impl.RecommendEntityPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, RecommendEntity> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from w  ww  . ja  v a2  s . c  o  m

    Map<Serializable, RecommendEntity> map = new HashMap<Serializable, RecommendEntity>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        RecommendEntity recommendEntity = fetchByPrimaryKey(primaryKey);

        if (recommendEntity != null) {
            map.put(primaryKey, recommendEntity);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Serializable serializable = entityCache.getResult(RecommendEntityModelImpl.ENTITY_CACHE_ENABLED,
                RecommendEntityImpl.class, primaryKey);

        if (serializable != nullModel) {
            if (serializable == null) {
                if (uncachedPrimaryKeys == null) {
                    uncachedPrimaryKeys = new HashSet<Serializable>();
                }

                uncachedPrimaryKeys.add(primaryKey);
            } else {
                map.put(primaryKey, (RecommendEntity) serializable);
            }
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_RECOMMENDENTITY_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append((long) primaryKey);

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (RecommendEntity recommendEntity : (List<RecommendEntity>) q.list()) {
            map.put(recommendEntity.getPrimaryKeyObj(), recommendEntity);

            cacheResult(recommendEntity);

            uncachedPrimaryKeys.remove(recommendEntity.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(RecommendEntityModelImpl.ENTITY_CACHE_ENABLED, RecommendEntityImpl.class,
                    primaryKey, nullModel);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.roster.service.persistence.impl.ClubPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, Club> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from   w  ww .j  ava  2 s .c  o m

    Map<Serializable, Club> map = new HashMap<Serializable, Club>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        Club club = fetchByPrimaryKey(primaryKey);

        if (club != null) {
            map.put(primaryKey, club);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Club club = (Club) entityCache.getResult(ClubModelImpl.ENTITY_CACHE_ENABLED, ClubImpl.class,
                primaryKey);

        if (club == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, club);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_CLUB_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (Club club : (List<Club>) q.list()) {
            map.put(club.getPrimaryKeyObj(), club);

            cacheResult(club);

            uncachedPrimaryKeys.remove(club.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(ClubModelImpl.ENTITY_CACHE_ENABLED, ClubImpl.class, primaryKey, _nullClub);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.roster.service.persistence.impl.RosterMemberPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, RosterMember> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*from ww w .j ava 2 s.  com*/

    Map<Serializable, RosterMember> map = new HashMap<Serializable, RosterMember>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        RosterMember rosterMember = fetchByPrimaryKey(primaryKey);

        if (rosterMember != null) {
            map.put(primaryKey, rosterMember);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        RosterMember rosterMember = (RosterMember) entityCache
                .getResult(RosterMemberModelImpl.ENTITY_CACHE_ENABLED, RosterMemberImpl.class, primaryKey);

        if (rosterMember == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }

            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, rosterMember);
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_ROSTERMEMBER_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));

        query.append(StringPool.COMMA);
    }

    query.setIndex(query.index() - 1);

    query.append(StringPool.CLOSE_PARENTHESIS);

    String sql = query.toString();

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        for (RosterMember rosterMember : (List<RosterMember>) q.list()) {
            map.put(rosterMember.getPrimaryKeyObj(), rosterMember);

            cacheResult(rosterMember);

            uncachedPrimaryKeys.remove(rosterMember.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(RosterMemberModelImpl.ENTITY_CACHE_ENABLED, RosterMemberImpl.class,
                    primaryKey, _nullRosterMember);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}