1 / 25

Building Business Logic

Building Business Logic. Objectives. After completing this lesson, you should be able to do the following: Decide where to place business logic Describe entity objects’ role in business logic implementation Create entity objects

Download Presentation

Building Business Logic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building Business Logic

  2. Objectives • After completing this lesson, you should be able to • do the following: • Decide where to place business logic • Describe entity objects’ role in business logic implementation • Create entity objects • Describe the different methods of implementing business logic in ADF Business Components • Add business logic to an ADF Business Components application • Use the Business Components Modeler to create and manage Business Components

  3. Business Logic Validation Client tier Middle tier EIS tier Web Container ADF Business Services Tier Controller ADFApplicationModule ADFView Object ADFEntity Object Database Model ClientValidation Business LogicValidation DatabaseValidation

  4. Implementing Validation in the Business Services Tier • Business logic tier: • Is used when creating or updating data • Assumes that existing data in the database is valid • Is defined at entity object level • Uses programmatic or declarative techniques • Declarative: Defined in wizards and editors • Programmatic: Coded in Java • Is specified in Java or XML or both

  5. Entity Object: Overview Entity object Customers IdNameStatusEmail Attributes Status List(Gold Silver Platinum) Validation rule CUSTOMERS Database table ID NAME STATUS Email 201 Steve Gold msmith@company.com 202 Mike Silver dgonzales@company.com

  6. Entity Object • Represents a database table or other data source • Handles all database interaction • Contains attributes representing the database columns • Encapsulates attribute-level and entity-level validation logic • Can contain custom business methods Customer Order

  7. Creating an Entity Object • Select the Business Components node in the New Gallery, and then select Entity Object. • Right-click the package name in the navigator, and select New Entity Object.

  8. Entity Object Wizard Enter a name. Select a database object. Move to the next step.

  9. Files Generated for the CustomersEntity Object • Customers.xml: Metadata • The Entity Object Wizard obtains all its information from this file. • Is created by default (mandatory) • CustomersImpl.java: Entity object class • Extends the EntityImpl class • Is row level • Includes getter and setter methods for attributes • Is created by default (optional)

  10. Optional Files Generated for the Customers Entity Object • CustomersDefImpl.java: Entity definition class • Extends the EntityDefImplclass • Contains run-time metadata describing the entity object • Describes all instances of the entity • CustomersCollImpl.java: Entity collection class • Extends the EntityCache class • Contains run-time querying the entity collection • Caches queried rows of the entity

  11. Using the Business Components Modeler for Entity Objects 1. Create a diagram from the New Gallery. 2. Drag objects to the diagram. • Entity objects • Database definitions

  12. Using the Business Components Modeler for Entity Objects • Create entity objects by using the Component Palette. • Use the Entity Object Editor for Entity Object properties.

  13. Assigning an Initial Value to an Entity Attribute • Add code to the create() method in EntityImpl.java. • create() runs automatically when the entity is instantiated. Optional Java filesselection Select the Create Method check box to generate a create() method.

  14. Mapping an Attribute to a Database Sequence create or replace trigger insert_ord_id BEFORE INSERT ON orders FOR EACH ROW DECLARE new_id number; BEGIN SELECT orders_seq.NextVal INTO new_id from Dual; :new.order_id := new_id; END; 1. Create a databasetrigger. • 2. Set the attribute typeto DBSequence.

  15. Practice 4-1: Overview • This practice covers the following topics: • Initializing an attribute to a default value • Assigning a database sequence to an attribute

  16. Adding Validation Entity-level validation Attribute-level validation

  17. Declarative Validation Rules • Use declarative validation rules to validate an entity attribute. • Use the Entity Object Wizard to add and edit rules. • The Entity Object Wizard provides different types of declarative rules: • Compare with a single value • Compare with a list of valid values—either hard coded or the results of a SQL query • Compare with the minimum value, maximum value, or a range of values • Validate using a custom method • Declarative validation is XML based.

  18. … ListValidator: Example • Specify a list of values for Customers.Status. Customers.xml

  19. Adding UniqueKeyValidator to an Entity • A UniqueKeyValidator: • Implements validation in the middle tier • Checks uniqueness of the primary key for an entity object • Checks that values are unique in the entity cache

  20. Domains • Use domains for more complex validation: • Format of a phone number • Validity of a URL • Validity of an e-mail address • Checksum of digits of a credit card number • Validation is done by the domain constructor. • A domain is not bound to a particular entity or attribute. • You can use domains to validate multiple attributes across multiple entity objects.

  21. Domains: Example • URLDomain verifies that an attribute is a valid URL. • The validate() method is called by the domain’s constructor. URLDomain.java protected void validate() { try { // Make sure the user entered a valid URL java.net.URL u = new java.net.URL(mData); } catch (java.net.MalformedURLException e) {throw new oracle.jbo.domain.DomainValidationException ("Invalid URL"); }

  22. How to Create a Domain 1. Create the domain from the New Gallery. 2. Add validation code to the validate() method automatically created in URLDomain.java.

  23. How to Use a Domain Edit the entity object and change the type of an attribute to URLDomain. URLDomain appears in the list of types.

  24. Summary • In this lesson, you should have learned how to: • Implement declarative business logic • Create entity objects • Generate Java code for entity objects • Validate entity attributes using validation rules or domain objects • Use the Business Component modeler

  25. Practice 4-2: Overview • This practice covers the following topics: • Adding a list validator to an attribute • Creating a domain • Assigning an attribute to a domain

More Related