Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liferay Portlet: How to generate service.xml (service builder) from existing database

I am new to liferay, Can anyone please suggest some way to generate the service.xml for existing database Discussion on Liferay Website . I hope people might have developed some way or liferay have developed some plugin for this.

like image 310
Navdeep Singh Avatar asked Sep 27 '13 09:09

Navdeep Singh


4 Answers

I see no particular use in introducing servicebuilder to large existing databases: You can connect servicebuilder entities to "legacy datasources" or "legacy tables" (those make good search terms) but service.xml generation has not been done AFAIK.

Some problem with this approach are:

  • servicebuilder has certain assumptions about operations in a database. It's done to encapsulate all different databases that Liferay runs on, thus might not use every database to its fullest extent possible
  • If you have a large existing database, you probably have a lot of existing business logic to make sure correct data goes in and out of the database. You might even work with stored procedures etc.
  • While you can make servicebuilder work with stored procedures, you'd have to introduce custom sql to work around servicebuilder's assumptions. Same goes for explicit foreign key relationships etc.

My recommendation is to rather have a proper interface on the existing business logic, e.g. Webservice, JSON, Rest, whatever is popular. Then use this interface in Liferay's portlets.

Another option might be to bring the existing persistence code into Liferay and just expose services without making use of the persistence features of Servicebuilder. For this you'd just define empty <entity> blocks (with names etc). This will generate the appropriate DoSomethingLocalService, but omit the persistence implementation - and you can wire your existing code in these services.

like image 126
Olaf Kock Avatar answered Oct 17 '22 12:10

Olaf Kock


You can go through below link to understand Service Builder in liferay

https://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/service-build-2

Also below link have sample service builder portlet

https://www.liferay.com/community/forums/-/message_boards/message/17609606

Hope it Helps !

like image 28
Ankit P Avatar answered Oct 17 '22 10:10

Ankit P


Not done yet AFAIK. Since Liferay directly doesnot support all data properties of DB like foreign key, one to n mapping etc, it is a challenge to create the reverese engineering. But you can give a try.

like image 22
Raghavendra Reddy Busireddy Avatar answered Oct 17 '22 12:10

Raghavendra Reddy Busireddy


Service Builder is generally a nice feature to create relatively small databases, and simple business Logic, while giving you the advantage that your tables will be auto-generated when you deploy your portlet, and having finders (search by X attribute) with no effort. If this is the case with your database, it will be much easier to create a new service.xml from scratch.

Other that that, I think that having an extended database in Liferay's Service Builder will introduce more problems and slow development while you're implementing a complex business Logic, create custom Finders whenever you need to query on a join of tables and so on. So it seems quite normal to me that a conversion of a database to Service Builder is not available.

In other words, if your database is too large to write it in service.xml, you shouldn't use Service Builder in the first place

like image 33
yannicuLar Avatar answered Oct 17 '22 12:10

yannicuLar