naam adf development more tales from the trenches aino andriessen amis services

117
NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Post on 21-Dec-2015

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

NAAM

ADF DevelopmentMore tales from the

trenchesAino Andriessen

AMIS Services

Page 2: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• Systems integrator• Co-sourcing• Maintenance• Oracle, Java, Open Source, ADF, DBA, SOA• AMIS technology school• Pagoni

• http://www.amis.nl• http://technology.amis.nl/blog/

Page 3: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Aino Andriessen• Technical Consultant• Technical Architect• Java, ADF, PL/SQL, XML, ...• SOA , Integration• Software engineering• Quality management• Agile development

[email protected]• http://www.fttech.net

Page 4: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 5: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 6: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 7: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 8: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Stakeholders

customer

project lead

maintenancedeveloper

Page 9: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

better according to... Customer

Page 10: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

better according to... Project lead

Page 11: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

better according to... Developer

Page 12: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

better according to... Maintenance

Page 13: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

better according to... Girlfriend

Page 14: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• How can we make better ADF applications?

Page 15: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 16: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

5 essentials

• Communication• Responsibility• Knowledge• Organization• Fun

Page 17: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• Let's start coding...

Page 18: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• Sorry, not yet...

Page 19: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Organization...• Project• Development process• Skills• Project structure (file structure)• Code• Design and Architecture• Documentation• Communication• Infrastructure

Page 20: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 21: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 22: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Delivery environments

Library

Developer2Developer

2

Custom

Production

Developer2Developer

Source control

CorporateLibrary

Build automation

Test

Documentationsite

Development

Issue management

Tests

Inspection

Public Library

Reports

Documentation

Issue reports

Acceptance

Integration

Page 23: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• Can we now start coding?

Page 24: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• Almost...

Page 25: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Development principles

Page 26: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 27: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 28: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 29: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 30: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 31: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• OK, wake up and let's get to business...

Page 32: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• Build an ADF - JHeadstart application• Address common and not so common issues• ADF 10g

– Some 11g

Page 33: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Demo

• Regatta Management System

• Application to support sailing regatta's. – maintain regatta's– registration– enter racing data– results

Page 34: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Development Goal

• Match implementation against stakeholders' concerns :– Functional– Maintainable– Stable– Budget– Organized– Fun– . . .

Page 35: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 36: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Business Logic implementation• Business Logic can be implemented at many locations

– ADF Faces components• Managed beans• Backing beans• EL-expressions• Attributes

– Service methods– VO's

• Attributes : transient, calculated• Methods

– Entities• Attributes• Validators

– Database• Constraints• Views• Stored procedures

– ...

Page 37: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

The (ADF) challenge

• Consistent and comprehensible implementation of business logic.

Page 38: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 39: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

FD• Requirements

– Maintain regatta information– Allow sailors / boats to enter a regatta.

• Register skipper and captain (owner) with some personal details– Schedule racings– Easy registration of race details, only by certain people– Publish results– Nice look and feel– Easy to use– Handle handicap system

• Business rules– Participant, skipper, must be older than 18– Same boat may enter only once– Finishtime after starttime– Participant can have only one result– It should be able to reset the finish of a participants, in case of error– Register if the boat didn't start or finish, using the common codes like DNF, DNS, DSQ etc.

• Extra information about this situation must be entered– Races cannot be scheduled at the same time

Page 40: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Functions / Use cases

• Maintain regatta's• Register for a regatta• Enter racing data• Publish results• Supportive functions

Page 41: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 42: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

ADF 'architecture'

• ADF applications tend to evolve instead of being designed.– Viewobjects are created when needed– Managed beans are created as needed– Application Modules function merely as a service-hatch

• ADF doesn't force you into an organized application, except maybe the model and viewController.

• ADF offers multiple solutions for the same problem and in the end all of them will eventually appear in the application.

Page 43: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

ADF architecture

Database

ADF Faces

ADF model (binding)

ADF BC

Page 44: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

ADF architecture

Database

ADF Faces

ADF model (binding)

ADF BC

Managed beans

Application Modules

ViewObjects

EntitiesObjects

ViewsStored Procedures

Tables

Page 45: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Application Integration

ADF Application

DatabaseWebservices

Files Messaging

Notification

Page 46: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 47: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Function / Use Case approach

• The application module, the service, is the core of the application

• Each function / use case is implemented as a service.

• Services can be nested

Page 48: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

ADF architecture

Database

ADF Faces

ADF model (binding)

ADF BC

Webservices

Webservices

Files Messaging

Notification

Service Service Service Service Service

Page 49: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 50: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

RMS Services

Page 51: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 52: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Datamodel

Page 53: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Datamodel 2

• Views– 1 : 1 on tables : vpd, – complex queries

• Stored procedures• app_owner and app_user

Page 54: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Development

Page 55: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 56: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Development environment

• JDeveloper 10g 10.1.3.4• JHeadstart 10g 10.1.3.3• Oracle 11g R1• OC4J 10.1.3.4• Maven 2.1• Subversion 1.5

Page 57: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

JDeveloper Setup• External tools

• Encoding UTF-8– Preferences -> Environment

• Upgrade JDev svn client to 1.5– http://technology.amis.nl/blog/5253/upgrade-jdeveloper-

10g-subversion-client

Page 58: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

JDeveloper

• Organize imports• Define .vm as text file

– preferences -> filetypes

• Default editors : source– preferences -> filetypes

Page 59: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 60: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Project setup

Page 61: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Projects

common General code, Baseclasses

Reusable's

database Database code, scripts

deployment (automated) Deploy to iAS

ear Build deliverable, ear

model ADF BC's

viewController UI

ADF Faces

lib 'External' libraries

Page 62: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Maven conventions - code

Page 63: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Maven conventions - unittests

Page 64: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 65: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 66: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

General

• SRDemo• JHeadstart framework• Weblogs• Documentation

– Developer’s Guide For Forms/4GL Developers

• Simple Emp reference project

Page 67: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

BC Creation

Page 68: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Default - create BC's from table

Page 69: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Default - create BC's from table

Page 70: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

BC creation

1. Services2. Entities3. Associations4. Viewobjects5. Viewlinks6. VO usages

• Apply naming conventions– Refactor if needed

• Organize, organize, organize

Page 71: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Create Entities

• Create Business components from table– Refactor associations

• Base on table, change later to database view

Page 72: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Edit entities

• Set Id from sequence

– DBSequence is a nightmare to refactor

• Control Hints

– Enter once, use often

Page 73: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Associations

• Association properties– apply correct plural and singular

• Define Composition Association– Developer’s Guide For Forms/4GL

Developers - Chapter 6.3.3

Page 74: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 75: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Business rulesBR Implementation

Participant, skipper, must be older than 18

Same boat may enter only once

Finishtime after starttime

Participant can have only one result

It should be able to reset the finish of a participants, in case of error

Register if the boat didn't start or finish, using the common codes like DNF, DNS, DSQ etc.

Extra information about this situation must be entered

Races cannot be scheduled at the same time

A boat either has a finishtime or a special situation

Entity validation

FE or DB or 'complex' entity

Unique key

FE function

Datamodel, domain

FE, mandatory dependency

Unique key?

Row validation

Unique key

Page 76: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Entity Business Rules• Mandatory, PK, UK• Validation

– Declarative– Method– Rules

• Declare in project properties– Very Reusable

• [Entity constraint]– NO validation– Only present for creating table from entity

Page 77: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Validators / Rules

• Create Registered Rule in project properties– Or reuse an existing one

• Implement code in validateValue method

Page 78: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Validators

• Select the Rule as attribute validation• Test

Page 79: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Entity Validation - remarks• The setter immediate triggers the validation

– actually the setAttributeInternal(...)• Validations are executed top to bottom• Row validation is performed 'independent' of attribute validation.• Declarative Date validators are limited

– Use Validators• Using a select statement for validation is very limited (if it works at

all)– Avoid it.

• Consider Validator when the same validation is entered multiple times.

• Validator exception msg not published to the front-end (as we'll see later)

Page 80: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

(J)Unittesting Entities

• Create Application Module :

• Create entity :

import oracle.jbo.client.Configuration;

RegistrationServiceImpl _am;

public void setUp() { _am = Configuration.createRootApplicationModule ("nl.amis.demo.rms.model.services.RegistrationService" ,"RegistrationServiceLocalURL");}public void tearDown () { Configuration.releaseRootApplicationModule(_am, true);}

EntityDefImpl empdef = (EntityDefImpl)EntityDefImpl.findDefObject ("nl.amis.demo.rms.model.entities.CrewMember");

crewMember = (CrewMemberImpl)empdef.createInstance2 (_am.getDBTransaction(), null);

Page 81: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• Execute test :Date testDate = (Date)Date.getCurrentDate();try { crewMember.setBirthdate(testDate); fail();}catch (Exception e) { e.printStackTrace();}

testDate = (Date)testDate.addMonths(-12*20);try { crewMember.setBirthdate(testDate);}catch (Exception e) { fail(); e.printStackTrace();}

Page 82: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Unit-testing

↑ code control ↑ code quality↓ development time

• 'Automatic' regression test• TDD improves the testability of your code• Unit-testing increases your ADF skills• Easy debugging of BC's• Automated execution at continuous integration

Page 83: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Unittest framework

• TestBase per application module– provide ServiceImpl

• Utility methods– Create entity

• Standardization– Authorization– Context

Page 84: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

I don't write unittests because it takes too much time

Gee, How long does that take?

Then, how do you test your code?

I'll start the application, login, navigate to the right screen and then perform the correct actions?

Page 85: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 86: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

VO Remarks• Often screen, Use Case driven• Organize

– the number may increase rapidly– Separate list-only VO's

• Apply naming conventions– plural– Lkp– Trnsnt– ...By...

• Don't use 'automatic BC creation from database'– Unless you like refactoring...

Page 87: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

VO remarks

• Calculated attributes are not updated automatically, but need a requery– This may often result in complex code

Page 88: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Domain driven logic

• NoFinishCode– DSQ, DNF, DNS

• define constants or enum

• IsXXX attributes

Page 89: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

VO client interface methods

• Implement VO related functions– startRace()– disqualifyParticipant()– ..

• Maybe also published as Service interface method

• Beware with nested applicationmodules to bind the correct method– or else the getCurrentRow does not work– NB, bindings work ok

Page 90: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Bindings and Nested AM

Page 91: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Viewobject validation

• Override validate() method• setter method• throw JboException

– define your own

Page 92: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

View object usages

• Naming conventions• Organize them in services

Page 93: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Unittesting VO's (Usages)

• Basic test– executeQuery

• Business Logic• Beware of detail VO's

– they are direct available on the AM, but relate to their parent

Page 94: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Programmatic viewobjects

• e.g. for Webservice clients• See Developer’s Guide For Forms/4GL Developers -

Chapter 9 • JhsProgrammaticViewObject

– getJhsProgrammaticResultSet• ! Executed many times

– Override executeQuery() to actually retrieve data– Store result in JhsProgrammaticResultSet class variable– Convert using JhsProgrammaticHelper.convertBean

• Match attributes with ws return object

Page 95: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 96: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Re-use• Bases classes• Validators• Unittest utilities• Date handling• ADF Binding (model) methods

– SRDemo : JSFUtils and ADFUtils• JHeadstart templates• Business Components• Task flows• Beans• Converters• Filters• ...

Page 97: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Organize Re-use

• Separate projects, libraries, and owners• Review / audit criteria

Page 98: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Reuse BC's

• Separate project• Create deliverable• Add jar to project• Import jar

• Beware, sharing database connection from root application module

Page 99: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 100: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Refactoring BC's

• http://technology.amis.nl/blog/2859/fear-for-renaming-refactoring-adf-bc-objects-in-jdeveloper-is-not-unfounded

• Renaming and moving BC's is handled quite well.• Bindings are not automatically adjusted• JHeadstart is not automatically updated

– Generation errors– Just reselect the attribute / group

• Try to be strongly typed

Page 101: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Refactoring remarks

• Matching subversion clients• Refactoring DBSequence attributes is a pain...• ADF does not always allow you to refactor, in

case of dependencies.• Validator

– Re-registration of the Rule

• Beware of static 'dependencies' in the JHeadstart templates

Page 102: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 103: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

JHeadstart

• One application definition vs. multiple– Can merge and split quite easily– 11g support for multiple improved

• JHeadstart supports nested application modules• Apply standards and naming conventions• Configuration

– tools -> preferences• e.g. item prompt

– AppDef root node• AM superclass

Page 104: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Custom Templates

• Application hierarchy matches the default• Documentation of templates• Try to avoid hard-coded bindings

– difficult to refactor– custom properties

• Buttons can be generated – however, the binding is not

Page 105: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Common recommendations

• Understand the framework• Avoid 'bindings', use a managed bean and

dependencies• Custom bindings : Disable 'Clear Page

Definition'• Close pagedefs before generation

Page 106: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 107: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Date and time

• Using Java Date and Calendar and oracle.jbo.domain.Date and Timestamp can be tricky– new oracle.jbo.domain.Date() ?

– new oracle.jbo.domain.Timestamp() ?

– Date.getCurrentDate() ?

– ((Date)Date.getCurrentDate()).timestampValue

• actually java.sql.Timestamp

• Current time?

Page 108: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Date and time - Calendar

Calendar c = Calendar.getInstance();

oracle.jbo.domain.Timestamp ts =

new Timestamp(c.getTime());

Timestamp ts =

new Timestamp(c. getTimeInMillis());

c.set(Calendar.HOUR_OF_DAY,5)

Page 109: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Date Time - JodaTimeDateTime dt = new DateTime();Timestamp ts = new Timestamp(dt.getMillis());

DateTime dt=new Da dt.getHourOfDay(); dt.plusMinutes(10); dt.minusWeeks(5); dt.isAfter(dt2); dt.isBefore(dt2); dt.isBeforeNow();teTime(2009,6,14,13,0,0,0)

Page 110: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Search Programmatic viewobject

• Standard JHeadstart Search – Allows searching using the VO attributes– Creates 'SQL formatted' ViewCriteria

• oracle.jheadstart.model.QueryCondition• unusable for Programmatic viewobject

1. Somehow retrieve actual data from viewcriteria1. Strip the formatting

2. Provide the actual value1. e.g. via the oracle.jheadstart.model.QueryCondition2. Override JhsApplicationModuleImpl.advancedSearch()

Page 111: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

Store search criteria• On login requery the latest search

• Extend JhsSearchBean• Override advancedSearch()

– Serialize the criteria to file– Use the userId as name for the file

• Constructor– Retrieve the criteria from file

Page 112: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 113: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 114: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 115: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 116: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services
Page 117: NAAM ADF Development More tales from the trenches Aino Andriessen AMIS Services

• http://groups.google.com/group/adf-methodology