Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
Aswin Giridhar
Liferay Service Builder
16 de marzo de 2012 12:43
Respuesta

Aswin Giridhar

Ranking: New Member

Mensajes: 15

Fecha de incorporación: 9 de febrero de 2011

Mensajes recientes

Hey guys,

I am currently stuck in a problem where I have the following scenario:

I am creating a table called "Region", which has a relationship with the existing liferay table "Country". So the scenario is something like this, one region can have many countries.

In order to achieve this, I am creating a table regioncountry, which holds the foreign key of Region and Country table.

DB Schema:
Region: RegionId, Name
RegionCountry: RegionId, CountryId

How do i achieve this using Liferay Service builder ?

I have seen something similar in Liferay Portal service.xml (for relationship between Groups and Organization), but i I am not able to find any entity Groups_Orgs on the service.xml.

What is the best solution for this scenario ?
- Going for the above method
- Creating new column regionid on the existing liferay table Country
- Creating a new table altogether ?

Any help will be appreciated.

Thanks,
David H Nebinger
RE: Liferay Service Builder
16 de marzo de 2012 12:53
Respuesta

David H Nebinger

Ranking: Liferay Legend

Mensajes: 6799

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

If region contains multiple countries, then region would be an entity w/ a collection of countries, and country would be an entity w/ a region id.

You don't need the many to many relationship join table.
Aswin Giridhar
RE: Liferay Service Builder
16 de marzo de 2012 13:07
Respuesta

Aswin Giridhar

Ranking: New Member

Mensajes: 15

Fecha de incorporación: 9 de febrero de 2011

Mensajes recientes

David H Nebinger:
If region contains multiple countries, then region would be an entity w/ a collection of countries, and country would be an entity w/ a region id.

You don't need the many to many relationship join table.


Hi David,

Thanks for your reply.
So, that would mean overriding existing Liferay Country table to add the regionId there ?
I am just skeptical to change existing Liferay Entities, is that advisable to do ?
David H Nebinger
RE: Liferay Service Builder
16 de marzo de 2012 13:14
Respuesta

David H Nebinger

Ranking: Liferay Legend

Mensajes: 6799

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

Oh, the part about wanting to use the Liferay country entity was not apparent.

You're right about not wanting to modify the Liferay entities, it would make upgrades difficult.

So instead I'd do the Region entity that has a collection of "MyCountry" entities. The MyCountry entity would have the region id and the Liferay Country as an entity. That should give you what you're looking for, correct?
Joaquin Cabal
RE: Liferay Service Builder
16 de marzo de 2012 13:15
Respuesta

Joaquin Cabal

Ranking: Junior Member

Mensajes: 49

Fecha de incorporación: 7 de septiembre de 2009

Mensajes recientes

Hi David,
Is ok the modeling, but what would be the way for create these services?
If I have to create a new service I would create it in a new portlet for example, but if a have a relationship with an existing Liferay model like "Country", How would be this? Could be in a Hook plugin or maybe an Ext plugin , overriding the portal service builder?
David H Nebinger
RE: Liferay Service Builder
16 de marzo de 2012 13:18
Respuesta

David H Nebinger

Ranking: Liferay Legend

Mensajes: 6799

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

No, you'd stick w/ your regular portlet w/ the service builder in there.

You will still have access to Liferay's CountryLocalServiceUtil (or whatever it is) for fetching countries, you'd just be setting the result into the MyCountry entity...
David H Nebinger
RE: Liferay Service Builder
16 de marzo de 2012 13:28
Respuesta

David H Nebinger

Ranking: Liferay Legend

Mensajes: 6799

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

David H Nebinger:
No, you'd stick w/ your regular portlet w/ the service builder in there.

You will still have access to Liferay's CountryLocalServiceUtil (or whatever it is) for fetching countries, you'd just be setting the result into the MyCountry entity...


The more I think about this, I realize it's not going to work. The Country object you get back from Liferay is actually an interface to an instance from another class loader.

I guess I would make the MyCountry entity hold the region id and the country id. Get the list of MyCountry entities using the region, then you'd have to manually call the CountryLocalServiceUtil (or whatever it is) to pull back the country instance.

Adding it as an EXT plugin would get around this issue, but SB usage in EXT plugins is either deprecated now or will be in the future (I know I saw a note about that somewhere). Since a hook is in a different class loader, it would face the same issue as a regular portlet implementation...
Joaquin Cabal
RE: Liferay Service Builder
16 de marzo de 2012 13:38
Respuesta

Joaquin Cabal

Ranking: Junior Member

Mensajes: 49

Fecha de incorporación: 7 de septiembre de 2009

Mensajes recientes

Thanks David, I have sent last post, viewing only your first post.
Is a good idea to have two entities for this case, and MyCountry entity having a relation to Liferay Country
Aswin Giridhar
RE: Liferay Service Builder
16 de marzo de 2012 13:40
Respuesta

Aswin Giridhar

Ranking: New Member

Mensajes: 15

Fecha de incorporación: 9 de febrero de 2011

Mensajes recientes

David H Nebinger:
Oh, the part about wanting to use the Liferay country entity was not apparent.

You're right about not wanting to modify the Liferay entities, it would make upgrades difficult.

So instead I'd do the Region entity that has a collection of "MyCountry" entities. The MyCountry entity would have the region id and the Liferay Country as an entity. That should give you what you're looking for, correct?



How do we do that ?
is this something like this ?
<entity name="myRegion" local-service="true" remote-service="true">

<column name="regionId" primary="true" type="long"></column>

<column name="name" type="String"></column>
<column name="defaultLanguage" type="long"></column>
<column name="countries" type="Collection" entity="MyCountry" mapping-key="regionId" />

</entity>
<entity name="myCountry" local-service="true" remote-service="true">

<column name="countryId" primary="true" type="long"></column>
<column name="regionId" type="long"></column>

<column name="countries" type="Collection" entity="Country" mapping-key="countryId" />
<reference entity="Country" package-path="com.liferay.portal"/>
</entity>
Joaquin Cabal
RE: Liferay Service Builder
16 de marzo de 2012 13:47
Respuesta

Joaquin Cabal

Ranking: Junior Member

Mensajes: 49

Fecha de incorporación: 7 de septiembre de 2009

Mensajes recientes

Hi Aswin,

It would be like that

<entity name="myRegion" local-service="true" remote-service="true">
<column name="regionId" primary="true" type="long"></column>

<column name="name" type="String"></column>
<column name="defaultLanguage" type="long"></column>
<column name="countries" type="Collection" entity="MyCountry" mapping-key="regionId" />

</entity>
<entity name="myCountry" local-service="true" remote-service="true">

<column name="countryId" primary="true" type="long"></column>
<column name="regionId" type="long"></column>
</entity>

MyCountry is only for have a relation to Liferay Country
Aswin Giridhar
RE: Liferay Service Builder
16 de marzo de 2012 14:45
Respuesta

Aswin Giridhar

Ranking: New Member

Mensajes: 15

Fecha de incorporación: 9 de febrero de 2011

Mensajes recientes

Joaquin Cabal:
Hi Aswin,

It would be like that

<entity name="myRegion" local-service="true" remote-service="true">
<column name="regionId" primary="true" type="long"></column>

<column name="name" type="String"></column>
<column name="defaultLanguage" type="long"></column>
<column name="countries" type="Collection" entity="MyCountry" mapping-key="regionId" />

</entity>
<entity name="myCountry" local-service="true" remote-service="true">

<column name="countryId" primary="true" type="long"></column>
<column name="regionId" type="long"></column>
</entity>

MyCountry is only for have a relation to Liferay Country



So when we use mycountry, we create a custom finder and add methods on that mycountry service and then query the liferay country (CountryLocalServiceUtil) to populate myCountry right ?
Joaquin Cabal
RE: Liferay Service Builder
18 de marzo de 2012 16:54
Respuesta

Joaquin Cabal

Ranking: Junior Member

Mensajes: 49

Fecha de incorporación: 7 de septiembre de 2009

Mensajes recientes

Exactly! when you add some Country for the region, you get the Liferay Country id, with CountryLocalServiceUtil
sheela mk
RE: Liferay Service Builder
25 de abril de 2012 3:41
Respuesta

sheela mk

Ranking: Regular Member

Mensajes: 112

Fecha de incorporación: 16 de febrero de 2012

Mensajes recientes

Oh My God..Got Solution!!!

emoticon