tag:blogger.com,1999:blog-77474812466300043692024-03-08T01:57:35.273-05:00Java PersistenceA blog dedicated to Java Persistence issues and solutions related to EclipseLink and Oracle TopLink.Doughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.comBlogger23125tag:blogger.com,1999:blog-7747481246630004369.post-19472593162115473292012-06-27T10:00:00.000-04:002012-06-27T10:00:04.024-04:00EclipseLink 2.4:<h2>
</h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://eclipse.org/juno/" target="_blank"><img border="0" height="108" src="http://www.eclipse.org/juno/images/eclipse_juno242x132.jpg" width="200" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.eclipse.org/eclipselink/images/logo.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="58" src="http://www.eclipse.org/eclipselink/images/logo.png" width="200" /></a></div>
<h2>
EclipseLink 2.4.0 Juno - RELEASED</h2>
As part of the Juno Eclipse release train the EclipseLink project has released EclipseLink 2.4.0. The<a href="http://www.eclipse.org/eclipselink/releases/2.4.php" target="_blank"> release landing page</a> describes some of the new and noteworthy features as well as providing links to documentation and examples so you can get started. What I would like to do is provide some colour commentary on the features new in this release.<br />
<h3>
JSON Binding</h3>
<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">EclipseLink’s
MOXy component has offered a JAXB compliant implementation for
many years now. <span style="mso-spacerun: yes;"> </span>It not
only supports the standard JAXB features but also goes well
beyond the standard to offer powerful advanced features,
including XPath mappings, and support for defining mappings in
XML instead of just annotations. </span></div>
<div class="MsoNormal" style="line-height: normal;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">In
EclipseLink 2.4.0, MOXy has expanded its scope to support
mapping Java objects to JSON. This support covers all of the
MOXy mappings available in annotations, XML<b>, and now JSON</b>.
<span style="mso-spacerun: yes;"> </span>MOXy’s JSON support is
enabled simply by setting the desired media-type <b>on</b> a
marshaller or unmarshaller. <span style="mso-spacerun: yes;"> </span>This
support is unique as it marshalls/unmarshalls objects directly
to and from JSON without any intermediate conversions.<span style="mso-spacerun: yes;"> </span>And EclipseLink MOXy’s
integration with EclipseLink JPA, originally written for XML
mapping, makes serializing JPA entities to and from JSON easy.</span></div>
<div style="text-align: right;">
<a href="http://wiki.eclipse.org/EclipseLink/Release/2.4.0/JSONBinding" target="_blank">Learn more about EclipseLink MOXy's JSON ...</a></div>
<br />
<h3>
HTML5/Mobile</h3>
During the development of 2.4 the team introduced JSON binding and we started building sample applications illustrating how this functionality could be leveraged with JAX-RS to simplify development. This lead us to discussions with the <a href="http://jersey.java.net/" target="_blank">Jersey </a>team as to how EclipseLink could better integrated. I parallel we continue to look at different client technologies to see what we can do in the persistence layer to simplify development. The convergence of these efforts is EclipseLink's JPA-RS feature which provides RESTful access to persistence units with either XML or JSON data formats.<br />
<br />
What I find most interesting about JPA-RS is what it offers to developers looking to access data for <a href="http://www.thinserverarchitecture.com/" target="_blank">Thin Server Architecture</a> (TSA) clients. In many cases client developers just need data in a consumable (and of course efficient and secure) format and having to build a full Java EE application to expose this data can be a barrier to entry. What we have done with JPA-RS is simplified how new applications can be developed with a JAX-RS+JPA back-end with minimal server side development.<br />
<div style="text-align: right;">
<a href="http://wiki.eclipse.org/EclipseLink/Release/2.4.0/JPA-RS" target="_blank">Learn more about JPA-RS...</a></div>
<h3>
Cloud Enabled Persistence</h3>
Starting in EclipseLink 2.3 the EclipseLink team started exposing features to simplify development of applications that will be deployed in a cloud infrastructure or need to work in PaaS or SaaS scenarios. The solutions introduced included:<br />
<ul>
<li>@Multitenant(SINGLE_TABLE) allowing tables to store data from multiple tenants leveraging row level filtering.</li>
<li>Extensible entities using virtual attributes so that the entity types can be customized post deployment to manage additional state. </li>
<li>MetadataSource allows overriding mapping metadata (JPA and MOXy) to be retrieved dynamically during deployment or on refresh request. This allows persistence unit customization post development so that applications can be customizable at runtime as well as supporting deployment architectures where tenant specific extensions are enabled.</li>
</ul>
In EclipseLink 2.4 we have further extended this support to include some additional tenant isolation options. <br />
<ul>
<li>@Multitenant(TABLE_PER_TENANT) allows different tables in the same schema to be used per tenant or dedicated schemas per tenant.</li>
<li>MetadataSource has been extended to allow persistence unit properties, including data source information, to be dynamically provided at startup and refresh. This allows PaaS deployed application instances to retrieve isolated data source information per tenant.</li>
</ul>
<div style="text-align: right;">
<a href="http://wiki.eclipse.org/EclipseLink/DesignDocs/Multi-Tenancy/TablePerTenant" target="_blank">Learn more about EclipseLink's Tenant Isolation features ...</a></div>
<h3>
NoSQL</h3>
<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt;">EclipseLink,
even before it was open
sourced at Eclipse, offered developers support for mapping their
persistent
entities to non-relational data sources. This support was done
using the
little known EIS features where JCA resource adapters were used
and mappings
were made to XML or record structures. This
core support in the foundation component has been reborn in the
EclipseLink
NoSQL component. This first release of EclipseLink NoSQL that
ships in
conjunction with our primary 2.4.0 release provides mapping and
querying
capabilities with MongoDB and Oracle NoSQL.</span></div>
<div class="MsoNormal" style="line-height: normal;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt;">Although
Object-Relational
persistence for NoSQL may not apply in all scenarios it does
appeal to
developers who wish to use Objects and find the existing Java
Persistence
interfaces more natural to integrate with versus a unique
data-centric API
provided by the NoSQL vendors.</span></div>
<div class="MsoNormal" style="line-height: normal;">
<br /></div>
<span style="font-family: "Times New Roman","serif"; font-size: 12pt;">This area
of EclipseLink persistence
will be challenging given the lack of standards and wide variety
of NoSQL
stores available and we are hoping this first release will allow
us to gain
experience with how developers want to access NoSQL from their
Java
applications. We'll learn both where a solution like this fits
well as well as
where it is best not used. We will be looking to the community
for feedback on
the support offered, new features wanted, as well as what
additional NoSQL databases
we should consider supporting in future releases of EclipseLink
NoSQL.</span><br />
<div style="text-align: right;">
<a href="http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/NoSQL" target="_blank">Learn more about EclipseLink NoSQL ...</a> </div>
<br />
<h3>
And Much More...</h3>
We continue to evolve what a Java Persistence solution can do and have many plans for new features. The primary source of our requirements is based on our users. If you are using EclipseLink and like what you see then please let the developers know. If you don't like something we also want to hear about that. If you have never tried EclipseLink then what are you waiting for. <a href="http://www.eclipse.org/eclipselink/downloads/2.4" target="_blank">Download the new EclipseLink 2.4</a> release and let us know what you think.<br />
<h4>
Feedback</h4>
<ul>
<li><a href="http://www.eclipse.org/forums/index.php/f/111/" target="_blank">EclipseLink Newsgroup</a></li>
<li>Twitter:<a href="https://twitter.com/#%21/search/EclipseLink" target="_blank"> #EclipseLink</a> or <a href="https://twitter.com/#%21/EclipseLink" target="_blank">@EclipseLink</a></li>
<li><a href="https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EclipseLink" target="_blank">EclipseLink Bugzilla</a></li>
</ul>Doughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-57958298011737816632011-06-03T14:08:00.006-04:002011-06-03T14:26:55.898-04:00Czech Republic visit and EclipseLink Indigo (2.3)Last week when I was in Prague I had the oppurtunity to catch up with <a href="http://blogs.oracle.com/alexismp/">Alexis-Moussine Pouchkine</a> (<a href="http://twitter.com/#%21/alexismp">@alexismp</a>). While there Alexis recorded an interview with me about EclipseLink and we both spoke at the Java Developer Conference in Brno.<br /><ul><li><a href="http://blogs.oracle.com/alexismp/entry/brno_oracle_java_developer_event">Alexis Summary of developer conference</a></li><li><a href="http://blogs.oracle.com/glassfishpodcast/entry/episode_074_eclipselink_discussion_with">GlassFish PodCast on EclipseLink</a></li></ul>The developer conference was my first opportunity to present a talk on the work we have been doing within the EclipseLink project to address development of applications for the cloud. More specifically we have been busy working on some features which I think will be very interesting to all Java EE developers using JPA. These include:<br /><ul><li><span style="font-weight: bold;">@Multitenant</span>: Support for configuring entities which have data from different tenants stored in the same table. EclipseLink will automatically apply additional criteria on all queries to only read and modify the rows for your current tenant.</li><li>Extensible Entities with Virtual Attributes (<span style="font-weight: bold;">@VirtualAccessMethods</span>): Allow for attributes to be mapped to database flex columns on the fly. This includes both JPA and JAXB mappings/bindings as well as tenant specific extensions.</li><li><span style="font-weight: bold;">MetadataSource</span>: Allow for your XML specified JPA mappings or JAXB bindings to be dynamically loaded and used by your application from an external source. This allows you to customize your application on-the-fly from an external source.</li></ul>In my presentation I did a demo of my new MySports demo application which I am busy wrapping up and documenting for the Eclipse Indigo release (June 22). This application shows off the new features with a multitenant JSF application which includes dynamic JSF rendering of extended attributes using the JPA 2.0 metamodel. The tenant configuration and provisioning is done using an admin application which uses REST and EclipseLink MOXy's binding support.<br /><br />It should be a busy month wrapping up all of the necessary documentation and examples for the Indigo release so that EclipseLinkDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-78798702374824682752011-02-25T15:51:00.002-05:002011-02-25T15:53:33.650-05:00Oracle @ EclipseConAlthough it does not look like I will make it to Santa Clara this year for EclipseCon the rest of the team here at Oracle has put together an impressive set of sessions. If you are planning on attending EclipseCon here is a summary of the Oracle related sessions.<br /><br /><a href="http://wikis.sun.com/display/EC2011/Oracle+at+EclipseCon+2011">http://wikis.sun.com/display/EC2011/Oracle+at+EclipseCon+2011</a>Doughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-20222752829778631272011-02-09T15:55:00.004-05:002011-02-09T15:58:52.477-05:00JPA 2.0 in WebLogic with OEPETo add to my previous post. <a href="http://blogs.oracle.com/gstachni/2011/02/using_jpa_20_with_weblogic_ser.html">Greg Stachnick has posted the steps for enabling JPA through the Oracle Enterprise Pack for Eclipse</a>.<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-66277625306419663412011-02-01T10:56:00.003-05:002011-02-01T11:10:42.374-05:00Using JPA 2.0 in WebLogic 10.3.4Starting with the <a href="http://www.oracle.com/technetwork/middleware/weblogic/overview/index.html">Oracle WebLogic</a> <a href="http://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html">10.3.4</a><a href="http://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html"> release</a> it is now possible to upgrade to using JPA 2.0. The release includes <a href="http://www.oracle.com/technetwork/middleware/toplink/downloads/index.html">TopLink 11.1.1.4</a> (with <a href="http://www.eclipse.org/eclipselink/downloads/index.php#2.1.2">EclipseLink 2.1.2</a>).<br /><br />Since WebLogic 10.3.4 is a compliant Java EE 5 implementation it is required to ship out of the box with support for EJB 3.0 and thus JPA 1.0. If you wish to upgrade your install to allow JPA 2.0 use you must follow install a small patch, which is documented <a href="http://download.oracle.com/docs/cd/E17904_01/web.1111/e13720/using_toplink.htm#EJBAD1309">here</a>.<br /><br />If you are making use of <a href="http://www.oracle.com/technetwork/developer-tools/eclipse/overview/index.html">Oracle Enterprise Pack for Eclipse</a> the new 11.1.1.6.1 includes support for using the JPA 2.0 capabilities.<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com2tag:blogger.com,1999:blog-7747481246630004369.post-40301215469396632012010-08-11T13:09:00.002-04:002010-08-11T13:34:35.572-04:00EclipseLink Filters How-ToI have been assisting customers with their comparison of JPA/Object-relational frameworks as well as assisting them with migrating to EclipseLink JPA. One issue I ran into recently involves migrating users of Hibernate who use Filters over to EclipseLink. A filter is basically an additional set of criteria with session specific arguments that are applied to all queries of a given entity type.<br /><br />EclipseLink has long supported additional criteria being configured on a descriptor (mapping for an entity type). In this blog I just wanted to post some simple example code that illustrates how additional criteria can be applied to a an entity type with parameters that are then specified in the creation of the EntityManager where the criteria is to be applied.<br /><br />Using either an annotation on the entity class as:<br /><blockquote style="font-family: courier new;">@Entity<br /><span style="font-weight: bold;">@Customizer(AddEmployeeGenderCriteria.class)</span><br />public class Employee<br /></blockquote>Alternatively this customizer can be configured in persistence unit properties as well as in the eclipselink-orm.xml mapping file.<br /><br />This allows for a provided customer to be called and the descriptor for the entity type, Employee in this case, to be customized. Here we'll add the additional criteria (filter) that will later be used.<br /><blockquote><span style="font-family: courier new;">public static class AddEmployeeGenderCriteria implements DescriptorCustomizer {<br /><br />public void customize(ClassDescriptor descriptor) throws Exception {<br />ExpressionBuilder eb = new <br /> ExpressionBuilder(descriptor.getJavaClass());<br />Expression genderExp = eb.get("gender").equal(new<br /> SessionPropertyValue("gender"));<br />descriptor.getQueryManager().setAdditionalJoinExpression(genderExp);<br />}<br /><br />}<br /></span></blockquote><span style="font-style: italic;">Note: The SessionPropertyValue class is an extension and is only required if the criteria has a parameter value that will be supplied dynamically per EntityManager.</span><br /><br />Now with the descriptor has been customized with the additional criteria for all Employee queries we simply need to provide the argument value when creating the EntityManager.<br /><blockquote><span style="font-family: courier new;">properties.put("gender", "M");<br />EntityManager em = emf.createEntityManager(properties);<br /></span></blockquote>This will cause all queries such as:<br /><blockquote></blockquote><blockquote><span style="font-family: courier new;">em.createQuery("SELECT e FROM Employee e WHERE e.firstName LIKE 'J%'", Employee.class).getResultList();</span></blockquote>To have the addtitional criteria added and the SQL generated appears as:<br /><blockquote><span style="font-family: courier new;">SELECT t0.EMP_ID, t1.EMP_ID, t0.L_NAME, t0.END_TIME, t0.VERSION, t0.START_TIME, t0.GENDER, t1.SALARY, t0.F_NAME, t0.MANAGER_ID, t0.ADDR_ID, t0.START_DATE, t0.END_DATE FROM EMPLOYEE t0, SALARY t1 WHERE (t0.F_NAME LIKE ? AND ((t1.EMP_ID = t0.EMP_ID) AND (t0.GENDER = ?)))<br />bind => [J%, M]</span></blockquote>The only additional requirement is that the entity types with the <span class="blsp-spelling-error" id="SPELLING_ERROR_0">EntityManager</span> specific 'filters' be only cached in the <span class="blsp-spelling-error" id="SPELLING_ERROR_1">EntityManager</span> (isolated/<span class="blsp-spelling-error" id="SPELLING_ERROR_2">txn</span> cache) instead of the default shared cache to ensure that filtered collections from one context are not incorrectly presented in another where different parameter values are used.<br /><br />The use of these types of filters is not all that common in my experience so improving the configuration has not been a priority. If you use these filters and would like to have the usage of them in <span class="blsp-spelling-error" id="SPELLING_ERROR_3">EclipseLink</span> improved we are eager to get your feedback.Doughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com4tag:blogger.com,1999:blog-7747481246630004369.post-58264962559299418442010-06-06T21:09:00.007-04:002010-06-06T22:07:17.379-04:00Off to Epicenter in Dublin<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://epicenter.ie/2010_Doug_Clarke_Page"><img style="float: left; margin: 0pt 10px 10px 0pt; cursor: pointer; width: 183px; height: 101px;" src="http://epicenter.ie/images/logo_small.png" alt="" border="0" /></a><br />I am once again off to Dublin this week to speak at the <a href="http://epicenter.ie/2010_Doug_Clarke_Page">Epicenter 2010 Conference</a> again. Although I do enjoy a good Guiness I am also looking forward to the conference and the topics I am covering this week as well as the hours of travel to catch up on some pre-release tasks. We are just wrapping up our 2.1 release of EclipseLink as part of the Eclipse Helios release train and there are many new features I am excited about so travelling this week will give me a chance to complete some examples for the release and blog about the features all EclipseLink users will want to learn about.<br /><br />I am speaking this week on <a href="http://epicenter.ie/2010.html?zone_id=20&mode=agenda&session=144#session">performance </a>and <a href="http://epicenter.ie/2010.html?zone_id=20&mode=agenda&session=145#session">scalability</a>. Even after 13 years of helping customers use TopLink and now <a href="http://www.eclipse.org/eclipselink">EclipseLink </a>I still find diagnosing, solving, and innovating in these areas some of the most interesting work I take part in. Helping customers learn what they need to know about their models and application use cases and translating them into their object-relational mappings, schema, and usage of their persistence layer is challenging and often poorly understand by Java developers.<br /><br />The persistence layer enables performance and scalability but there are many simple decisions developers can make while configuring and coding to their persistence layer which are made early in projects and have big effects late in projects when trying to reach their performance and scalability goals. Understanding what these decisions are and what the trade-offs are is so important and hopefully I'll help some of our Irish community avoid common pitfalls.<br /><br />After working with a couple clients this week dealing with tough performance goals and very complex models I have some great examples I'll be adding to my cook book of slides on my way over the Atlantic.<br /><br />Hope to see you in Dublin...Doughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-70434240112399911462010-02-01T13:30:00.002-05:002010-02-01T13:41:39.271-05:00EclipseLink on LinkedInI was back in the field last week helping a customer with their migration to EclipseLink from a 3rd party developed solution using TopLink Essentials. Generally these migrations are very straight forward but in this case we bumped into a few unique wrinkles caused by the original solution being developed on a very early version of our JPA 1.0 solution and the consultants building it introducing a partial JPA container that changed the default behaviour. <br /><br />Ultimately we got the issues resolved in relatively short order and enjoyed a great meal with some of the consultants on the project in Halifax. I truly enjoy any chance I get to down into an application and help developers solve their persistence challenges. <br /><br />During my visit I made some notes on a couple of take-aways.<br /><br />1. Update the EclipseLink wiki's best practices to include a couple of additional scenarios around long-running transactions.<br /><br />2. Help connect the existing community of Java professionals using EclipseLink.<br /><br />I have already started on the first and will post some highlights here when the work is completed. To address the second action item I created the <a href="http://www.linkedin.com/groups?home=&gid=2720577&trk=anet_ug_hm">EclipseLink Group</a> on LinkedIn. <br /><br />The goal of this group is to allow any and all Java professionals who use LinkedIn to connect and share ideas, job opportunities, news, and upcoming events. If this sounds interesting to you please join the group and share your ideas.<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com1tag:blogger.com,1999:blog-7747481246630004369.post-63924193428179960202009-03-24T19:46:00.003-04:002009-03-24T19:51:49.432-04:00Oracle Enterprise Pack for Eclipse 11g released at EclipseCon 2009Enjoying another fun and informative week at EclipseCon. <br /><br />The OEPE 11g release announced today includes excellent ORM tooling based on Dali as well as specific support for EclipseLink. Check out <a href="http://blogs.oracle.com/devtools/2009/03/oracle_enterprise_pack_for_ecl_1.html">Pieter Humphrey's Blog entry</a> for all the details.<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com1tag:blogger.com,1999:blog-7747481246630004369.post-67934546387956556132008-07-10T06:17:00.005-04:002008-07-10T07:11:57.240-04:00My Thoughts on EclipseLink 1.0We released EclipseLink 1.0. You can read about it on the <a href="http://eclipselink.blogspot.com/2008/07/eclipselink-10-released.html">EclipseLink Team Blog</a>. Please do <a href="http://www.eclipse.org/eclipselink/downloads">download</a> it and try it out.<br /><br />Its been an interesting year since we first announced the contribution of Oracle TopLink to open source and the creation of the EclipseLink project. Taking a large product and all of its testing and moving it to a new repository with new build and test servers was technically challenging. Probably the more interesting changes however have been in how we developed 1.0 and the future releases of the project. Learning the Eclipse 'way' (project reviews, code contributions and the IP process, detailed road maps and public updates, web site, portal, wiki, bugzilla, ...) has been fun and interesting while only occasionally painful. Transitioning a large development team to this new open process was well worth the effort. We are now a community of committers that expands beyond just Oracle.<br /><br />This 1.0 release is really based on several years of development. This past year within the EclipseLink project plus all of the functionality developed in Oracle TopLink since our 10.1.3 release (February 2006) is included. While we tend to focus on the efforts of the past year many Oracle TopLink customers will find a significant amount of new features in the classic ORM/OXM support in addition to all the great new JPA/JAXB/SDO support. Over the next few weeks I will try to post blogs highlighting many of these features and how they can be used.<br /><br />There are a few high level items about this release I would like to point out:<br /><br /><b>Minimal Dependencies</b>: We ship with an eclipselink.jar library for JavaSE/EE users that can be used easily with minimal additional libraries. JPA users in JavaSE will just need to include the JPA 1.0 library (included as /jlib/jpa/persistence_1.0.0.jar) and their favourite JDBC driver. Within a JavaEE5 container you will just need the EclipseLink library as JPA should already be available as well as your JDBC drivers within the container's Data Source. Minimal dependencies is very important as it simplifies usage and avoids conflicts with other frameworks and your container's use of common libraries.<br /><br /><b>Full Functionality</b>: No matter how many times I say this I still get questions after my talks and webinars. All of the persistence functionality of Oracle TopLink is included in EclipseLink. All of the TopLink development team now exclusively develops new functionality in EclipseLink. <br /><br />We have also done a fair bit of work to enable the usage of our many advanced features through JPA. This includes custom annotations as well as XML configuration. Our goal is to keep developers as close to standard JPA as possible and simplify usage when you do need <a href="http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29">EclipseLink JPA's advanced features</a>. <br /><br /><b>OSGi Support</b>: While I still personally feel like a newbie in the OSGi space I am very proud of how our developers have managed to address class-loader flexibility so that we can bundle our EclipseLink components for use in OSGi. The optional Equinox functionality to enable Dynamic/Load-Time weaving allows developers using Equinox (typically RCP) to build full featured JPA applications without fighting the persistence implementation. We have an <a href="http://wiki.eclipse.org/EclipseLink/Examples/JPA/RCP">example available</a> if you want to try it out. <br /><br /><b>Flexible Object Binding</b>: The MOXy component does support JAXB2's annotations and XML schema compiler but what I think is most interesting is the ability to externalize the XML binding information. EclipseLink MOXy has its own XML mapping file as well as supporting mappings defined in code (statically or dynamically). Using this externalized mapping support with the standard JAXB marshal/unmarshal API is very powerful and allows a domain model to be easily persisted to multiple data sources/formats.<br /><br /><b>Performance and Scalability</b>: One aspect of Oracle TopLink development is that while we continued to evolve the product over the past 12 years we have always focussed on ensuring we had a well tuned core engine and many tuneable options available so our customers can address their performance and scalability goals. The Oracle TopLink product has been a key contributor to Oracle's world record SpecJ benchmarks and all of the optimizations introduced to address high levels of concurrent processing are now available in EclipseLink. We believe we have the fastest persistence solution available and will work hard to continue proving that through public benchmarking activities.<br /><br />I would like to thank everyone involved in making the EclipseLink 1.0 release happen. From the developers/QA/writers/managers who helped produce it (and put up with me) to the Oracle management who supported us through this process and all of our user community for the feedback and encouragement. <br /><br />Cheers,<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com8tag:blogger.com,1999:blog-7747481246630004369.post-28450756607383306032008-06-26T22:40:00.002-04:002008-06-26T22:48:26.723-04:00GraduationIts been a big week for graduations. Earlier this week my son completed his time in kindergarden and today the EclipseLink project graduated from incubation status. Tonight I took a few minutes to finally remove the big egg from the <a href="http://www.eclipse.org/eclipselink">EclipseLink home page</a>.<br /><br />As for my son, he is pretty focussed on spending every waking hour swimming until September. As for EclipseLink we are about ready to ship our 1.0 release on July 9th. In both cases it should be a fun and exciting summer.<br /><br />We have been getting great feedback so far on EclipseLink and I would like to invite the entire Java community to download EclipseLink and try it out. We are eager to get your feedback and continue to expand the usage of our project.<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com5tag:blogger.com,1999:blog-7747481246630004369.post-29395269632425081942008-03-17T13:28:00.006-04:002008-03-19T14:21:34.746-04:00EclipseLink in the NewsPretty exciting day so far at <span class="blsp-spelling-error" id="SPELLING_ERROR_0">EclipseCon</span>. We have been involved in two press releases at the conference so far.<br /><h3><a href="http://www.eclipse.org/org/press-release/20080317_Eclipselink.php">Eclipse Announces <span class="blsp-spelling-error" id="SPELLING_ERROR_1">EclipseLink</span> Project to Deliver <span class="blsp-spelling-error" id="SPELLING_ERROR_2">JPA</span> 2.0 Reference Implementation</a></h3><ul><li><a href="http://eclipselink.blogspot.com/2008/03/eclipselink-to-provide-jpa-20-reference.html">Read more on the <span class="blsp-spelling-error" id="SPELLING_ERROR_3">EclipseLink</span> Team BLOG</a></li></ul><h3><a href="http://www.eclipse.org/org/press-release/20080317_Equinox.php">Eclipse Announces New <span class="blsp-spelling-error" id="SPELLING_ERROR_4">Runtime</span> Initiative around Equinox</a></h3><blockquote><a href="http://ianskerrett.wordpress.com/2008/03/17/the-next-thing-at-eclipse/"><blockquote></blockquote>Ian <span class="blsp-spelling-error" id="SPELLING_ERROR_5">Skerrett</span></a> discusses this announcement and its implications. This announcement has a couple effects to the <span class="blsp-spelling-error" id="SPELLING_ERROR_6">EclipseLink</span> project. First off it provides a new top level project for us. We will move from the Technology project to the newly created <span class="blsp-spelling-error" id="SPELLING_ERROR_7">Runtime</span> project in the near future. This also formalizes our relationship with Equinox. We will soon be checking in our work to enabled <span class="blsp-spelling-error" id="SPELLING_ERROR_8">EclipseLink's</span> effective use in an <span class="blsp-spelling-error" id="SPELLING_ERROR_9">OSGi</span> environment.<br /></blockquote>Now that we have these announcements out I am looking forward to spending more time talking to other attendees about their work and how <span class="blsp-spelling-error" id="SPELLING_ERROR_10">EclipseLink</span> may be of use in their projects and applications.<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-22409240405366786152008-02-25T13:52:00.007-05:002008-03-20T13:01:05.423-04:00Testing EclipseLink JPA applications in JavaSEI spend part of my work days writing examples and helping users debug issues. I spend the majority of this time using JPA with our TopLink and now EclipseLink's advanced features.<br /><br />One little piece of code I always find myself looking for is a way to take a JPA persistence unit configuration and use it in JavaSE without changing it. The idea is that my persistence unit which should run in the container should also be testable easily outside.<br /><br />In the past I posted some examples of using XML to accomplish this but the following is the Java code that I use in my JavaSE examples and unit tests without going down the road of a separate persistence unit definition in XML for both worlds.<br /><br /><pre><br />import static org.eclipse.persistence.jpa.config.PersistenceUnitProperties.*;<br /><br />...<br /><br />Map properties = new HashMap();<br /><br />// Ensure RESOURCE_LOCAL transactions is used.<br />properties.put(TRANSACTION_TYPE,<br /> PersistenceUnitTransactionType.RESOURCE_LOCAL.name());<br /><br />// Configure the internal EclipseLink connection pool<br />properties.put(JDBC_DRIVER, "oracle.jdbc.OracleDriver");<br />properties.put(JDBC_URL, "jdbc:oracle:thin:@localhost:1521:ORCL");<br />properties.put(JDBC_USER, "user-name");<br />properties.put(JDBC_PASSWORD, "password");<br />properties.put(JDBC_READ_CONNECTIONS_MIN, "1");<br />properties.put(JDBC_WRITE_CONNECTIONS_MIN, "1");<br /><br />// Configure logging. FINE ensures all SQL is shown<br />properties.put(LOGGING_LEVEL, "FINE");<br /><br />// Ensure that no server-platform is configured<br />properties.put(TARGET_SERVER, TargetServer.None);<br /></pre><br /><br />I can then create my EntityManagerFactory using:<br /><br /><pre><br />Persistence.createEntityManagerFactory("unit-name", properties);<br /></pre><br /><br />The only remaining struggle I have is specifying which classes are my entities. The simplest way is to explicitly reference them in the persistence.xml or an associated orm.xml file. If they are listed explicitly then I do not need to worry about the automatic discovery.<br /><br />EclipseLink does support automatic discovery of entity classes in JavaSE but you need to enable its usage using:<br /><br /><persistence-unit name="unit-name"><br /><exclude-unlisted-classes>false</exclude-unlisted-classes><br /></persistence-unit><br /><br />Hopefully having these snippets of code and XML handy will help some of you out and now I can easily find them wherever I am working.<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com4tag:blogger.com,1999:blog-7747481246630004369.post-52149665216534109542008-01-25T04:46:00.000-05:002008-01-25T05:01:12.157-05:00Java Search Engine Integration for EclipseLink JPAThe creator and primary contributor to Compass has taken the initiative to provide support for using <a href="http://www.eclipse.org/eclipselink/">EclipseLink (www.eclipselink.org)</a> with Compass. I hope to find the time to build an application that illustrates the use of the two projects but thought I would post some early information to the community about the integration. <br /><br /><a href="http://www.opensymphony.com/compass/versions/2.0M1-SNAPSHOT/html/gps-embeddedeclipselink.html"> See the documentation</a><br /><br /><span style="font-weight:bold;"><br /><a href="http://www.opensymphony.com/compass/">Compass</a></span> is described as:<br /><br /><blockquote>Compass is a first class open source Java Search Engine Framework, enabling the power of Search Engine semantics to your application stack decoratively. Built on top of the amazing Lucene Search Engine, Compass integrates seamlessly to popular development frameworks like Hibernate, [and now EclipseLink] and Spring. It provides search capability to your application data model and synchronizes changes with the datasource. With Compass: write less code, find data quicker.</blockquote><br /><br />For those of you interested in adding richer search capabilities to your JPA applications you can now combine the capabilities of <a href="http://lucene.apache.org/java/docs/index.html">Lucene</a>with EclipseLink JPA through the Compass integration.<br /><br />Cheers,<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-34573765830390679062007-11-07T09:22:00.001-05:002007-11-07T15:00:10.910-05:00EclipseLink 1.0 Milestone 1: Now AvailableWe just made our first milestone build available for download. See the <a href="http://eclipselink.blogspot.com/2007/11/10-milestone-1-now-available.html">EclipseLink team blog for more information</a>.<br /><br />This is an important step for our project. Our plan is to produce monthly milestone builds as we work toward our 1.0 release. It does seem very odd to be starting back at a 1.0 release after over 10 years of shipping this Java persistence solution. For those familiar with TopLink this milestone is the complete capabilities from the <a href="http://www.oracle.com/technology/products/ias/toplink/preview/index.html">Oracle TopLink 11gR1 Technology Preview 2</a>. Since we were near completion of our development cycle for this release the new features available are complete and well tested.<br /><br />We are also in the process of publishing the complete documentation from Oracle TopLink as the EclipseLink user manuals. This will be done on the <a href="http://wiki.eclipse.org/EclipseLink/UserManual">wiki</a>. This in conjunction with the evolving set of <a href="http://wiki.eclipse.org/EclipseLink/Examples">examples</a> should help developers easily evaluate the use of this project.<br /><br />Any and all feedback is appreciated. There is a <a href="http://www.eclipse.org/newsportal/thread.php?group=eclipse.technology.eclipselink">newsgroup </a>and <a href="https://dev.eclipse.org/mailman/listinfo/eclipselink-users">users mailing list</a> where feedback can be provided. <br /><br />All information on the EclipseLink project can be found linked from our <a href="http://www.eclipse.org/eclipselink/">home page</a>.<br /><br />Cheers,<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com1tag:blogger.com,1999:blog-7747481246630004369.post-30318863970854177082007-08-24T10:48:00.000-04:002007-08-24T10:49:28.712-04:00EclipseLink Update: Source Checked in and team Blog<a href="http://eclipselink.blogspot.com/2007/08/eclipselink-update-source-checked-in.html">See the EclipseLink team blog for regular updates on the project.</a><br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-59668837938502218472007-07-06T08:11:00.000-04:002007-07-16T09:45:30.165-04:00Its alive...I am just heading out on vacation this morning and wanted to update the community on our progress in the Eclipse new project process. We have completed our initial incubation provisioning of the Eclipse Persistence Services Project (EclipseLink).<br /><br />We now have our home page up (<a href="http://www.eclipse.org/eclipselink/">www.eclipse.org/eclipselink</a>) with a wiki home and developer mailing list.<br /><br />We are initiating the Eclipse Parallel IP review process to get the TopLink source and test case contribution into the subversion repository in the near future. This process of re-packaging and organizing the source has been very interesting.<br /><br />In the coming weeks we'll get the source code in and builds and testing working. We'll publish our roadmap and focus on building new features and a strong community. Stay tuned....<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com1tag:blogger.com,1999:blog-7747481246630004369.post-57352454443917314522007-06-08T12:33:00.000-04:002007-06-08T12:36:17.895-04:00Eclipse Persistence Services Project - Passed Creation ReviewWe are now busy working through the logistics of provisioning the product and getting the initial code contribution available through the parallel IP process. <br /><br />If you have any questions please post them to the <a href="http://www.eclipse.org/newsportal/thread.php?group=eclipse.technology.eclipselink">forum</a>.<br /><br />Cheers,<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-83197016330948320762007-04-25T17:21:00.000-04:002007-04-25T17:51:37.765-04:00Simple Auditing using TopLink JPA<span style="font-family:arial;">In a forum post on the </span><a style="font-family: arial;" href="http://forums.oracle.com/forums/forum.jspa?forumID=48">Oracle TopLink forum</a><span style="font-family:arial;"> on OTN there was a request for an approach to tracking entity history in a separate table. While Oracle TopLink includes support for automatic </span><a style="font-family: arial;" href="http://www.oracle.com/technology/products/ias/toplink/doc/10131/main/_html/sesun006.htm#CACIIGEF">historical versioning</a><span style="font-family:arial;"> this support does not exist in TopLink Essentials.</span><br /><br /><span style="font-family:arial;">The following is a simple example for how you might do historical versioning of your persistent entities using TopLink Essentials and JPA. There are many approaches to how you would design your schema for managing this additional state. I kept my approach simple where the primary data table uses an integer version optimistic locking column and the history table stores a row for each version of the primary table.</span><br /><br /><span style="font-family:arial;">The sample model is simply an Employee entity and its history is stored in an EmployeeHistory entity.</span><br /><br /><blockquote></blockquote><blockquote><span style="font-family:courier new;">@Entity</span><br /><span style="font-family:courier new;">@NamedQuery(name = "Employee.findAll", </span><br /><span style="font-family:courier new;"> query = "select e from Employee e ORDER BY e.lastName ASC, e.firstName ASC")</span><br /><span style="font-family:courier new;">@TableGenerator(name = "emp-seq-table", table = "SEQUENCE", </span><br /><span style="font-family:courier new;"> pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT", </span><br /><span style="font-family:courier new;"> pkColumnValue = "EMP_SEQ", allocationSize = 26)</span><br /><span style="font-family:courier new;">public class Employee {</span><br /><span style="font-family:courier new;"> @Id</span><br /><span style="font-family:courier new;"> @GeneratedValue(strategy = GenerationType.TABLE, </span><br /><span style="font-family:courier new;"> generator = "emp-seq-table")</span><br /><span style="font-family:courier new;"> @Column(name = "EMP_ID", nullable = false)</span><br /><span style="font-family:courier new;"> private int id;</span><br /><br /><span style="font-family:courier new;"> @Column(name = "F_NAME")</span><br /><span style="font-family:courier new;"> private String firstName;</span><br /><br /><span style="font-family:courier new;"> @Column(name = "L_NAME")</span><br /><span style="font-family:courier new;"> private String lastName;</span><br /><br /><span style="font-family:courier new;"> private String gender;</span><br /><br /><span style="font-family:courier new;"> @Version</span><br /><span style="font-family:courier new;"> private long version;</span><br /><br /><span style="font-family:courier new;"> ...</span><br /></blockquote><br /><blockquote><span style="font-family:courier new;">@Entity</span><br /><span style="font-family:courier new;">@IdClass(EmployeeHistory.ID.class)</span><br /><span style="font-family:courier new;">@Table(name = "EMPLOYEE_HISTORY")</span><br /><span style="font-family:courier new;">@NamedQuery(name="EmployeeHistory.findAllForEmployee", query="SELECT eh FROM EmployeeHistory eh WHERE eh.employee = :EMP")</span><br /><span style="font-family:courier new;">public class EmployeeHistory {</span><br /><span style="font-family:courier new;"> @Id</span><br /><span style="font-family:courier new;"> @Column(name = "EMP_ID")</span><br /><span style="font-family:courier new;"> private int id;</span><br /><br /><span style="font-family:courier new;"> @Id</span><br /><span style="font-family:courier new;"> private long version;</span><br /><br /><span style="font-family:courier new;"> @ManyToOne</span><br /><span style="font-family:courier new;"> @JoinColumn(name = "EMP_ID", referencedColumnName = "EMP_ID", insertable=false, updatable=false)</span><br /><span style="font-family:courier new;"> private Employee employee;</span><br /><br /><span style="font-family:courier new;"> @Column(name = "F_NAME")</span><br /><span style="font-family:courier new;"> private String firstName;</span><br /><br /><span style="font-family:courier new;"> @Column(name = "L_NAME")</span><br /><span style="font-family:courier new;"> private String lastName;</span><br /><br /><span style="font-family:courier new;"> private String gender;</span><br /><br /><span style="font-family:courier new;"> /**</span><br /><span style="font-family:courier new;"> * </span><br /><span style="font-family:courier new;"> * @param emp</span><br /><span style="font-family:courier new;"> */</span><br /><span style="font-family:courier new;"> protected EmployeeHistory(Employee emp) {</span><br /><span style="font-family:courier new;"> this.id = emp.getId();</span><br /><span style="font-family:courier new;"> this.version = emp.getVersion();</span><br /><span style="font-family:courier new;"> this.firstName = emp.getFirstName();</span><br /><span style="font-family:courier new;"> this.lastName = emp.getLastName();</span><br /><span style="font-family:courier new;"> this.gender = emp.getGender();</span><br /><br /><span style="font-family:courier new;"> this.employee = emp;</span><br /><span style="font-family:courier new;"> }</span><br /><br /><span style="font-family:courier new;"> ...</span><br /></blockquote><br /><span style="font-family:arial;">Now to have the creation and modification of all Employee instances cause the creation of an EmployeeHistory instance I will use a TopLink Essentials specific event listener.<br /><br />The descriptor event listener used looks like:<br /><br /><blockquote style="font-family: courier new;">/**<br />* This is an example of how a TopLink Essentials DescriptorEventListener can be<br />* used to populate an audit record whenever an update occurs. This class must be<br />* registered as a persistence unit property in the creation of the<br />* EntityManagerFactory.<br />*<br />* property name="toplink.descriptor.customizer.Employee" value="model.jpa.auditing.EmployeeAuditingHandler" <property name="toplink.descriptor.customizer.Employee" value="model.jpa.auditing.EmployeeAuditingHandler"><br />*<br />* @since TopLink Essentials v2-Build-41<br />*/<br />public class EmployeeAuditingHandler extends DescriptorEventAdapter implements DescriptorCustomizer {<br /><br /> /**<br /> * This is where the real work of this class happens. For any INSERT or UPDATE<br /> * operation an INSERT of a new history object is forced.<br /> */<br /> private void insertEmployeeHistory(DescriptorEvent event) {<br /> EmployeeHistory empHist = new EmployeeHistory((Employee)event.getSource());<br /> InsertObjectQuery insertQuery = new InsertObjectQuery(empHist);<br /> event.getSession().executeQuery(insertQuery);<br /> }<br /><br /> public void aboutToUpdate(DescriptorEvent event) {<br /> insertEmployeeHistory(event);<br /> }<br /><br /> public void aboutToInsert(DescriptorEvent event) {<br /> insertEmployeeHistory(event);<br /> }<br /><br /> /**<br /> * This method is invoked through this class's registration as a descriptor<br /> * customizer. All it does is register this same object as an event listener<br /> */<br /> public void customize(ClassDescriptor descriptor) {<br /> descriptor.getEventManager().addListener(this);<br /> }<br />}</property></blockquote>Now with this event listener in place I can proceed in my application using standard JPA coding. Every time I create or modify an Employee entity I will see the associated EmployeeHistory INSERT during the transaction commit.<br /><br />I hope you find this helpful.<br /><br />Doug<br /><br /><br /><br /><br /><br /><br /><br /></span><br /><br /><br /><br /><blockquote></blockquote>Doughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com1tag:blogger.com,1999:blog-7747481246630004369.post-79577011248753497812007-04-22T13:58:00.000-04:002007-04-22T14:04:11.361-04:00TopLink Essentials using Oracle Spatial ... a sample applicationAndrejus Baranovskis has posted a sample application using Oracle Spatial with TopLink Essentials JPA. The steps are based upon my previous post.<br /><br /><a href="http://andrejusb.blogspot.com/2007/04/oracle-spatial-and-toplink-essentials.html">andrejusb.blogspot.com</a><br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.comtag:blogger.com,1999:blog-7747481246630004369.post-46228629733371365872007-04-12T19:15:00.000-04:002007-04-19T06:42:51.029-04:00 <h1> Oracle Spatial using TopLink Essentials JPA </h1> <div style="margin-left: 40px;"> <br> As discussed in my previous post the usage of <a href="http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14255/toc.htm" target="blank_" title="Oracle Database's Spatial support">Oracle Database Spatial support</a> is definitely growing in popularity. This post describes how <a href="http://otn.oracle.com/jpa" target="blank_" title="TopLink Essentials">TopLink Essentials</a>, the reference implementation of <a href="https://glassfish.dev.java.net/javaee5/persistence/entity-persistence-support.html" target="blank_" title="JPA within GlassFish">JPA within GlassFish</a>, can be extended to support mapping to MDSYS.SDO_GEOMETRY columns and leveraging the Oracle Spatial custom SQL operators within your queries.<br> <br> Extending TopLink Essentials (TLE) for Spatial support involves a couple of key steps:<br> <br> <ol> <li> A custom database platform is required to handle the STRUCT <-> JGeometry (oracle.spatial.geometry) conversions and statement binding.<br> <br> </li> <li> Customize the mappings to ensure the default serialized mapping for the unknown JGeometry type is not used.<br> <br> </li> <li> Usage of custom TLE expression operators for defining the queries.<br> </li> </ol> <br> </div> <h2> 1. Custom Database Platform </h2> <div style="margin-left: 40px;"> TLE uses a <a href="http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-extensions.html#toplink.target-database" target="blank_" title="target database configuration">target database configuration</a> to control custom SQL generation leveraging the different dialects supported by each of the database vendors. The platform is automatically detected by default but can be specified. For our purposes we will write a custom database platform extending the shipped OraclePlatform. To configure the use of our custom platform a persistence unit property (toplink.target-database) will need to be set.<br> <br> <div> <table bgcolor="#ccccff" border="0" cellpadding="3" cellspacing="0" width="100%"> <tbody> <tr> <td width="100%"> <br> <property name="toplink.target-database" value ="oracle.toplink.essentials.extension.spatial.Oracle10SpatialPlatform"/><br> <br> </td> </tr> </tbody> </table> </div> <br> The custom platform must be written and packaged where the class-loader can access it.<br> <br> Here is an example of what that platform might look like. <a href="http://docs.google.com/Doc?id=dgdsqc2h_8fw3tqh" title="Oracle10SpatialPlatform.java">Oracle10SpatialPlatform.java</a><br> <br> </div> <h2> 2. Customizing the Mappings<br> </h2> <div style="margin-left: 40px;"> The default mapping with JPA is to consider unknown types to be serialized basic (direct to field) mappings. In the case of JGeometry attribute types it is up to the developer to remove the converter that will be configured by default. The following descriptor customizer illustrates how the converter can be easily removed.<br> <br> <div> <table bgcolor="#ccccff" border="0" cellpadding="3" cellspacing="0" width="100%"> <tbody> <tr> <td width="100%"> <pre> <br> /**<br> * Descriptor customizer. This must be configured as a persistence unit property<br> * for each entity type containing a JGeometry attribute.<br> * <br> * property name="toplink.descriptor.customizer.SimpleSpatial" value="model.jpa.spatial_simple.toplink.SimpleSpatialCustomizer"<br> * <br> */<br>public class SimpleSpatialCustomizer implements DescriptorCustomizer {<br><br> public void customize(ClassDescriptor descriptor) {<br> DirectToFieldMapping mapping = <br> (DirectToFieldMapping)descriptor.getMappingForAttributeName("geometry");<br> mapping.setConverter(null);<br><br><br> }<br>}<br><br> <br></pre> </td> </tr> </tbody> </table> </div> <br> </div> <h2> 3. Using Custom Expression Operators<br> </h2> <div style="margin-left: 40px;"> While the above two steps are pretty straight forward with one time configurations the more involved process is using spatial operators across dynamic and named queries. Based on a set of custom expression operators the following examples illustrate how a named query definition and usage might look.<br> <br> <div> <table bgcolor="#ccccff" border="0" cellpadding="3" cellspacing="0" width="100%"> <tbody> <tr> <td width="100%"> <div style="text-align: center;"> <h3> EXAMPLE: Defining a Named Query with Custom Spatial Operators<br> </h3> </div> <br> <pre>/**<br> * Session customizer. This must be configured as a persistence unit property<br> * for each entity type containing a JGeometry attribute.<br> * <br> * <property name="toplink.session.customizer" value="model.jpa.spatial_simple.toplink.SS_SessionCustomizer/>"<br> * <br> */<br>public class SS_SessionCustomizer implements SessionCustomizer {<br><br> public void customize(Session session) {<br> SpatialParameters params = new SpatialParameters();<br> params.setMask(SpatialParameters.Mask.ANYINTERACT);<br> params.setQueryType(SpatialParameters.QueryType.WINDOW);<br><br> ReadAllQuery raq = new ReadAllQuery(SimpleSpatial.class);<br> ExpressionBuilder eb = new ExpressionBuilder(SimpleSpatial.class);<br> Expression relateExp = <br> SpatialOperator.RELATE.buildExpression(eb.get("geometry"), <br> eb.getParameter("GEOMETRY"), <br> params);<br> Expression idExp = eb.get("id").greaterThan(0);<br><br> raq.setSelectionCriteria(idExp.and(relateExp));<br><br> raq.addArgument("GEOMETRY");<br><br> raq.addAscendingOrdering("id");<br><br> session.addQuery("SimpleSpatial.sampleQuery", raq);<br><br> }<br>}<br> <br> </pre> </td> </tr> </tbody> </table> </div> <br> </div> <div style="margin-left: 40px;"> </div> <div style="margin-left: 40px;"> Now to execute the above query within the application code standard JPA usage is followed.<br> <br> <div> <table bgcolor="#ccccff" border="0" cellpadding="3" cellspacing="0" width="100%"> <tbody> <tr> <td width="100%"> <div style="text-align: center;"> <h3> EXAMPLE: Invoking the Named Query<br> </h3> </div> double[] points = new double[] { 1, 1, 1, 20, 10, 20, 20, 1, 1, 1 };<br> JGeometry rectangle = JGeometry.createLinearPolygon(points, 2, 0);<br> <br> <br> Query query = getEntityManager().createNamedQuery("SimpleSpatial.sampleQuery");<br> query.setParameter("GEOMETRY", rectangle);<br> <br> List<SimpleSpatial> results = query.getResultList();<br> <br> </td> </tr> </tbody> </table> </div> <br> <br> In order to make all of this work a couple of helper classes are required to define the spatial operators and parameters.<br> <br> <a href="http://docs.google.com/Doc?id=dgdsqc2h_9ffc92t" target="blank_" title="SpatialOperator">SpatialOperator</a>: Captures the definition of expression operators and acts as a factory for function expressions for use in queries.<br> <br> <a href="http://docs.google.com/Doc?id=dgdsqc2h_10g9wznr" target="blank_" title="SpatialParameters">SpatialParameters</a>: Simplifies configurations of parameters for the MDSYS spatial operators<br> <br> These classes must be compiled and made available on the application's classpath or packaged within a JAR with TopLink Essentials.<br> <br> </div> <br> This support will be available in the next release of Oracle TopLink and will also be included in the initial contribution to <a href="http://www.eclipse.org/proposals/eclipselink" target="blank_" title="EclipseLink.">EclipseLink.</a> The final API in these version may vary from what I am providing now as a sample of how to extend TopLink.<br> <br> Doug<br> <br>Doughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com2tag:blogger.com,1999:blog-7747481246630004369.post-38297061909604984512007-04-04T22:26:00.000-04:002007-04-05T08:17:42.331-04:00<h1> Using Oracle Spatial with TopLink </h1> <div style="margin-left: 40px;"> I have been working a growing number of customers assisting them with their usage of Oracle Database Spatial support through TopLink. Actually my first exposure with Spatial and TopLink dates back to 1999, long before I joined (through acquisition) Oracle. It was an extended consulting engagement assisting Oracle Consulting in their usage of TopLink on a customer's application. Those Oracle consultants are now my co-workers managing the Oracle Consulting teams I deal with and I am now product manager for TopLink. Our recent work assisting customers in their extensions of TopLink for Spatial data mapping and querying has already produced results (<a title="GE Energy Press Release" target="blank_" href="http://www.gepower.com/about/press/en/2007_press/030507a.htm">GE Energy Press Release</a>).<br /><br />TopLink does not offer formal support for Oracle Spatial in the current 10.1.3.X versions or earlier. TopLink can however, be extended to support custom data types and query operators/functions. This post will walk through the basics of extended the expression framework and show some examples using Spatial data types.<br /><br />In order to have TopLink both read and write SDO_GEOMETRY columns as well as generate the necessary SQL to query these columns two extensions to TopLink need to be made.<br /><br /><ol><li>Provide a custom database platform enabling the SDO_GEOMETRY <-> JGeometry (oracle.spatial.geometry) conversion<br /><br /></li><li>Define and use custom expression operators to allow the generation of these operators into SQL<br /></li></ol> </div><br /><p style="margin-left: 40px;"> I will leave it to you to read about the Oracle DB's Spatial support <a title="here" target="blank_" href="http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14255/toc.htm">in the docs</a>, <a title="Oracle Spatial on OTN" href="http://www.oracle.com/technology/products/spatial/index.html">on OTN</a> or download a <a title="OTN" target="blank_" href="http://www.oracle.com/technology/sample_code/products/spatial/index.html">sample</a>.<br /></p><br /><h2> Struct Conversions - Custom Database Platform<br /></h2> <div style="margin-left: 40px;"> The SDO_GEOMETRY object type which is used to store geometries in the database passes through JDBC as a Struct. The spatial Java library provides an implementation of JGeometry (oracle.spatial.geometry) that simplifies conversion and usage within a Java object model. In order to get TopLink to work with JGeometry types in the object model and properly handle the Struct with JDBC a custom database platform is required.<br /><br /><div style="margin-left: 40px; font-style: italic;">Note: TopLink's existing support for mapping custom object types (Structs) is not an option with some Oracle Advanced Data Types such as Spatial. An active JDBC connection is required for conversion and the conversions at the mapping level do not necessarily have the connection available.<br /></div><br /><div><table bg="" style="color: rgb(255, 204, 153);" border="0" cellpadding="3" cellspacing="0" width="100%"><tbody><tr><td width="100%"><span style="font-weight: bold; text-decoration: underline; color: rgb(255, 102, 0);">Example 1:</span><span style="text-decoration: underline; color: rgb(255, 102, 0);"><span style="font-weight: bold;"> JGeometry - Struct Conversion Code</span></span><br /><pre style="color: rgb(255, 102, 0);"><br />public Object convertToObject(Struct struct) throws SQLException {<br /> if (struct == null) {<br /> return null;<br /> }<br /> return JGeometry.load((STRUCT)struct);<br />}<br /><br />public Struct convertToStruct(Object geometry,<br /> Connection connection) throws SQLException {<br /> if (geometry == null) {<br /> return null;<br /> }<br /> return JGeometry.store((JGeometry)geometry, connection);<br />}<br /></pre><br /></td></tr></tbody></table></div><br />To use these conversions within TopLink you must create a custom DatabasePlatform (most likely a subclass of Oracle10Platform) and incorporate these conversions into the platform.<br /></div> <h2> Custom Expression Operators </h2><br /><div style="margin-left: 40px;"> TopLink's query framework makes use of expressions for defining the selection criteria as well as for specifying many query configuration options relative to the mapped object model. The expressions are basically a tree node object structure defining navigation through the mapped domain model as well as common query operators. For those of you more familiar with RedHat<sup>TM</sup>/JBoss<sup>TM </sup>Hibernate<sup>TM</sup> the expression framework provides a super-set of these capabilities to their criteria API.<br /></div><br /><div style="margin-left: 40px;"> Using the TopLink expressions developers are able to build very complex queries and have the platform specific SQL generated for them. Expressions also allow the queries to be processed in-memory and avoid unnecessary database trips.<br /><h3> ExpressionOperator<br /></h3> All operations used in expressions are defined by an ExpressionOperator. This capability can be extended to define additional operations.<br /><br /><div> <table bg="" style="color: rgb(255, 204, 153);" border="0" cellpadding="3" cellspacing="0" width="100%"> <tbody> <tr> <td width="100%"> <p style="color: rgb(255, 102, 0);"> <span style="font-weight: bold; text-decoration: underline;">Example 2: SDO_RELATE ExpressionOperator</span> </p> <p style="color: rgb(255, 102, 0);"> <span style="font-weight: bold; text-decoration: underline;"></span><br /> </p><span style="color: rgb(255, 102, 0);"> public static ExpressionOperator RELATE_OP = relateOperator();</span><br /> <br /><span style="color: rgb(255, 102, 0);"> public static ExpressionOperator relateOperator() {</span><br /><span style="color: rgb(255, 102, 0);"> ExpressionOperator exOperator = new ExpressionOperator();</span><br /><span style="color: rgb(255, 102, 0);"> exOperator.setType(ExpressionOperator.FunctionOperator);</span><br /><span style="color: rgb(255, 102, 0);"> Vector v = NonSynchronizedVector.newInstance(4);</span><br /><span style="color: rgb(255, 102, 0);"> v.addElement("MDSYS.SDO_RELATE(");</span><br /><span style="color: rgb(255, 102, 0);"> v.addElement(", ");</span><br /><span style="color: rgb(255, 102, 0);"> v.addElement(", ");</span><br /><span style="color: rgb(255, 102, 0);"> v.addElement(")");</span><br /><span style="color: rgb(255, 102, 0);"> exOperator.printsAs(v);</span><br /><span style="color: rgb(255, 102, 0);"> exOperator.bePrefix();</span><br /><span style="color: rgb(255, 102, 0);"> exOperator.setNodeClass(ClassConstants.FunctionExpression_Class);</span><br /><span style="color: rgb(255, 102, 0);"> return exOperator;</span><br /><span style="color: rgb(255, 102, 0);"> }</span><br /> <br /> </td> </tr> </tbody> </table> </div><br />These operators should be defined only once and re-used as needed when defining specific named or dynamic queries. In the above example a singleton operator (RELATE_OP) is used to store the custom operator.<br /><h3> FunctionExpression </h3> To use an ExpressionOperator with specific parameter values a FunctionExpression must be built and incorporated within the selection criteria expression of a TopLink query.<br /><br /><div> <table bg="" style="color: rgb(255, 204, 153);" border="0" cellpadding="3" cellspacing="0" width="100%"> <tbody> <tr> <td width="100%"> <span style="text-decoration: underline; color: rgb(255, 102, 0);"><span style="font-weight: bold;">Example 3: Using a FunctionExpression in a Query</span></span><br /> <span style="font-style: italic; color: rgb(255, 102, 0);"><br /> </span> <pre><span style="color: rgb(255, 102, 0);"> ReadAllQuery raq = </span><span style="color: rgb(255, 102, 0);"><b>new</b></span><span style="color: rgb(255, 102, 0);"> ReadAllQuery(MyEntity.class);</span><br /><span style="color: rgb(255, 102, 0);"> ExpressionBuilder eb = raq.getExpressionBuilder();</span><br /><span style="color: rgb(255, 102, 0);"> </span><br /><span style="color: rgb(255, 102, 0);"> FunctionExpression relateOpExp = </span><span style="color: rgb(255, 102, 0);"><b>new</b></span><span style="color: rgb(255, 102, 0);"> FunctionExpression();</span><br /><span style="color: rgb(255, 102, 0);"> relateOpExp.setOperator(RELATE_OP);</span><br /><span style="color: rgb(255, 102, 0);"> // RELATE_OP is a static holding a singleton instance of the operator defined in Example 1.</span><br /><span style="color: rgb(255, 102, 0);"> relateOpExp.setBaseExpression(eb);</span><br /><br /><span style="color: rgb(255, 102, 0);"> relateOpExp.addChild(Expression.from(eb.get(</span><span style="color: rgb(255, 102, 0);">"geometry"</span><span style="color: rgb(255, 102, 0);">), eb)); // References a geometry attribute/column</span><br /><span style="color: rgb(255, 102, 0);"> relateOpExp.addChild(Expression.from(someJGeometry, eb)); // Passes in a JGeometry instance</span><br /><span style="color: rgb(255, 102, 0);"> relateOpExp.addChild(Expression.from(</span><span style="color: rgb(255, 102, 0);">"mask=ANYINTERACT"</span><span style="color: rgb(255, 102, 0);">, eb)); // Provides the parameters string for the operator</span><br /><span style="color: rgb(255, 102, 0);"> </span><br /><span style="color: rgb(255, 102, 0);"> Expression relateExpression = relateOpExp.equal(Boolean.TRUE.toString());</span><br /><span style="color: rgb(255, 102, 0);"> </span><br /><span style="color: rgb(255, 102, 0);"> raq.setSelectionCriteria(relateExpression);</span><br /><span style="color: rgb(255, 102, 0);"> </span><br /><span style="color: rgb(255, 102, 0);"> session.executeQuery(raq);</span><br /></pre> <span style="font-style: italic;"></span> </td> </tr> </tbody> </table> </div> <h3> Preview of Future TopLink Spatial Query API<br /></h3> In the next major release of TopLink we will offer out of the box support for Spatial mapping and querying. The following example illustrates how the same query as above would be written.<br /><br /><div> <table style="color: rgb(255, 204, 153);" bg="" border="0" cellpadding="3" cellspacing="0" width="100%"> <tbody> <tr> <td width="100%"> <span style="text-decoration: underline; color: rgb(255, 102, 0);"><span style="font-weight: bold;">Example 4: Spatial Queries in the future TopLink release</span></span><br /> <br /><span style="color: rgb(255, 102, 0);"> ReadAllQuery raq = new ReadAllQuery(SimpleSpatial.class);</span><br /><span style="color: rgb(255, 102, 0);"> ExpressionBuilder eb = raq.getExpressionBuilder();</span><br /> <br /><span style="color: rgb(255, 102, 0);"> SpatialParameters params = new SpatialParameters();</span><br /><span style="color: rgb(255, 102, 0);"> params.setMask(Mask.ANYINTERACT);</span><br /><br /><span style="color: rgb(255, 102, 0);"> Expression relateExp = SpatialExpressionFactory.relate(eb.get("geometry"), someJGeometry, params);</span><br /><span style="color: rgb(255, 102, 0);"> raq.setSelectionCriteria(relateExp);</span><br /><span style="color: rgb(255, 102, 0);"> raq.addAscendingOrdering("id");</span><br /> <br /><span style="color: rgb(255, 102, 0);"> List<SimpleSpatial> results = (List<SimpleSpatial>)session.executeQuery(raq);</span><br /> <br /> </td> </tr> </tbody> </table> </div><br />This new API incorporates the same expression operator functionality within the SpatialExpressionFactory class. The SpatialParameters provides some easy to use enums for providing the parameter values instead of building the string value yourself. If you do want to provide the string value directly this is also available.<br /></div><br /><h2><br /></h2> The goal of this post is to provide a simple example of how you can extend the expression framework for custom operators. When we preview the next release I am sure those of you using these extensions will find the provided functionality and simplified API a great asset.<br /><br />Doug<br /><div style="margin-left: 40px;"><br /><br /><br /></div>Doughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com0tag:blogger.com,1999:blog-7747481246630004369.post-38332086864887804842007-04-01T19:50:00.000-04:002007-04-01T19:56:06.336-04:00A new homeWith the launching of the Java Persistence Platform Project (aka EclipseLink) I decided to increase the scope of my blog so that it is not focussed just on TopLink. I also wanted to move to a different host.<br /><br />After working on TopLink in many different roles for over a decade I am looking forward to this new challenge. Delivering a high quality open source solution in an open and transparent manor is our goal. I plan to make this blog my way to express my opinion on persistence related subjects and also deliver technical content to assist in the project's adoption.<br /><br />DougDoughttp://www.blogger.com/profile/02383574560699818383noreply@blogger.com4