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.evp.admin.service.persistence.impl.VolunteerPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Volunteer volunteer = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Volunteer volunteer = (Volunteer) EntityCacheUtil.getResult(VolunteerModelImpl.ENTITY_CACHE_ENABLED,
                VolunteerImpl.class, primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_VOLUNTEER_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 (Volunteer volunteer : (List<Volunteer>) q.list()) {
            map.put(volunteer.getPrimaryKeyObj(), volunteer);

            cacheResult(volunteer);

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

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

    return map;
}

From source file:com.liferay.example.servicebuilder.extdb.service.persistence.impl.UserLoginPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, UserLogin> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*from   w w  w.java2  s .  c om*/

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

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

        Serializable primaryKey = iterator.next();

        UserLogin userLogin = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_USERLOGIN_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 (UserLogin userLogin : (List<UserLogin>) q.list()) {
            map.put(userLogin.getPrimaryKeyObj(), userLogin);

            cacheResult(userLogin);

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

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

    return map;
}

From source file:com.liferay.expando.taglib.servlet.taglib.CustomAttributesAvailableTag.java

License:Open Source License

@Override
public int doStartTag() throws JspException {
    try {/*  w w  w .j  a va2s. c  o  m*/
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        long companyId = _companyId;

        if (companyId == 0) {
            companyId = themeDisplay.getCompanyId();
        }

        ExpandoBridge expandoBridge = null;

        if (_classPK == 0) {
            expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(companyId, _className);
        } else {
            expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(companyId, _className, _classPK);
        }

        List<String> attributeNames = ListUtil.remove(Collections.list(expandoBridge.getAttributeNames()),
                ListUtil.fromString(_ignoreAttributeNames, StringPool.COMMA));

        if (attributeNames.isEmpty()) {
            return SKIP_BODY;
        }

        if (_classPK == 0) {
            return EVAL_BODY_INCLUDE;
        }

        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

        for (String attributeName : attributeNames) {
            Serializable value = expandoBridge.getAttribute(attributeName);

            if (Validator.isNull(value)) {
                continue;
            }

            UnicodeProperties properties = expandoBridge.getAttributeProperties(attributeName);

            boolean propertyHidden = GetterUtil
                    .getBoolean(properties.get(ExpandoColumnConstants.PROPERTY_HIDDEN));
            boolean propertyVisibleWithUpdatePermission = GetterUtil
                    .getBoolean(properties.get(ExpandoColumnConstants.PROPERTY_VISIBLE_WITH_UPDATE_PERMISSION));

            if (_editable && propertyVisibleWithUpdatePermission) {
                if (ExpandoColumnPermissionUtil.contains(permissionChecker, companyId, _className,
                        ExpandoTableConstants.DEFAULT_TABLE_NAME, attributeName, ActionKeys.UPDATE)) {

                    propertyHidden = false;
                } else {
                    propertyHidden = true;
                }
            }

            if (!propertyHidden && ExpandoColumnPermissionUtil.contains(permissionChecker, companyId,
                    _className, ExpandoTableConstants.DEFAULT_TABLE_NAME, attributeName, ActionKeys.VIEW)) {

                return EVAL_BODY_INCLUDE;
            }
        }

        return SKIP_BODY;
    } catch (Exception e) {
        throw new JspException(e);
    } finally {
        if (!ServerDetector.isResin()) {
            _className = null;
            _classPK = 0;
            _companyId = 0;
            _editable = false;
            _ignoreAttributeNames = null;
        }
    }
}

From source file:com.liferay.expando.web.internal.portlet.ExpandoPortlet.java

License:Open Source License

protected Serializable getValue(PortletRequest portletRequest, String name, int type) throws PortalException {

    String delimiter = StringPool.COMMA;

    Serializable value = null;/*from  www.j  a  v  a 2s  .  c  o  m*/

    if (type == ExpandoColumnConstants.BOOLEAN) {
        value = ParamUtil.getBoolean(portletRequest, name);
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
    } else if (type == ExpandoColumnConstants.DATE) {
        User user = _portal.getUser(portletRequest);

        int valueDateMonth = ParamUtil.getInteger(portletRequest, name + "Month");
        int valueDateDay = ParamUtil.getInteger(portletRequest, name + "Day");
        int valueDateYear = ParamUtil.getInteger(portletRequest, name + "Year");
        int valueDateHour = ParamUtil.getInteger(portletRequest, name + "Hour");
        int valueDateMinute = ParamUtil.getInteger(portletRequest, name + "Minute");
        int valueDateAmPm = ParamUtil.getInteger(portletRequest, name + "AmPm");

        if (valueDateAmPm == Calendar.PM) {
            valueDateHour += 12;
        }

        value = _portal.getDate(valueDateMonth, valueDateDay, valueDateYear, valueDateHour, valueDateMinute,
                user.getTimeZone(), ValueDataException.class);
    } else if (type == ExpandoColumnConstants.DATE_ARRAY) {
    } else if (type == ExpandoColumnConstants.DOUBLE) {
        value = ParamUtil.getDouble(portletRequest, name);
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getDoubleValues(values);
    } else if (type == ExpandoColumnConstants.FLOAT) {
        value = ParamUtil.getFloat(portletRequest, name);
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getFloatValues(values);
    } else if (type == ExpandoColumnConstants.INTEGER) {
        value = ParamUtil.getInteger(portletRequest, name);
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getIntegerValues(values);
    } else if (type == ExpandoColumnConstants.LONG) {
        value = ParamUtil.getLong(portletRequest, name);
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getLongValues(values);
    } else if (type == ExpandoColumnConstants.NUMBER) {
        value = ParamUtil.getNumber(portletRequest, name);
    } else if (type == ExpandoColumnConstants.NUMBER_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getNumberValues(values);
    } else if (type == ExpandoColumnConstants.SHORT) {
        value = ParamUtil.getShort(portletRequest, name);
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getShortValues(values);
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        value = StringUtil.split(paramValue, delimiter);
    } else if (type == ExpandoColumnConstants.STRING_LOCALIZED) {
        value = (Serializable) LocalizationUtil.getLocalizationMap(portletRequest, name);
    } else {
        value = ParamUtil.getString(portletRequest, name);
    }

    return value;
}

From source file:com.liferay.faces.demos.bean.DocUploadBackingBean.java

License:Open Source License

public String uploadSingleAttachments(UploadedFileWrapper fileToUpload) {
    boolean success = true;
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Locale locale = facesContext.getViewRoot().getLocale();
    if (locale == null) {
        locale = Locale.getDefault();
    }/*from ww  w  .  j av  a2 s. c  o m*/
    ArrayList<UploadedFileWrapper> uploadedFiles = new ArrayList<UploadedFileWrapper>();
    uploadedFiles.add(fileToUpload);
    DLFolder dlFolder = docLibModelBean.getSelectedNodeDlFolder();
    try {
        for (UploadedFileWrapper uploadedFile : uploadedFiles) {
            //               DLFolder dlFolder = folderUserObject.getDlFolder();
            String name = stripInvalidFileNameCharacters(uploadedFile.getName());
            String title = name;
            String description = null;
            String changeLog = null;
            File file = new File(uploadedFile.getAbsolutePath());
            ServiceContext serviceContext = new ServiceContext();
            // Temporary: Make the default setting be that community members can view the file. Need to develop a
            // "Viewable By" permissions Facelet composite component UI similar to
            // portal-web/docroot/html/taglib/ui/input_permissions/page.jsp
            serviceContext.setAddGroupPermissions(true);
            try {
                long fileEntryTypeId = DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT;
                Map<String, Fields> fieldsMap = new HashMap<String, Fields>();
                FileInputStream inputStream = new FileInputStream(file);
                DLFileEntryServiceUtil.addFileEntry(dlFolder.getGroupId(), dlFolder.getRepositoryId(),
                        dlFolder.getFolderId(), name, uploadedFile.getContentType(), title, description,
                        changeLog, fileEntryTypeId, fieldsMap, file, inputStream, file.length(),
                        serviceContext);
                inputStream.close();
                file.delete();
            } catch (DuplicateFileException e) {
                success = false;
                liferayFacesContext.addGlobalErrorMessage("please-enter-a-unique-document-name");
            } catch (FileNameException e) {
                success = false;

                String extensions = StringUtil.merge(
                        PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA),
                        StringPool.COMMA_AND_SPACE);
                String message = liferayFacesContext
                        .getMessage("document-names-must-end-with-one-of-the-following-extensions");
                message = message + extensions;
                liferayFacesContext.addGlobalErrorMessage(message);
            } catch (FileSizeException e) {
                success = false;

                String message = liferayFacesContext.getMessage("please-enter-a-file-with-a-valid-file-size");
                message = message + " (" + getMaxFileSizeKB() + "k max)";
                liferayFacesContext.addGlobalErrorMessage(message);
            } catch (SourceFileNameException e) {
                success = false;
                liferayFacesContext.addGlobalErrorMessage(
                        "the-source-file-does-not-have-the-same-extension-as-the-original-file");
            }
        }
    } catch (Exception e) {
        success = false;
        logger.error(e.getMessage(), e);
        liferayFacesContext.addGlobalUnexpectedErrorMessage();
    }
    docLibModelBean.forceDocumentRequery();
    String nextPage = success ? "/views/portletViewMode.xhtml" : "error.xhtml";
    return nextPage;
}

From source file:com.liferay.gs.hack.service.persistence.impl.ClientPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Client client = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_CLIENT_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 (Client client : (List<Client>) q.list()) {
            map.put(client.getPrimaryKeyObj(), client);

            cacheResult(client);

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

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

    return map;
}

From source file:com.liferay.gs.hack.service.persistence.impl.ProjectPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Project project = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_PROJECT_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 (Project project : (List<Project>) q.list()) {
            map.put(project.getPrimaryKeyObj(), project);

            cacheResult(project);

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

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

    return map;
}

From source file:com.liferay.gs.hack.service.persistence.impl.ProjectTaskPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, ProjectTask> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }//from  w  ww  . jav a2 s . co  m

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

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

        Serializable primaryKey = iterator.next();

        ProjectTask projectTask = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_PROJECTTASK_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 (ProjectTask projectTask : (List<ProjectTask>) q.list()) {
            map.put(projectTask.getPrimaryKeyObj(), projectTask);

            cacheResult(projectTask);

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

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

    return map;
}

From source file:com.liferay.gs.hack.service.persistence.impl.ProjectUserPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        ProjectUser projectUser = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_PROJECTUSER_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 (ProjectUser projectUser : (List<ProjectUser>) q.list()) {
            map.put(projectUser.getPrimaryKeyObj(), projectUser);

            cacheResult(projectUser);

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

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

    return map;
}

From source file:com.liferay.gs.hack.service.persistence.impl.TimesheetApprovalPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        TimesheetApproval timesheetApproval = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_TIMESHEETAPPROVAL_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 (TimesheetApproval timesheetApproval : (List<TimesheetApproval>) q.list()) {
            map.put(timesheetApproval.getPrimaryKeyObj(), timesheetApproval);

            cacheResult(timesheetApproval);

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

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

    return map;
}