
Creating and applying property sets
In the Using a custom property to populate a sequence attribute and Overriding doDML() to populate an attribute with a gapless sequence recipes of this chapter, we introduced custom properties for generic ADF business component programming. In this recipe, we will present a technique to organize your custom properties in reusable property sets. By organizing application-wide properties in a property set and exporting them as part of an ADF Library JAR, you can then reference them from any other ADF-BC project. This in turn will allow you to centralize the custom properties used throughout your ADF application in a single property set.
getting ready
We will create a property set in the SharedComponets
workspace. I suggest that you go over the Using a custom property to populate a sequence attribute and Overriding doDML() to populate an attribute with a gapless sequence recipes in this chapter before continuing with this recipe. To run the recipe's test cases, you will need access to the HR
schema in the database.
How to do it...
- Start by opening the
SharedComponets
workspace. If needed, follow the steps in the referenced recipe to create it. - Right-click on the
SharedBC
project and select New…. - On the New Gallery dialog select ADF Business Components under the Business Tier node and Property Set from the Items on the right.
- Click OK to proceed. This will open the Create Property Set dialog.
- Enter the property set name and package in the appropriate fields. For this recipe, we will call it
SharedProperties
and use thecom.packt.jdeveloper.cookbook.shared.bc.properties
package. Click OK to continue. - JDeveloper will create and open the
SharedProperties
property set. - To add a custom property to the property set, click on the Add Custom Property button (the green plus sign icon).
- Go ahead and add two non-translatable properties called CommitSequenceDepartmentDepartmentId and CreateSequenceEmployeeEmployeeId. Set their values to DEPARTMENTS_SEQ and EMPLOYEES_SEQ respectively. Your property set should look similar to the following screenshot:
- Next you need to change the
create()
method in the custom entity framework class so that the custom property is now similar to the following block of code:// construct the custom property name from the entity name and attribute String propertyName = CREATESEQ_PROPERTY + getEntityDef().getName() + atrbDef.getName(); // check for a custom property called CREATESEQ_PROPERTY String sequenceName =(String)atrbDef.getProperty(propertyName);
- Similarly change the
doDML()
method in the custom entity framework class so that the custom property is also constructed, as shown in the following block of code:// construct the custom property name from the entity name and attribute String propertyName = COMMITSEQ_PROPERTY + getEntityDef().getName() + atrbDef.getName(); // check for a custom property called COMMITSEQ_PROPERTY String sequenceName =(String)atrbDef.getProperty(propertyName);
- Redeploy the
SharedComponets
workspace into an ADF Library JAR. - Open the
HREmployees
workspace and double-click on theHREmployeesBC
business components project to bring up the Project Properties dialog. - Select Imports under the ADF Business Components node and click on the Import… button on the right.
- On the Import Business Components XML File dialog browse for the shared components ADF Library JAR file in the
ReUsableJARs
directory. Select it and click Open. - You should see the imported
SharedBC
project under the Imported Business Component Projects along with the imported packages and package contents. Click OK to continue with importing the business components. - Double-click on the Employee entity object and go to the Attributes tab.
- Click on the Details tab, and from the Property Set choice list select the imported property set.
- Repeat steps 12-17 for the
HRDepartments
workspace and apply the property set to theDepartmentId
attribute of theDepartment
entity object.
How it works...
Property sets are a way to gather all of your custom properties together into logical collections. Instead of applying each custom property separately to a business components object or to any of its attributes, custom properties defined in these collections can be applied at once on them. Property sets can be applied to entity objects and their attributes, view objects and their attributes, and application modules. You access custom properties programmatically as indicated earlier, by calling AttributeDef.getProperty()
for properties applied to attributes, EntityDefImpl.getProperty()
for properties applied to entity objects, ViewDefImpl.getProperty()
for properties applied to view objects, and so on.
How you organize your custom properties into property sets is up to you. In this recipe, for example, we use a single property set called SharedProperties
, which we define in the shared components ADF library. In this way, we kept all custom properties used by the application in a single container. For this to work, we had to devise a way to differentiate among them. The algorithm that we used was to combine the property name with the business components object name and the attribute name that the property applies to. So we have properties called CommitSequenceDepartmentDepartmentId
and CreateSequenceEmployeeEmployeeId
.
Finally, we import the property set from the SharedComponets
workspace into the relevant business components projects using the Import Business Components facility of the business components Project Properties dialog.
There's more...
To test the recipe, you can run the EmployeeAppModule
and DepartmentAppModule
application modules in the HREmployees
and HRDepartments
workspaces respectively.
Note
Note that you can override any of the properties defined in a property set by explicitly adding the same property to the business component object or to any of its attributes.
Also note that property sets can be applied onto entity objects, view objects, and application modules by clicking on the Edit property set selection button (the pen icon) on the business component object definition General tab. On the same tab, you can add custom properties to the business component object by clicking on the Add Custom Property button (the green plus sign icon).
See also
- Breaking up the application in multiple workspaces, Chapter 1, Pre-requisites to Success: ADF Project Setup and Foundations
- Setting up BC base classes, Chapter 1, Pre-requisites to Success: ADF Project Setup and Foundations
- Using a custom property to populate a sequence attribute, in this chapter
- Overriding doDML() to populate an attribute with a gapless sequence, in this chapter