08 PRGM Customizing
08 PRGM Customizing
08 PRGM Customizing
• EntityImpl
– The entity class
– Represents a row
– Provides getter and
setter methods
• EntityDefImpl
– The entity definition class
– Represents the whole entity
– Can be used to modify the entity definition
• EntityCollImpl
– Represents the cached set of rows from the entity
– Not usually necessary to modify or override methods in this
class
PersonEOToOrderEO OrderEO
PersonEO
getPersonEO()
getOrderEO() setPersonEO()
getEmail() getPersonEmail()
Accessor in source Accessors in destination
to get destination to get and set source
// In <Entity name>Impl.java
// In ProductEOImpl.java
import oracle.jbo.server.SequenceImpl;
// Default ProdId value from PRODUCTS_SEQ sequence at
1 protected void initDefaults() {
2 super.initDefaults();
SequenceImpl sequence = new
3 SequenceImpl("PRODUCTS_SEQ",getDBTransaction());
DBSequence dbseq = new
4
DBSequence(seq.getSequenceNumber());
5 populateAttributeAsChanged(ProdId, dbseq);
}
• ViewObjectImpl
– The view class
– Provides methods
to manage the row
set
• ViewDefImpl
– The view definition class
– Represents the whole view
– Can be used to modify the view definition
• ViewRowImpl
– The view object row class
– Instantiated for each record returned by the query
– Provides attribute accessors
• Created by default:
– <AppMod>AM.xml: Includes detailed metadata about the
View Objects included
– bc4j.xcfg: Contains all the configuration and connection
details
• Supporting Java classes:
– <AppMod>AMImpl.java: Contains all the methods and
behaviors that affect each application module instance
– <AppMod>AMDef.java: Contains methods to be used by
all instances of the application module
X Code to
manipulate
view objects
Click Execute.
Observe results.
Post phase
Commit phase
public
public void
void postChanges(TransactionEvent
postChanges(TransactionEvent e)e) {{
if
if (getPostState()
(getPostState() ==== Entity.STATUS_DELETED)
Entity.STATUS_DELETED) {{
//
// Custom
Custom code
code to
to mark
mark database
database rows,
rows, such
such as
as
//
// by
by updating
updating aa Deleted
Deleted flag
flag in
in the
the record
record
}}
else
else {{
super.postChanges(e);
super.postChanges(e);
}}
}}
• Implement a TransactionListener.
• Implement beforeCommit() and afterCommit().
• Add your listener to the transaction’s list of
event subscribers.
• Alternatively, override the entity object’s
beforeCommit() or afterCommit() methods.
Example: In PersonEOImpl, print notification that record is committed:
@Override
@Override
public
public void
void afterCommit(TransactionEvent
afterCommit(TransactionEvent transactionEvent)
transactionEvent) {{
System.out.println("Record
System.out.println("Record committed
committed for
for "" ++
getFirstName()
getFirstName() ++ "" "" ++ getLastName());
getLastName());
super.afterCommit(transactionEvent);
super.afterCommit(transactionEvent);
}}
public
public String
String findOrderID(long
findOrderID(long orderId)
orderId) {{
String
String entityName
entityName == "oracle.fod.storefront.model.entity.OrderEO";
"oracle.fod.storefront.model.entity.OrderEO";
1 EntityDefImpl
EntityDefImpl orderDef
orderDef == EntityDefImpl.findDefObject(entityName);
EntityDefImpl.findDefObject(entityName);
2 Key
Key orderKey
orderKey == new
new Key(new
Key(new Object[]{orderId});
Object[]{orderId});
3 EntityImpl
EntityImpl order
order == orderDef.findByPrimaryKey(getDBTransaction(),
orderDef.findByPrimaryKey(getDBTransaction(),
orderKey);
orderKey);
4 if
if (order
(order !=
!= null)
null) {{
return
return (String)order.getAttribute(“ShipToName");
(String)order.getAttribute(“ShipToName"); }}
else
else {{ return
return null;
null; }} }}
public
public void
void updateEmpEmail(long
updateEmpEmail(long empId,
empId, String
String newEmail)
newEmail) {{
1 EntityImpl
EntityImpl emp
emp == retrieveEmployeeById(empId);
retrieveEmployeeById(empId);
if
if (emp
(emp !=
!= null)
null) {{
2 emp.setAttribute(“Email",newEmail);
emp.setAttribute(“Email",newEmail);
try
try {{
3 getDBTransaction().commit();
getDBTransaction().commit(); }}
catch
catch (JboException
(JboException ex)ex) {{
getDBTransaction().rollback();
getDBTransaction().rollback();
throw
throw ex;
ex; }} }} }}
public
public long
long createProduct(String
createProduct(String name,
name, String
String description)
description) {{
String
String entityName
entityName == “oracle.
“oracle. fod.storefront.
fod.storefront. model.entity.ProductEO";
model.entity.ProductEO";
1 EntityDefImpl
EntityDefImpl productDef
productDef == EntityDefImpl.findDefObject(entityName);
EntityDefImpl.findDefObject(entityName);
2 EntityImpl
EntityImpl newProduct
newProduct ==
productDef.createInstance2(getDBTransaction(),null);
productDef.createInstance2(getDBTransaction(),null);
newProduct.setAttribute("Name",name);
3 newProduct.setAttribute("Name",name);
newProduct.setAttribute("Description",description);
newProduct.setAttribute("Description",description);
try
try {{
4 getDBTransaction().commit();
getDBTransaction().commit(); }}
catch
catch (JboException
(JboException ex)
ex) {{
throw
throw ex;
ex; }}
5 DBSequence
DBSequence newIdAssigned
newIdAssigned ==
(DBSequence)newProduct.getAttribute("ProdId");
(DBSequence)newProduct.getAttribute("ProdId");
return
return newIdAssigned.getSequenceNumber().longValue();
newIdAssigned.getSequenceNumber().longValue();
[Ctrl]+[Enter]
ViewObject
setWhereClause
Row RowSet setNamedWhereClauseParam setNamedWhereClauseParam
Row executeQuery executeQuery
Row
hasNext hasNext hasNext
RowSetIterator
next next next
ViewCriteria
ViewCriteria vc
vc == custOrdVO.createViewCriteria();
custOrdVO.createViewCriteria(); 1
ViewCriteriaRow
ViewCriteriaRow promotionRow
promotionRow == vc.createViewCriteriaRow();
vc.createViewCriteriaRow(); 2
ViewCriteriaRow
ViewCriteriaRow noPromRow
noPromRow == vc.createViewCriteriaRow();
vc.createViewCriteriaRow();
promotionRow.setAttribute("OrderTotal",
promotionRow.setAttribute("OrderTotal", ">
"> 500");
500");
promotionRow.setAttribute("CreditLimit",
promotionRow.setAttribute("CreditLimit", ">
"> 2500");
2500");
promotionRow.setAttribute(“DiscountId",
3
promotionRow.setAttribute(“DiscountId", “<>
“<> NULL");
NULL");
noPromRow.setAttribute("OrderTotal",
noPromRow.setAttribute("OrderTotal", ">
"> 1000");
1000");
noPromRow.setAttribute(“CreditLimit",
noPromRow.setAttribute(“CreditLimit", ">
"> 5000");
5000");
vc.addElement(promotionRow);
vc.addElement(promotionRow); 4
vc.addElement(noPromRow);
vc.addElement(noPromRow);
5
custOrdVO.applyViewCriteria(vc);
custOrdVO.applyViewCriteria(vc);
6
custOrdVO.executeQuery();
custOrdVO.executeQuery();
public
public class
class TestClient
TestClient {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
TestClient
TestClient testClient
testClient == new
new TestClient();
TestClient();
String
String amDef
amDef == "oracle.hr.test.TestAM";
"oracle.hr.test.TestAM";
String
String config
config == "TestAMLocal";
"TestAMLocal";
ApplicationModule
ApplicationModule am am ==
Configuration.createRootApplicationModule(amDef,config);
Configuration.createRootApplicationModule(amDef,config);
1 ViewObject
ViewObject dept
dept == am.findViewObject("DepartmentsView1");
am.findViewObject("DepartmentsView1");
dept.executeQuery();
dept.executeQuery();
2
while
while (dept.hasNext())
(dept.hasNext()) {{
3 Row
Row department
department == dept.next();
dept.next();
System.out.println("Department
System.out.println("Department "" ++
4 department.getAttribute("DepartmentId"));
department.getAttribute("DepartmentId"));
5 RowSet
RowSet emps
emps == (RowSet)department.getAttribute("EmployeesView");
(RowSet)department.getAttribute("EmployeesView");
while
while (emps.hasNext())
(emps.hasNext()) {{
6 Row
Row emp
emp == emps.next();
emps.next();
System.out.println("
System.out.println(" Employee
Employee Name:
Name: "" ++
7 emp.getAttribute("LastName"));
emp.getAttribute("LastName")); }} }}
Configuration.releaseRootApplicationModule(am,true);}}
Configuration.releaseRootApplicationModule(am,true);}}
public
public class
class TestClient
TestClient {{
public
public static void
static void main(String[]
main(String[] args)
args) {{
TestClient
TestClient testClient
testClient == new new TestClient();
TestClient();
String
String amDef = "oracle.hr.test.TestAM";
amDef = "oracle.hr.test.TestAM";
String
String config
config == "TestAMLocal";
"TestAMLocal";
ApplicationModule
ApplicationModule am =am =
Configuration.createRootApplicationModule(amDef,config);
Configuration.createRootApplicationModule(amDef,config);
1 ViewObject
ViewObject vo vo == am.findViewObject("EmployeesView1");
am.findViewObject("EmployeesView1");
Row newEmp = vo.createRow();
2 Row newEmp = vo.createRow();
vo.insertRow(newEmp);
vo.insertRow(newEmp);
newEmp.setAttribute("EmployeeId",999);
newEmp.setAttribute("EmployeeId",999);
newEmp.setAttribute("FirstName","Pam");
3 newEmp.setAttribute("FirstName","Pam");
newEmp.setAttribute("LastName","Gamer");
newEmp.setAttribute("LastName","Gamer");
Date
Date now
now == new
new Date();
Date();
newEmp.setAttribute("HireDate",now);
newEmp.setAttribute("HireDate",now);
newEmp.setAttribute("JobId","IT_PROG");
newEmp.setAttribute("JobId","IT_PROG");
newEmp.setAttribute("Email","[email protected]");
newEmp.setAttribute("Email","[email protected]");
newEmp.setAttribute("DepartmentId",60);
newEmp.setAttribute("DepartmentId",60);
newEmp.setAttribute("ManagerId",103);
newEmp.setAttribute("ManagerId",103);
4 am.getTransaction().commit();
am.getTransaction().commit();
System.out.println("Added
System.out.println("Added employeeemployee "" ++
5 newEmp.getAttribute("EmployeeId")
newEmp.getAttribute("EmployeeId") ++ "" to to Department
Department "" ++
newEmp.getAttribute("DepartmentId"));
newEmp.getAttribute("DepartmentId"));
Configuration.releaseRootApplicationModule(am,true);
Configuration.releaseRootApplicationModule(am,true); }} }}