Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
David H Nebinger
Support Catalog and Schema in ServiceBuilder...
May 3, 2012 5:22 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8560

Join Date: September 1, 2006

Recent Posts

So I've made some modifications to ServiceBuilder to support using a catalog and/or schema in the entities in the service.xml and am going through the steps for contributing the changes back. The first step is to post to the forum to get some feedback, so here I go...

Proposed Change: Support the Catalog and Schema for Entities in ServiceBuilder's service.xml file.

Why the Change is Needed: The service.xml file is used to create entities for custom services, entities backed by an underlying database. Although the Liferay database session can be used, all entities will fall under the catalog and/or schema that are the default values for the credentials used to connect to the database (when that database supports catalogs and/or schemas).

It is possible to use a different session factory (backed by a different database connection) to bind entities to an alternate catalog/schema; this overhead would not be necessary when qualifying the catalog and/or schema is enough.

By adding catalog and schema to the entity definition, other tables can be accessed w/o adding other connections (as long as they are available on the same database server).

Example: In my SqlServer database server, I have the LPORTAL database, but I also have the CUSTOM database. The connection string for my Liferay system is basically "jdbc:jdts:sqlserver://<my ip>/LPORTAL".

The system handles "SELECT * FROM User_" as though I actually typed "SELECT * FROM LPORTAL.dbo.User_". In my SQL tool connected using the same URL info, I could also query using "SELECT * FROM CUSTOM.dbo.MyTable"; since it is fully qualified, SqlServer happily processes the query and returns results (just as Oracle would w/ the right schema).

Since I cannot qualify entities w/ catalog and schema, I'm forced to create and maintain a separate connection back to the same database server with credentials that default to the CUSTOM database.

Scope of the Change: Since Hibernate already supports both the catalog and schema attributes on the mapping files, the scope of the change is fairly limited:

  1. Add the attributes to the liferay-service-builder DTD file.
  2. Add the members and methods to the com.liferay.portal.tools.servicebuilder.Entity class.
  3. Add support for populating the members to the com.liferay.portal.tools.servicebuilder.ServiceBuilder class.
  4. Modify the freemarker templates hbm_xml.ftl and persistence_impl.ftl in com.liferay.portal.tools.servicebuilder.dependencies package to support code generation using the new members.


Unhandled Impact: The Liferay IDE and Liferay Developer Studio have GUI-based editors for the service.xml file. Since the editor doesn't know anything about the new attributes, upon opening a service.xml that has the attributes the editor will mark the entities as errors.

Conclusion

So this is my proposal. What do you all think?
Nagendra Kumar Busam
RE: Support Catalog and Schema in ServiceBuilder...
May 30, 2012 4:02 AM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 638

Join Date: July 7, 2009

Recent Posts

Hi David,

This really looks like very good use case. This way really we can connect to any database with-in same engine/different engine all-together. +1 for this feature on my behalf
David H Nebinger
RE: Support Catalog and Schema in ServiceBuilder...
May 30, 2012 5:29 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8560

Join Date: September 1, 2006

Recent Posts

Well, the intent is to support the same engine...

For example, if you have one oracle database you typically have your database partitioned into schemas, like "lportal" for the Liferay stuff but "sales" schema for sales tables...

Without the schema support, you must use a separate connection to get to the sales schema, even though it's in the same database.
Nagendra Kumar Busam
RE: Support Catalog and Schema in ServiceBuilder...
May 30, 2012 6:17 AM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 638

Join Date: July 7, 2009

Recent Posts

I got what you are saying about same engine. If service builder provides some way to support different engine that might be a good use case as well.

You look into a case where company has some proprietary data in an engine different from what we are using from Liferay portal - still they want to list the some of the details from other engine.
David H Nebinger
RE: Support Catalog and Schema in ServiceBuilder...
May 30, 2012 6:23 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8560

Join Date: September 1, 2006

Recent Posts

Well, hibernate dialect is definitely tied to the underlying database, so a separate database connection is necessary in that situation...
Christophe Cariou
RE: Support Catalog and Schema in ServiceBuilder...
October 16, 2012 1:27 AM
Answer

Christophe Cariou

Rank: Junior Member

Posts: 45

Join Date: October 1, 2007

Recent Posts

Hi David,

exactly what I Need. Totally agree with you.

As far as I can see, this will only impact Liferay IDE and/or SDK. Existing Liferay portal will implicitly support this.

Nagendra, do you know if this feature is planned?

Christophe
David H Nebinger
RE: Support Catalog and Schema in ServiceBuilder...
October 16, 2012 5:40 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8560

Join Date: September 1, 2006

Recent Posts

Actually the changes are pretty much isolated to the SB code/templates and the DTD. IDE changes would only be needed to support the attributes in the visual service builder editor (otherwise it thinks they're all errors).