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

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

Introduction

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

Prototype

String CLOSE_PARENTHESIS

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

Click Source Link

Usage

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of bookmarks entries that the user has permission to view where groupId = ? and userId = ? and folderId = any ? and status = ?.
 *
 * @param groupId the group ID//w ww.  j a v a2s. co m
 * @param userId the user ID
 * @param folderIds the folder IDs
 * @param status the status
 * @return the number of matching bookmarks entries that the user has permission to view
 */
@Override
public int filterCountByG_U_F_S(long groupId, long userId, long[] folderIds, int status) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_U_F_S(groupId, userId, folderIds, status);
    }

    if (folderIds == null) {
        folderIds = new long[0];
    } else if (folderIds.length > 1) {
        folderIds = ArrayUtil.unique(folderIds);

        Arrays.sort(folderIds);
    }

    StringBundler query = new StringBundler();

    query.append(_SQL_COUNT_BOOKMARKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_U_F_S_GROUPID_2);

    query.append(_FINDER_COLUMN_G_U_F_S_USERID_2);

    if (folderIds.length > 0) {
        query.append(StringPool.OPEN_PARENTHESIS);

        query.append(_FINDER_COLUMN_G_U_F_S_FOLDERID_7);

        query.append(StringUtil.merge(folderIds));

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_U_F_S_STATUS_2);

    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1);

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), BookmarksEntry.class.getName(),
            _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN, groupId);

    Session session = null;

    try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(userId);

        qPos.add(status);

        Long count = (Long) q.uniqueResult();

        return count.intValue();
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        BookmarksEntry bookmarksEntry = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_BOOKMARKSENTRY_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 (BookmarksEntry bookmarksEntry : (List<BookmarksEntry>) q.list()) {
            map.put(bookmarksEntry.getPrimaryKeyObj(), bookmarksEntry);

            cacheResult(bookmarksEntry);

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

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

    return map;
}

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksFolderFinderImpl.java

License:Open Source License

protected int doCountF_E_ByG_F(long groupId, long folderId, QueryDefinition<?> queryDefinition,
        boolean inlineSQLHelper) {

    Session session = null;/*  w ww.j  a v a 2  s.  com*/

    try {
        session = openSession();

        StringBundler sb = new StringBundler(5);

        sb.append(StringPool.OPEN_PARENTHESIS);

        String sql = null;

        if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) {
            sql = CustomSQLUtil.get(getClass(), COUNT_F_BY_G_P);
        } else {
            sql = CustomSQLUtil.get(getClass(), COUNT_F_BY_G_P_S);

            sql = replaceExcludeStatus(sql, queryDefinition);
        }

        if (inlineSQLHelper) {
            sql = InlineSQLHelperUtil.replacePermissionCheck(sql, BookmarksFolder.class.getName(),
                    "BookmarksFolder.folderId", groupId);
        }

        sb.append(sql);
        sb.append(") UNION ALL (");

        if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) {
            sql = CustomSQLUtil.get(getClass(), COUNT_E_BY_G_F);
        } else {
            sql = CustomSQLUtil.get(getClass(), COUNT_E_BY_G_F_S);

            sql = replaceExcludeStatus(sql, queryDefinition);
        }

        if (inlineSQLHelper) {
            sql = InlineSQLHelperUtil.replacePermissionCheck(sql, BookmarksEntry.class.getName(),
                    "BookmarksEntry.fileEntryId", groupId);
        }

        sb.append(sql);
        sb.append(StringPool.CLOSE_PARENTHESIS);

        sql = sb.toString();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);
        qPos.add(folderId);

        if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
            qPos.add(queryDefinition.getStatus());
        }

        qPos.add(groupId);
        qPos.add(folderId);

        if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
            qPos.add(queryDefinition.getStatus());
        }

        int count = 0;

        Iterator<Long> itr = q.iterate();

        while (itr.hasNext()) {
            Long l = itr.next();

            if (l != null) {
                count += l.intValue();
            }
        }

        return count;
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksFolderPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        BookmarksFolder bookmarksFolder = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_BOOKMARKSFOLDER_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 (BookmarksFolder bookmarksFolder : (List<BookmarksFolder>) q.list()) {
            map.put(bookmarksFolder.getPrimaryKeyObj(), bookmarksFolder);

            cacheResult(bookmarksFolder);

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

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

    return map;
}

From source file:com.liferay.bootcamp.service.persistence.impl.BookPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Book book = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Book book = (Book) entityCache.getResult(BookModelImpl.ENTITY_CACHE_ENABLED, BookImpl.class,
                primaryKey);

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

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

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

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

    query.append(_SQL_SELECT_BOOK_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 (Book book : (List<Book>) q.list()) {
            map.put(book.getPrimaryKeyObj(), book);

            cacheResult(book);

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

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

    return map;
}

From source file:com.liferay.calendar.service.persistence.CalendarResourcePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the calendar resources where groupId = any &#63; and code LIKE &#63; and active = &#63;.
 *
 * <p>//from  w  w w .j  a va2 s .  c o m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </p>
 *
 * @param groupIds the group IDs
 * @param code the code
 * @param active the active
 * @param start the lower bound of the range of calendar resources
 * @param end the upper bound of the range of calendar resources (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching calendar resources
 * @throws SystemException if a system exception occurred
 */
public List<CalendarResource> findByG_C_A(long[] groupIds, String code, boolean active, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_A;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        finderArgs = new Object[] { StringUtil.merge(groupIds), code, active };
    } else {
        finderArgs = new Object[] { StringUtil.merge(groupIds), code, active,

                start, end, orderByComparator };
    }

    List<CalendarResource> list = (List<CalendarResource>) FinderCacheUtil.getResult(finderPath, finderArgs,
            this);

    if ((list != null) && !list.isEmpty()) {
        for (CalendarResource calendarResource : list) {
            if (!ArrayUtil.contains(groupIds, calendarResource.getGroupId())
                    || !Validator.equals(code, calendarResource.getCode())
                    || (active != calendarResource.getActive())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_SELECT_CALENDARRESOURCE_WHERE);

        boolean conjunctionable = false;

        if ((groupIds == null) || (groupIds.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < groupIds.length; i++) {
                query.append(_FINDER_COLUMN_G_C_A_GROUPID_5);

                if ((i + 1) < groupIds.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        if (code == null) {
            query.append(_FINDER_COLUMN_G_C_A_CODE_4);
        } else {
            if (code.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_G_C_A_CODE_6);
            } else {
                query.append(_FINDER_COLUMN_G_C_A_CODE_5);
            }
        }

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_C_A_ACTIVE_5);

        conjunctionable = true;

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        }

        else {
            query.append(CalendarResourceModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (groupIds != null) {
                qPos.add(groupIds);
            }

            if (code != null) {
                qPos.add(code);
            }

            qPos.add(active);

            list = (List<CalendarResource>) QueryUtil.list(q, getDialect(), start, end);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (list == null) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);
            } else {
                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            }

            closeSession(session);
        }
    }

    return list;
}

From source file:com.liferay.calendar.service.persistence.CalendarResourcePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the calendar resources where groupId = any &#63; and name LIKE &#63; and active = &#63;.
 *
 * <p>//from   w ww .  j  a  v  a  2 s  .  co m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
 * </p>
 *
 * @param groupIds the group IDs
 * @param name the name
 * @param active the active
 * @param start the lower bound of the range of calendar resources
 * @param end the upper bound of the range of calendar resources (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching calendar resources
 * @throws SystemException if a system exception occurred
 */
public List<CalendarResource> findByG_N_A(long[] groupIds, String name, boolean active, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_A;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        finderArgs = new Object[] { StringUtil.merge(groupIds), name, active };
    } else {
        finderArgs = new Object[] { StringUtil.merge(groupIds), name, active,

                start, end, orderByComparator };
    }

    List<CalendarResource> list = (List<CalendarResource>) FinderCacheUtil.getResult(finderPath, finderArgs,
            this);

    if ((list != null) && !list.isEmpty()) {
        for (CalendarResource calendarResource : list) {
            if (!ArrayUtil.contains(groupIds, calendarResource.getGroupId())
                    || !Validator.equals(name, calendarResource.getName())
                    || (active != calendarResource.getActive())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_SELECT_CALENDARRESOURCE_WHERE);

        boolean conjunctionable = false;

        if ((groupIds == null) || (groupIds.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < groupIds.length; i++) {
                query.append(_FINDER_COLUMN_G_N_A_GROUPID_5);

                if ((i + 1) < groupIds.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        if (name == null) {
            query.append(_FINDER_COLUMN_G_N_A_NAME_4);
        } else {
            if (name.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_G_N_A_NAME_6);
            } else {
                query.append(_FINDER_COLUMN_G_N_A_NAME_5);
            }
        }

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_N_A_ACTIVE_5);

        conjunctionable = true;

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        }

        else {
            query.append(CalendarResourceModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (groupIds != null) {
                qPos.add(groupIds);
            }

            if (name != null) {
                qPos.add(name);
            }

            qPos.add(active);

            list = (List<CalendarResource>) QueryUtil.list(q, getDialect(), start, end);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (list == null) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);
            } else {
                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            }

            closeSession(session);
        }
    }

    return list;
}

From source file:com.liferay.calendar.service.persistence.CalendarResourcePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of calendar resources where groupId = any &#63; and code LIKE &#63; and active = &#63;.
 *
 * @param groupIds the group IDs//from   ww w. ja va2 s.  c  om
 * @param code the code
 * @param active the active
 * @return the number of matching calendar resources
 * @throws SystemException if a system exception occurred
 */
public int countByG_C_A(long[] groupIds, String code, boolean active) throws SystemException {
    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds), code, active };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_A, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_COUNT_CALENDARRESOURCE_WHERE);

        boolean conjunctionable = false;

        if ((groupIds == null) || (groupIds.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < groupIds.length; i++) {
                query.append(_FINDER_COLUMN_G_C_A_GROUPID_5);

                if ((i + 1) < groupIds.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        if (code == null) {
            query.append(_FINDER_COLUMN_G_C_A_CODE_4);
        } else {
            if (code.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_G_C_A_CODE_6);
            } else {
                query.append(_FINDER_COLUMN_G_C_A_CODE_5);
            }
        }

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_C_A_ACTIVE_5);

        conjunctionable = true;

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (groupIds != null) {
                qPos.add(groupIds);
            }

            if (code != null) {
                qPos.add(code);
            }

            qPos.add(active);

            count = (Long) q.uniqueResult();
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (count == null) {
                count = Long.valueOf(0);
            }

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_A, finderArgs, count);

            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:com.liferay.calendar.service.persistence.CalendarResourcePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of calendar resources where groupId = any &#63; and name LIKE &#63; and active = &#63;.
 *
 * @param groupIds the group IDs//  ww  w  . j ava 2 s  .  co m
 * @param name the name
 * @param active the active
 * @return the number of matching calendar resources
 * @throws SystemException if a system exception occurred
 */
public int countByG_N_A(long[] groupIds, String name, boolean active) throws SystemException {
    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds), name, active };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_N_A, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_COUNT_CALENDARRESOURCE_WHERE);

        boolean conjunctionable = false;

        if ((groupIds == null) || (groupIds.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < groupIds.length; i++) {
                query.append(_FINDER_COLUMN_G_N_A_GROUPID_5);

                if ((i + 1) < groupIds.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        if (name == null) {
            query.append(_FINDER_COLUMN_G_N_A_NAME_4);
        } else {
            if (name.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_G_N_A_NAME_6);
            } else {
                query.append(_FINDER_COLUMN_G_N_A_NAME_5);
            }
        }

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_N_A_ACTIVE_5);

        conjunctionable = true;

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (groupIds != null) {
                qPos.add(groupIds);
            }

            if (name != null) {
                qPos.add(name);
            }

            qPos.add(active);

            count = (Long) q.uniqueResult();
        } catch (Exception e) {
            throw processException(e);
        } finally {
            if (count == null) {
                count = Long.valueOf(0);
            }

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_N_A, finderArgs, count);

            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:com.liferay.calendar.service.persistence.impl.CalendarBookingPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the calendar bookings where calendarId = &#63; and status = any &#63;.
 *
 * <p>/*w w  w. j  a v  a 2  s. co m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.calendar.model.impl.CalendarBookingModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param calendarId the calendar ID
 * @param statuses the statuses
 * @param start the lower bound of the range of calendar bookings
 * @param end the upper bound of the range of calendar bookings (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching calendar bookings
 */
@Override
public List<CalendarBooking> findByC_S(long calendarId, int[] statuses, int start, int end,
        OrderByComparator<CalendarBooking> orderByComparator) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    if (statuses.length == 1) {
        return findByC_S(calendarId, statuses[0], start, end, orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { calendarId, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { calendarId, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<CalendarBooking> list = (List<CalendarBooking>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (CalendarBooking calendarBooking : list) {
            if ((calendarId != calendarBooking.getCalendarId())
                    || !ArrayUtil.contains(statuses, calendarBooking.getStatus())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_SELECT_CALENDARBOOKING_WHERE);

        query.append(_FINDER_COLUMN_C_S_CALENDARID_2);

        if (statuses.length > 0) {
            query.append(StringPool.OPEN_PARENTHESIS);

            query.append(_FINDER_COLUMN_C_S_STATUS_7);

            query.append(StringUtil.merge(statuses));

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

        query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1);

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(CalendarBookingModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(calendarId);

            if (!pagination) {
                list = (List<CalendarBooking>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<CalendarBooking>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}