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

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

Introduction

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

Prototype

String COMMA

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

Click Source Link

Usage

From source file:com.liferay.school.service.persistence.impl.CoursePersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, Course> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*from  www  .  ja  v  a2  s. co  m*/

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

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

        Serializable primaryKey = iterator.next();

        Course course = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Course course = (Course) entityCache.getResult(CourseModelImpl.ENTITY_CACHE_ENABLED, CourseImpl.class,
                primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_COURSE_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 (Course course : (List<Course>) q.list()) {
            map.put(course.getPrimaryKeyObj(), course);

            cacheResult(course);

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

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

    return map;
}

From source file:com.liferay.shopping.service.impl.ShoppingItemLocalServiceImpl.java

License:Open Source License

protected void validate(long companyId, long itemId, String sku, String name, boolean smallImage,
        String smallImageURL, File smallImageFile, byte[] smallImageBytes, boolean mediumImage,
        String mediumImageURL, File mediumImageFile, byte[] mediumImageBytes, boolean largeImage,
        String largeImageURL, File largeImageFile, byte[] largeImageBytes)
        throws PortalException, SystemException, Exception {

    if (Validator.isNull(sku)) {
        throw new ItemSKUException();
    }//from   w ww  .  j a v a  2 s .c o  m

    ShoppingItem item = shoppingItemPersistence.fetchByC_S(companyId, sku);

    if (item != null) {
        if (itemId > 0) {
            if (item.getItemId() != itemId) {
                throw new DuplicateItemSKUException();
            }
        } else {
            throw new DuplicateItemSKUException();
        }
    }

    if (Validator.isNull(name)) {
        throw new ItemNameException();
    }

    String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.SHOPPING_IMAGE_EXTENSIONS,
            StringPool.COMMA);

    // Small image

    if (smallImage && Validator.isNull(smallImageURL) && smallImageFile != null && smallImageBytes != null) {

        String smallImageName = smallImageFile.getName();

        if (smallImageName != null) {
            boolean validSmallImageExtension = false;

            for (int i = 0; i < imageExtensions.length; i++) {
                if (StringPool.STAR.equals(imageExtensions[i])
                        || StringUtil.endsWith(smallImageName, imageExtensions[i])) {

                    validSmallImageExtension = true;

                    break;
                }
            }

            if (!validSmallImageExtension) {
                throw new ItemSmallImageNameException(smallImageName);
            }
        }

        long smallImageMaxSize = GetterUtil
                .getLong(PrefsPropsUtil.getString(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE));

        if ((smallImageMaxSize > 0)
                && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) {

            throw new ItemSmallImageSizeException();
        }
    }

    // Medium image

    if (mediumImage && Validator.isNull(mediumImageURL) && mediumImageFile != null
            && mediumImageBytes != null) {

        String mediumImageName = mediumImageFile.getName();

        if (mediumImageName != null) {
            boolean validMediumImageExtension = false;

            for (int i = 0; i < imageExtensions.length; i++) {
                if (StringPool.STAR.equals(imageExtensions[i])
                        || StringUtil.endsWith(mediumImageName, imageExtensions[i])) {

                    validMediumImageExtension = true;

                    break;
                }
            }

            if (!validMediumImageExtension) {
                throw new ItemMediumImageNameException(mediumImageName);
            }
        }

        long mediumImageMaxSize = GetterUtil
                .getLong(PrefsPropsUtil.getString(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE));

        if ((mediumImageMaxSize > 0)
                && ((mediumImageBytes == null) || (mediumImageBytes.length > mediumImageMaxSize))) {

            throw new ItemMediumImageSizeException();
        }
    }

    // Large image

    if (largeImage && Validator.isNull(largeImageURL) && largeImageFile != null && largeImageBytes != null) {

        String largeImageName = largeImageFile.getName();

        if (largeImageName != null) {
            boolean validLargeImageExtension = false;

            for (int i = 0; i < imageExtensions.length; i++) {
                if (StringPool.STAR.equals(imageExtensions[i])
                        || StringUtil.endsWith(largeImageName, imageExtensions[i])) {

                    validLargeImageExtension = true;

                    break;
                }
            }

            if (!validLargeImageExtension) {
                throw new ItemLargeImageNameException(largeImageName);
            }
        }

        long largeImageMaxSize = GetterUtil
                .getLong(PrefsPropsUtil.getString(PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE));

        if ((largeImageMaxSize > 0)
                && ((largeImageBytes == null) || (largeImageBytes.length > largeImageMaxSize))) {

            throw new ItemLargeImageSizeException();
        }
    }
}

From source file:com.liferay.so.service.persistence.impl.FavoriteSitePersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, FavoriteSite> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*from  w  w w  .ja  v a2  s .  com*/

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

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

        Serializable primaryKey = iterator.next();

        FavoriteSite favoriteSite = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        FavoriteSite favoriteSite = (FavoriteSite) EntityCacheUtil
                .getResult(FavoriteSiteModelImpl.ENTITY_CACHE_ENABLED, FavoriteSiteImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_FAVORITESITE_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 (FavoriteSite favoriteSite : (List<FavoriteSite>) q.list()) {
            map.put(favoriteSite.getPrimaryKeyObj(), favoriteSite);

            cacheResult(favoriteSite);

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

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

    return map;
}

From source file:com.liferay.so.service.persistence.impl.MemberRequestPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        MemberRequest memberRequest = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        MemberRequest memberRequest = (MemberRequest) EntityCacheUtil
                .getResult(MemberRequestModelImpl.ENTITY_CACHE_ENABLED, MemberRequestImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_MEMBERREQUEST_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 (MemberRequest memberRequest : (List<MemberRequest>) q.list()) {
            map.put(memberRequest.getPrimaryKeyObj(), memberRequest);

            cacheResult(memberRequest);

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

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

    return map;
}

From source file:com.liferay.so.service.persistence.impl.ProjectsEntryPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        ProjectsEntry projectsEntry = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        ProjectsEntry projectsEntry = (ProjectsEntry) EntityCacheUtil
                .getResult(ProjectsEntryModelImpl.ENTITY_CACHE_ENABLED, ProjectsEntryImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_PROJECTSENTRY_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 (ProjectsEntry projectsEntry : (List<ProjectsEntry>) q.list()) {
            map.put(projectsEntry.getPrimaryKeyObj(), projectsEntry);

            cacheResult(projectsEntry);

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

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

    return map;
}

From source file:com.liferay.social.activity.customizer.service.persistence.impl.CustomSocialActivitySetPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        CustomSocialActivitySet customSocialActivitySet = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_CUSTOMSOCIALACTIVITYSET_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 (CustomSocialActivitySet customSocialActivitySet : (List<CustomSocialActivitySet>) q.list()) {
            map.put(customSocialActivitySet.getPrimaryKeyObj(), customSocialActivitySet);

            cacheResult(customSocialActivitySet);

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

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

    return map;
}

From source file:com.liferay.socialcoding.service.persistence.impl.JIRAActionPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        JIRAAction jiraAction = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        JIRAAction jiraAction = (JIRAAction) EntityCacheUtil.getResult(JIRAActionModelImpl.ENTITY_CACHE_ENABLED,
                JIRAActionImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_JIRAACTION_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 (JIRAAction jiraAction : (List<JIRAAction>) q.list()) {
            map.put(jiraAction.getPrimaryKeyObj(), jiraAction);

            cacheResult(jiraAction);

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

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

    return map;
}

From source file:com.liferay.socialcoding.service.persistence.impl.JIRAChangeGroupPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        JIRAChangeGroup jiraChangeGroup = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        JIRAChangeGroup jiraChangeGroup = (JIRAChangeGroup) EntityCacheUtil.getResult(
                JIRAChangeGroupModelImpl.ENTITY_CACHE_ENABLED, JIRAChangeGroupImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_JIRACHANGEGROUP_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 (JIRAChangeGroup jiraChangeGroup : (List<JIRAChangeGroup>) q.list()) {
            map.put(jiraChangeGroup.getPrimaryKeyObj(), jiraChangeGroup);

            cacheResult(jiraChangeGroup);

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

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

    return map;
}

From source file:com.liferay.socialcoding.service.persistence.impl.JIRAChangeItemPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, JIRAChangeItem> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from  w w  w .j av a  2 s.  co  m

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

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

        Serializable primaryKey = iterator.next();

        JIRAChangeItem jiraChangeItem = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        JIRAChangeItem jiraChangeItem = (JIRAChangeItem) EntityCacheUtil
                .getResult(JIRAChangeItemModelImpl.ENTITY_CACHE_ENABLED, JIRAChangeItemImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_JIRACHANGEITEM_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 (JIRAChangeItem jiraChangeItem : (List<JIRAChangeItem>) q.list()) {
            map.put(jiraChangeItem.getPrimaryKeyObj(), jiraChangeItem);

            cacheResult(jiraChangeItem);

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

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

    return map;
}

From source file:com.liferay.socialcoding.service.persistence.impl.JIRAIssuePersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, JIRAIssue> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*w  w w.j a v  a2s.  com*/

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

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

        Serializable primaryKey = iterator.next();

        JIRAIssue jiraIssue = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        JIRAIssue jiraIssue = (JIRAIssue) EntityCacheUtil.getResult(JIRAIssueModelImpl.ENTITY_CACHE_ENABLED,
                JIRAIssueImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_JIRAISSUE_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 (JIRAIssue jiraIssue : (List<JIRAIssue>) q.list()) {
            map.put(jiraIssue.getPrimaryKeyObj(), jiraIssue);

            cacheResult(jiraIssue);

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

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

    return map;
}