留言板

How to use WHERE attribute of FINDER tag in service.xml?

thumbnail
Kravchenko Dmitry,修改在12 年前。

How to use WHERE attribute of FINDER tag in service.xml?

Regular Member 帖子: 139 加入日期: 10-10-4 最近的帖子
How to use WHERE attribute of FINDER tag in service.xml?

For example, is it possible to create finder, which receives single parameter P : String and looks for all rows where columns A and B satisfy A=P OR B=P?

In this example I need a finder column to have a name, which differs from any column name in a table. Is it possible?

Is it possible to use wilcard matching in finders, for example, how to find all rows which N field starts from "guest"?

Thanks
thumbnail
Ravi Kumar Gupta,修改在12 年前。

RE: How to use WHERE attribute of FINDER tag in service.xml?

Liferay Legend 帖子: 1302 加入日期: 09-6-24 最近的帖子
I guess its already there.. Like see this

<finder name="G_F_N" return-type="DLFileEntry" unique="true">
			<finder-column name="groupId" />
			<finder-column name="folderId" />
			<finder-column name="name" />
		</finder>

This is supposed to be a finder method with 3 arguments long, long, string.. and below is something that you are referring to(as it seems to me)

<finder name="A_B" return-type="collection">
			<finder-column name="A" />
			<finder-column name="B" />
		</finder>

provided both A and B are type string.. In the implementation according to what you want.. P will be passed as both A and B.. or say whenever you are going to call this finder method call like this..
xxx.findByA_B(P,P);


I am still learning services but I hope this is the way it works.. if not, correct me please.. emoticon
-Ravi
thumbnail
Kravchenko Dmitry,修改在12 年前。

RE: How to use WHERE attribute of FINDER tag in service.xml?

Regular Member 帖子: 139 加入日期: 10-10-4 最近的帖子
But where are you using WHERE attribute? I was interesting namely in it.
thumbnail
Amos Fong,修改在12 年前。

RE: How to use WHERE attribute of FINDER tag in service.xml?

Liferay Legend 帖子: 2047 加入日期: 08-10-7 最近的帖子
Hi,

Do you mean the where attribute in <finder> as defined in the dtd?
<!--ATTLIST finder
	name CDATA #REQUIRED
	return-type CDATA #REQUIRED
	unique CDATA #IMPLIED
	where CDATA #IMPLIED
	db-index CDATA #IMPLIED
-->


Here is an example from the source code:
		<finder name="L_L_P" return-type="Collection" where="status != 5">
			<finder-column name="layoutSetBranchId" />
			<finder-column name="layoutBranchId" />
			<finder-column name="plid" />
		</finder>


As for wildcards in it, I'm not sure, try a like with %'s emoticon
thumbnail
Kravchenko Dmitry,修改在12 年前。

RE: How to use WHERE attribute of FINDER tag in service.xml?

Regular Member 帖子: 139 加入日期: 10-10-4 最近的帖子
So, according to your example, I can't use WHERE to control filtering by finder parameters? It is just an additional filtering which can't refer finder columns?

For example,


        <finder name="People" return-type="Collection" where="age <= askedage">
            <finder-column name="askedage" />
        </finder>


with no 'askedage' column in the table.
thumbnail
Nagendra Kumar Busam,修改在12 年前。

RE: How to use WHERE attribute of FINDER tag in service.xml?

Liferay Master 帖子: 678 加入日期: 09-7-7 最近的帖子
I am not sure about WHERE clause, if you want to do wild card you can do it as below

Suppose if you want search for firstNames starting with Brain pass "Brain%" OR if you want firstNames ending with Brain pass "%Brain"

        <finder name="ByFirstName" return-type="Collection">
            <finder-column name="firstName" [b]comparator="LIKE" [ b] />
        </finder>


HTH
thumbnail
kartik shiroya,修改在8 年前。

RE: How to use WHERE attribute of FINDER tag in service.xml?

Junior Member 帖子: 47 加入日期: 14-12-29 最近的帖子
Nagendra Kumar Busam:
I am not sure about WHERE clause, if you want to do wild card you can do it as below

Suppose if you want search for firstNames starting with Brain pass "Brain%" OR if you want firstNames ending with Brain pass "%Brain"

        <finder name="ByFirstName" return-type="Collection">
            <finder-column name="firstName" [b]comparator="LIKE" [ b] />
        </finder>


HTH


Hello Nagendra

If i m putting comparator="LIKE" parameter in finder column then it will search like
Select * from user_ where firstName like "test";

But i am looking for LIKE operator as like below
Select * from user_ where firstName like "%test%";

so how should i have to implement it.

Note: i am not getting for 'b' with square bracket in your comment, please elaborate it.

Regards
Kartik
thumbnail
David H Nebinger,修改在8 年前。

RE: How to use WHERE attribute of FINDER tag in service.xml?

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
kartik shiroya:
But i am looking for LIKE operator as like below
Select * from user_ where firstName like "%test%";


Just surround the value with what you are passing to the finder with the percent signs.

Note: i am not getting for 'b' with square bracket in your comment, please elaborate it.


Formatting tags such as bold are not enforced within code blocks.