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.bemis.portal.customer.service.persistence.impl.CustomerLocationPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        CustomerLocation customerLocation = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_CUSTOMERLOCATION_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 (CustomerLocation customerLocation : (List<CustomerLocation>) q.list()) {
            map.put(customerLocation.getPrimaryKeyObj(), customerLocation);

            cacheResult(customerLocation);

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

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

    return map;
}

From source file:com.bemis.portal.inventory.service.persistence.impl.OrderInventoryBatchPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        OrderInventoryBatch orderInventoryBatch = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_ORDERINVENTORYBATCH_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 (OrderInventoryBatch orderInventoryBatch : (List<OrderInventoryBatch>) q.list()) {
            map.put(orderInventoryBatch.getPrimaryKeyObj(), orderInventoryBatch);

            cacheResult(orderInventoryBatch);

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

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

    return map;
}

From source file:com.bemis.portal.inventory.service.persistence.impl.OrderInventoryPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        OrderInventory orderInventory = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_ORDERINVENTORY_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 (OrderInventory orderInventory : (List<OrderInventory>) q.list()) {
            map.put(orderInventory.getPrimaryKeyObj(), orderInventory);

            cacheResult(orderInventory);

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

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

    return map;
}

From source file:com.bemis.portal.migration.customer.service.persistence.impl.CustomerUserPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        CustomerUser customerUser = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_CUSTOMERUSER_WHERE_PKS_IN);

    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(StringPool.APOSTROPHE);
        query.append((String) primaryKey);
        query.append(StringPool.APOSTROPHE);

        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 (CustomerUser customerUser : (List<CustomerUser>) q.list()) {
            map.put(customerUser.getPrimaryKeyObj(), customerUser);

            cacheResult(customerUser);

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

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

    return map;
}

From source file:com.bemis.portal.order.service.persistence.impl.OrderPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Order order = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_ORDER__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 (Order order : (List<Order>) q.list()) {
            map.put(order.getPrimaryKeyObj(), order);

            cacheResult(order);

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

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

    return map;
}

From source file:com.bemis.portal.order.service.persistence.impl.OrderRequestPersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        OrderRequest orderRequest = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_ORDERREQUEST_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 (OrderRequest orderRequest : (List<OrderRequest>) q.list()) {
            map.put(orderRequest.getPrimaryKeyObj(), orderRequest);

            cacheResult(orderRequest);

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

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

    return map;
}

From source file:com.bemis.portal.order.service.persistence.impl.ReleasePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the releases where orderId = &#63;, optionally using the finder cache.
 *
 * <p>/* www.  j av  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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ReleaseModelImpl}. 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 orderId the order ID
 * @param start the lower bound of the range of releases
 * @param end the upper bound of the range of releases (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching releases
 */
@Override
public List<Release> findByOrderId(long[] orderIds, int start, int end,
        OrderByComparator<Release> orderByComparator, boolean retrieveFromCache) {
    if (orderIds == null) {
        orderIds = new long[0];
    } else if (orderIds.length > 1) {
        orderIds = ArrayUtil.unique(orderIds);

        Arrays.sort(orderIds);
    }

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

                start, end, orderByComparator };
    }

    List<Release> list = null;

    if (retrieveFromCache) {
        list = (List<Release>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID, finderArgs,
                this);

        if ((list != null) && !list.isEmpty()) {
            for (Release release : list) {
                if (!ArrayUtil.contains(orderIds, release.getOrderId())) {
                    list = null;

                    break;
                }
            }
        }
    }

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

        query.append(_SQL_SELECT_RELEASE_WHERE);

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

            query.append(_FINDER_COLUMN_ORDERID_ORDERID_7);

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

            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(ReleaseModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

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

            cacheResult(list);

            finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID, finderArgs);

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

    return list;
}

From source file:com.bemis.portal.order.service.persistence.impl.ReleasePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of releases where orderId = any &#63;.
 *
 * @param orderIds the order IDs//  ww  w  .  ja  v a 2  s  .  c  om
 * @return the number of matching releases
 */
@Override
public int countByOrderId(long[] orderIds) {
    if (orderIds == null) {
        orderIds = new long[0];
    } else if (orderIds.length > 1) {
        orderIds = ArrayUtil.unique(orderIds);

        Arrays.sort(orderIds);
    }

    Object[] finderArgs = new Object[] { StringUtil.merge(orderIds) };

    Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ORDERID, finderArgs, this);

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

        query.append(_SQL_COUNT_RELEASE_WHERE);

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

            query.append(_FINDER_COLUMN_ORDERID_ORDERID_7);

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

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

            count = (Long) q.uniqueResult();

            finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ORDERID, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_ORDERID, finderArgs);

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

    return count.intValue();
}

From source file:com.bemis.portal.order.service.persistence.impl.ReleasePersistenceImpl.java

License:Open Source License

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

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

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

        Serializable primaryKey = iterator.next();

        Release release = fetchByPrimaryKey(primaryKey);

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

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

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

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

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

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

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

    query.append(_SQL_SELECT_RELEASE_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 (Release release : (List<Release>) q.list()) {
            map.put(release.getPrimaryKeyObj(), release);

            cacheResult(release);

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

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

    return map;
}

From source file:com.bemis.portal.report.service.persistence.impl.ReportDefinitionPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the report definitions that the user has permission to view where category = any &#63; and companyId = &#63; and groupId = &#63;.
 *
 * <p>//from  ww w  . jav  a  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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ReportDefinitionModelImpl}. 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 categories the categories
 * @param companyId the company ID
 * @param groupId the group ID
 * @param start the lower bound of the range of report definitions
 * @param end the upper bound of the range of report definitions (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching report definitions that the user has permission to view
 */
@Override
public List<ReportDefinition> filterFindByC_C_G(String[] categories, long companyId, long groupId, int start,
        int end, OrderByComparator<ReportDefinition> orderByComparator) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByC_C_G(categories, companyId, groupId, start, end, orderByComparator);
    }

    if (categories == null) {
        categories = new String[0];
    } else if (categories.length > 1) {
        categories = ArrayUtil.distinct(categories, NULL_SAFE_STRING_COMPARATOR);

        Arrays.sort(categories, NULL_SAFE_STRING_COMPARATOR);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_NO_INLINE_DISTINCT_WHERE_1);
    }

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

        for (int i = 0; i < categories.length; i++) {
            String category = categories[i];

            if (category == null) {
                query.append(_FINDER_COLUMN_C_C_G_CATEGORY_4);
            } else if (category.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_C_C_G_CATEGORY_6);
            } else {
                query.append(_FINDER_COLUMN_C_C_G_CATEGORY_5);
            }

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

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_C_C_G_COMPANYID_2);

    query.append(_FINDER_COLUMN_C_C_G_GROUPID_2);

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

    if (!getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_REPORTDEFINITION_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(ReportDefinitionModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(ReportDefinitionModelImpl.ORDER_BY_SQL);
        }
    }

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), ReportDefinition.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, ReportDefinitionImpl.class);
        } else {
            q.addEntity(_FILTER_ENTITY_TABLE, ReportDefinitionImpl.class);
        }

        QueryPos qPos = QueryPos.getInstance(q);

        for (String category : categories) {
            if ((category != null) && !category.isEmpty()) {
                qPos.add(category);
            }
        }

        qPos.add(companyId);

        qPos.add(groupId);

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