List of usage examples for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS
String CLOSE_PARENTHESIS
To view the source code for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS.
Click Source Link
From source file:com.liferay.content.targeting.service.persistence.UserSegmentPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the user segments that the user has permission to view where groupId = any ?. * * <p>/*from w ww . j a va2 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.content.targeting.model.impl.UserSegmentModelImpl}. 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 groupIds the group IDs * @param start the lower bound of the range of user segments * @param end the upper bound of the range of user segments (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching user segments that the user has permission to view * @throws SystemException if a system exception occurred */ @Override public List<UserSegment> filterFindByGroupId(long[] groupIds, int start, int end, OrderByComparator orderByComparator) throws SystemException { if (!InlineSQLHelperUtil.isEnabled(groupIds)) { return findByGroupId(groupIds, start, end, orderByComparator); } StringBundler query = new StringBundler(); if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_USERSEGMENT_WHERE); } else { query.append(_FILTER_SQL_SELECT_USERSEGMENT_NO_INLINE_DISTINCT_WHERE_1); } 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_GROUPID_GROUPID_5); if ((i + 1) < groupIds.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_USERSEGMENT_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(UserSegmentModelImpl.ORDER_BY_JPQL); } else { query.append(UserSegmentModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), UserSegment.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds); Session session = null; try { session = openSession(); SQLQuery q = session.createSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, UserSegmentImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, UserSegmentImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (groupIds != null) { qPos.add(groupIds); } return (List<UserSegment>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.content.targeting.service.persistence.UserSegmentPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the user segments where groupId = any ?. * * <p>//w ww . jav 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.content.targeting.model.impl.UserSegmentModelImpl}. 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 groupIds the group IDs * @param start the lower bound of the range of user segments * @param end the upper bound of the range of user segments (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching user segments * @throws SystemException if a system exception occurred */ @Override public List<UserSegment> findByGroupId(long[] groupIds, int start, int end, OrderByComparator orderByComparator) throws SystemException { if ((groupIds != null) && (groupIds.length == 1)) { return findByGroupId(groupIds[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(groupIds) }; } else { finderArgs = new Object[] { StringUtil.merge(groupIds), start, end, orderByComparator }; } List<UserSegment> list = (List<UserSegment>) FinderCacheUtil .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (UserSegment userSegment : list) { if (!ArrayUtil.contains(groupIds, userSegment.getGroupId())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_USERSEGMENT_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_GROUPID_GROUPID_5); if ((i + 1) < groupIds.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(UserSegmentModelImpl.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 (!pagination) { list = (List<UserSegment>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = new UnmodifiableList<UserSegment>(list); } else { list = (List<UserSegment>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.content.targeting.service.persistence.UserSegmentPersistenceImpl.java
License:Open Source License
/** * Returns the number of user segments where groupId = any ?. * * @param groupIds the group IDs//ww w .j a v a2 s .c o m * @return the number of matching user segments * @throws SystemException if a system exception occurred */ @Override public int countByGroupId(long[] groupIds) throws SystemException { Object[] finderArgs = new Object[] { StringUtil.merge(groupIds) }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_USERSEGMENT_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_GROUPID_GROUPID_5); if ((i + 1) < groupIds.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); 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); } count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.content.targeting.service.persistence.UserSegmentPersistenceImpl.java
License:Open Source License
/** * Returns the number of user segments that the user has permission to view where groupId = any ?. * * @param groupIds the group IDs/*from ww w . j a v a 2 s. c om*/ * @return the number of matching user segments that the user has permission to view * @throws SystemException if a system exception occurred */ @Override public int filterCountByGroupId(long[] groupIds) throws SystemException { if (!InlineSQLHelperUtil.isEnabled(groupIds)) { return countByGroupId(groupIds); } StringBundler query = new StringBundler(); query.append(_FILTER_SQL_COUNT_USERSEGMENT_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_GROUPID_GROUPID_5); if ((i + 1) < groupIds.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), UserSegment.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds); Session session = null; try { session = openSession(); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); if (groupIds != null) { qPos.add(groupIds); } Long count = (Long) q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.customsql.CustomSQL.java
License:Open Source License
public String replaceKeywords(String sql, String field, boolean last, int[] values) { if ((values != null) && (values.length == 1)) { return sql; }/* w ww . j a v a2 s. c o m*/ StringBundler oldSql = new StringBundler(4); oldSql.append(StringPool.OPEN_PARENTHESIS); oldSql.append(field); oldSql.append(" = ?)"); if (!last) { oldSql.append(" [$AND_OR_CONNECTOR$]"); } if (ArrayUtil.isEmpty(values)) { return StringUtil.replace(sql, oldSql.toString(), StringPool.BLANK); } StringBundler newSql = new StringBundler(values.length * 4 + 3); newSql.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < values.length; i++) { if (i > 0) { newSql.append(" OR "); } newSql.append(StringPool.OPEN_PARENTHESIS); newSql.append(field); newSql.append(" = ?)"); } newSql.append(StringPool.CLOSE_PARENTHESIS); if (!last) { newSql.append(" [$AND_OR_CONNECTOR$]"); } return StringUtil.replace(sql, oldSql.toString(), newSql.toString()); }
From source file:com.liferay.customsql.CustomSQL.java
License:Open Source License
public String replaceKeywords(String sql, String field, boolean last, long[] values) { if ((values != null) && (values.length == 1)) { return sql; }//w w w .j av a 2 s. c o m StringBundler oldSql = new StringBundler(4); oldSql.append(StringPool.OPEN_PARENTHESIS); oldSql.append(field); oldSql.append(" = ?)"); if (!last) { oldSql.append(" [$AND_OR_CONNECTOR$]"); } if (ArrayUtil.isEmpty(values)) { return StringUtil.replace(sql, oldSql.toString(), StringPool.BLANK); } StringBundler newSql = new StringBundler(values.length * 4 + 3); newSql.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < values.length; i++) { if (i > 0) { newSql.append(" OR "); } newSql.append(StringPool.OPEN_PARENTHESIS); newSql.append(field); newSql.append(" = ?)"); } newSql.append(StringPool.CLOSE_PARENTHESIS); if (!last) { newSql.append(" [$AND_OR_CONNECTOR$]"); } return StringUtil.replace(sql, oldSql.toString(), newSql.toString()); }
From source file:com.liferay.customsql.CustomSQL.java
License:Open Source License
public String replaceKeywords(String sql, String field, String operator, boolean last, String[] values) { if ((values != null) && (values.length <= 1)) { return sql; }/*w w w . j a va 2 s. co m*/ StringBundler oldSql = new StringBundler(6); oldSql.append(StringPool.OPEN_PARENTHESIS); oldSql.append(field); oldSql.append(" "); oldSql.append(operator); oldSql.append(" ? [$AND_OR_NULL_CHECK$])"); if (!last) { oldSql.append(" [$AND_OR_CONNECTOR$]"); } StringBundler newSql = new StringBundler(values.length * 6 + 3); newSql.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < values.length; i++) { if (i > 0) { newSql.append(" OR "); } newSql.append(StringPool.OPEN_PARENTHESIS); newSql.append(field); newSql.append(" "); newSql.append(operator); newSql.append(" ? [$AND_OR_NULL_CHECK$])"); } newSql.append(StringPool.CLOSE_PARENTHESIS); if (!last) { newSql.append(" [$AND_OR_CONNECTOR$]"); } return StringUtil.replace(sql, oldSql.toString(), newSql.toString()); }
From source file:com.liferay.demo.todo.service.persistence.impl.TodoPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, Todo> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }//from www .j av a 2s . c om Map<Serializable, Todo> map = new HashMap<Serializable, Todo>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Todo todo = fetchByPrimaryKey(primaryKey); if (todo != null) { map.put(primaryKey, todo); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(TodoModelImpl.ENTITY_CACHE_ENABLED, TodoImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (Todo) serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_TODO_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 (Todo todo : (List<Todo>) q.list()) { map.put(todo.getPrimaryKeyObj(), todo); cacheResult(todo); uncachedPrimaryKeys.remove(todo.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(TodoModelImpl.ENTITY_CACHE_ENABLED, TodoImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.document.library.repository.cmis.internal.CMISRepository.java
License:Open Source License
protected List<String> getCmisFolderIds(Session session, long folderId) throws PortalException { StringBundler sb = new StringBundler(4); sb.append("SELECT cmis:objectId FROM cmis:folder"); if (folderId > 0) { sb.append(" WHERE IN_FOLDER("); String objectId = toFolderId(session, folderId); sb.append(StringUtil.quote(objectId)); sb.append(StringPool.CLOSE_PARENTHESIS); }//from ww w. ja va2 s. c om String query = sb.toString(); if (_log.isDebugEnabled()) { _log.debug("Calling query " + query); } ItemIterable<QueryResult> queryResults = session.query(query, isAllVersionsSearchableSupported(session)); List<String> cmsFolderIds = new ArrayList<>(); for (QueryResult queryResult : queryResults) { PropertyData<String> propertyData = queryResult.getPropertyById(PropertyIds.OBJECT_ID); List<String> values = propertyData.getValues(); String value = values.get(0); cmsFolderIds.add(value); } return cmsFolderIds; }
From source file:com.liferay.document.library.repository.cmis.internal.CMISRepository.java
License:Open Source License
protected List<String> getDocumentIds(Session session, long folderId, String[] mimeTypes) throws PortalException { StringBundler sb = new StringBundler(); sb.append("SELECT cmis:objectId FROM cmis:document"); if (ArrayUtil.isNotEmpty(mimeTypes)) { sb.append(" WHERE cmis:contentStreamMimeType IN ("); for (int i = 0; i < mimeTypes.length; i++) { sb.append(StringUtil.quote(mimeTypes[i])); if ((i + 1) < mimeTypes.length) { sb.append(", "); }/*from w w w . j av a 2 s .c o m*/ } sb.append(StringPool.CLOSE_PARENTHESIS); } if (folderId > 0) { if (ArrayUtil.isNotEmpty(mimeTypes)) { sb.append(" AND "); } else { sb.append(" WHERE "); } sb.append("IN_FOLDER("); String objectId = toFolderId(session, folderId); sb.append(StringUtil.quote(objectId)); sb.append(StringPool.CLOSE_PARENTHESIS); } String query = sb.toString(); if (_log.isDebugEnabled()) { _log.debug("Calling query " + query); } ItemIterable<QueryResult> queryResults = session.query(query, false); List<String> cmisDocumentIds = new ArrayList<>(); for (QueryResult queryResult : queryResults) { String objectId = queryResult.getPropertyValueByQueryName(PropertyIds.OBJECT_ID); cmisDocumentIds.add(objectId); } return cmisDocumentIds; }