Wednesday, August 11, 2010

EclipseLink Filters How-To

I 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.

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.

Using either an annotation on the entity class as:
@Entity
@Customizer(AddEmployeeGenderCriteria.class)
public class Employee
Alternatively this customizer can be configured in persistence unit properties as well as in the eclipselink-orm.xml mapping file.

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.
public static class AddEmployeeGenderCriteria implements DescriptorCustomizer {

public void customize(ClassDescriptor descriptor) throws Exception {
ExpressionBuilder eb = new
ExpressionBuilder(descriptor.getJavaClass());
Expression genderExp = eb.get("gender").equal(new
SessionPropertyValue("gender"));
descriptor.getQueryManager().setAdditionalJoinExpression(genderExp);
}

}
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.

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.
properties.put("gender", "M");
EntityManager em = emf.createEntityManager(properties);
This will cause all queries such as:
em.createQuery("SELECT e FROM Employee e WHERE e.firstName LIKE 'J%'", Employee.class).getResultList();
To have the addtitional criteria added and the SQL generated appears as:
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 = ?)))
bind => [J%, M]
The only additional requirement is that the entity types with the EntityManager specific 'filters' be only cached in the EntityManager (isolated/txn 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.

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 EclipseLink improved we are eager to get your feedback.

Sunday, June 6, 2010

Off to Epicenter in Dublin


I am once again off to Dublin this week to speak at the Epicenter 2010 Conference 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.

I am speaking this week on performance and scalability. Even after 13 years of helping customers use TopLink and now EclipseLink 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.

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.

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.

Hope to see you in Dublin...

Monday, February 1, 2010

EclipseLink on LinkedIn

I 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.

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.

During my visit I made some notes on a couple of take-aways.

1. Update the EclipseLink wiki's best practices to include a couple of additional scenarios around long-running transactions.

2. Help connect the existing community of Java professionals using EclipseLink.

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 EclipseLink Group on LinkedIn.

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.

Doug

Tuesday, March 24, 2009

Oracle Enterprise Pack for Eclipse 11g released at EclipseCon 2009

Enjoying another fun and informative week at EclipseCon.

The OEPE 11g release announced today includes excellent ORM tooling based on Dali as well as specific support for EclipseLink. Check out Pieter Humphrey's Blog entry for all the details.

Doug

Thursday, July 10, 2008

My Thoughts on EclipseLink 1.0

We released EclipseLink 1.0. You can read about it on the EclipseLink Team Blog. Please do download it and try it out.

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.

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.

There are a few high level items about this release I would like to point out:

Minimal Dependencies: 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.

Full Functionality: 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.

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 EclipseLink JPA's advanced features.

OSGi Support: 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 example available if you want to try it out.

Flexible Object Binding: 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.

Performance and Scalability: 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.

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.

Cheers,

Doug

Thursday, June 26, 2008

Graduation

Its 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 EclipseLink home page.

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.

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.

Doug

Monday, March 17, 2008

EclipseLink in the News

Pretty exciting day so far at EclipseCon. We have been involved in two press releases at the conference so far.

Eclipse Announces EclipseLink Project to Deliver JPA 2.0 Reference Implementation

Eclipse Announces New Runtime Initiative around Equinox

Ian Skerrett
discusses this announcement and its implications. This announcement has a couple effects to the EclipseLink project. First off it provides a new top level project for us. We will move from the Technology project to the newly created Runtime project in the near future. This also formalizes our relationship with Equinox. We will soon be checking in our work to enabled EclipseLink's effective use in an OSGi environment.
Now that we have these announcements out I am looking forward to spending more time talking to other attendees about their work and how EclipseLink may be of use in their projects and applications.

Doug