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.knowledgebase.service.persistence.impl.KBArticlePersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        KBArticle kbArticle = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        KBArticle kbArticle = (KBArticle) EntityCacheUtil.getResult(KBArticleModelImpl.ENTITY_CACHE_ENABLED,
                KBArticleImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_KBARTICLE_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 (KBArticle kbArticle : (List<KBArticle>) q.list()) {
            map.put(kbArticle.getPrimaryKeyObj(), kbArticle);

            cacheResult(kbArticle);

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

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

    return map;
}

From source file:com.liferay.knowledgebase.service.persistence.impl.KBCommentPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        KBComment kbComment = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        KBComment kbComment = (KBComment) EntityCacheUtil.getResult(KBCommentModelImpl.ENTITY_CACHE_ENABLED,
                KBCommentImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_KBCOMMENT_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 (KBComment kbComment : (List<KBComment>) q.list()) {
            map.put(kbComment.getPrimaryKeyObj(), kbComment);

            cacheResult(kbComment);

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

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

    return map;
}

From source file:com.liferay.knowledgebase.service.persistence.impl.KBFolderPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        KBFolder kbFolder = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        KBFolder kbFolder = (KBFolder) EntityCacheUtil.getResult(KBFolderModelImpl.ENTITY_CACHE_ENABLED,
                KBFolderImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_KBFOLDER_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 (KBFolder kbFolder : (List<KBFolder>) q.list()) {
            map.put(kbFolder.getPrimaryKeyObj(), kbFolder);

            cacheResult(kbFolder);

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

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

    return map;
}

From source file:com.liferay.knowledgebase.service.persistence.impl.KBTemplatePersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        KBTemplate kbTemplate = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        KBTemplate kbTemplate = (KBTemplate) EntityCacheUtil.getResult(KBTemplateModelImpl.ENTITY_CACHE_ENABLED,
                KBTemplateImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_KBTEMPLATE_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 (KBTemplate kbTemplate : (List<KBTemplate>) q.list()) {
            map.put(kbTemplate.getPrimaryKeyObj(), kbTemplate);

            cacheResult(kbTemplate);

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

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

    return map;
}

From source file:com.liferay.mail.imap.IMAPAccessor.java

License:Open Source License

protected String getFlags(Message jxMessage) throws MessagingException {
    StringBundler sb = new StringBundler();

    if (jxMessage.isSet(Flags.Flag.FLAGGED)) {
        sb.append(MailConstants.FLAG_FLAGGED);
        sb.append(StringPool.COMMA);
    }//w w  w. jav a  2s  . c  o  m

    if (jxMessage.isSet(Flags.Flag.SEEN)) {
        sb.append(MailConstants.FLAG_SEEN);
        sb.append(StringPool.COMMA);
    }

    return sb.toString();
}

From source file:com.liferay.mail.imap.IMAPAccessor.java

License:Open Source License

protected InternetAddress[] getRecipients(long messageId) throws PortalException {

    try {// w w  w .j  av  a  2  s . com
        com.liferay.mail.model.Message message = MessageLocalServiceUtil.getMessage(messageId);

        StringBundler sb = new StringBundler(6);

        sb.append(message.getTo());
        sb.append(StringPool.COMMA);
        sb.append(message.getCc());
        sb.append(StringPool.COMMA);
        sb.append(message.getBcc());
        sb.append(StringPool.COMMA);

        return InternetAddress.parse(sb.toString(), true);
    } catch (AddressException ae) {
        throw new MailException(MailException.MESSAGE_INVALID_ADDRESS, ae);
    }
}

From source file:com.liferay.mail.service.persistence.impl.AccountPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Account account = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Account account = (Account) EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
                AccountImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_ACCOUNT_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 (Account account : (List<Account>) q.list()) {
            map.put(account.getPrimaryKeyObj(), account);

            cacheResult(account);

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

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

    return map;
}

From source file:com.liferay.mail.service.persistence.impl.AttachmentPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Attachment attachment = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Attachment attachment = (Attachment) EntityCacheUtil.getResult(AttachmentModelImpl.ENTITY_CACHE_ENABLED,
                AttachmentImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_ATTACHMENT_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 (Attachment attachment : (List<Attachment>) q.list()) {
            map.put(attachment.getPrimaryKeyObj(), attachment);

            cacheResult(attachment);

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

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

    return map;
}

From source file:com.liferay.mail.service.persistence.impl.FolderPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Folder folder = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Folder folder = (Folder) EntityCacheUtil.getResult(FolderModelImpl.ENTITY_CACHE_ENABLED,
                FolderImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_FOLDER_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 (Folder folder : (List<Folder>) q.list()) {
            map.put(folder.getPrimaryKeyObj(), folder);

            cacheResult(folder);

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

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

    return map;
}

From source file:com.liferay.mail.service.persistence.impl.MessagePersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Message message = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Message message = (Message) EntityCacheUtil.getResult(MessageModelImpl.ENTITY_CACHE_ENABLED,
                MessageImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_MESSAGE_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 (Message message : (List<Message>) q.list()) {
            map.put(message.getPrimaryKeyObj(), message);

            cacheResult(message);

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

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

    return map;
}