1 / 88

Workshop ADF BC pka BC4J 2 and 3 June 2005

Agenda. Introductie doel en achtergrondOntwikkel ADF BC business service met wizardsGebruik van TesterProgrammatische toegang tot ADF BCRead OnlySearchingNavigating through resultsData Manipulatie via ADF BCValidationsException Handling. ADF BC. ADF BC : Business Components for Java(BC4J

issac
Télécharger la présentation

Workshop ADF BC pka BC4J 2 and 3 June 2005

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. Workshop ADF BC (pka BC4J) 2 and 3 June 2005

    3. ADF BC ADF BC : Business Components for Java (BC4J pre JDeveloper 10g) Doel: Communicatie Java Database (persistency) Implementatie Model Deployment locally of remote Business Rules Java Framework Library van classes Extensie mogelijkheden

    4. ADF BC Historie 1999, JDeveloper 2.0 Zie: http://radio.weblogs.com/0118231/stories/2005/02/25/historyOfJdeveloperReleases.html Java Business Objects (jbo) Client-server trekjes Events, view synchronisatie, 3-Tier apps Internet applicaties Pooling, Struts integratie Oracle Applications

    5. Architectuur ADF BC Applicatie

    6. Oracle 10g JDeveloper ADF Architecture

    7. Model-View-Controller

    8. Persistency Omzetting database Data naar objectvorm en vv Database communicatie vanuit Java: JDBC JDBC code Handmatig schrijven / genereren Voor elke insert, update, delete, select Voor elk object Correct omgaan met Connections, Statements, ResultSets Exception Handling

    9. Persistency public Dossier( Connection conn, int iDsrId) throws SQLException { this( iDsrId); StringBuffer sb = new StringBuffer(); sb.append("select dsr.dsr_name, "); sb.append("dsr.dsr_birthdate, dsr.dsr_instnumber, "); sb.append("dsr.dsr_creationdate, dsr.dsr_phase, "); sb.append("from dlt_dossiers dsr "); sb.append("where dsr.dsr_id = ?"); PreparedStatement sql = conn.prepareStatement(sb.toString()); try { sql.setInt(1 , this.id); ResultSet set = sql.executeQuery(); while ( set.next() ) { this.setName( set.getString(1) ); this.setGebDatum( set.getString(2) ); this.setInstNo( set.getString(3) ); this.setDossierDatum( set.getString(4) ); this.setFase( set.getInt(5) ); } } finally { set.close(); sql.close(); } }

    10. Persistency Winst: (net als bij andere frameworks als TopLink, Hibernate, JDO) Geen JDBC coderen Design-time checks (bijv op SQL syntax) Features van de API (bijv XML generatie) Locking management Optimalisaties Data Caching JDBC Statement hergebruik Prepared statements Update batching Integratie ADF Binding Framework Deployment locally/remotely

    11. Business Rules in ADF BC Voordeel: Centralisatie (verg database trigger) Herbruikbaarheid Nadeel: Alleen beschikbaar voor ADF BC applicaties Alternatief: Logica in database : centraal + Logica in POJOs : echt herbruikbaar ADF BC inzetten voor persistency

    12. ADF BC Objecten Bouwstenen van het Framework Library met Java classes Geconfigureerd d.m.v. XML files JDeveloper Tools: wizards & editors Runtime: Framework classes lezen XML Op te splitsen in 2 delen: Business Domain Data Model

    13. ADF BC Objecten Business Domain Entity Association Domain Representeren Data / Entiteiten / Business Objecten Staan los van applicaties Meest herbruikbaar, nl in verschillende applicaties. Logica / Business Rules op entiteit niveau

    14. ADF BC Objecten Data model ViewObject ViewLink ApplicationModule Datamodel voor een applicatie / applicatiedeel Gebaseerd op (subset van) entiteiten Minder generiek, dus minder herbruikbaar

    15. Samenhang ADF BC Objecten

    16. ADF BC Objecten Georganiseerd in package structuur bv nl.amis.urenregistratie.model.ADF BC Java files & XML Files Advies: Scheiden Business Domain <> Data Model Ondersteund vanaf JDeveloper 10g

    17. ADF BC Objecten EntityObject ~ Database Tabel / View Definieert Attributen van een entiteit Attributen hebben datatype: java Class Definieert dus mapping SQL Type Java Type Subclassen voor Business Logic Nodig bij modificatie data (insert, update, delete)

    18. Entity Entity Definition editor Aanpassen Naam, onderliggende Tabel Synchronisatie met Database Definitie Attributen Generatie Java Files NB: eenmaal gegenereerde files blijven op disk Base classes Declaratieve validatie rules Event mechanisme Properties (+custom)

    19. Entity

    20. Entity Attributen Persistent (checkbox persistent) Transient (tijdelijk, bijv tbv business logic) Column constraints

    21. Entity Attribute Type Mapping Zie JDeveloper Help: Developing Buss. Components, Buss.Components reference, Buss.Components Data Types

    22. ADF BC Objecten Association Definition Relatie tussen attributen van 2 entiteiten ~ Foreign Key FK is geen voorwaarde! 1:1, 1:n, m:n

    23. Association Relatie tussen 2 entities Source: Master - PK Destination: Detail FK Accessors in Entity Methods om bij andere kant te komen Source: accessor retourneert een RowIterator Destination: accessor retourneert een Entity

    24. Association Kan Compositie zijn: Bijv. Order - Orderregels On Cascade Delete Automatische invulling FK bij creatie detail

    25. ADF BC Objecten Domain Definition Java Class Datatype van een Attribuut bijv oracle.jbo.domain.Number, oracle.jbo.domain.BlobDomain Oracle object type kolom Validatie Bijv. url, e-mailaddress Custom domain class schrijven Dus herbruikbaar

    26. ADF BC Objecten ViewObject Definition Definieert (sub)set van attributen Gebaseerd op Entity 1 op 1 Obv meerdere entities Alle entities zijn updatable(?). Default alleen de 1e. SQL only Obv select statement

    27. ADF BC Objecten ViewObject Definition Attributen Obv Entity Attribuut (persistent, entity derived) Obv SQL (sql derived, select only) Geen van beiden (transient) Dynamic (created at runtime - addDynamicAttribute)

    28. ViewObject ViewObject definition editor Entity Objects (optioneel) Attribuut Definities Select statement Whereclause, Order By Expert mode Test (syntax check) & Execution plan Mapping Attributen op Database kolommen Java file generatie Tuning Properties (+custom)

    29. ViewObject

    30. ADF BC Objecten ViewLink Definition Relateert 2 views (master & detail) Koppeling tussen attributen Zorgt runtime voor synchronisatie detail tov master

    31. ViewLink ViewLink Definition Editor 2 Views waartussen link komt Attributen (1 of meer), of obv Association SQL voor join Cardinaliteit: 1:1, 1:n, m:n Accessors

    32. ADF BC Objecten ApplicationModule Definition Verzameling ViewObjects & ViewLinks Definieert Data Model voor een applicatie Aanspreekpunt voor applicatie Bevat connectie met Database (1 sessie) Configureerbaar; ondermeer: logging, pooling, type database,..

    33. Application Module ApplicationModule Editor ViewObjecten in DataModel Bevat instances: ViewObject kan meerdere malen worden gebruikt Elke instance heeft unieke naam ViewObject kan via ViewLink worden opgenomen Kunnen genest worden (bv modulen) Deployment (EJB SessionBean, Corba) Definitie Client methods Properties (+custom)

    34. Application Module

    35. Application Module Opsplitsen & nesten van Modules Logische groepering functies Duidelijker structuur Hergebruik ViewObject cache klein houden Alle gefetchte Data wordt gecached AppMod met veel ViewObjects => grote cache

    36. Configuration Deployment Mogelijkheden ADF BC App Local Remote Definitie: Rightclick op appmod

    37. ADF BC Objecten Aanmaken ADF BC objecten Entity generatie obv tabellen Entity obv UML design Kan ook andersom: Tabellen genereren obv Entity Definitions Advies: alleen voor POCs, hacks Productie systeem: Designer of vergelijkbaar tool

    38. ADF BC Tester ADF BC tester Testen van Business Components Onafhankelijk van andere onderdelen zoals UserInterface Runt de ApplicationModule (main method) Genereert UI voor alle ViewObjecten & ViewLinks in de ApplicationModule

    39. ADF BC XML files Bevatten definitie van de Objecten vastgelegd als xml Ingelezen door Framework classes @runtime In JDeveloper bewerkt dmv editors/wizards Niet met XML editor Wel nuttig om inhoud te kennen: Afhankelijkheden tussen files Source control Herstel bij fouten Refactoren

    40. ADF BC XML files 1 file per ADF BC Object: <objectname>.xml Definieert object bv ApplicationModule: welke ViewObjecten/links ViewObject: Attributen, ViewLink accessors Locatie: package directory 1 file per ADF BC package: <packagename>.xml Welke objecten bevat package Locatie: package directory

    41. ADF BC XML files 1 file per project: <projectname>.jpx Database connectie (designtime) Base classes (ivm extensies) Code generation opties (Java files / XML only) Locatie: project directory Configuratiefile: bc4j.xcfg Runtime configuratie (oa Database connectie) Wordt gegenereerd obv project settings Aanpassen na deployment Locatie: <appmods package>/common/bc4j.xcfg

    42. ADF BC API Programmatisch werken met ADF BC Applicaties die ADF BC gebruiken API: oracle.jbo en subpackages Coderen tegen Interfaces Alleen bij Local config: evt tegen Impls Startpunt: ApplicationModule (root) Vandaar: ViewObjecten

    43. ADF BC API Framework Interfaces oracle.jbo package ApplicationModule ViewObject Row RowSet RowIterator, RowSetIterator

    44. ADF BC API Belangrijkste taken: Verkrijgen ApplicationModule en retourneren ViewObject verkrijgen Query uitvoeren Rows fetchen Attribute values ophalen Insert, Update, Delete Transacties

    45. ADF BC API oracle.jbo.client.Configuration class ApplicationModule verkrijgen: static ApplicationModule createRootApplicationModule(String qualifiedAMDefName, String configName) Na gebruik teruggeven aan ADF BC: static void releaseRootApplicationModule( ApplicationModuleappModule, booleanremove)

    46. ADF BC API Viewobject verkrijgen: ApplicationModule Interface ViewObject findViewObject(StringvoName) Query uitvoeren ViewObject Interface void executeQuery();

    47. ADF BC API Rows fetchen: ViewObject methods: Boolean hasNext(); Row next(); Attributen opvragen Row method: getAttribute(String attributeName);

    48. ADF BC API Insert Methods op ViewObject Row createRow() void insertRow(Row) Update Fetch Row Call Row method setAttribute(String name, Object value) Delete Fetch Row Call Row method remove()

    49. ADF BC API Transactions ApplicationModule: public Transaction getTransaction() Transaction: commit() rollback() postChanges()

    50. ADF BC API Calling PL/SQL stored procedures getTransaction van ApplicationModule Cast naar DBTransaction createCallableStatement() method Verder als bij JDBC

    51. ADF BC API Andere common operaties Filteren / zoeken Detail rows benaderen Sorteren Dynamische (runtime) query opbouw

    52. ADF BC API XML Genereer XML mbv WriteXML method op ViewObject

    53. ADF BC API opgaven Vragen? Opgaven Gebruik ADF BC JavaDoc (JDeveloper Help)

    54. Quiz Waar vind je welke method De voornaamste classes and interfaces Configuration ApplicationModule ViewObject RowSet (RowSet)Iterator Row Waar vind je deze methodes findViewObject() getRootApplicationModule() next() getAttributeDefs() getAttribute() getTransaction().commit() executeQuery() getViewObjectNames() setRangeSize() writeXML() getName() remove()

    55. Demo/Recapitulatie Preparation Create Workspace Create Project Create Database Connection Setup Business Service Create Business Components from Tables Set package name, application module name Select Tables and Views Indicate 1:1 mapped ViewObjects (updateable and read only) Add constraints, associations and viewlinks Refine ViewObjects with calculated and transient attributes Add ViewObjectInstances to application module

    56. Demo/Recapitulatie (2) Testing the Business Service Run the Application Module Tester and browse ViewObjectInstances Programmatic Access Get hold of ApplicationModule from Configuration Using fully qualified name: nl.amis.hrm.HrmService Using Configuration Name: HrmServiceLocal Get hold of ViewObject from ApplicationModule: findViewObject( viewObjectInstanceName) Refine Query bind parameter values, order by clause, additional where clause Execute Query Iterate through results Use attribute values

    57. Additional ViewObject concepts and features Result of Query is (held in) a RowSet vo.getRowSet() This (default) RowSet is refreshed whenever query is executed A ViewObject can have multiple (named) RowSets, that can coexist RowSet rsA = vo.createRowSet(a); rsA.executeQuery(); RowSet rsB = vo.createRowSet(b); rsB.executeQuery(); Multiple resultsets, alive simultaneously

    58. Additional ViewObject concepts and features RowSets allow for page-wise scrolling These methods are available on ViewObject and RowSet interface vo.setRangeSize(int) vo.scrollRange(int) vo.getPreviousRangeSet() getNextRangeSet() vo.getRangeIndexOfRow(Row) vo.getRowCountInRange() Handy for Web Applications that want to display Google-style result pages page 4, 40-49 of approximately 10.000.002 results

    59. Additional ViewObject concepts and features ViewObject (and Row) can write data as XML Using the org.w3c.dom.Node writeXML() method Multiple levels detail traversal based on ViewLinks Example: vo.executeQuery(); Node n = vo.writeXML(0,XMLInterface.XML_OPT_ALL_ROWS); Document d = n.getOwnerDocument(); n = ((XMLDocument)d).adoptNode(n); d.appendChild(n); try { File xmlFile = new File("c:/temp/emps.xml"); OutputStream out = new FileOutputStream(xmlFile); ((XMLDocument)d).print(out); } catch (Exception e){}

    60. AMIS Addins for JDeveloper and ADF BC Developed against JDeveloper API Configured through addin mechanism Published on JDeveloper addin exchange on OTN Extended Copy ViewObjects Including attributes and properties Including ViewLinks Force Delete ViewObjects Including attributes Including ViewLinks Including ApplicationModule ViewObject Instances (in Data Model)

    61. Data Manipulatie via ADF BC Time to create, update or delete rows through ADF BC Look at locking policy and transaction control At ApplicationModule level Pessimistic Locking = acquire lock when first setter is called on ViewObject Oracle Forms style Optimistic Locking = acquire lock when record is posted Verify whether records in database is changed compared to data in EntityObject cache

    62. ADF BC API Insert Methods op ViewObject Row createRow() void insertRow(Row) Update Fetch Row Call Row method setAttribute(String name, Object value) Delete Fetch Row Call Row method remove()

    63. ADF BC API Transactions ApplicationModule: public Transaction getTransaction() Transaction: commit() rollback() postChanges()

    64. ADF BC API Calling PL/SQL stored procedures getTransaction van ApplicationModule Cast naar DBTransaction createCallableStatement() method Verder als bij JDBC

    65. Framework extension Subclassen van de framework classes Doelen Business Logic Applicatie Logica, service methods Typesafety

    66. Framework extension Base classes oracle.jbo.server package EntityImpl entity row EntityDefImpl entity definitie ViewObjectImpl query (definitie + resultset) ViewRowImpl result record ViewDefImpl ApplicationModuleImpl ApplicationModuleDefImpl

    67. Framework extension EntityImpl Meest gangbaar Methods voor create, update, delete van rows Stored Procedures voor DML Business Logic op row level Bijv in setter method EntityDefImpl Methods om Entity definitie te modificeren Bijv attributen toevoegen, verwijderen

    68. Framework extension ViewObjectImpl Toevoegen methods die specifiek zijn voor query resultaat ViewObject + logica herbruikbaar in meerdere ApplicationModules ViewRowImpl Logica die specifiek is voor een row Bijv. getter voor afgeleid attribuut

    69. Framework extension ApplicationModuleImpl Toevoegen Servicemethods ~ faade voor module Voor aanroep vanuit client: custom Interface maken

    70. Framework extension Specifieke subclass Logica specifiek voor een bepaald object Bv: CountriesImpl extends EntityImpl Generieke subclass Logica gedeeld door meerdere objecten Bv: AmisEntityImpl extends EntityImpl + CountriesImpl extends AmisEntityImpl Definitie: Globaal in JDeveloper Preferences Per project in JPX file / editor Per Object in Object editor

    71. Framework Extension Client Interfaces

    72. Business Logic Business Logic in ADF BC Al een aantal gerelateerde zaken gezien: Extension points als EntityImpl Validatie Domains Welke logic zet je waar ? Wanneer logic triggeren?

    73. Business Logic Entity Attribuut validatie Validation Rules Validation Domain Setter method

    74. Business Logic Validation Rules Declaratief koppelen aan attribuut (Entity Object editor) Standaard rules CompareValidator ListValidator RangeValidator MethodValidator Custom Rule Implement oracle.jbo.server.rules.JbiValidator public boolean validateValue(java.lang.Objectvalue) Registreren in project

    75. Business Logic Validation dmv Domain Herbruikbaar voor meerdere entities Bijv email adres in Employees Attribuut is String; vervangen door email domain Custom class In JDev: Template dmv new Domain Implementeer logic in validate() method Throw JboException indien invalid

    76. Business Logic Setter method Gecodeerd in de EntityImpl subclass, dus Kan bij andere attributen via getters Kan bij andere entities via accessors Indien invalid, throw JboException

    77. Business Logic Setter method Hoe public void setCountryName(String newName) { if (Germany.equals(newName) ) { throw new NoKrautsException(); } else { setAttributeInternal(COUNTRYNAME, value); } } En als je via setAttribute() gaat ?? Roept setter aan (indien die bestaat)

    78. Business Logic Volgorde: Domain validate() Setter method, Validation Rules Logisch: eerst wordt waarde in een domain geplaats, dan aan setter doorgegeven Setter roept setAttributeInternal aan Die roept validatie rules aan

    79. Business Logic Entity level validation Row-level check Validation Rule MethodValidator UniqueKeyValidator Custom Rule: Implement JbiValidator Lastig herbruikbaar voor meerdere entities Override EntityImpls validateEntity() Call super!

    80. Business Logic Entity level validation Compositions Bij wijziging in deel van een Compositie worden alle sources (masters) gemarkeerd voor validatie Bij uitvoer validateEntity method worden alle destinations (details) gevalideerd.

    81. Business Logic Default values Entity attribute: fixed value voor alle instances EntityImpl create() method: dynamische value Call super.create() !

    82. Business Logic Interactie met Database Logic Sequence Refresh after insert Kolom obv sequence in trigger DBSequence domain Idem, maar tijdelijke unique value SequenceImpl fetch value van sequence Verliest waarde bij rollback Afgeleide kolommen Triggers, defaults refresh after insert/update

    83. Performance Performance tuning Tuning opties in ADF BC Object editors Entity: Update batching ViewObject: Fetchsize setForwardOnly method (schakelt VO-cache uit) Altijd gebruiken voor readonly Hints op query

    84. Performance ViewLinks / Associations: FK is geen voorwaarde Leg wel index op join kolommen!

    85. Pooling ApplicationModule Pooling Connection Pooling Waarom poolen: Creatie kost tijd Geen dedicated AppMod / Connectie per user Kan meer users bedienen met 1 Connectie / ApplicationModule Mag dan geen state vasthouden Of moet state herstellen (bijv database context, VPD)

    86. Pooling ApplicationModule Pooling State ? ViewObject caches, whereclauses, pending changes, etc Statefull Mode Affiniteit met usersession AppMod recycling Stateless Mode State reset, rollback op connectie Details & configuratie: http://www.oracle.com/technology/products/jdev/tips/muench/ampooling/index.html

    87. ADF BC Vragen ? Opgaven

    88. Resources JDeveloper Help Tutorials (JDev 9.0.4 in 10g zijn ze verdwenen) JDeveloper 9i / 10g Handbook OTN JDeveloper site JDeveloper Forum Blogs Steve Muench - http://radio.weblogs.com/0118231/

More Related