Exforsys

Home arrow Reviews arrow Oracle Coherence

Oracle Coherence: Other built-in value extractors

Author: Packt Publishing     Published on: 28th Jun 2010

While the ReflectionExtractor is definitely the one that is used most often, there are several other value extractors that ship with Coherence.

Ads

IdentityExtractor

The simplest extractor is the IdentityExtractor, which doesn't really extract anything from the target object, but returns the target object itself. This extractor can come in handy when you actually want filters to operate on the cache value itself instead of on one of its attributes, which is typically the case only if the value is of a simple type, such as one of the intrinsic numeric types or a string.

ChainedExtractor and MultiExtractor

There are also two composite value extractors, ChainedExtractor and MultiExtractor. Both of them accept an array of value extractors as a constructor argument, but they use them differently.

The ChainedExtractor executes extractors one by one, using the result of the previous extractor as the target object to evaluate the next extractor against. For example, you can use the ChainedExtractor to extract the accountId attribute from a Transaction instance:


Sample Code
  1.     ValueExtractor ex =
  2.         new ChainedExtractor(new ValueExtractor[] {
  3.                       new ReflectionExtractor("getId"),
  4.                       new ReflectionExtractor("getAccountId") })<p> </p><br>
Copyright exforsys.com


This is necessary because the Transaction class does not expose the accountId attribute directly--we need to extract the id attribute from a transaction first, and then extract accountId from a Transaction.Id instance.

Avoiding the need for chaining Of course, we could've easily avoided the need for chaining if we simply exposed the accountId attribute directly on the Transaction class. Doing that is trivial and makes perfect sense in this case. However, if I had done that, I'd have to come up with an example of ChainedExtractor usage that is outside of our domain.

When creating a ChainedExtractor you can also use a convenience constructor that will parse a dot-separated string and create an array of ReflectionExtractor instances automatically:


Sample Code
  1.     ValueExtractor ex =
  2.         new ChainedExtractor("getId.getAccountId")
  3.  
Copyright exforsys.com



As a matter of fact, you don't even need to go that far--all built-in filters will automatically create a ChainedExtractor containing an array of ReflectionExtractors from a dot-separated string, which is the feature we relied on earlier when we defined a query that returns transactions for a specific account.

On the other hand, MultiExtractor will execute all extractors against the same target object and return the list of extracted values. While you will rarely use this extractor when querying the cache, it can be very convenient when you want to extract only a subset of an object's attributes during aggregation (which we'll discuss shortly), in order to minimize the amount of data that needs to be transferred across the wire.

PofExtractor

One of the features introduced in Coherence 3.5 is PofExtractor--an extractor that can be used to extract values from the POF-serialized binaries without deserialization. This can provide a huge performance boost and reduced memory footprint for queries that would otherwise have to deserialize every single object in the cache in order to evaluate the filter.

Ads

However, you will only see those benefits when working with caches containing large objects. For small objects, the overhead of initializing a structure that is used to keep track of the location of serialized attributes within a binary POF value will likely be higher (both from memory and performance perspective) than the full deserialization of an object.



 
This tutorial is part of a Oracle Coherence tutorial series. Read it from the beginning and learn yourself.

Oracle Coherence

 

Comments