59
Jaime Chavarriaga William Lovaton Universidad San Buenaventura - Coomeva EPS (Colombia) Enterprise Software Development using Oracle and Oracle Jaime Chavarriaga William Lovaton

Jaime Chavarriaga William Lovaton Universidad San Buenaventura - Coomeva EPS (Colombia) Enterprise Software Development using Oracle and Oracle Jaime Chavarriaga

Embed Size (px)

Citation preview

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Software Development using Oracle and Oracle

Jaime Chavarriaga

William Lovaton

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Initial Questions

• Can you develop enterprise applications using PHP?

• Using PHP and Oracle?• What is the appropriated

architecture for enterprise development using PHP and Oracle?

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Agenda

• Enterprise Applications– Differences with Web Applications

• Enterprise Applications Architecture– The (suggested) Software layers

• Development options using PHP and Oracle– Technological options– Implementation ideas

• Enterprise Applications Architecture using PHP and Oracle– The selected strategy

• A Case Study – Cicklos - Coomeva

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications

• Are enterprise applications just like another web application?

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications

• The enterprise applications are different to traditional web applications– Even, when the enterprise applications are based on

web technologies (http, html, xml, etc.)

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications

• The enterprise applications…– Include “business logic” (often complex, ever changing)– Include reports and user defined queries (ever growing number)– Must handle different user interface types and information

needs.– Define different “views”. (Not all the users can access the same

data and/or options)– Often include several data sources.– Often require integration with other enterprise applications

(sync, web services, RPC, EDI)

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications Architecture

• The enterprise applications architecture must consider these differences…– The ever-changing

business logic.– The multiple user interface

views and options.– The ever-changing number

of reports and queries.– The need for application

integration strategies.

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications Architecture

• It’s necessary reuse the business logic– In every new interface / form / report

• It’s necessary keep the business logic…– Easy to maintain– Easy for detect/correct bugs

• Almost all the enterprise applications architecture are based on layers definition– Logic separation of the software.– Let you to isolate the changes on each one of the layers

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications Architecture

• What is a software (abstraction) layer?– The simplest explanation– If you duplicate functionality (i.e. validations,

business processes, etc.) across all the application

• It’s harder to maintain• It’s harder to detect the errors• It’s harder to correct them

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications Architecture

• i.e., the database access…

Mysql_connect(…)

Mysql_connect(…)

Mysql_connect(…) MySQL

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications Architecture

• If you define a function for that functionality…

connect(…)

connect(…)

connect(…) MySQL

function connect() { Mysql_connect(…)}

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications Architecture

• …it’s easier to maintain and detect errors.

connect(…)

connect(…)

connect(…) PostgreSQL

function connect() { pg_connect(…)}

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications Architecture

• The layers are created defining a interface to access a specific set of functionalities– Can be procedural- or object oriented-based

interfaces (API).– To use these functionalities, the program must call

these functions or class methods– The application is easier to maintain.– The application (can) get slower.

• Dilemma: maintainability vs. performance

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications Architecture

• Which are the layers for an enterprise application?

• About the layered architecture there are several proposals…– Three layers architecture (Fowler / Microsoft)

• Presentation – Domain Logic – Data Access– Five layers architecture (Brown)

• Presentation – Controller / Mediator – Domain Logic – Data Mapping – Data Sources

• Always… isolating the business logic.

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications Architecture

• The three layered architecture

Presentation Layer

Domain Logic Layer

Data Access Layer

Presentation Controllers

View Components

Domain logic components Data Access

Components

External Applications

External Applications

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureThe Business Logic• The approach is create an abstraction layer for

the business logic.• There is two different architectural styles

depending on the implementation of this business logic layer– Procedural style – using transaction modules.

– OO style – using domain models.

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureProcedural style• The procedural style is normally based on

transaction script modules.– Modules running transactions over a database

management system– Every use case is implemented issuing SQL

statements or database server requests.– i.e:

• Database stored procedures• MTS components (Microsoft DNA)• Session EJB (Java)

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureProcedural style

Transaction Module

doUseCase1 (…)doUseCase2(…)

:

BEGIN TRANS…SELECT …SELECT …INSERT …UPDATE …

COMMIT …

• The transaction modules define the database operations to perform the business logic…

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureProcedural style

Presentation Layer

Domain Logic Layer

Data Access Layer

Front Controllers

Template based view

Transaction Scripts

Data Gateways

External Applications

External Applications

• …but the business logic doesn’t should do SQL (must be isolated).

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureProcedural style

Transaction Module

doUseCase1 (…)doUseCase2(…)

:

Data Gateways

get(…)getAll(…)update(…)delete(…)

:

SQL Statements Validations and Operations

• Data gateways (DAOs, in example) can be used for data access.

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureProcedural style• The procedural style normally behave well with

non-too complex domain logic– The business logic can be defined using simple

algorithms

• The overall performance depends mainly on the speed of database connection / interaction.

• It fits perfectly in the nothing-shared PHP behavior approach

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureOO style• The object oriented style is based on the

handling of an domain object model.– Functions and methods executing operations over

objects in memory. – The data must be loaded from databases to in-

memory objects.– The operations over the objects must be mapped

back to the database.– i.e:

• Components or Beans• Entity EJB (Java)

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureOO style• The use case controllers perform operations over object

structures…

Use Case Contollers

doUseCase1(…)doUseCase2(…)

:

obj = Registro.get()obj.setValue(value)obj.remove(obj2)…

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureOO style

Presentation Layer

Domain Logic Layer

Data Access Layer

Front Controller

Template based view

External Applications

External Applications

Use Case Controllers

Object Relational MapperCollections

Objects

• … the business logic don’t know anything about the database

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureOO style• In the object oriented style the transactions

requires the creation of objects in memory (upload) for all the transaction-related data.

• Map the data from the database to memory and write it back to the database represents one of the biggest performance issues.

• The application performance is often based on a shared object space.– Don’t load all the objects (lazy load)– Don’t load the object twice

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureOO style

Use Case Controllers

doUseCase1 (…)doUseCase2(…)

:

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Enterprise Applications ArchitectureOO style• Currently, you cannot define a shared object

space for different PHP processes (threads)

• Normally… – You need load all the (necessary) objects, all the time– You can get better performance for OO business logic

processing in other technologies (Java?)

– In the future, SRM (Script Running Machine) and its “banana” PHP-programming, will offer a better OO solution.

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture

• How implement the architecture?

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture

• A set of classes for business logic and data access are needed.

TransactionScripts

+ doOperation()+ doOperation2()

RowDataGateway

+ add()+ remove()+ update()+ getAll()+ getById()

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture• The Business Logic : All in PHP

<?php class BankAccountManager { function transferMoney ($originAccount,

$targetAccount, $amount) { $data = DataGateway::get(“Accounts”);

if($data->getBalance($originAccount) > $amount) { if ($data->decreaseBalance($originAccount, $amount) {

$data->incrementBalance($destinationAmmount, $amount); } } }

// other domain logic functions }

?>

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture

• The Business Logic in Oracle

• Two source code fragments are needed:

– the specification and the body

CREATE OR REPLACE PACKAGE BankAccountManager AS

PROCEDURE transferMoney ( originAccount VARCHAR2(10), targetAccount VARCHAR2(10), amount NUMBER(9,2)) ;

END BankAccountManager;/

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture• The Business Logic in Oracle

CREATE OR REPLACE PACKAGE BODY BankAccountManager AS PROCEDURE transferMoney (

originAccount VARCHAR2(10), targetAccount VARCHAR2(10), amount NUMBER(9,2)) IS

balance NUMBER(9,2); BEGIN balance := BankAccountManager.getBalance(originAccount); IF balance > amount THEN

BankAccountManager.decreaseBalance(originAccount, amount); BankAccountManager.increaseBalance(targetAccount, amount); END IF;

END transferMoney;END BankAccountManager;

/

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture• The Business Logic : the PHP proxy

<?class BankAccountManager { function transferMoney ($originAccount,

$targetAccount, $amount) { // obtain an ADOdb connection with the proper config

$db = ADOHandler::getConnection(); // build the calling code

// the binding variables must include ‘:’ $plsql = "begin ". " :retval := ". " BanckAcountManager.transferMoney(". " :originAccount, :targetAccount, :amount); ". " end;";

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture

• The Business Logic : the PHP proxy

// prepare the statement $stmt =& $db->Prepare($plsql); $db->Parameter($stmt, $retval, 'retval'); $db->Parameter($stmt, $originAccount, ' originAccount'); $db->Parameter($stmt, $targetAccount, 'targetAccount'); $db->Parameter($stmt, $amount, 'amount');

// execute the code $success = $db->Execute($stmt);

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture• The Business Logic : the PHP proxy

// there is an error ?? if (!$success) { trigger_error(("transferMoney error "), E_USER_WARNING);

return FALSE;

// the query returned a value } else if ($success->_numOfRows == 0 && isset($retval)) {

return $retval; }

// return the query result return $success;

}}?>

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture

• Even, if you want, your program can select which business logic use.. – Including the full PHP business logic– Including the PHP-proxy for Oracle business logic

– … you can use a PHP Object Factory

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Implementing the Architecture

• Selecting the business logic implementation

<?php

require_once “BankAccountManager.proxy.class”;

// if you want, you can include the non-proxy php class // require_once “BankAccountManager.class”;

// get the request parameters and call the function BankAccountManager::transferMoney ( $_REQUEST[‘originAccount’], $_REQUEST[‘targetAccount’], $_REQUEST[‘amount’]);

?>

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

PHP and Oracle Alternatives

• What options do you have when using PHP and Oracle?

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

PHP and Oracle Alternatives

PHP Oracle

PresentationDomain

LogicData

Access

• All in PHP… the database only as data store

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

• Use stored procedures for data handling

PHP and Oracle Alternatives

PHP OraclePL/SQL

PresentationDomainLogic

Data Access

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

• Use stored procedures for domain logic

PHP and Oracle Alternatives

PHP OraclePL/SQL

PresentationDomain

LogicData

Access

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

• Use java-based business logic (portable?)

Oracle

PHP and Oracle Alternatives

PHP OracleJava EJB

PresentationDomain

LogicData Access

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Architecture using PHP and Oracle

• What is the selected architecture?

• Portability vs. Performance

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Architecture using PHP and Oracle

• The best of both worlds– Use PHP for the presentation logic.

• PHP (with opcode caching and template compiling) is a winner in web programming.

– Use PL/SQL stored procedures for business logic and data access.

• 30% increase in insert performance• 10 times improves on select speed• http://php.weblogs.com/oracle_mysql_performance

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

• Use stored procedures for domain logic

Architecture using PHP and Oracle

PHP OraclePL/SQL

PresentationDomain

LogicData

Access

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Architecture using PHP and Oracle

• Something like this…Presentation Layer Domain Logic Layer Data Access Layer

Front Controller

Template based view

Transaction Scripts

BasicData

Gateways

Smarty plugins

ActionCommands

ExtendedData

Gateways

Proxy

Proxy

Auth ACL Log

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Architecture using PHP and Oracle

• The database connection/access, the main bottleneck

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Coomeva Ciklos: A Case Study

• A real-life application

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Coomeva Ciklos: A Case Study

• General Architecture

Gateways

Table Modules

Transaction Script

Oracle

ADODB Abstraction Layer

BL ProxiesCache

View

Smarty Browser

Front Controller

(PHRAME)

PHP

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Coomeva Ciklos: A Case Study

Web ServersPHPTurck mmCacheShared memoryFile-based cache

Soon…Connection pool

Business Logic Database serversOracleStored ProceduresDatabases

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Coomeva Ciklos: A Case Study

Highlights of the Development Process

• MVC-2 pattern with a customized version of PHRAME• Automatically generated gateways• Automatic menu generation in JavaScript• Error Handling and Logging• Caching of data (AppCache)

– File based cache (phpApplication)– Shared Memory based cache– Cache maintenance

• Performance monitoring

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Coomeva Ciklos: A Case Study

Application Statistics

• 20 Offices around the country• 480 PHP Sessions per day• Up to 82 hits in the very same second• 600 MB of access_log in seven days• Memory consumption:

– Only Apache: 2 GB (More than 200 Apache processes)– Apache and Tux: 800 MB (Up to 110 Apache processes)– Up to 16 MB for caching common data

• 58 Directories, 642 Files, Aprox. 500Kb of compressed code• 8 Functional modules implementing business logic

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Coomeva Ciklos: A Case Study

Optimization Strategies• Always use a opcode caching system• Tux – The kernel web server• ADVX – Advanced extranet server (a modified Apache)• SQLRelay – Database pool connection manager• MSession – A session server with shared memory• Caching database result sets in the application server• Dynamic content compression (with PHP)• Static content compression (with Tux)• Turn off register globals• Caching dynamic content (404 Error)• Use the ADODB PHP module (C code runs faster)

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Coomeva Ciklos: A Case Study

The Working Team• Claudia Liliana Jaramillo (PHP Developer)• William Alberto Lovaton (PHP Developer)• Juan Carlos Madrid (Oracle Developer)• Patricia Velez (Oracle Developer)• Carlos Augusto Penilla (Graphic Designer)• Farid Buenaventura (Process Engineer, Trainer)• Monica Marcela Arias (Process Engineer)• Jorge Arturo Zapata (Stake Holder, Trainer)• Maria de Vuono (Stake Holder)• Jesus Alberto Bolaños (Project Leader)• Jaime Alberto Chavarriaga (Project Consultant)

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

In the future

• A better business logic framework• Automatically generated Applications based on database

metadata• Development environments with better support for

business logic / stored procedures

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Additional Resources

• Where can i learn more?

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Additional Resources

• Books

– Martin Fowler et al. Patterns of Enterprise Applications Architecture.

– Johnson et Al. Evolving Frameworks.– IBM. San Francisco Design Patterns / e-

Business Design Patterns

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Additional Resources

• Web Sites

– Martin Fowler website• http://www.martinfowler.com

– Design Patterns for eBusiness • http://www.ibm.com/sanfrancisco

– PHP optimization / PHP and oracle performance

• http://php.weblogs.com

Jaime Chavarriaga William Lovaton

Universidad San Buenaventura - Coomeva EPS (Colombia)

Questions