Combination View Flat View Tree View
Threads [ Previous | Next ]
Lorenzo Bugiani
Service builder
February 14, 2013 2:47 AM
Answer

Lorenzo Bugiani

Rank: New Member

Posts: 9

Join Date: January 28, 2013

Recent Posts

Hi all,

maybe is a strange question but: what can I do with service builder?
I mean, the documentation says that with service builder we can create new classes that can be use to access to new database table, and then we could expose out classes to the portal or both to external service.

What I would like to do is the same thing, but without create table. There were a way to use service builder only to create classes that can be use by other object of the portal, like portlets?

Thanks!
Meera Prince
RE: Service builder
February 14, 2013 5:31 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 814

Join Date: February 8, 2011

Recent Posts

Hi Lorenzo Bugiani,

IN any application we need to get data and insert data into data base tables. so if develop any application we need minimum basic CURD Operation like add row,update row, delete row like this operations are requires.
If we want insert any data into tables from java we are using JDBC or Hibernate. To handle these operation we need to write insert , delete and update logic according to our requirement. So for every requirement these operation are mandatory.
When we write all these data base operation we wil maintain layer called DAO(Data Access Layers).

What service builder do in Liferay?

By using SB we need not write DAO related java clasess or java code. Service Builder itself can do all these thing write database relation service like java methods.
we just use those methods we can insert data and delete data like that. if new requirement come then we can use finder methods or custome sql.
All data base related calsess SB will create we just use those classes to complete our requirement.
SO this kind of operation is requires for any portlet when we develop so from service build e we can do in minits. In the service.xml file we just mention what are the tables are required for our application like table name and column names. what are the tages availble for Sb liferay provide service builde dtd document from tthat we can know all the tags.
http://www.liferay.com/community/wiki/-/wiki/Main/Service+Builder

http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/service-build-2
http://www.javabeat.net/2011/06/using-liferays-service-builder-part-1/
http://innovationliferay.blogspot.in/p/service-builder-concept.html


Regards,
Meera Prince
http://www.liferaysavvy.com/
David H Nebinger
RE: Service builder
February 14, 2013 5:42 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6680

Join Date: September 1, 2006

Recent Posts

Lorenzo Bugiani:
maybe is a strange question but: what can I do with service builder?


1. Share access to database resources across multiple plugins w/o issues with stale caches and excessive resource usage.
2. Expose data access as a web service automagically.
3. Create shared code that can be accessed by multiple plugins.
4. Expose the shared code as a web service automagically.

The best example of what you can do with ServiceBuilder is Liferay itself. Liferay uses SB entirely, and it uses it for all of these things.
Hitoshi Ozawa
RE: Service builder
February 14, 2013 1:34 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

There's a chapter on it in Liferay's online documentation.

http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/service-build-5
Lorenzo Bugiani
RE: Service builder
February 17, 2013 9:18 AM
Answer

Lorenzo Bugiani

Rank: New Member

Posts: 9

Join Date: January 28, 2013

Recent Posts

David H Nebinger:
Lorenzo Bugiani:
maybe is a strange question but: what can I do with service builder?


3. Create shared code that can be accessed by multiple plugins.


Ok, so sorry for my questions, but i'm relative new to liferay.

How I can create shared code that can be accessed from other project (like other portlet or hook)? I habe to create the service inside a portlet? Inside a Hook? In a ext-plugin?
And, second question: Is possibie to write common code that doesn't use database? For example, i like to write CommonClass.java, that is a Class containing some common code for all my project in Liferay. I have to use service builder (how)? Or i have to use another method?

Thanks again.
Gnaniyar Zubair
RE: Service builder
February 17, 2013 10:37 PM
Answer

Gnaniyar Zubair

Rank: Liferay Master

Posts: 602

Join Date: December 19, 2007

Recent Posts

//How I can create shared code that can be accessed from other project (like other portlet or hook)?//


You can see the <entity>-service.jar file inside the plugin after generating the services through service builder. There are different way to share the services between plugins. Easiest way is, copying the service jar file into other plugins manually or setting this property in Portlet 1 to access the Portlet 2 services.

required-deployment-contexts=Library-portlet


To avoid the copying service jar into other plugins, you can create all dependency services in one service.xml.

// I have to create the service inside a portlet? Inside a Hook? In a ext-plugin?//


Purpose of Hook / EXT is to customize the core functionalists from Liferay. You can override /extend other portlet's services through Hook / EXT.

You should create the service inside the portlet. Through Liferay IDE, create basic MVC portlet and create Service-Builder for that portlet. you can see the basic service.xml template inside the WEB-INF folder. From there, you can customize as per your models.

//Is possible to write common code that doesn't use database? For example, i like to write CommonClass.java, that is a Class containing some common code for all my project in Liferay. I have to use service builder (how)? Or i have to use another method?//


Common Code : No Need serviceBuilder for your common utility classes. Service Builder generates all the necessary transaction layers. you can create your own classes and call that classes inside the implementation classes .

if you are developing Multi portlets in one WAR file, you can use Common utility classes which can be accessed by all the portlets.
Lorenzo Bugiani
RE: Service builder
February 18, 2013 12:41 AM
Answer

Lorenzo Bugiani

Rank: New Member

Posts: 9

Join Date: January 28, 2013

Recent Posts

ok thanks. Only one things I haven't understand:
Suppose you would write SharedClass.java, and you would like to share this classes to all portlet and hook of Liferay. How do you implement this?
Thanks a lot.
Gnaniyar Zubair
RE: Service builder
February 18, 2013 1:15 AM
Answer

Gnaniyar Zubair

Rank: Liferay Master

Posts: 602

Join Date: December 19, 2007

Recent Posts

Services you can share across the plugins but common classes we cannot share like that.

Otherwise, you can create the common classes in ext-service/src level and deploy it. it will be stored in global classpath which will be accessed by all the plugin.
Gnaniyar Zubair
RE: Service builder
February 18, 2013 1:31 AM
Answer

Gnaniyar Zubair

Rank: Liferay Master

Posts: 602

Join Date: December 19, 2007

Recent Posts

Otherwise, create a simple Java project with your custom classes and convert it as JAR file and place it in global class path . If you dont have any decencies with Liferay API with that classes. then you can do like this. For every changes of that jar, should restart the server.

In this case, you can access that classes from any plugins.
Lorenzo Bugiani
RE: Service builder
February 22, 2013 1:45 AM
Answer

Lorenzo Bugiani

Rank: New Member

Posts: 9

Join Date: January 28, 2013

Recent Posts

So, theese are the only ways to make a common component?
There's no way, for example, to crate a component (like a hook or a portlet) and they say to other project to use classes defined in the first?

Because using ext or external jar in tomcat's lib directory is a little bit boring.
If I use a ext plugin, every time i modify it I have to do a clean-app-server, deploy the ext, restar server and redeploy all.
If I use a shared tomcat lib, if I modify it I have to restart the server.

Even if isn't a problem when i'm developing, is a problem for the customer, thath have to restart every time his server...
Jaynil A Bagdai
RE: Service builder
February 22, 2013 1:58 AM
Answer

Jaynil A Bagdai

Rank: Regular Member

Posts: 120

Join Date: March 3, 2012

Recent Posts

Lorenzo,

To create a common component you can have a separate java project, you can have jar file of this project as dependency in each and every portlet/hooks, this will give you benefit of hot deployment and cause your dependent jar will go with portlet/hook's war file in server and your server need not to be restarted for the same.

But this will heavily load your server. If you don't want that then you can copy this jar file to your ext lib directory and every time you make change in code you need to restart your server again.

Regards,
Jaynil