Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/DBWS/Using SessionCustomizer"

m (New page: {{EclipseLink_UserGuide |info=y |toc=y |eclipselink=y |eclipselinktype=DBWS }} ==Using an EclipseLink SessionCustomizer==)
 
m
Line 1: Line 1:
 
{{EclipseLink_UserGuide
 
{{EclipseLink_UserGuide
 
|info=y
 
|info=y
|toc=y
+
|toc=n
 
|eclipselink=y
 
|eclipselink=y
 
|eclipselinktype=DBWS
 
|eclipselinktype=DBWS
Line 7: Line 7:
  
 
==Using an EclipseLink SessionCustomizer==
 
==Using an EclipseLink SessionCustomizer==
 +
When using an EclipseLink <tt>SessionCustomizer</tt> 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 [http://wiki.eclipse.org/Introduction_to_EclipseLink_Sessions_%28ELUG%29#Session_Customization EclipseLink Documentation] for details on the <tt>SessionCustomizer</tt>.
 +
===Example===
 +
This example illustrates how to implement an EclipseLink <tt>SessionCustomizer</tt>:
 +
 +
<source lang="java">
 +
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);
 +
  }
 +
}
 +
</source>
 +
 +
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'''
 +
<source lang="xml">
 +
<?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>
 +
</source>
 +
 +
'''ORX Project'''
 +
<source lang="xml">
 +
<?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>
 +
</source>

Revision as of 18:28, 26 October 2011

EclipseLink DBWS

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source


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>

Copyright © Eclipse Foundation, Inc. All Rights Reserved.