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.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();
    }//  w w w. j  a  v  a2 s.c  om

    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;
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryFinderImpl.java

License:Open Source License

protected String getAssetTagTagIds(long[] assetTagIds, boolean equalsOperator) {

    StringBundler sb = new StringBundler((assetTagIds.length * 4) + 1);

    sb.append(" (");

    for (int i = 0; i < assetTagIds.length; i++) {
        sb.append("AssetEntries_AssetTags.tagId ");

        if (equalsOperator) {
            sb.append(StringPool.EQUAL);
        } else {//from   w  w  w  .  ja  va  2s .  c  o m
            sb.append(StringPool.NOT_EQUAL);
        }

        sb.append(" ? ");

        if ((i + 1) != assetTagIds.length) {
            if (equalsOperator) {
                sb.append("OR ");
            } else {
                sb.append("AND ");
            }
        }
    }

    sb.append(StringPool.CLOSE_PARENTHESIS);

    return sb.toString();
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the tasks entries where userId = &#63; and status = any &#63;.
 *
 * <p>/*from w w w .  java 2 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. 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.tasks.model.impl.TasksEntryModelImpl}. 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 userId the user ID
 * @param statuses the statuses
 * @param start the lower bound of the range of tasks entries
 * @param end the upper bound of the range of tasks entries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching tasks entries
 */
@Override
public List<TasksEntry> findByU_S(long userId, int[] statuses, int start, int end,
        OrderByComparator<TasksEntry> orderByComparator) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    if (statuses.length == 1) {
        return findByU_S(userId, 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[] { userId, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { userId, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<TasksEntry> list = (List<TasksEntry>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_S, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (TasksEntry tasksEntry : list) {
            if ((userId != tasksEntry.getUserId()) || !ArrayUtil.contains(statuses, tasksEntry.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_TASKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_U_S_USERID_2);

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

            query.append(_FINDER_COLUMN_U_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(TasksEntryModelImpl.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(userId);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of tasks entries where userId = &#63; and status = any &#63;.
 *
 * @param userId the user ID//from ww w.  j a  v  a  2 s. co m
 * @param statuses the statuses
 * @return the number of matching tasks entries
 */
@Override
public int countByU_S(long userId, int[] statuses) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    Object[] finderArgs = new Object[] { userId, StringUtil.merge(statuses) };

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

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

        query.append(_SQL_COUNT_TASKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_U_S_USERID_2);

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

            query.append(_FINDER_COLUMN_U_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);

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(userId);

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_S, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_S, finderArgs);

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

    return count.intValue();
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the tasks entries where assigneeUserId = &#63; and status = any &#63;.
 *
 * <p>//from w  ww  .  j  a  v a  2  s .  c om
 * 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.tasks.model.impl.TasksEntryModelImpl}. 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 assigneeUserId the assignee user ID
 * @param statuses the statuses
 * @param start the lower bound of the range of tasks entries
 * @param end the upper bound of the range of tasks entries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching tasks entries
 */
@Override
public List<TasksEntry> findByA_S(long assigneeUserId, int[] statuses, int start, int end,
        OrderByComparator<TasksEntry> orderByComparator) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    if (statuses.length == 1) {
        return findByA_S(assigneeUserId, 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[] { assigneeUserId, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { assigneeUserId, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<TasksEntry> list = (List<TasksEntry>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_A_S, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (TasksEntry tasksEntry : list) {
            if ((assigneeUserId != tasksEntry.getAssigneeUserId())
                    || !ArrayUtil.contains(statuses, tasksEntry.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_TASKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_A_S_ASSIGNEEUSERID_2);

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

            query.append(_FINDER_COLUMN_A_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(TasksEntryModelImpl.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(assigneeUserId);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of tasks entries where assigneeUserId = &#63; and status = any &#63;.
 *
 * @param assigneeUserId the assignee user ID
 * @param statuses the statuses//from www  .  j  a  v  a  2  s .  c  om
 * @return the number of matching tasks entries
 */
@Override
public int countByA_S(long assigneeUserId, int[] statuses) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    Object[] finderArgs = new Object[] { assigneeUserId, StringUtil.merge(statuses) };

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

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

        query.append(_SQL_COUNT_TASKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_A_S_ASSIGNEEUSERID_2);

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

            query.append(_FINDER_COLUMN_A_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);

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(assigneeUserId);

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_A_S, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_A_S, finderArgs);

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

    return count.intValue();
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the tasks entries that the user has permission to view where groupId = &#63; and userId = &#63; and status = any &#63;.
 *
 * <p>/*  w w  w.ja  va 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.tasks.model.impl.TasksEntryModelImpl}. 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 groupId the group ID
 * @param userId the user ID
 * @param statuses the statuses
 * @param start the lower bound of the range of tasks entries
 * @param end the upper bound of the range of tasks entries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching tasks entries that the user has permission to view
 */
@Override
public List<TasksEntry> filterFindByG_U_S(long groupId, long userId, int[] statuses, int start, int end,
        OrderByComparator<TasksEntry> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_U_S(groupId, userId, statuses, start, end, orderByComparator);
    }

    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_TASKSENTRY_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_TASKSENTRY_NO_INLINE_DISTINCT_WHERE_1);
    }

    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);

    query.append(_FINDER_COLUMN_G_U_S_USERID_2);

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

        query.append(_FINDER_COLUMN_G_U_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 (!getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_TASKSENTRY_NO_INLINE_DISTINCT_WHERE_2);
    }

    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true);
        }
    } else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(TasksEntryModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(TasksEntryModelImpl.ORDER_BY_SQL);
        }
    }

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        if (getDB().isSupportsInlineDistinct()) {
            q.addEntity(_FILTER_ENTITY_ALIAS, TasksEntryImpl.class);
        } else {
            q.addEntity(_FILTER_ENTITY_TABLE, TasksEntryImpl.class);
        }

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(userId);

        return (List<TasksEntry>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the tasks entries where groupId = &#63; and userId = &#63; and status = any &#63;.
 *
 * <p>//w  w  w  .  j  av a  2  s  .  com
 * 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.tasks.model.impl.TasksEntryModelImpl}. 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 groupId the group ID
 * @param userId the user ID
 * @param statuses the statuses
 * @param start the lower bound of the range of tasks entries
 * @param end the upper bound of the range of tasks entries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching tasks entries
 */
@Override
public List<TasksEntry> findByG_U_S(long groupId, long userId, int[] statuses, int start, int end,
        OrderByComparator<TasksEntry> orderByComparator) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    if (statuses.length == 1) {
        return findByG_U_S(groupId, userId, 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[] { groupId, userId, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { groupId, userId, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<TasksEntry> list = (List<TasksEntry>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (TasksEntry tasksEntry : list) {
            if ((groupId != tasksEntry.getGroupId()) || (userId != tasksEntry.getUserId())
                    || !ArrayUtil.contains(statuses, tasksEntry.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_TASKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);

        query.append(_FINDER_COLUMN_G_U_S_USERID_2);

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

            query.append(_FINDER_COLUMN_G_U_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(TasksEntryModelImpl.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(groupId);

            qPos.add(userId);

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of tasks entries where groupId = &#63; and userId = &#63; and status = any &#63;.
 *
 * @param groupId the group ID/*from   w w  w  .  j av  a  2  s .co m*/
 * @param userId the user ID
 * @param statuses the statuses
 * @return the number of matching tasks entries
 */
@Override
public int countByG_U_S(long groupId, long userId, int[] statuses) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    Object[] finderArgs = new Object[] { groupId, userId, StringUtil.merge(statuses) };

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

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

        query.append(_SQL_COUNT_TASKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);

        query.append(_FINDER_COLUMN_G_U_S_USERID_2);

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

            query.append(_FINDER_COLUMN_G_U_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);

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

            qPos.add(userId);

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_S, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_S, finderArgs);

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

    return count.intValue();
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of tasks entries that the user has permission to view where groupId = &#63; and userId = &#63; and status = any &#63;.
 *
 * @param groupId the group ID//  w  w  w. java  2  s. c o m
 * @param userId the user ID
 * @param statuses the statuses
 * @return the number of matching tasks entries that the user has permission to view
 */
@Override
public int filterCountByG_U_S(long groupId, long userId, int[] statuses) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_U_S(groupId, userId, statuses);
    }

    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_TASKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);

    query.append(_FINDER_COLUMN_G_U_S_USERID_2);

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

        query.append(_FINDER_COLUMN_G_U_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);

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(userId);

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

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