Professional Documents
Culture Documents
Home
Liferay
Hook
Alloy
Code Snippet
How To
Contact Us
About Us
Privacy Policy
Tags
Alloy
alloy ui
DXP
hook
liferay
custom attribute
javascript
json
search container
We know Liferay service builder tool which generate all our necessary stuffs to
ipc
liferay 7
liferay theme
velocity
angular js
service builder
OSGI
spring mvc
velocity template
interact with database. By Liferay Custom SQL we can query database by writing
raw SQL query. You might be thinking of Liferay Finder to fetch data. But it has some
limitations. If we need to aggregate data from from different tables then Liferay
Custom
By continuing to use the site, you agree to the use of cookies. more information
Query would be very handy. Liferay Custom Query is nothing but native query. For example
Accept
Top
01/12/2016 20:31
2 of 8
we are writing custom query for oracle but it may not work for MySQL. Liferay Custom
Query is very easy to use by means of using XML file where we write our SQL Query. This
article explains in details about how to create Liferay Custom Query in our custom portlet.
Before starting the topic I am assuming that you have basic knowledge of Liferay Service
builder tool. If you are new to Liferay Service builder then it would be better to
understand the concept of Liferay Service Builder first and then learn how to build Lifery
Custom SQL. Follow the below links to know Liferay Service Builder
http://proliferay.com/an-introduction-to-liferay-service-builder/
http://proliferay.com/crud-operations-in-liferay-portlet/
I am considering the below service.xml file for explaining Liferay Custom SQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
RSS Feed
Note:
RSS - Posts
RSS - Comments
The main purpose of Liferay Custom SQL is to execute our own hand written query to fetch data from one
table or many tables.
Continue reading
Consume OSGI Service in Liferay Portlet
Accept
Top
01/12/2016 20:31
3 of 8
1.
Liferay should know the location of our custom query. In src folder of our portlet we need to create a new
directory called custom-sql. Under custom-sql folder we should create one new file called default.xml
file. In default.xml file we can write our all the custom query. But its better to write custom queries in
separate files if number of custom queries are more. The content of default.xml is
Publisher ADT
1
2
3
4
Which means that book.xml is another file where our custom queries are available. Download the source
2.
Have a look into the service.xml shown in the above. We write finder class based on service.xml. Initially
BookFinderImpl class is created with below content.
1
2
3
4
5
6
7
8
9
package com.proliferay.sbuilder.example.customquery.service.persistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import com.proliferay.sbuilder.example.customquery.model.Book;
Note: BookFinderImpl class implements BookFinder. BookFinder interface will be generated only after
building the service.
By continuing to use the site, you agree to the use of cookies. more information
Angular JS Expression
Accept
Top
01/12/2016 20:31
4 of 8
Angular JS Directive
AuthType:3 Ways to Login Liferay
Liferay Portlet Show Caps Lock On for
Password Field
Getting Started with Angular JS
. Write
<![CDATA[
SELECT
*
FROM
CUSTOMQUERY_BOOK_PORTLET
WHERE
price = ?
]]>
</sql>
</custom-sql>
Note: The ? mark in the above SQL is dynamic. We can execute this query from BookFinderImpl class
Liferay
4.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package com.proliferay.sbuilder.example.customquery.service.persistence;
import java.util.List;
import
import
import
import
import
import
import
com.liferay.portal.kernel.dao.orm.QueryPos;
com.liferay.portal.kernel.dao.orm.SQLQuery;
com.liferay.portal.kernel.dao.orm.Session;
com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
com.liferay.util.dao.orm.CustomSQLUtil;
com.proliferay.sbuilder.example.customquery.model.Book;
com.proliferay.sbuilder.example.customquery.model.impl.BookImpl;
CRUD
Operations
in more
Liferay
Portlet
By continuing to use the site, you agree
to the
use of cookies.
information
Accept
Top
01/12/2016 20:31
5 of 8
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
5.
Write a new method in BookLocalServiceImpl and call the above method. Hit ant
package com.proliferay.sbuilder.example.customquery.service.impl;
import java.util.List;
import com.proliferay.sbuilder.example.customquery.model.Book;
import com.proliferay.sbuilder.example.customquery.service.base.BookLocalServiceBaseImpl;
import com.proliferay.sbuilder.example.customquery.service.persistence.BookFinderUtil;
/**
* The implementation of the book local service.
*
* <p>
* All custom service methods should be put in this class. Whenever methods are
* added, rerun ServiceBuilder to copy their definitions into the
* {@link com.proliferay.sbuilder.example.customquery.service.BookLocalService}
* interface.
*
* <p>
* This is a local service. Methods of this service will not have security
By continuing to use the site, you agree to the use of cookies. more information
* checks based on the propagated JAAS credentials because this service can only
* be accessed from within the same VM.
* </p>
Accept
Top
01/12/2016 20:31
6 of 8
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
*
* @author Hamidul Islam
* @see com.proliferay.sbuilder.example.customquery.service.base.BookLocalServiceBaseImpl
* @see com.proliferay.sbuilder.example.customquery.service.BookLocalServiceUtil
*/
public class BookLocalServiceImpl extends BookLocalServiceBaseImpl {
/*
* NOTE FOR DEVELOPERS:
*
* Never reference this interface directly. Always use {@link
* com.proliferay.sbuilder.example.customquery.service.BookLocalServiceUtil}
* to access the book local service.
*/
6.
1
Summery:
In this article we have discussed only the basic concept of Liferay Custom SQL. We will discuss some
advance topic in another article.
G WhatsApp
9 Email
Like this:
Related
By continuing to use the site, you agree to the use of cookies. more information
Accept
Top
01/12/2016 20:31
7 of 8
Post Tagged with liferay, Liferay Custom Query, Liferay Custom SQL, Lifery Custom Query Example
Previous Post
Next Post
Hi, thanks for that nice tutorial, I would like to call the
**BookLocalServiceUtil.getBooksByPrice(123);** service from another portlet, I tried to add the
following to the portlet using the service:
required-deployment-contexts=mf3-plugin-service-portlet
The jar le of the portlet is added to the WEB_INF/lib directory, but when calling the methode, I
get a NoSuchBean Exception.
Woould be glad if you could assit me on this
Reply
Leave a Reply
Comment
By continuing to use the site, you agree to the use of cookies. more information
Accept
Top
01/12/2016 20:31
8 of 8
Name
By continuing to use the site, you agree to the use of cookies. more information
Accept
Top
01/12/2016 20:31