Skip Headers
Oracle TopLink Developer's Guide
10g Release 3 (10.1.3)
B13593-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Configuring Method Accessing

By default, TopLink uses direct access to access public attributes. Alternatively, you can use getter and setter methods to access object attributes when writing the attributes of the object to the database, or reading the attributes of the object from the database. This is known as method access.

The attribute's visibility (public, protected, private, or package visibility) and the supported version of JDK may restrict the type of access that you can use.

Using private, protected or package variable or method access requires you to enable the Java reflect security setting. This is enabled by default in most application servers (see "Security Permissions"), but may need to be enabled explicitly in certain JVM configurations. If necessary, use the java.policy file to grant ReflectPermission to the entire application or the application's code base. For example:

grant{
     permission java.lang.reflect.ReflectPermission;
};

Oracle recommends using direct access whenever possible to improve performance and avoid executing any application-specific behavior while building objects.

Table 35-7 summarizes which mappings support this option.

For information on configuring method accessing at the project level, see "Configuring Mapped Field Access at the Project Level".

Using TopLink Workbench

To complete the field access method for a mapping, use this procedure:

  1. Select the mapped attribute in the Navigator. Its properties appear in the Editor.

  2. Click the General tab. The General tab appears.

    Figure 35-7 General Tab, Method Accessing Options

    Description of Figure 35-7  follows
    Description of "Figure 35-7 General Tab, Method Accessing Options"

Use the following information to complete the Method Accessing fields on this tab:

Field Description
Method Accessing Specify if this mapping uses specific accessor methods instead directly accessing public attributes. By default, this option is not selected (that is, the mapping uses direct access).
    Get Method Select a specific get method.
    Set Method Select a specific set method.

To change the default access type used by all new mappings, use the Defaults tab on the project Editor window. See "Configuring Mapped Field Access at the Project Level" for more information.

Using Java

Use the following DatabaseMapping methods to configure the user-defined getters and setters that TopLink will use to access the mapped attribute:

For mappings not supported in TopLink Workbench, use the setGetMethodName and setSetMethodName methods to access the attribute through user-defined methods, rather than directly.

  • setGetMethodName–set the String name of the user-defined method to get the mapped attribute

  • setSetMethodName–set the String name of the user-defined method to set the mapped attribute

Example 35-9 shows how to use these methods with a class that has an attribute phones and accessor methods getPhones and setPhones in an object-relational mapping.

Example 35-9 Configuring Access Method in Java

// Map the phones attribute
phonesMapping.setAttributeName("phones");
 
// Specify access method
phonesMapping.setGetMethodName("getPhones");
phonesMapping.setSetMethodName("setPhones");