Foros de discusión

Service builder

Lorenzo Bugiani, modificado hace 11 años.

Service builder

New Member Mensajes: 9 Fecha de incorporación: 28/01/13 Mensajes recientes
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!
thumbnail
meera prince, modificado hace 11 años.

RE: Service builder

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
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/
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Service builder

Liferay Legend Mensajes: 14915 Fecha de incorporación: 2/09/06 Mensajes recientes
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.
Lorenzo Bugiani, modificado hace 11 años.

RE: Service builder

New Member Mensajes: 9 Fecha de incorporación: 28/01/13 Mensajes recientes
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.
thumbnail
Gnaniyar Zubair, modificado hace 11 años.

RE: Service builder

Liferay Master Mensajes: 722 Fecha de incorporación: 19/12/07 Mensajes recientes
//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, modificado hace 11 años.

RE: Service builder

New Member Mensajes: 9 Fecha de incorporación: 28/01/13 Mensajes recientes
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.
thumbnail
Gnaniyar Zubair, modificado hace 11 años.

RE: Service builder

Liferay Master Mensajes: 722 Fecha de incorporación: 19/12/07 Mensajes recientes
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.
thumbnail
Gnaniyar Zubair, modificado hace 11 años.

RE: Service builder

Liferay Master Mensajes: 722 Fecha de incorporación: 19/12/07 Mensajes recientes
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, modificado hace 11 años.

RE: Service builder

New Member Mensajes: 9 Fecha de incorporación: 28/01/13 Mensajes recientes
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...
thumbnail
Jaynil A Bagdai, modificado hace 11 años.

RE: Service builder

Regular Member Mensajes: 119 Fecha de incorporación: 3/03/12 Mensajes recientes
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
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: Service builder

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
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