Accessing Data Stored on Non-Liferay Databases

Liferay will support our API and resolve any issues and answer any questions having to do with the API itself or any other part of Liferay's software. Issues and questions regarding custom development may be handled by our Global Services team or by the developer of those customizations.

This article documents how to access data stored on non-Liferay databases (e.g. different database schema or server) in Liferay DXP and beyond.

解決

  1. Specify the appropriate external datasource, etc., as necessary in the service.xml
    1. For example, specify extDataSource
  2. Follow the steps for creating a service builder module according to this documentation: Service Builder and Services (e.g., generating services, etc.)
  3. Add your custom datasource definition in a spring configuration file and call it liferayDataSource
  4. Add an alias definition from liferayDataSource to extDataSource 
    1. For example <alias name="liferayDataSource" alias="extDataSource" />

This will allow you to leverage the base functionality provided by the liferay-portal-spring-extender, assuming you defined in your Bnd directives to activate Liferay-Spring-Context and Liferay-Service.

Constraints to Consider:

  1. Only one data source per module may be used.  Therefore, each external data source will need to be encapsulated in its own service builder module.
  2. Cannot mix usage of the Liferay database with an external data source within the same module.

追加情報

注意

  1. Anytime multiple data sources are used with intent to WRITE to multiple data sources within the same transaction, you MUST use an XA transaction manager and XA datasources (otherwise known as 2-phase commit).  If you do not, transactional integrity will be lost. This same principal applied even prior to DXP 7.0.
  2. If you need additional flexibility (e.g. create multiple-data-sources) you can ask the spring extender to not activate the default service support but still use Spring for transactional control, etc. Specify Liferay-Service: false and Liferay-Spring-Context: true.
  3. This will basically tell the spring extender to not load the base spring configs (e.g. portal-spring-extender/src/main/resources/META-INF/spring/parent). The configurations in this directory setup base Liferay Service requirements (e.g. aspects, etc).  You can always set up your own, including any datasources and transaction managers used within the service builder generated code.  You must use the Liferay-Spring-Context directive because transaction management aspects are not supported in OSGi's Declarative Services at this stage.
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています