Copy helpers (access beans)
A copy helper access bean has the same basic characteristics as a Java bean wrapper, but introduces some additional characteristics of its own.
It is, for example, optimized for use with a single entity enterprise bean instance. Unlike a Java bean wrapper, a copy helper incorporates a single copy helper object that contains a local copy of attributes from a remote entity bean. Note: Not supported for enterprise beans with only a local client view.
Access beans employ copy helper objects, which are essentially caches of user-selected entity bean attributes stored inside the access bean. The getter and setter methods for these attributes deal directly with the local cache rather than calling straight through to the remote getter and setter call. Methods are provided to flush the cache to the actual enterprise bean database and to refresh the cache from the actual enterprise bean. This improves performance significantly for entity enterprise beans that have a large number of attributes, since issuing a single remote call to get and set a large number of attributes is faster than issuing a remote call for each attribute.
When you create a copy helper, the remote interface of the enterprise bean is changed to extend the CopyHelper interface and the EJBObject interface. You can select all of the enterprise bean attributes or only a subset when creating the copy helper object. The selected attributes are saved in the enterprise bean metamodel and are redisplayed if you decide to change the selection.
The copy helper object is stored inside the access bean. A getter and setter method is delegated to the local copy helper object instead of the remote enterprise bean object. To commit the changes in the copy helper to the remote enterprise bean or to refresh the local copy helper from the remote enterprise bean, your client program must call commitCopyHelper() and refreshCopyHelper() respectively.
Getter and setter methods must be defined for your enterprise bean properties according to the JavaBeans conventions for defining getter and setter methods. If you don't have getter and setter methods, then you won't be able to add the corresponding fields to the copy helper. The getter and setter methods should also not throw any exceptions.
Along with user-selected enterprise bean attributes, the key object is also stored in the copy helper cache as soon as the enterprise bean is instantiated by the access bean. To get the key object from an access bean, use the __getKey() method.
When you call a getter method for a cached attribute, the access bean adheres to the following protocol:
- If the cache is empty or contains only the key object, then a complete cache refresh is performed using refreshCopyHelper().
- If the cache is not empty and does not contain the key object, it is first flushed to the enterprise bean to update any attributes that might have been set, then completely refreshed.
- The attribute's value is retrieved from the cache.
Parent topic
Access beans