资源预览内容
第1页 / 共21页
第2页 / 共21页
第3页 / 共21页
第4页 / 共21页
第5页 / 共21页
第6页 / 共21页
第7页 / 共21页
第8页 / 共21页
第9页 / 共21页
第10页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
ADF-BC EO 介绍介绍资深技术顾问甲骨文 开发者计划ADF-BC Entities ObjectCharacteristics of Entity ObjectsEntity objects:Represent a row in a database table or other data sourceHandle database cachingContain attributes representing the database columnsEncapsulate attribute-level and entity-level validation logicCan contain custom business methodsUsing Entity Objects to Persist DataCustomersEOIdNameStatusEmailEntity objectAttributesDatabase tableStatus List(Gold Silver Platinum)Validation ruleID201NAMESteveSTATUSGoldEmail202MikeSilverCUSTOMERSCreating Entity Objects from Tables, Views, or SynonymsWhen you create an entity object, JDeveloper:Interrogates the data dictionary for information about attribute Names, types, relationships based on primary/foreign key relationships,Infers primary key, or creates one from RowIDCreates implicit validators for database constraintsCreates the XML component definition file (.xml)Creates optional Java files if selected, such as entity object class Impl.javaGenerates associations based on foreign keys, if applicable (FkAS.xml) these should be renamedModifying the Default Behavior of Entity ObjectsWith declarative settings, you can:Define attribute control hintsUse alternate key entity constraintsRefactor (rename or move) objectsCreate and publish eventsValidate user input (presented in a later lesson)Many other modifications are possible with coding, such as:Overriding base class methodsImplementing calculation and recalculation of transient attributesDefining Attribute Control Hints12AssociationsDefine a relationship between EOsFacilitate access to data in related entity objectsMay be based on database constraintsMay be independent of database constraintsAre used in defining validations and LOV metadataConsist of a source (master) and a destination (detail) entitySourceDestinationOrdersPersonsFkASAssociationPersonsEOOrdersEOCreating AssociationsAutomatically created when creating 2nd EO with foreign keyCreating AssociationsUsing the Create Association wizardAssociation TypesAssociationEntities are related but not completely dependentEither end of the association can exist without the otherEither can be deleted without deleting the otherCompositionDestination entity is completely dependent on the source entityThe source entity owns the destination entityNo destination entity can be created without the owning entity existing firstThe source entity cannot be deleted without deleting all its associated destination entitiesUsing Alternate Key Entity ConstraintsAlternate keys are:Used for efficient uniqueness checksUsed for direct row lookups with findByKey() methodsDifferent from primary keys or unique keysRefactoring ObjectsWith refactoring you can:Rename objects, such as associations and view linksMove objects or packages to a different packageChange all references throughout the applicationWorking Programatically with Entities and AssociationsFinding an Entity Object by Primary KeypublicStringfindOrderID(longorderId)StringentityName=oracle.apps.str.model.entity.OrderEO;EntityDefImplorderDef=EntityDefImpl.findDefObject(entityName);KeyorderKey=newKey(newObjectorderId);EntityImplorder=orderDef.findByPrimaryKey(getDBTransaction(),orderKey);if(order!=null)return(String)order.getAttribute(“ShipToName);elsereturnnull;1234 publicStringgetLocationId()returngetDepartmentEO().getLocationId();Traversing Associations:Source to DestinationThe destination entitys EntityImpl.java methods to get and set the source entity.For example, EmployeeEOImpl.java contains getDepartmentEO() and setDepartmentEO().You could add a method to EmployeeEO.java to get the Location ID of the department to which the employee belongs:getEmployeeEO()DepartmentEODepartmentEOToEmployeeEOEmployeeEOgetDepartmentEO()getLocationId()Updating or Removingan Existing Entity RowpublicvoidupdateEmpEmail(longempId,StringnewEmail)EntityImplemp=retrieveEmployeeById(empId);if(emp!=null)emp.setAttribute(“Email,newEmail);trygetDBTransaction().commit();catch(JboExceptionex)getDBTransaction().rollback();throwex;123Creating a New Entity RowpubliclongcreateProduct(Stringname,Stringdescription)StringentityName=“oracle.apps.str.model.entity.ProductEO;EntityDefImplproductDef=EntityDefImpl.findDefObject(entityName);EntityImplnewProduct=productDef.createInstance2(getDBTransaction(),null);newProduct.setAttribute(Name,name);newProduct.setAttribute(Description,description);trygetDBTransaction().commit();catch(JboExceptionex)throwex;DBSequencenewIdAssigned=(DBSequence)newProduct.getAttribute(ProdId);returnnewIdAssigned.getSequenceNumber().longValue();12345Coding: The Supporting Java ClassesEntityImpl The entity classRepresents a row Provides getter and setter methodsEntityDefImplThe entity definition classRepresents the whole entityCan be used to modify the entity definitionEntityCollImplRepresents the cached set of rows from the entityIt is not necessary to modify or override methods in this classOverriding Base Class MethodsYou can override methods in the base classes for objects. For example, you can override methods in EntityImpl.java, such as:doDML() Use to log changes in another entitybeforeCommit() Use to validate multiple instances of the same entityremove() Use to log a deletion in an entityOverriding Base Class Methods Example: Updating a Deleted Flag Instead of Deleting Rows/InImpl.javapublicvoidremove()setDeleted(Y);super.remove();protectedvoiddoDML(intoperation,TransactionEvente)if(operation=DML_DELETE)operation=DML_UPDATE;super.doDML(operation,e);12
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号