introducing adf business components

29
1 Chapter 8 Chapter 8 Introducing ADF Business Introducing ADF Business Components Components

Upload: prabhat-gangwar

Post on 16-Apr-2017

150 views

Category:

Education


6 download

TRANSCRIPT

Page 1: Introducing adf business components

1

Chapter 8Chapter 8Introducing ADF Business Introducing ADF Business

ComponentsComponents

Page 2: Introducing adf business components

2

Introducing ADF Business Introducing ADF Business ComponentsComponents

ADF BCADF BC is a Java and XML based framework for is a Java and XML based framework for developing:developing:

• Business logic, including validation and default logicBusiness logic, including validation and default logic

• QueriesQueries

• Transaction handlingTransaction handling

• Data accessData access

It does not create a user interface, but is a pure It does not create a user interface, but is a pure encapsulation of business logic that communicates with a encapsulation of business logic that communicates with a separate client application, which handles user interaction.separate client application, which handles user interaction.

Using ADF BC is the simplest way to design data-aware Using ADF BC is the simplest way to design data-aware applications with JDeveloper. This chapter presents an applications with JDeveloper. This chapter presents an overview of ADF BC by describing its components and uses. overview of ADF BC by describing its components and uses.

Page 3: Introducing adf business components

3

Why Use ADF BC?Why Use ADF BC? The advantage of ADF BC over UI-enforced business The advantage of ADF BC over UI-enforced business logic is reusability. For example, a single ADF BC layer logic is reusability. For example, a single ADF BC layer can provide the business logic for all a company's can provide the business logic for all a company's needs. The business components can be used again and needs. The business components can be used again and again, with multiple interfaces (a time saver). again, with multiple interfaces (a time saver).

Page 4: Introducing adf business components

4

Advantages of ADF BCAdvantages of ADF BCBy maintaining a cache of data in memory, ADF BC By maintaining a cache of data in memory, ADF BC reduces the number of database trips required by an reduces the number of database trips required by an application resulting in improved performance and application resulting in improved performance and scalability.scalability.

ADF BC allows the business logic to be written in Java, ADF BC allows the business logic to be written in Java, which saves the trouble of integrating a Java GUI or which saves the trouble of integrating a Java GUI or JSP application with business logic written in PL/SQL JSP application with business logic written in PL/SQL code.code.

Removing the business logic out of the database keeps Removing the business logic out of the database keeps the database from handling anything but data, which the database from handling anything but data, which increases an application's modularity and efficiency.increases an application's modularity and efficiency.

Page 5: Introducing adf business components

5

Advantages of ADF BC Advantages of ADF BC (continued)(continued)

There are also advantages to implementing some business There are also advantages to implementing some business logic directly in the database (more robust) since it will be logic directly in the database (more robust) since it will be enforced even in a SQL*Plus session. Business logic enforced even in a SQL*Plus session. Business logic implemented in the ADF BC layer is only enforced in implemented in the ADF BC layer is only enforced in applications using that layer, but increases performance.applications using that layer, but increases performance.

There is a trade-off between robustness and performance.There is a trade-off between robustness and performance.

Therefore, the most critical business logic should be Therefore, the most critical business logic should be implemented in the database or redundantly in both the implemented in the database or redundantly in both the database and a ADF BC layer. The remainder of the database and a ADF BC layer. The remainder of the business logic can be implemented in the ADF BC layer. business logic can be implemented in the ADF BC layer.

Page 6: Introducing adf business components

6

Advantages of ADF BC Advantages of ADF BC (continued)(continued)

ADF BC provides four ready-made architectures for business ADF BC provides four ready-made architectures for business component clients:component clients:

• JClientJClient, an architecture for creating Java GUIs (useful for , an architecture for creating Java GUIs (useful for intensive data-entry applications requiring high intensive data-entry applications requiring high interactivity).interactivity).

• Thin JSP clientsThin JSP clients are useful for web-based applications are useful for web-based applications where a thin client is more important than very high where a thin client is more important than very high interactivity, such as self-service and e-commerce interactivity, such as self-service and e-commerce applications.applications.

• XSQL clientsXSQL clients, which generate XML for either flexible , which generate XML for either flexible display with a style sheet or loose coupling between display with a style sheet or loose coupling between applications.applications.

• UIXUIX, a framework-based architecture for developing web , a framework-based architecture for developing web applications. applications.

Page 7: Introducing adf business components

7

Advantages of ADF BC Advantages of ADF BC (continued)(continued)

ADF BC also has the advantage of being "deployment-ADF BC also has the advantage of being "deployment-configuration independent". A single ADF BC layer can configuration independent". A single ADF BC layer can be deployed as local Java classes or as an Enterprise be deployed as local Java classes or as an Enterprise JavaBean (EJB), with no rewriting of code necessary. JavaBean (EJB), with no rewriting of code necessary. You can concentrate on the business logic of your You can concentrate on the business logic of your application instead of its deployment requirements.application instead of its deployment requirements.

ADF BC components (whether deployed to a J2EE web ADF BC components (whether deployed to a J2EE web module with JSP pages or as an EJB) are fully J2EE-module with JSP pages or as an EJB) are fully J2EE-compliant. The ADF BC framework automatically compliant. The ADF BC framework automatically implements the J2EE BluePrints design patterns implements the J2EE BluePrints design patterns suggested by Sun Microsystems so you do not need to suggested by Sun Microsystems so you do not need to worry about them. worry about them.

Page 8: Introducing adf business components

8

Business Components, Java, and Business Components, Java, and XMLXML

Entity objects, view objects, and application modules each Entity objects, view objects, and application modules each have two parts: a Java class file and an XML file. The files have two parts: a Java class file and an XML file. The files have different purposes. ADF BC is a framework, this means have different purposes. ADF BC is a framework, this means that much of its functionality is contained in a set of libraries. that much of its functionality is contained in a set of libraries. ADF BC classes extend (subclass) the base classes provided ADF BC classes extend (subclass) the base classes provided by these libraries to provide complex business logic, which by these libraries to provide complex business logic, which requires the procedural power of Java to implement. This requires the procedural power of Java to implement. This allows you (if needed) to:allows you (if needed) to:

• Easily write code to implement complex business rules Easily write code to implement complex business rules inside your entity object Java classesinside your entity object Java classes

• Code complex query logic in your view object classesCode complex query logic in your view object classes

• Code complex transaction handling in your application Code complex transaction handling in your application module classes.module classes.

Page 9: Introducing adf business components

9

Business Components, Java, and Business Components, Java, and XMLXML

The base classes in the ADF BC framework are programmed to The base classes in the ADF BC framework are programmed to work with XML files. Some business logic is common and simple work with XML files. Some business logic is common and simple and can be handled with a line or two of declarative XML. Instead and can be handled with a line or two of declarative XML. Instead of writing a procedure to implement this sort of business logic, of writing a procedure to implement this sort of business logic, you can just declare that an entity attribute, for example, must you can just declare that an entity attribute, for example, must obey a particular validation rule. The base entity object class (and obey a particular validation rule. The base entity object class (and by inheritance, your custom Java class) can automatically read the by inheritance, your custom Java class) can automatically read the XML file to enforce the rule. JDeveloper has wizards that write XML file to enforce the rule. JDeveloper has wizards that write and edit the XML files for you.and edit the XML files for you.

The ADF BC framework uses XML files to store static definitions The ADF BC framework uses XML files to store static definitions such as the structure of a database table or query. Its base such as the structure of a database table or query. Its base classes can obtain the structure of particular business classes can obtain the structure of particular business components by parsing the XML.components by parsing the XML.This can have performance advantages. For example, an entity This can have performance advantages. For example, an entity object dose not need to query the database at runtime for object dose not need to query the database at runtime for structural information about the table it represents.structural information about the table it represents.

Page 10: Introducing adf business components

10

ADF Business Component GroupsADF Business Component Groups ADF BC components are divided into two groups:ADF BC components are divided into two groups:

• Business domain componentsBusiness domain components

• Data model componentsData model components

Page 11: Introducing adf business components

11

Business Domain ComponentsBusiness Domain Components These components represent features of the database: These components represent features of the database: tables and views, constraints, and relationships. They tables and views, constraints, and relationships. They are the most reusable business components because are the most reusable business components because they can be used by any application that needs to they can be used by any application that needs to access the same data.access the same data.

There are three kinds of business domain components:There are three kinds of business domain components:

• Entity Object definitionsEntity Object definitions

• AssociationsAssociations

• DomainsDomains

Page 12: Introducing adf business components

12

Entity Object DefinitionsEntity Object Definitions An entity object definition usually represents a database table or An entity object definition usually represents a database table or database view, but it can also be used to represent EJB entity database view, but it can also be used to represent EJB entity beans. It acts as a representation of the table or database and beans. It acts as a representation of the table or database and handles all of the business rules for that table or view including handles all of the business rules for that table or view including validation, defaulting, and anything else that happens when a validation, defaulting, and anything else that happens when a row is created, deleted, or changed.row is created, deleted, or changed.

The power of ADF BC is its interface with the database used by The power of ADF BC is its interface with the database used by an application.an application.

The ADF BC layer represents the database table as an entity The ADF BC layer represents the database table as an entity object. An entity object has object. An entity object has entity attributesentity attributes that represent the that represent the table columns table columns (mapping may not always be one-to-one).(mapping may not always be one-to-one).

The types of the properties are Java classes that correspond to The types of the properties are Java classes that correspond to the SQL types of the columns.the SQL types of the columns.

Page 13: Introducing adf business components

13

Entity Object DefinitionsEntity Object Definitions Example: Example: DEPARTMENTSDEPARTMENTS table table

Entity objects for the above table may have the Entity objects for the above table may have the followingfollowing

entity attributes: entity attributes:

Page 14: Introducing adf business components

14

Entity Object DefinitionsEntity Object Definitions Java does not directly support SQL datatypes, but each SQL Java does not directly support SQL datatypes, but each SQL datatype can be mapped to a Java type. Some Java types are datatype can be mapped to a Java type. Some Java types are classes in classes in java.langjava.lang and others in the package and others in the package oracle.jbo.domainoracle.jbo.domain (discussed later). (discussed later).Entity objects have two parts:Entity objects have two parts:

1.1. AA Java class Java class (like DepartmentsImpl.java) – This (like DepartmentsImpl.java) – This contains the contains the procedural code to implement the entity object.procedural code to implement the entity object.

2.2. An An XML fileXML file (like Departments.xml) – This includes (like Departments.xml) – This includes metadata metadata describing the entity object, its attributes, and the table describing the entity object, its attributes, and the table upon upon which it is based, as well as declarative code.which it is based, as well as declarative code.

Page 15: Introducing adf business components

15

ADF BC Relationships (page 228)ADF BC Relationships (page 228)

Page 16: Introducing adf business components

16

AssociationsAssociationsLike tables, entity objects are often related to one Like tables, entity objects are often related to one another. The relationships between entity objects are another. The relationships between entity objects are called called associationsassociations. An association matches one or . An association matches one or more attributes of a "source" entity object with one or more attributes of a "source" entity object with one or more attributes of a "destination" entity object.more attributes of a "destination" entity object.

This is like a foreign key constraint that matches one This is like a foreign key constraint that matches one or more columns of a child table with one or more or more columns of a child table with one or more columns of a parent table.columns of a parent table.

Associations are stored in an XML file. Associations are stored in an XML file.

Page 17: Introducing adf business components

17

Domains Domains DomainsDomains are special java types used by ADF BC as the types for many are special java types used by ADF BC as the types for many entity object and view object attributes. In the coverage of entity objects entity object and view object attributes. In the coverage of entity objects earlier, a class that implements the earlier, a class that implements the DepartmentsDepartments entity object has some entity object has some entity attributes of type entity attributes of type oracle.jbo.domain.Numberoracle.jbo.domain.Number. The entity . The entity attributes of an entity object Java class are objects, not primitive Java attributes of an entity object Java class are objects, not primitive Java types such as types such as intint..

Database columns of SQL datatype VARCHAR2 have the Java class Database columns of SQL datatype VARCHAR2 have the Java class java.lang.Stringjava.lang.String. For other SQL types (NUMBER, etc.), ADF BC provides . For other SQL types (NUMBER, etc.), ADF BC provides domainsdomains to wrap the SQL datatype. Domains like to wrap the SQL datatype. Domains like oracle.jbo.domain.Numberoracle.jbo.domain.Number are basically object wrappers for scalar are basically object wrappers for scalar types.types.

JDeveloper will automatically create a JDeveloper will automatically create a domaindomain if you base an entity object if you base an entity object on a table with an Oracle object type column in it. This on a table with an Oracle object type column in it. This domaindomain represents represents the Oracle object type, giving you Java wrappers for each of the object the Oracle object type, giving you Java wrappers for each of the object type's fields and methods.type's fields and methods.

You can also create your own You can also create your own domainsdomains. .

Page 18: Introducing adf business components

18

Data Model ComponentsData Model Components They are business components that collect data and They are business components that collect data and present it to the view and controller through the ADF present it to the view and controller through the ADF model layer. They are not reusable as business model layer. They are not reusable as business domain components because their design is based on domain components because their design is based on the data needs of a particular client application.the data needs of a particular client application.

They are still independent of a user interface.They are still independent of a user interface.

There are three kinds of data model components:There are three kinds of data model components:

• View object definitionsView object definitions

• View link definitionsView link definitions

• Application module definitionsApplication module definitions

Page 19: Introducing adf business components

19

View Object DefinitionsView Object Definitions Generally you should not present all of the Generally you should not present all of the information stored in a database object (entity object) information stored in a database object (entity object) in one application. You may also want/need data in one application. You may also want/need data taken from more than one database object. taken from more than one database object.

SQL provides the queries necessary to select exactly SQL provides the queries necessary to select exactly the data you need from one or more tables. This is the data you need from one or more tables. This is why ADF BC has why ADF BC has view object definitionsview object definitions, which , which correspond to SQL queries. A view object definition correspond to SQL queries. A view object definition actually stores a SQL query.actually stores a SQL query.

Page 20: Introducing adf business components

20

View Object DefinitionsView Object Definitions (continued)(continued)

A view object definition has A view object definition has view attributesview attributes (like (like entity objects have entity attributes) that correspond entity objects have entity attributes) that correspond the columns of a query result. For example, consider the columns of a query result. For example, consider the view object for the following query: the view object for the following query: SELECT Departments.DEPARTMENT_ID,

Departments.DEPARTMENT_NAME, Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME

FROM DEPARTMENTS Departments, EMPLOYEES EmployeesWHERE Departments.MANAGER_ID=Employees.EMPLOYEE_ID;

This view object would have the following view attributes:

Page 21: Introducing adf business components

21

View Object DefinitionsView Object Definitions (continued)(continued)

The above view attributes may be (but not required to The above view attributes may be (but not required to be) associated with attributes from entity objects.be) associated with attributes from entity objects.

View objects have two parts:View objects have two parts:

1.1. AA Java class Java class (like ManagerViewImpl.java) – This (like ManagerViewImpl.java) – This class handles the complex logic or the queries, class handles the complex logic or the queries, controlling the client's access to the data.controlling the client's access to the data.

2.2. An An XML fileXML file (like ManagerView.xml) – This (like ManagerView.xml) – This stores information about the query and its stores information about the query and its relationships to entity objects.relationships to entity objects.

Page 22: Introducing adf business components

22

View Link DefinitionsView Link Definitions A A View linkView link represents a relationship between the represents a relationship between the query result sets of two view objects. It associates query result sets of two view objects. It associates one or more attributes of one view object with one or one or more attributes of one view object with one or more attributes of another.more attributes of another.

Page 23: Introducing adf business components

23

View Link DefinitionsView Link Definitions (continued) (continued)

For example:For example:

A view object, A view object, DepartmentsViewDepartmentsView, containing the following , containing the following query:query:

Another view object, Another view object, EmployeesViewEmployeesView, containing the following , containing the following query:query:

A view link,A view link, DeptEmpFkLink, DeptEmpFkLink, that associated thethat associated the DepartmentId DepartmentId attribute ofattribute of EmployeesView EmployeesView with thewith the DepartmentId DepartmentId attribute ofattribute of DepartmentsView DepartmentsView. .

SELECT Departments.DEPARTMENT_ID, Departments.DEPARTMENT_NAMEFROM DEPARTMENTS Departments

SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.DEPARTMENT_ID,FROM EMPLOYEES Employees

Page 24: Introducing adf business components

24

View Link DefinitionsView Link Definitions (continued) (continued)

DeptEmpFkLink DeptEmpFkLink represents a master-detail represents a master-detail relationship between the query result sets of relationship between the query result sets of DepartmentsView DepartmentsView and and EmployeesViewEmployeesView..

View links between view objects can be (but do not View links between view objects can be (but do not have to be) based on associations between underlying have to be) based on associations between underlying entity objects. A view link is represented in an XML entity objects. A view link is represented in an XML file (more on this in later chapters). file (more on this in later chapters).

Page 25: Introducing adf business components

25

Application Module DefinitionsApplication Module Definitions An An application moduleapplication module is a container for is a container for view view usages usages (instances of (instances of view objectsview objects). It lists all of the ). It lists all of the view usages your application requires and specifies view usages your application requires and specifies how they are related by view links. These how they are related by view links. These relationshipsrelationshipscan be represented by a tree (application module's can be represented by a tree (application module's data modeldata model).).

For example, an application module might contain For example, an application module might contain usage of usage of DepartmentsViewDepartmentsView, called , called AllDepartmentsAllDepartments, , and a usage of and a usage of EmployeesViewEmployeesView, called , called DepartmentEmployeesDepartmentEmployees, linked by an instance of , linked by an instance of EmpDeptFkLinkEmpDeptFkLink, called, called DepartmentToEmployees DepartmentToEmployees. .

Page 26: Introducing adf business components

26

Application Module DefinitionsApplication Module Definitions (continued)(continued)

This uses the following data model: This uses the following data model:

Using this model, the two view usages are tied together by a link representing a master-detail relationship between them (EmpDeptFkLink). Using this application module, your client application could select a row in AllDepartments, and the ADF BC framework would immediately synchronize DepartmentEmployees so that it would only return employees from the selected department.

Page 27: Introducing adf business components

27

Application Module DefinitionsApplication Module Definitions (continued)(continued)

Your application module could contain a usage of Your application module could contain a usage of DepartmentsViewDepartmentsView and a usage of and a usage of EmployeesViewEmployeesView without using without using EmpDeptFkLinkEmpDeptFkLink, as in the following , as in the following data model: data model:

This module provides usages of the same two view objects, but the view usages are linked. Your client application could select rows in AllDepartments and Allmployees usages independently.

Page 28: Introducing adf business components

28

Application Module DefinitionsApplication Module Definitions (continued)(continued)

You can even include two instances of You can even include two instances of EmployeesViewEmployeesView in an in an applicationapplication module: one a detail of an instance of module: one a detail of an instance of DepartmentsViewDepartmentsView and one independent as in the data model and one independent as in the data model below: below:

With this application module, a client application could select rows in DepartmentEmployees and have them automatically synchronized with AllDepartments and could also select rows in AllEmployees independently.

Page 29: Introducing adf business components

29

Application Module DefinitionsApplication Module Definitions (continued)(continued)

An application module definition is a template for An application module definition is a template for application module instancesapplication module instances, which are individual , which are individual copies of the data model used by particular instances copies of the data model used by particular instances of the application. Each instance represents an of the application. Each instance represents an individual database transaction.individual database transaction.