+ All Categories
Home > Documents > Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Date post: 26-Dec-2015
Category:
Upload: amber-ellis
View: 217 times
Download: 0 times
Share this document with a friend
Popular Tags:
60
Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?
Transcript
Page 1: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Avrom Roy-FadermanSenior Instructor and Programmer

February 19, 2008

Whither Business Logic?Whither Business Logic?

Page 2: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

About MeAbout Me

• Former member of Oracle JDeveloper/ADF

teams

• Eight years’ experience with JDeveloper

and ADF

• Co-author of JDeveloper Handbooks– 9i

– 10g

– 11g (coming soon)

[email protected]

Page 3: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

AgendaAgenda

• The Options

• Business Logic in the Database

• Business Logic in the Middle Tier

• Business Logic on the Client

• Business Logic in Multiple Places

• Summary and Q&A

Page 4: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The ProblemThe Problem

• Implementing business logic for J2EE

applications– Validation logic and calculation logic

• Business logic can be put multiple places

• Many people don’t know where to start– Often go by biases based on comfort level

– Comfort level important but not everything

Page 5: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The OptionsThe Options

• The Database

• The Middle Tier– Model layer

– Controller layer

• The Client

Page 6: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The TradeoffsThe Tradeoffs

• Comfort level

• Robustness and Security

• Responsiveness

• Server Load vs. Client Load

• Maintenance Effort

Page 7: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

AgendaAgenda

• The Options

• Business Logic in the Database

• Business Logic in the Middle Tier

• Business Logic on the Client

• Business Logic in Multiple Places

• Summary and Q&A

Page 8: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the DatabaseBusiness Logic in the Database

• Intro

• PPR

• Integration with the Application

• To JDBC or not to JDBC?

Page 9: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The DatabaseThe Database

• Implemented in constraints or triggers

• Runs in the database

• Language: PL/SQL– Or procedural language supported by other DB

Page 10: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The Database: AdvantagesThe Database: Advantages

• Language: PL/SQL (?)

• Most robust and secure option

• Good for business logic relying on large

amounts of data

• Easy maintenance and reuse

Page 11: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The Database: ProblemsThe Database: Problems

• Language: PL/SQL (?)

• Requires Internet round-trip– PPR may mitigate

• Requires posting of data

• Integrating with J2EE applications not

trivial

Page 12: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the DatabaseBusiness Logic in the Database

• Intro

• PPR

• Integration with the Application

• To JDBC or not to JDBC?

Page 13: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

PPRPPR

• Short for “Partial Page Refresh”

• AJAX technology

• Reduces the time and interruption required

by internet round-trips

Page 14: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Ordinary Form CycleOrdinary Form Cycle

User clicks Submit button

Form data sent to server

Server validates/ calculates

Server re-creates page

Server sends page to browser

Browser re-renders page

User responds

Page 15: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

PPR CyclePPR Cycle

User uses a control

Form data sent to server

Server validates/ calculates

Server re-creates some controls

Server sends controls to browser

Browser replaces controls in page

User responds

Page 16: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

PPR LimitationsPPR Limitations

• Still requires a round trip– Latency

– Processing time on server

• Shouldn’t invoke PPR constantly

Page 17: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the DatabaseBusiness Logic in the Database

• Intro

• PPR

• Integration with the Application

• To JDBC or not to JDBC?

Page 18: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Integrating with Calculation LogicIntegrating with Calculation Logic

• “Refresh on Insert” and “Refresh on

Update”

• DBSequence Domain– Temporary sequence number

– Always refreshes on insert

– Watch out for foreign key relationships!

Page 19: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Integrating with Validation LogicIntegrating with Validation Logic

• ADF has no automatic way to integrate DB

error messages in a user-friendly fashion

• Default way– Ugly

– Possibly not secure

• Requires some changes to DB-side error

messages for best results

• Requires Java Framework Code

Page 20: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Error DesiderataError Desiderata

• Cleanly displayed global error messages

• Linked and flagged field-specific error

messages

Page 21: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

DB-Side Error Message ChangesDB-Side Error Message Changes

• Required for linking/flagging field-specific

messages

• Need a machine-readable way to identify

relevant columns

[COMMISSION_PCT][JOB_ID]Commissionmust be zero for non-sales employees

Page 22: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Java FrameworkJava Framework

• Custom entity object class– Override doDML() to catch SQLExceptions

• Custom code create exceptions– Parse error messages– Create exceptions based on them

• Custom exception class for column-level errors– Store error message– Store column information

Page 23: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Java FrameworkJava Framework

• Custom exception class– Marshal the individual exceptions

• Custom error handler– Unmarshal the exceptions– Find controls corresponding to column

information– Create appropriate FacesMessage objects

Page 24: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the DatabaseBusiness Logic in the Database

• Intro

• PPR

• Integration with the Application

• To JDBC or not to JDBC?

Page 25: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Does the Extra DB Hit Slow you Down?Does the Extra DB Hit Slow you Down?

• Yes, in general– DB connectivity is pretty fast, but in a large-

scale application, any network hit hurts

• No, in some cases– Auto-commit requires DB hit after every request

anyway

– Consider delaying DB validation/recalculation to

times when you already need to post

Page 26: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

AgendaAgenda

• The Options

• Business Logic in the Database

• Business Logic in the Middle Tier

• Business Logic on the Client

• Business Logic in Multiple Places

• Summary and Q&A

Page 27: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the Middle TierBusiness Logic in the Middle Tier

• Intro

• Business Logic in the Model

• Business Logic in the Controller

Page 28: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The Middle TierThe Middle Tier

• Implemented in the web application– Business components (model)

– JSF Controller

• Runs on the application server

• Language: Java, with some declarative

XML support

Page 29: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The Middle Tier: AdvantagesThe Middle Tier: Advantages

• Language: Java (?)– Get to use JDeveloper’s great toolset

• Integration with ADF very easy

• Reasonably robust and secure

• Maintenance and reuse within an

application easy

• No JDBC hits

Page 30: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The Middle Tier: ProblemsThe Middle Tier: Problems

• Language: Java (?)

• Not quite as robust as DB

• Questionable for business logic relying on large

amounts of data

• Requires Internet round-trip– PPR may mitigate

– Some special PPR problems

• Currently, maintaining across applications a bit

of a pain– JDeveloper 11g should mitigate this issue

Page 31: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the Middle TierBusiness Logic in the Middle Tier

• Intro

• Business Logic in the Model

• Business Logic in the Controller

Page 32: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the ModelBusiness Logic in the Model

• Traditional location for business logic in

MVC architecture

• Most commonly ADF Business Components

• Some logic can be implemented

declaratively

• More complex logic requires Java coding– JDeveloper 11g will allow complex logic via

“Groovy” expression language

Page 33: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

PPR and the ModelPPR and the Model

• WARNING: By default, all application

business logic will be executed on any

form submission

• This includes PPR

• This may not be desired behavior

• Should be fixed in Jdeveloper 11g

Page 34: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Stopping PPR ValidationStopping PPR Validation

• Custom page lifecycle

• Block validateModelUpdates() for PPR

public void validateModelUpdates( LifecycleContext lctx) { FacesContext fctx = FacesContext.getCurrentInstance(); if (! PartialPageUtils.isPartialRequest(fctx)) { super.validateModelUpdates(lctx); }}

Non-public API

Page 35: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the Middle TierBusiness Logic in the Middle Tier

• Intro

• Business Logic in the Model

• Business Logic in the Controller

Page 36: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the ControllerBusiness Logic in the Controller

• Not traditional location in MVC architecture– But validators are part of JavaServer Faces

standard

• Jdeveloper supplies default “ADF Faces

Validators”– Ranges

– Date/Time

– Regular Expression

• Can write and register your own

Page 37: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

PPR and the ControllerPPR and the Controller

• All business logic will be executed on any

form submission, including PPR

• This is not part of validateModelUpdates()

and so cannot be blocked easily

• Can be useful– If you need some, but not all, validation to fire

on PPR

– Combine with (blocked on PPR) model validation

Page 38: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

AgendaAgenda

• The Options

• Business Logic in the Database

• Business Logic in the Middle Tier

• Business Logic on the Client

• Business Logic in Multiple Places

• Summary and Q&A

Page 39: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the Client TierBusiness Logic in the Client Tier

• Intro

• Client-Side Calculation

• Client-Side Validation

• Javascript and Data

Page 40: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The Client TierThe Client Tier

• Implemented in the web application

• Runs in the browser

• Language: Javascript

Page 41: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The Client Tier: AdvantagesThe Client Tier: Advantages

• Language: Javascript (?)

• Very high interactivity and responsiveness

• No network round trips of any kind

• Offloads processing to the client machine

Page 42: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

The Client Tier: ProblemsThe Client Tier: Problems

• Language: Javascript (?)– Poor development tools

– At best so-so debugging tools

• Any moderately competent hacker can

circumvent

• Bad for business rules relying on large

amounts of data

• No easy way to share across applications

Page 43: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the Client TierBusiness Logic in the Client Tier

• Intro

• Client-Side Calculation

• Client-Side Validation

• Javascript and Data

Page 44: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Javascript HandlersJavascript Handlers

• ADF Faces components include standard

Javascript handlers, which show up in the

generated HTML– onchange

– onclick

– onkeypress

– etc.

• These can contain inline code or call

Javascript functions

Page 45: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Know Your DOMKnow Your DOM

• “Domain Object Model”

• Allows you to easily work with any HTML

element– Change element attributes or contained HTML

– Find elements by ID, as opposed to “find a form

and get its controls by name” method

– This includes, e.g., links and <SPAN> tags

generated by <af:outputText>

Page 46: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the Client TierBusiness Logic in the Client Tier

• Intro

• Client-Side Calculation

• Client-Side Validation

• Javascript and Data

Page 47: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Javascript Handlers and ADFJavascript Handlers and ADF

• Traditional validation with Javascript

Handlers– Return “false” on failed validation

– This blocks the normal operation of the

component

• This is unreliable in ADF

Page 48: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Client-Side ValidatorsClient-Side Validators

• ADF Faces validators come with “client

side” version– This is a Java class that returns Javascript code

from a method, getClientScript()

– The Javascript is downloaded with the page

• You can create a client-side version of a

custom validator

• These fire on submit, but instantly

Page 49: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Client-Side Validators and PPRClient-Side Validators and PPR

• Client-side validators will fire on PPR

• No way to turn this off without disabling

client-side validation altogether

• Put completeness checks in the Javascript

returned by getClientScript()

Page 50: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Business Logic in the Client TierBusiness Logic in the Client Tier

• Intro

• Client-Side Calculation

• Client-Side Validation

• Javascript and Data

Page 51: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Javascript and Data: StaticJavascript and Data: Static

• Assemble data on the server– Create Javascript arrays and tables

– Or use <af:inputHidden> objects to create

hidden fields in the HTML

• Refer to it from your Javascript code

• Not appropriate for large amounts of data– May be mitigated for midsize amounts in 11g

Page 52: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Javascript and Data: DynamicJavascript and Data: Dynamic

• Create a web service exposing your data

• Access the web service from the page

using, e.g., SOAP

• A little faster than PPR– No reconstruction of components on server

– Less data to transfer

– Can be made asynchronous

– Still has latency issues, though

Page 53: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

AgendaAgenda

• The Options

• Business Logic in the Database

• Business Logic in the Middle Tier

• Business Logic on the Client

• Business Logic in Multiple Places

• Summary and Q&A

Page 54: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Dividing Business LogicDividing Business Logic

• “Break-your-business” logic must run

server-side– Database for most security

– In the application if security vs. saving Database

access worthwhile

• Convenience-only logic can go in

Javascript

• For highest interactivity, all logic should

run in Javascript unless impractical

Page 55: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Maintenance: ADF Faces ValidatorsMaintenance: ADF Faces Validators

• For validation only

• Still need to be maintained in separate

files– Files closely related

– Usually one developer can be in charge of both

• You may not need PPR

Page 56: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Maintenance: Single-SourcingMaintenance: Single-Sourcing

• Store Javascript in the DB

• Generate from declaratively expressed

business rules– Triggers

– Javascript

• A lot of trouble up front– Not easy to find engines that generate Javascript

– Not worth it for a few mid-sized web applications

Page 57: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

AgendaAgenda

• The Options

• Business Logic in the Database

• Business Logic in the Middle Tier

• Business Logic on the Client

• Business Logic in Multiple Places

• Summary and Q&A

Page 58: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

SummarySummary

• Using the DB is most secure– Integration not automatic

– Lots of network trips; PPR may mitigate

• Using the middle tier almost as secure– May (or may not) save DB hits

• Using the client tier is most interactive– Not a secure method of enforcement

• Consider doubling up if you can solve the

maintenance issues

Page 59: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

Q&AQ&A

Page 60: Avrom Roy-Faderman Senior Instructor and Programmer February 19, 2008 Whither Business Logic?

About QuoveraAbout Quovera

• Books co-authored with Peter Koletzke and Dr. Paul Dorsey

ORACLE9iJdeveloperHandbook

Also co-authoredwith Duncan

Mills

OracleJdeveloper 10gHandbook

OracleJdeveloper 11gHandbook

Comingsoon

• www.quovera.com• Founded in 1995 as Millennia Vision

Corp.• Strong High-Tech industry background

• 200+ clients/300+ projects• Oracle Partner

• More technical white papers and presentations on the web site


Recommended