List of usage examples for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS
String OPEN_PARENTHESIS
To view the source code for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS.
Click Source Link
From source file:com.kisti.science.platform.app.service.persistence.ScienceAppPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the science apps where name LIKE any ? and title LIKE any ? and targetLanguage = all ?. * * <p>/*from w w w. j a v a 2s. 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.kisti.science.platform.app.model.impl.ScienceAppModelImpl}. 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 names the names * @param titles the titles * @param targetLanguages the target languages * @param start the lower bound of the range of science apps * @param end the upper bound of the range of science apps (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching science apps * @throws SystemException if a system exception occurred */ @Override public List<ScienceApp> findByNameTitleWithTarget(String[] names, String[] titles, String[] targetLanguages, int start, int end, OrderByComparator orderByComparator) throws SystemException { if ((names != null) && (names.length == 1) && (titles != null) && (titles.length == 1) && (targetLanguages != null) && (targetLanguages.length == 1)) { return findByNameTitleWithTarget(names[0], titles[0], targetLanguages[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(names), StringUtil.merge(titles), StringUtil.merge(targetLanguages) }; } else { finderArgs = new Object[] { StringUtil.merge(names), StringUtil.merge(titles), StringUtil.merge(targetLanguages), start, end, orderByComparator }; } List<ScienceApp> list = (List<ScienceApp>) FinderCacheUtil .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NAMETITLEWITHTARGET, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (ScienceApp scienceApp : list) { if (!ArrayUtil.contains(names, scienceApp.getName()) || !ArrayUtil.contains(titles, scienceApp.getTitle()) || !ArrayUtil.contains(targetLanguages, scienceApp.getTargetLanguage())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_SCIENCEAPP_WHERE); boolean conjunctionable = false; if ((names == null) || (names.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < names.length; i++) { String name = names[i]; if (name == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_4); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_5); } if ((i + 1) < names.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if ((titles == null) || (titles.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < titles.length; i++) { String title = titles[i]; if (title == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_4); } else if (title.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_5); } if ((i + 1) < titles.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if ((targetLanguages == null) || (targetLanguages.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < targetLanguages.length; i++) { String targetLanguage = targetLanguages[i]; if (targetLanguage == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_4); } else if (targetLanguage.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_5); } if ((i + 1) < targetLanguages.length) { query.append(WHERE_AND); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(ScienceAppModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (names != null) { qPos.add(names); } if (titles != null) { qPos.add(titles); } if (targetLanguages != null) { qPos.add(targetLanguages); } if (!pagination) { list = (List<ScienceApp>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = new UnmodifiableList<ScienceApp>(list); } else { list = (List<ScienceApp>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NAMETITLEWITHTARGET, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NAMETITLEWITHTARGET, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.kisti.science.platform.app.service.persistence.ScienceAppPersistenceImpl.java
License:Open Source License
/** * Returns the number of science apps where name LIKE any ? and title LIKE any ? and targetLanguage = all ?. * * @param names the names/*from www .j a va2 s . c om*/ * @param titles the titles * @param targetLanguages the target languages * @return the number of matching science apps * @throws SystemException if a system exception occurred */ @Override public int countByNameTitleWithTarget(String[] names, String[] titles, String[] targetLanguages) throws SystemException { Object[] finderArgs = new Object[] { StringUtil.merge(names), StringUtil.merge(titles), StringUtil.merge(targetLanguages) }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NAMETITLEWITHTARGET, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_SCIENCEAPP_WHERE); boolean conjunctionable = false; if ((names == null) || (names.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < names.length; i++) { String name = names[i]; if (name == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_4); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_5); } if ((i + 1) < names.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if ((titles == null) || (titles.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < titles.length; i++) { String title = titles[i]; if (title == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_4); } else if (title.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_5); } if ((i + 1) < titles.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if ((targetLanguages == null) || (targetLanguages.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < targetLanguages.length; i++) { String targetLanguage = targetLanguages[i]; if (targetLanguage == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_4); } else if (targetLanguage.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_5); } if ((i + 1) < targetLanguages.length) { query.append(WHERE_AND); } } 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 (names != null) { qPos.add(names); } if (titles != null) { qPos.add(titles); } if (targetLanguages != null) { qPos.add(targetLanguages); } count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NAMETITLEWITHTARGET, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NAMETITLEWITHTARGET, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.adaptive.media.image.web.html.AdaptiveMediaImageHTMLTagFactoryImpl.java
License:Open Source License
private Optional<String> _getMediaQueryString(MediaQuery mediaQuery) { List<Condition> conditions = mediaQuery.getConditions(); if (conditions.isEmpty()) { return Optional.empty(); }// w ww. ja va2 s. c o m String[] conditionStrings = new String[conditions.size()]; for (int i = 0; i < conditionStrings.length; i++) { Condition condition = conditions.get(i); StringBundler sb = new StringBundler(5); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(condition.getAttribute()); sb.append(StringPool.COLON); sb.append(condition.getValue()); sb.append(StringPool.CLOSE_PARENTHESIS); conditionStrings[i] = sb.toString(); } return Optional.of(String.join(" and ", conditionStrings)); }
From source file:com.liferay.alloy.mvc.jsonwebservice.AlloyControllerInvokerManager.java
License:Open Source License
protected byte[] generateAlloyControllerInvokerClassData(Class<?> controllerClass, String alloyControllerInvokerClassName) throws NoClassNecessaryException { boolean jsonWebServiceMethodsPresent = false; ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); String alloyControllerInvokerClassBinaryName = getClassBinaryName(alloyControllerInvokerClassName); String baseAlloyControllerInvokerClassBinaryName = getClassBinaryName( BaseAlloyControllerInvokerImpl.class.getName()); classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, alloyControllerInvokerClassBinaryName, null, baseAlloyControllerInvokerClassBinaryName, null); MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode();/*from w w w . j a v a 2s .c o m*/ methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, baseAlloyControllerInvokerClassBinaryName, "<init>", "()V"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); Method[] methods = controllerClass.getDeclaredMethods(); for (Method method : methods) { if (!Modifier.isPublic(method.getModifiers())) { continue; } JSONWebServiceMethod jsonWebServiceMethod = method.getAnnotation(JSONWebServiceMethod.class); if (jsonWebServiceMethod == null) { continue; } jsonWebServiceMethodsPresent = true; String methodName = jsonWebServiceMethod.methodName(); if (Validator.isNull(methodName)) { methodName = method.getName(); } Class<?>[] parameterTypes = jsonWebServiceMethod.parameterTypes(); StringBundler sb = new StringBundler(parameterTypes.length + 3); sb.append(StringPool.OPEN_PARENTHESIS); for (Class<?> parameterType : parameterTypes) { sb.append(Type.getDescriptor(parameterType)); } sb.append(StringPool.CLOSE_PARENTHESIS); sb.append(Type.getDescriptor(JSONSerializable.class)); String methodDescriptor = sb.toString(); methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, methodName, methodDescriptor, null, new String[] { getClassBinaryName(Exception.class.getName()) }); methodVisitor.visitCode(); for (int i = 0; i < parameterTypes.length; i++) { String parameterName = jsonWebServiceMethod.parameterNames()[i]; Class<?> parameterType = parameterTypes[i]; methodVisitor.visitLocalVariable(parameterName, Type.getDescriptor(parameterType), null, new Label(), new Label(), i + 1); } methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitLdcInsn(jsonWebServiceMethod.lifecycle()); methodVisitor.visitIntInsn(Opcodes.BIPUSH, parameterTypes.length * 2 + 2); methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, getClassBinaryName(Object.class.getName())); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_0); methodVisitor.visitLdcInsn("action"); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_1); methodVisitor.visitLdcInsn(method.getName()); methodVisitor.visitInsn(Opcodes.AASTORE); for (int i = 0; i < parameterTypes.length; i++) { String parameterName = jsonWebServiceMethod.parameterNames()[i]; methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitIntInsn(Opcodes.BIPUSH, (i + 1) * 2); methodVisitor.visitLdcInsn(parameterName); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitIntInsn(Opcodes.BIPUSH, (i + 1) * 2 + 1); methodVisitor.visitVarInsn(Opcodes.ALOAD, i + 1); methodVisitor.visitInsn(Opcodes.AASTORE); } sb = new StringBundler(5); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(Type.getDescriptor(String.class)); sb.append(Type.getDescriptor(Object[].class)); sb.append(StringPool.CLOSE_PARENTHESIS); sb.append(Type.getDescriptor(JSONSerializable.class)); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, alloyControllerInvokerClassBinaryName, "invokeAlloyController", sb.toString()); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(-1, -1); methodVisitor.visitEnd(); } classWriter.visitEnd(); if (!jsonWebServiceMethodsPresent) { throw new NoClassNecessaryException(); } return classWriter.toByteArray(); }
From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the bookmarks entries that the user has permission to view where groupId = ? and folderId = any ?. * * <p>// w w w . j a v 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 BookmarksEntryModelImpl}. 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 folderIds the folder IDs * @param start the lower bound of the range of bookmarks entries * @param end the upper bound of the range of bookmarks entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching bookmarks entries that the user has permission to view */ @Override public List<BookmarksEntry> filterFindByG_F(long groupId, long[] folderIds, int start, int end, OrderByComparator<BookmarksEntry> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return findByG_F(groupId, folderIds, start, end, orderByComparator); } 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_SELECT_BOOKMARKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_F_GROUPID_2); if (folderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_F_FOLDERID_7); query.append(StringUtil.merge(folderIds)); 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 { query.append(BookmarksEntryModelImpl.ORDER_BY_JPQL); } 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); return (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the bookmarks entries where groupId = ? and folderId = ?, optionally using the finder cache. * * <p>/*from w w w .j a va 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 BookmarksEntryModelImpl}. 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 folderId the folder ID * @param start the lower bound of the range of bookmarks entries * @param end the upper bound of the range of bookmarks entries (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 bookmarks entries */ @Override public List<BookmarksEntry> findByG_F(long groupId, long[] folderIds, int start, int end, OrderByComparator<BookmarksEntry> orderByComparator, boolean retrieveFromCache) { if (folderIds == null) { folderIds = new long[0]; } else if (folderIds.length > 1) { folderIds = ArrayUtil.unique(folderIds); Arrays.sort(folderIds); } if (folderIds.length == 1) { return findByG_F(groupId, folderIds[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, StringUtil.merge(folderIds) }; } else { finderArgs = new Object[] { groupId, StringUtil.merge(folderIds), start, end, orderByComparator }; } List<BookmarksEntry> list = null; if (retrieveFromCache) { list = (List<BookmarksEntry>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (BookmarksEntry bookmarksEntry : list) { if ((groupId != bookmarksEntry.getGroupId()) || !ArrayUtil.contains(folderIds, bookmarksEntry.getFolderId())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_F_GROUPID_2); if (folderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_F_FOLDERID_7); query.append(StringUtil.merge(folderIds)); 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(BookmarksEntryModelImpl.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); if (!pagination) { list = (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java
License:Open Source License
/** * Returns the number of bookmarks entries where groupId = ? and folderId = any ?. * * @param groupId the group ID// w w w.ja va 2 s.com * @param folderIds the folder IDs * @return the number of matching bookmarks entries */ @Override public int countByG_F(long groupId, long[] folderIds) { if (folderIds == null) { folderIds = new long[0]; } else if (folderIds.length > 1) { folderIds = ArrayUtil.unique(folderIds); Arrays.sort(folderIds); } Object[] finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) }; Long count = (Long) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_BOOKMARKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_F_GROUPID_2); if (folderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_F_FOLDERID_7); query.append(StringUtil.merge(folderIds)); 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); count = (Long) q.uniqueResult(); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F, finderArgs, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
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 folderId = any ?. * * @param groupId the group ID//w w w . j a v a 2 s . c om * @param folderIds the folder IDs * @return the number of matching bookmarks entries that the user has permission to view */ @Override public int filterCountByG_F(long groupId, long[] folderIds) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return countByG_F(groupId, folderIds); } 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_F_GROUPID_2); if (folderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_F_FOLDERID_7); query.append(StringUtil.merge(folderIds)); 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(), 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); 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
/** * Returns an ordered range of all the bookmarks entries that the user has permission to view where groupId = ? and folderId = any ? and status = ?. * * <p>/*from w ww .ja v 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 BookmarksEntryModelImpl}. 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 folderIds the folder IDs * @param status the status * @param start the lower bound of the range of bookmarks entries * @param end the upper bound of the range of bookmarks entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching bookmarks entries that the user has permission to view */ @Override public List<BookmarksEntry> filterFindByG_F_S(long groupId, long[] folderIds, int status, int start, int end, OrderByComparator<BookmarksEntry> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return findByG_F_S(groupId, folderIds, status, start, end, orderByComparator); } 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_SELECT_BOOKMARKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_F_S_GROUPID_2); if (folderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_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_F_S_STATUS_2); query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else { query.append(BookmarksEntryModelImpl.ORDER_BY_JPQL); } 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(status); return (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksEntryPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the bookmarks entries where groupId = ? and folderId = ? and status = ?, optionally using the finder cache. * * <p>/*from w w w. j av 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 BookmarksEntryModelImpl}. 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 folderId the folder ID * @param status the status * @param start the lower bound of the range of bookmarks entries * @param end the upper bound of the range of bookmarks entries (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 bookmarks entries */ @Override public List<BookmarksEntry> findByG_F_S(long groupId, long[] folderIds, int status, int start, int end, OrderByComparator<BookmarksEntry> orderByComparator, boolean retrieveFromCache) { if (folderIds == null) { folderIds = new long[0]; } else if (folderIds.length > 1) { folderIds = ArrayUtil.unique(folderIds); Arrays.sort(folderIds); } if (folderIds.length == 1) { return findByG_F_S(groupId, folderIds[0], status, 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, StringUtil.merge(folderIds), status }; } else { finderArgs = new Object[] { groupId, StringUtil.merge(folderIds), status, start, end, orderByComparator }; } List<BookmarksEntry> list = null; if (retrieveFromCache) { list = (List<BookmarksEntry>) finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (BookmarksEntry bookmarksEntry : list) { if ((groupId != bookmarksEntry.getGroupId()) || !ArrayUtil.contains(folderIds, bookmarksEntry.getFolderId()) || (status != bookmarksEntry.getStatus())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_BOOKMARKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_F_S_GROUPID_2); if (folderIds.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_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_F_S_STATUS_2); 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(BookmarksEntryModelImpl.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(status); if (!pagination) { list = (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<BookmarksEntry>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }