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.socialcoding.service.persistence.impl.JIRAProjectPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        JIRAProject jiraProject = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        JIRAProject jiraProject = (JIRAProject) EntityCacheUtil
                .getResult(JIRAProjectModelImpl.ENTITY_CACHE_ENABLED, JIRAProjectImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_JIRAPROJECT_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 (JIRAProject jiraProject : (List<JIRAProject>) q.list()) {
            map.put(jiraProject.getPrimaryKeyObj(), jiraProject);

            cacheResult(jiraProject);

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

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

    return map;
}

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

License:Open Source License

@Override
public Map<Serializable, SVNRepository> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }// www. ja  va  2s . co  m

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

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

        Serializable primaryKey = iterator.next();

        SVNRepository svnRepository = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        SVNRepository svnRepository = (SVNRepository) EntityCacheUtil
                .getResult(SVNRepositoryModelImpl.ENTITY_CACHE_ENABLED, SVNRepositoryImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_SVNREPOSITORY_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 (SVNRepository svnRepository : (List<SVNRepository>) q.list()) {
            map.put(svnRepository.getPrimaryKeyObj(), svnRepository);

            cacheResult(svnRepository);

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

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

    return map;
}

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

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        SVNRevision svnRevision = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        SVNRevision svnRevision = (SVNRevision) EntityCacheUtil
                .getResult(SVNRevisionModelImpl.ENTITY_CACHE_ENABLED, SVNRevisionImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_SVNREVISION_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 (SVNRevision svnRevision : (List<SVNRevision>) q.list()) {
            map.put(svnRevision.getPrimaryKeyObj(), svnRevision);

            cacheResult(svnRevision);

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

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

    return map;
}

From source file:com.liferay.socialnetworking.service.persistence.impl.MeetupsEntryPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        MeetupsEntry meetupsEntry = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        MeetupsEntry meetupsEntry = (MeetupsEntry) EntityCacheUtil
                .getResult(MeetupsEntryModelImpl.ENTITY_CACHE_ENABLED, MeetupsEntryImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_MEETUPSENTRY_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 (MeetupsEntry meetupsEntry : (List<MeetupsEntry>) q.list()) {
            map.put(meetupsEntry.getPrimaryKeyObj(), meetupsEntry);

            cacheResult(meetupsEntry);

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

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

    return map;
}

From source file:com.liferay.socialnetworking.service.persistence.impl.MeetupsRegistrationPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        MeetupsRegistration meetupsRegistration = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        MeetupsRegistration meetupsRegistration = (MeetupsRegistration) EntityCacheUtil.getResult(
                MeetupsRegistrationModelImpl.ENTITY_CACHE_ENABLED, MeetupsRegistrationImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_MEETUPSREGISTRATION_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 (MeetupsRegistration meetupsRegistration : (List<MeetupsRegistration>) q.list()) {
            map.put(meetupsRegistration.getPrimaryKeyObj(), meetupsRegistration);

            cacheResult(meetupsRegistration);

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

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

    return map;
}

From source file:com.liferay.socialnetworking.service.persistence.impl.WallEntryPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        WallEntry wallEntry = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        WallEntry wallEntry = (WallEntry) EntityCacheUtil.getResult(WallEntryModelImpl.ENTITY_CACHE_ENABLED,
                WallEntryImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_WALLENTRY_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 (WallEntry wallEntry : (List<WallEntry>) q.list()) {
            map.put(wallEntry.getPrimaryKeyObj(), wallEntry);

            cacheResult(wallEntry);

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

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

    return map;
}

From source file:com.liferay.stocks.util.StocksWebCacheItem.java

License:Open Source License

@Override
public Object convert(String key) throws WebCacheException {
    String symbol = _symbol;/*  w  w w.j  a  va2s. c  o m*/
    double lastTrade = 0.0;
    double change = 0.0;
    double open = 0.0;
    double dayHigh = 0.0;
    double dayLow = 0.0;
    long volume = 0;

    Stocks stocks = new Stocks(symbol, lastTrade, change, open, dayHigh, dayLow, volume);

    try {
        String text = HttpUtil
                .URLtoString("http://finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=sl1d1t1c1ohgv&e=.csv");

        StringTokenizer st = new StringTokenizer(text, StringPool.COMMA);

        // Skip symbol

        st.nextToken();

        try {
            lastTrade = GetterUtil.getDouble(st.nextToken().replace('"', ' ').trim());

            stocks.setLastTrade(lastTrade);
        } catch (NumberFormatException nfe) {
            stocks.setLastTradeAvailable(false);
        }

        // Skip date and time

        st.nextToken();
        st.nextToken();

        try {
            change = GetterUtil.getDouble(st.nextToken().replace('"', ' ').trim());

            stocks.setChange(change);
        } catch (NumberFormatException nfe) {
            stocks.setChangeAvailable(false);
        }

        try {
            open = GetterUtil.getDouble(st.nextToken().replace('"', ' ').trim());

            stocks.setOpen(open);
        } catch (NumberFormatException nfe) {
            stocks.setOpenAvailable(false);
        }

        try {
            dayHigh = GetterUtil.getDouble(st.nextToken().replace('"', ' ').trim());

            stocks.setDayHigh(dayHigh);
        } catch (NumberFormatException nfe) {
            stocks.setDayHighAvailable(false);
        }

        try {
            dayLow = GetterUtil.getDouble(st.nextToken().replace('"', ' ').trim());

            stocks.setDayLow(dayLow);
        } catch (NumberFormatException nfe) {
            stocks.setDayLowAvailable(false);
        }

        try {
            volume = GetterUtil.getLong(st.nextToken().replace('"', ' ').trim());

            stocks.setVolume(volume);
        } catch (NumberFormatException nfe) {
            stocks.setVolumeAvailable(false);
        }

        if (!stocks.isValid()) {
            throw new WebCacheException(symbol);
        }
    } catch (Exception e) {
        throw new WebCacheException(symbol + " " + e.toString());
    }

    return stocks;
}

From source file:com.liferay.sync.service.persistence.impl.SyncDevicePersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        SyncDevice syncDevice = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        SyncDevice syncDevice = (SyncDevice) entityCache.getResult(SyncDeviceModelImpl.ENTITY_CACHE_ENABLED,
                SyncDeviceImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_SYNCDEVICE_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 (SyncDevice syncDevice : (List<SyncDevice>) q.list()) {
            map.put(syncDevice.getPrimaryKeyObj(), syncDevice);

            cacheResult(syncDevice);

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

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

    return map;
}

From source file:com.liferay.sync.service.persistence.impl.SyncDLFileVersionDiffPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        SyncDLFileVersionDiff syncDLFileVersionDiff = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        SyncDLFileVersionDiff syncDLFileVersionDiff = (SyncDLFileVersionDiff) EntityCacheUtil.getResult(
                SyncDLFileVersionDiffModelImpl.ENTITY_CACHE_ENABLED, SyncDLFileVersionDiffImpl.class,
                primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_SYNCDLFILEVERSIONDIFF_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 (SyncDLFileVersionDiff syncDLFileVersionDiff : (List<SyncDLFileVersionDiff>) q.list()) {
            map.put(syncDLFileVersionDiff.getPrimaryKeyObj(), syncDLFileVersionDiff);

            cacheResult(syncDLFileVersionDiff);

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

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

    return map;
}

From source file:com.liferay.sync.service.persistence.impl.SyncDLObjectPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        SyncDLObject syncDLObject = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        SyncDLObject syncDLObject = (SyncDLObject) EntityCacheUtil
                .getResult(SyncDLObjectModelImpl.ENTITY_CACHE_ENABLED, SyncDLObjectImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_SYNCDLOBJECT_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 (SyncDLObject syncDLObject : (List<SyncDLObject>) q.list()) {
            map.put(syncDLObject.getPrimaryKeyObj(), syncDLObject);

            cacheResult(syncDLObject);

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

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

    return map;
}