Fórum

Join with DynamicQuery

Rob Lindbloom, modificado 15 Anos atrás.

Join with DynamicQuery

New Member Postagens: 15 Data de Entrada: 16/10/08 Postagens Recentes
I'm trying to do a SQL inner join using DynamicQuery. I can't find too much information on how to do this. I'm trying to join JournalArticle with Ratings or RatingStats. Has anyone implemented this using JournalArticle.findByDynamicQuery()?

Thanks, Rob
thumbnail
Jonas Yuan, modificado 15 Anos atrás.

RE: Join with DynamicQuery

Liferay Master Postagens: 993 Data de Entrada: 27/04/07 Postagens Recentes
Hi Rob,

Here is a real example -getting most popular articles TOP 10 - abstracted from 1st draft of Chapter 8: Building My Community - Liferay DEV BOOK.

public List<TagsAsset> getMostPopularArticles(String companyId, String groupId, String type, int limit) {
List<TagsAsset> results = Collections.synchronizedList(new ArrayList<TagsAsset>());
DynamicQuery dq0 = DynamicQueryFactoryUtil.forClass(JournalArticle.class, "journalarticle")
.setProjection(ProjectionFactoryUtil.property("resourcePrimKey"))
.add(PropertyFactoryUtil.forName("journalarticle.companyId").eqProperty("tagsasset.companyId"))
.add(PropertyFactoryUtil.forName("journalarticle.groupId").eqProperty("tagsasset.groupId"))
.add(PropertyFactoryUtil.forName("journalarticle.type").eq("article-content"));
DynamicQuery query = DynamicQueryFactoryUtil.forClass(TagsAsset.class, "tagsasset")
.add(PropertyFactoryUtil.forName("tagsasset.classPK").in(dq0))
.addOrder(OrderFactoryUtil.desc("tagsasset.viewCount"));
try{
List<Object> assets = TagsAssetLocalServiceUtil.dynamicQuery(query);
int index = 0;
for (Object obj: assets) {
TagsAsset asset = (TagsAsset)obj;
results.add(asset);
index ++;
if(index == limit) break;
}
}catch (Exception e){
_log.debug("Error: " + e.getMessage());
return results;
}
return results;
}

Enjoy!

Jonas Yuan
Liferay Book: Liferay Portal Enterprise Intranets
Rob Lindbloom, modificado 15 Anos atrás.

RE: Join with DynamicQuery

New Member Postagens: 15 Data de Entrada: 16/10/08 Postagens Recentes
Jonus... thanks for your quick reply on a Friday no less. I'll give this a try!

Gratefully, Rob
thumbnail
Ruben Aguilera, modificado 14 Anos atrás.

RE: Join with DynamicQuery

Junior Member Postagens: 47 Data de Entrada: 25/02/09 Postagens Recentes
Hi Jonas,

First, congratulations for your new book, I have it and I think that's fantastic.

I was thinking if you could give me an example about join three tables with a dynamicquery. Specifically, I want to know how I make a join with TagsAsset, TagsEntry and TagsAssets_TagsEntries tables using a dynamicquery like example in first comment but with these three tables.

I need that to finish an important portlet in my job. Thank you very much.
Sikendar Kumar, modificado 6 Anos atrás.

Unable to see tags for guest users in liferay 6.2

New Member Postagens: 22 Data de Entrada: 02/09/15 Postagens Recentes
Hi jonas,

can you please help in below issue.

I have implemented search functionality , in that i have implemented such a way so that when user select tag and click on search button they can able to see all document which all document associated with that tag but its not working for the Guest user.can any one help me out what needs to do for this.