Documente Academic
Documente Profesional
Documente Cultură
Objectives
After completing this lesson, you should be able to do the following: Extend the ADF Business Components (ADF BC) framework to support your application Override entity object data manipulation language (DML) to use a PL/SQL procedure Avoid database constraint violations
2-2
Agenda
General Considerations Extending the Framework Using PL/SQL for DML Operations Avoiding Database Constraint Violations
2-3
2-4
2-5
You should use Oracle stylenamed bind variables in queries: Where ID = :CustId and Name like :CustName
It is easy to create Query Input forms based on this.
You should think about ExecuteWithParams rather than custom methods when you set the WHERE clause.
2-6
2-7
2-8
2 - 10
2 - 11
Agenda
General Considerations Extending the Framework Using PL/SQL for DML Operations Avoiding Database Constraint Violations
2 - 12
2 - 13
2 - 14
2 - 15
2 - 16
2 - 17
2 - 18
Considerations
Do not update the EXTENDS clause in custom component Java files manually. Set up project-level preferences for framework extension classes.
You can have multiple levels of framework extension classes, but keep it simple.
2 - 19
2 - 20
Agenda
General Considerations Extending the Framework Using PL/SQL for DML Operations Avoiding Database Constraint Violations
2 - 21
Key
Entity Object B
Entity Object C
PL/SQL for Table A PL/SQL for Table B PL/SQL for Table C
Table-specific validation Attribute validation DML: INSERT, UPDATE, DELETE, and LOCK
Table A
Table B
Table C
2 - 22
Typical Environment
Background environment: A PL/SQL package that encapsulates insert, update, and delete access to an underlying table A companion database view for read access
create or replace package products_api is procedure insert_product(p_prod_id number, p_name varchar2, p_image varchar2, p_description varchar2); procedure update_product(p_prod_id number, p_name varchar2, p_image varchar2, p_description varchar2); procedure delete_product(p_prod_id number); end products_api; create or replace view products_v as select prod_id,name,image,description from products;
2 - 23
2 - 24
All Entity Object implementations extend the EntityImpl.java class. You override the doDML() operations and when necessary, override lock() and findByPrimaryKey().
2 - 25
// In PLSQLEntityImpl.java protected void doDML(int operation, TransactionEvent e) { if (operation == DML_INSERT) callInsertProcedure(e); else if (operation == DML_UPDATE) callUpdateProcedure(e); ... /* Override in a subclass to perform non-default processing */ protected void callInsertProcedure(TransactionEvent e) { super.doDML(DML_INSERT, e); ... }
The example shows how to call insert and update procedures. You can also add a call to a delete procedure.
2 - 26
Enable a custom Java class for the entity object. Select Source > Override Methods to override callInsertProcedure() and other helper methods.
2 - 27
Leveraging the Helper Method to Invoke Insert, Update, and Delete Procedures
In the ProductsVImpl.java file, add code to invoke the PL/SQL procedures:
// In ProductsVImpl.java protected void callInsertProcedure(TransactionEvent e) { callStoredProcedure("products_api.insert_product(?,?,?,?)", new Object[] { getProdId(), getName(), getImage(),getDescription()}); } protected void callUpdateProcedure(TransactionEvent e) { callStoredProcedure("products_api.update_product(?,?,?,?)", new Object[] { getProdId(), getName(), getImage(),getDescription()}); }
The example shows how to call insert and update procedures. You can also add a call to a delete procedure.
2 - 28
Agenda
General Considerations Extending the Framework Using PL/SQL for DML Operations Avoiding Database Constraint Violations
2 - 29
2 - 30
Database diagram
Association
2 - 31
Composition
2 - 32
2 - 33
2 - 34
A better solution is to make the entity objects handle the posting order:
Override the postChanges() method in the entity that contains the foreign key. Conditionally, force the new Suppliers row to post before the new Products row posts.
2 - 35
2 - 36
postChanges() Example
// In ProductsImpl.java public void postChanges(TransactionEvent e) { /* If current entity is new or modified */ if (getPostState() == STATUS_NEW || getPostState() == STATUS_MODIFIED) { /* Get the associated supplier for the product */ SuppliersImpl supplier = getSupplier(); /* If there is an associated supplier */ if (supplier != null) { /* And if it's post-status is NEW */ if (supplier.getPostState() == STATUS_NEW) { /* Post the supplier first, before posting this entity by calling super below*/ supplier.postChanges(e);}}} super.postChanges(e); }
2 - 37
2 - 38
2 - 39
2 - 40
Summary
In this lesson, you should have learned how to: Extend the ADF BC framework to support your application Override entity object DML to use a PL/SQL procedure Avoid database constraint violations
2 - 41
2 - 42