Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/DBWS/Using SessionCustomizer"
m (→Example) |
m |
||
Line 1: | Line 1: | ||
+ | For the current version, see: | ||
+ | '''[http://www.eclipse.org/eclipselink/documentation/2.4/dbws/toc.htm Developing Persistence Architectures Using EclipseLink Database Web Services, Release 2.4]''' | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
{{EclipseLink_UserGuide | {{EclipseLink_UserGuide | ||
|info=y | |info=y |
Revision as of 07:31, 14 August 2012
For the current version, see: Developing Persistence Architectures Using EclipseLink Database Web Services, Release 2.4
EclipseLink DBWS
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
Examples
Using an EclipseLink SessionCustomizer
When using an EclipseLink SessionCustomizer with DBWS, you can access to the EclipseLink API to retrieve the OR (object-relational) or OX (object-XML) mapping descriptors from the session. You can then use the descriptors to add, change, or delete mappings.
Refer to the EclipseLink Documentation for details on the SessionCustomizer.
Example
This example illustrates how to implement an EclipseLink SessionCustomizer:
package some.java.package; import org.eclipse.persistence.config.SessionCustomizer; import org.eclipse.persistence.sessions.Session; import org.eclipse.persistence.sessions.DatabaseLogin; public class MySessionCustomizer implements SessionCustomizer { public MySessionCustomizer() { } public void customize(Sesssion session) { DatabaseLogin login = (DatabaseLogin)session.getDatasourceLogin(); // enable 'dirty' reads login.setTransactionIsolation(DatabaseLogin.TRANSACTION_READ_UNCOMMITTED); } }
In the DBWSBuilder configuration file, you must use the orSessionCustomizerClassName or oxSessionCustomizerClassName to specify if the customization applies to the ORM or ORX project (respectively), as shown here:
ORM Project
<?xml version="1.0" encoding="UTF-8"?> <dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema" <properties> <property name="projectName">customize_test</property> ... <property name="orSessionCustomizerClassName">some.java.package.MyORSessionCustomizer</property>
ORX Project
<?xml version="1.0" encoding="UTF-8"?> <dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema" <properties> <property name="projectName">customize_test</property> ... <property name="oxSessionCustomizerClassName">some.java.package.MyOXSessionCustomizer</property>
Advanced Customization
You can further customize an EclipseLink DBWS service by creating your own EclipseLink project.xml and sessions.xml files. Using your preferred utility, you can do the following:
- map your objects to your relational database in an EclipseLink relational project;
- map your objects to your XML schema in an EclipseLink XML project:
- create an EclipseLink sessions.xml file that references both projects.
In this way, you can control all aspects of the relational and XML mapping. This approach is best when you want to customize most or all details.
Example
In this example, a DBWS service is constructed from existing EclipseLink project maps with identical case-sensitive aliases (for Descriptors that are common between the projects).
<?xml version="1.0" encoding="UTF-8"?> <object-persistence version="Eclipse Persistence Services - some version (some build date)" xmlns="http://www.eclipse.org/eclipselink/xsds/persistence" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:eclipselink="http://www.eclipse.org/eclipselink/xsds/persistence"> <name>SomeORProject</name> <class-mapping-descriptors> <class-mapping-descriptor xsi:type="relational-class-mapping-descriptor"> <class>some.package.SomeClass</class> <alias>SomeAlias</alias> ... <?xml version="1.0" encoding="UTF-8"?> <object-persistence version="Eclipse Persistence Services - some version (some build date)" xmlns="http://www.eclipse.org/eclipselink/xsds/persistence" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:eclipselink="http://www.eclipse.org/eclipselink/xsds/persistence"> <name>SomeOXProject</name> <class-mapping-descriptor xsi:type="xml-class-mapping-descriptor"> <class>some.package.SomeClass</class> <alias>SomeAlias</alias> ...
Note: When building a DBWS web service in this way (that is, without the DBWSBuilder Utility) be sure to create all the necessary deployment artifacts.