List of usage examples for com.liferay.portal.kernel.dao.orm QueryUtil iterate
public static Iterator<?> iterate(Query query, Dialect dialect, int start, int end)
From source file:com.liferay.asset.category.property.service.persistence.impl.AssetCategoryPropertyFinderImpl.java
License:Open Source License
@Override public List<AssetCategoryProperty> findByG_K(long groupId, String key, int start, int end) { Session session = null;/* w ww .j a v a 2 s . c o m*/ try { session = openSession(); String sql = CustomSQLUtil.get(getClass(), FIND_BY_G_K); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar("categoryPropertyValue", Type.STRING); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(key); List<AssetCategoryProperty> categoryProperties = new ArrayList<>(); Iterator<String> itr = (Iterator<String>) QueryUtil.iterate(q, getDialect(), start, end); while (itr.hasNext()) { String value = itr.next(); AssetCategoryProperty categoryProperty = new AssetCategoryPropertyImpl(); categoryProperty.setKey(key); categoryProperty.setValue(value); categoryProperties.add(categoryProperty); } return categoryProperties; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.blogs.service.persistence.impl.BlogsStatsUserFinderImpl.java
License:Open Source License
@Override public List<BlogsStatsUser> findByGroupIds(long companyId, long groupId, int start, int end) { Session session = null;//from w w w .java 2s . c om try { session = openSession(); String sql = CustomSQLUtil.get(getClass(), FIND_BY_GROUP_IDS); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar("userId", Type.LONG); q.addScalar("lastPostDate", Type.TIMESTAMP); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(groupId); qPos.add(groupId); qPos.add(groupId); List<BlogsStatsUser> statsUsers = new ArrayList<>(); Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), start, end); while (itr.hasNext()) { Object[] array = itr.next(); long userId = (Long) array[0]; Date lastPostDate = (Date) array[1]; List<BlogsStatsUser> curStatsUsers = BlogsStatsUserUtil.findByU_L(userId, lastPostDate); if (!curStatsUsers.isEmpty()) { BlogsStatsUser statsUser = curStatsUsers.get(0); statsUsers.add(statsUser); } } return statsUsers; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.bookmarks.service.persistence.impl.BookmarksFolderFinderImpl.java
License:Open Source License
protected List<Object> doFindF_E_ByG_F(long groupId, long folderId, QueryDefinition<?> queryDefinition, boolean inlineSQLHelper) { Session session = null;//from w w w .j a v a2s.co m try { session = openSession(); StringBundler sb = new StringBundler(5); sb.append("SELECT * FROM ("); String sql = null; if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) { sql = CustomSQLUtil.get(getClass(), FIND_F_BY_G_P); } else { sql = CustomSQLUtil.get(getClass(), FIND_F_BY_G_P_S); sql = replaceExcludeStatus(sql, queryDefinition); } if (inlineSQLHelper) { sql = InlineSQLHelperUtil.replacePermissionCheck(sql, BookmarksFolder.class.getName(), "BookmarksFolder.folderId", groupId); } sb.append(sql); sb.append(" UNION ALL "); if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) { sql = CustomSQLUtil.get(getClass(), FIND_E_BY_G_F); } else { sql = CustomSQLUtil.get(getClass(), FIND_E_BY_G_F_S); sql = replaceExcludeStatus(sql, queryDefinition); } if (inlineSQLHelper) { sql = InlineSQLHelperUtil.replacePermissionCheck(sql, BookmarksEntry.class.getName(), "BookmarksEntry.fileEntryId", groupId); } sb.append(sql); sb.append(") TEMP_TABLE ORDER BY modelName ASC"); sql = sb.toString(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar("modelId", Type.LONG); q.addScalar("modelName", Type.STRING); q.addScalar("modelFolder", Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(folderId); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } qPos.add(groupId); qPos.add(folderId); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } List<Object> models = new ArrayList<>(); Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd()); while (itr.hasNext()) { Object[] array = itr.next(); long modelId = (Long) array[0]; //String name = (String)array[1]; long modelFolder = (Long) array[2]; Object obj = null; if (modelFolder == 0) { obj = BookmarksFolderUtil.findByPrimaryKey(modelId); } else { obj = BookmarksEntryUtil.findByPrimaryKey(modelId); } models.add(obj); } return models; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.contacts.service.persistence.EntryFinderImpl.java
License:Open Source License
public List<BaseModel<?>> findByC_U_FN_EA(long companyId, long userId, String[] fullNames, String[] emailAddresses, boolean andOperator, int start, int end) throws SystemException { fullNames = CustomSQLUtil.keywords(fullNames, true); emailAddresses = CustomSQLUtil.keywords(emailAddresses, true); Session session = null;/*from w w w .j a v a 2 s .com*/ try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_C_U_FN_EA); sql = CustomSQLUtil.replaceKeywords(sql, "lower(User_.firstName)", StringPool.LIKE, false, fullNames); sql = CustomSQLUtil.replaceKeywords(sql, "lower(User_.middleName)", StringPool.LIKE, false, fullNames); sql = CustomSQLUtil.replaceKeywords(sql, "lower(User_.lastName)", StringPool.LIKE, false, fullNames); sql = CustomSQLUtil.replaceKeywords(sql, "lower(User_.screenName)", StringPool.LIKE, false, fullNames); sql = CustomSQLUtil.replaceKeywords(sql, "lower(User_.emailAddress)", StringPool.LIKE, true, emailAddresses); sql = CustomSQLUtil.replaceKeywords(sql, "lower(Contacts_Entry.fullName)", StringPool.LIKE, false, fullNames); sql = CustomSQLUtil.replaceKeywords(sql, "lower(Contacts_Entry.emailAddress)", StringPool.LIKE, true, emailAddresses); sql = CustomSQLUtil.replaceAndOperator(sql, andOperator); SQLQuery q = session.createSQLQuery(sql); q.addScalar("id", Type.LONG); q.addScalar("name", Type.STRING); q.addScalar("portalUser", Type.INTEGER); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(fullNames, 8); qPos.add(emailAddresses, 2); qPos.add(userId); qPos.add(fullNames, 2); qPos.add(emailAddresses, 2); List<BaseModel<?>> models = new ArrayList<BaseModel<?>>(); Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), start, end); while (itr.hasNext()) { Object[] array = itr.next(); long id = (Long) array[0]; //String name = (String)array[1]; int portalUser = (Integer) array[2]; BaseModel<?> model = null; if (portalUser == 1) { model = UserLocalServiceUtil.getUser(id); } else { model = EntryLocalServiceUtil.getEntry(id); } models.add(model); } return models; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.journal.service.persistence.impl.JournalFolderFinderImpl.java
License:Open Source License
protected List<Object> doFindF_A_ByG_F(long groupId, long folderId, QueryDefinition<?> queryDefinition, boolean inlineSQLHelper) { Session session = null;//from ww w . j a v a 2 s.c o m try { session = openSession(); StringBundler sb = new StringBundler(5); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(getFoldersSQL(FIND_F_BY_G_F, groupId, queryDefinition, inlineSQLHelper)); sb.append(") UNION ALL ("); sb.append(getArticlesSQL(FIND_A_BY_G_U_F, groupId, queryDefinition, inlineSQLHelper)); sb.append(StringPool.CLOSE_PARENTHESIS); String sql = updateSQL(sb.toString(), folderId); sql = CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator()); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar("modelFolderId", Type.LONG); q.addScalar("modelFolder", Type.LONG); q.addScalar("articleId", Type.STRING); q.addScalar("version", Type.DOUBLE); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(queryDefinition.getStatus()); if (folderId >= 0) { qPos.add(folderId); } qPos.add(groupId); if (queryDefinition.getOwnerUserId() > 0) { qPos.add(queryDefinition.getOwnerUserId()); qPos.add(WorkflowConstants.STATUS_IN_TRASH); } qPos.add(queryDefinition.getStatus()); if (folderId >= 0) { qPos.add(folderId); } List<Object> models = new ArrayList<>(); Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd()); while (itr.hasNext()) { Object[] array = itr.next(); long curFolderId = (Long) array[0]; long modelFolder = (Long) array[1]; Object obj = null; if (modelFolder == 1) { obj = JournalFolderUtil.findByPrimaryKey(curFolderId); } else { String articleId = (String) array[2]; double version = (Double) array[3]; obj = JournalArticleUtil.findByG_A_V(groupId, articleId, version); } models.add(obj); } return models; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.journal.service.persistence.impl.JournalFolderFinderImpl.java
License:Open Source License
protected List<Object> doFindF_A_ByG_F_L(long groupId, long folderId, Locale locale, QueryDefinition<?> queryDefinition, boolean inlineSQLHelper) { Session session = null;/*w w w. j av a 2s . c o m*/ try { session = openSession(); StringBundler sb = new StringBundler(5); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(getFoldersSQL(FIND_F_BY_G_F_L, groupId, queryDefinition, inlineSQLHelper)); sb.append(") UNION ALL ("); sb.append(getArticlesSQL(FIND_A_BY_G_U_F_L, groupId, queryDefinition, inlineSQLHelper)); sb.append(StringPool.CLOSE_PARENTHESIS); String sql = updateSQL(sb.toString(), folderId); sql = CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator()); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar("modelFolderId", Type.LONG); q.addScalar("modelFolder", Type.LONG); q.addScalar("articleId", Type.STRING); q.addScalar("version", Type.DOUBLE); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(queryDefinition.getStatus()); if (folderId >= 0) { qPos.add(folderId); } qPos.add(groupId); if (queryDefinition.getOwnerUserId() > 0) { qPos.add(queryDefinition.getOwnerUserId()); qPos.add(WorkflowConstants.STATUS_IN_TRASH); } qPos.add(queryDefinition.getStatus()); if (folderId >= 0) { qPos.add(folderId); } qPos.add(LocaleUtil.toLanguageId(locale)); List<Object> models = new ArrayList<>(); Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd()); while (itr.hasNext()) { Object[] array = itr.next(); long curFolderId = (Long) array[0]; long modelFolder = (Long) array[1]; Object obj = null; if (modelFolder == 1) { obj = JournalFolderUtil.findByPrimaryKey(curFolderId); } else { String articleId = (String) array[2]; double version = (Double) array[3]; obj = JournalArticleUtil.findByG_A_V(groupId, articleId, version); } models.add(obj); } return models; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.microblogs.service.persistence.impl.MicroblogsEntryFinderImpl.java
License:Open Source License
public List<MicroblogsEntry> findByUserId(long userId, int start, int end) { Session session = null;/*from w w w. ja v a 2s. c o m*/ try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_USER_ID); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar("microblogsEntryId", Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(MicroblogsEntryConstants.TYPE_EVERYONE); qPos.add(userId); qPos.add(SocialRelationConstants.TYPE_UNI_ENEMY); qPos.add(userId); qPos.add(userId); qPos.add(MicroblogsEntryConstants.TYPE_REPLY); Iterator<Long> itr = (Iterator<Long>) QueryUtil.iterate(q, getDialect(), start, end); List<MicroblogsEntry> microblogsEntries = new ArrayList<MicroblogsEntry>(); while (itr.hasNext()) { microblogsEntries.add(MicroblogsEntryLocalServiceUtil.fetchMicroblogsEntry((Long) itr.next())); } return microblogsEntries; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.portlet.asset.service.persistence.AssetCategoryPropertyFinderImpl.java
License:Open Source License
public List<AssetCategoryProperty> findByG_K(long groupId, String key, int start, int end) throws SystemException { Session session = null;// w w w .j a v a 2 s. c o m try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_G_K); SQLQuery q = session.createSQLQuery(sql); q.addScalar("categoryPropertyValue", Type.STRING); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(key); List<AssetCategoryProperty> categoryProperties = new ArrayList<AssetCategoryProperty>(); Iterator<String> itr = (Iterator<String>) QueryUtil.iterate(q, getDialect(), start, end); while (itr.hasNext()) { String value = itr.next(); AssetCategoryProperty categoryProperty = new AssetCategoryPropertyImpl(); categoryProperty.setKey(key); categoryProperty.setValue(value); categoryProperties.add(categoryProperty); } return categoryProperties; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.portlet.asset.service.persistence.AssetTagPropertyFinderImpl.java
License:Open Source License
public List<AssetTagProperty> findByG_K(long groupId, String key, int start, int end) throws SystemException { Session session = null;/* www . j a va 2 s . c o m*/ try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_G_K); SQLQuery q = session.createSQLQuery(sql); q.addScalar("tagPropertyValue", Type.STRING); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(key); List<AssetTagProperty> tagProperties = new ArrayList<AssetTagProperty>(); Iterator<String> itr = (Iterator<String>) QueryUtil.iterate(q, getDialect(), start, end); while (itr.hasNext()) { String value = itr.next(); AssetTagProperty tagProperty = new AssetTagPropertyImpl(); tagProperty.setKey(key); tagProperty.setValue(value); tagProperties.add(tagProperty); } return tagProperties; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.portlet.blogs.service.persistence.BlogsStatsUserFinderImpl.java
License:Open Source License
public List<BlogsStatsUser> findByGroupIds(long companyId, long groupId, int start, int end) throws SystemException { Session session = null;//from ww w.j a va2 s . c om try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_GROUP_IDS); SQLQuery q = session.createSQLQuery(sql); q.addScalar("userId", Type.LONG); q.addScalar("lastPostDate", Type.TIMESTAMP); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(groupId); qPos.add(groupId); qPos.add(groupId); List<BlogsStatsUser> statsUsers = new ArrayList<BlogsStatsUser>(); Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), start, end); while (itr.hasNext()) { Object[] array = itr.next(); long userId = (Long) array[0]; Date lastPostDate = (Date) array[1]; List<BlogsStatsUser> curStatsUsers = BlogsStatsUserUtil.findByU_L(userId, lastPostDate); if (!curStatsUsers.isEmpty()) { BlogsStatsUser statsUser = curStatsUsers.get(0); statsUsers.add(statsUser); } } return statsUsers; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }