* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download - Prairie Systems Group, Limited
Survey
Document related concepts
Tandem Computers wikipedia , lookup
Microsoft Access wikipedia , lookup
Oracle Database wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Team Foundation Server wikipedia , lookup
Concurrency control wikipedia , lookup
Functional Database Model wikipedia , lookup
Ingres (database) wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
ContactPoint wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Relational model wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Transcript
Thick DBApproach: Key to Successful Web Architecture Michael Rosenblum Dulcian, Inc. www.dulcian.com October 2, 2011 1 of 24 Quiz! How often is the DBA….. consulted when building a NEW web-based system? BLAMED for the performance of an EXISTING web-based system? 2 of 24 Web Application Architecture 3. Application Server 2. Send data from Client to app server 4. Send data from app server to database 1. Client 9. Data in client 5. Database 8. Return data from app server to client 6. Return Data from database to app server 7. Data in Application Server 3 of 24 Alternatives Instrument Requires all layers to find bottlenecks real discipline and coding standards! Redistribute the workload Goal is to decrease the number of moving parts Extremes like APEX on one side and NoSQL movement on the other Redistribute the workload AND split development process into smaller areas SOA Thick database approach (micro-SOA) 4 of 24 What is “Thick Database”? Key architectural approach Explicit and very formal division between the database and user interface (UI) portions of a system Key features: Nothing in the UI ever directly interacts with a database table. All interaction is accomplished through the isolation layer (database views or APIs) All data-driven behavior is handled in the database Majority of application behavior (including screen navigation) may also be handled in the database 5 of 24 Thick database architecture 3. Application Server 5. Database 2. Client to app server 4. From app server to DB 8. App server to client 6. From DB to app server 1. Client 9. Data in client Single round trip! 7. Data in Application Server Allows advanced functionality with high security! Interface layer: (views, triggers, public APIs) Processing layer (low-level APIs, administrative tools) Data 6 of 24 Why not just SOA? SOA (horizontal modularization) Always looks perfect “on paper” In real life… No single point of responsibility Artificial borders Duplication of functionality because of the lack of communication Thick database (vertical modularization) Quick detection of problem areas Agile development (quick prototypes, iterative approach) Frond-end developers stay focused on UI (not on the data behavior) Database experts have extra time to tune server modules 7 of 24 Thick Database Development Process Two portions of an application can be coded independently Teams can work in isolation until substantive portions are working. First Use as a testing environment for the database team Feedback can be received from users. Use version of the UI is built within a few days Agile process Minimal design work done to produce a partially working system. Additional functionality created in an iterative design process. 8 of 24 So what? 9 of 24 Thick Database Techniques UI screens NEVER touch tables. Interface stubbing De-normalized views Function-based views All complex data transformations in PL/SQL only! Effective utilization of: BULK operations CLOBs, XMLtype Other advanced data processing Single-round trip thinking 10 of 24 Interface Stubbing Stub out the code for the views and APIs. select <values> from dual APIs = functions that return a correct value (usually hard-coded). Interfaces will change as the application matures. 11 of 24 De-Normalized Views The idea: Convert relational data into something that will make user interface development easier. Easiest way to separate data representation in the front-end from the real model. The solution: Use a view with a set of INSTEAD-OF triggers. 12 of 24 De-Normalized View create or replace view v_customer as select c.cust_id, c.name_tx, a.addr_id, a.street_tx, a.state_cd, a.postal_cd from customer c left outer join address a on c.cust_id = a.cust_id 13 of 24 INSTEAD-OF Insert create or replace trigger v_customer_ii instead of insert on v_customer declare v_cust_id customer.cust_id%rowtype; begin if :new.name_tx is not null then insert into customer (cust_id,name_tx,phone_tx) values (object_seq.nextval,:new.name_tx,:new.phone_tx) returning cust_id into v_cust_id; if :new.street_tx is not null then insert into address (addr_id,street_tx,state_cd, postal_cd, cust_id) values (object_seq.nextval,:new.street_tx, :new.state_cd,:new.postal_cd, v_cust_id); end if; end; 14 of 24 Function-Based Views (1) Case: Complex search engine About 20 different filtering criteria Applicable to different tables Large data volume Problem: Unpredictable performance results in a single SQL query. Solution Function-based view with dynamic SQL under the hood. 15 of 24 Function-Based Views (2) A. Create an output object with corresponding collection. CREATE type search_ot as object (Name_TX Varchar2(50),Phone_TX varchar2(20)…) CREATE type search_nt as table of search_ot; B. Create a function to return collection all search criteria become input variables CREATE OR REPLACE FUNCTION f_search_tt (i_name_tx varchar2, i_phone_tx varchar2, …) RETURN search_nt IS v_tt search_nt:= search_nt(); BEGIN RETURN v_tt; END; 16 of 24 Function-Based Views (3) Use Dynamic SQL build the query FUNCTION f_search_tt IS v_sql_tx varchar2(32000); BEGIN v_sql_tx:='select search_ot(...) '||chr(10) 'from ... '||chr(10) 'where ...'; if i_name_tx is not null then v_sql_tx:=v_sql_tx|| ' and cust.name_tx like ''%'||i_name_tx||'%'' ' end if; ... execute immediate v_sql_tx bulk collect into v_tt; ... END; 17 of 24 Function-Based Views (4) Give code to developers select name_tx, address_tx, phone_tx, … from table( cast(f_search_nt (:1, -- name :2, -- phone … ) as search_nt) ) 18 of 24 Single-Round trip Thinking (1) Task #1: Issues to be resolved: Session-dependency Clean up Formatting Solution: There is a large organizational structure that could be versioned. New structural model should be validated before rolling it over Special function that returns CLOB and uses HTML-tags to format the output. Major points: A function takes a parameter and returns a CLOB in one round-trip. Temporary CLOBs are released automatically. Full formatting can be done in the CLOB itself. <<Example 11>> 19 of 24 Write your own HTML - 1 function f_validateOrgStruct_CL (...) return CLOB is v_out_cl CLOB; v_tx varchar2(32000); v_break_tx varchar2(4):='<BR>'; v_hasErrors_yn varchar2(1):='N'; <<...number of cursors...>> procedure p_add (in_tx varchar2, in_flush_yn varchar2:='N') is begin if length(v_tx)+length(in_tx)>32000 or in_flush_yn=‘Y’ then dbms_lob.writeappend(v_out_cl,length(v_tx),v_tx); v_tx:=in_tx; else v_tx:=v_tx||in_tx; end if; end; begin dbms_lob.createtemporary(v_out_cl,true,dbms_lob.Call); p_add('----VALIDATE RECRUITERS-----'||v_break_tx); 20 of 24 Write your own HTML - 2 for rec_recrtr in c_recrtr loop if rec_recrtr.ric_tx is null then p_add(' * '||rec_recrtr.rc_recrtr_dsp|| ' - missing code'||v_break_tx); v_hasErrors_yn:='Y'; end if; end loop; ... if v_hasErrors_yn='Y' then p_add(v_break_tx|| '<font color="red">*** ERRORS ARE DETECTED! ***</font>'); end if; p_add(null,’Y’); -- flush the buffer return v_out_cl; Exception When others then return '<font color="red">'|| ||'*ERRORS!*</font>'||v_break_tx||sqlerrm; end; 21 of 24 Single-Round Trip Thinking (2) Task #2: Issues to be resolved: User is presented with the grid The grid supports multi-select A set of actions has to be executed for all selected objects What is the most efficient way of manipulating with multi-select Options: From the front-end execute one action at a time for each selected object Create a comma-separated list of unique identifiers and pass it to the DB REALLY bad idea Better, but still not perfect Create an object collection with unique identifiers and pass it to the DB Much better! <<Example 11>> 22 of 24 When [not] to use Dynamic SQL Passing a list function f_getSumSal_nr (i_empno_tx VARCHAR2)RETURN NUMBER IS v_out_nr NUMBER:=0; v_sql_tx VARCHAR2(2000); BEGIN IF i_empno_tx IS NOT NULL THEN v_sql_tx:='SELECT sum(sal) FROM emp ' 'WHERE empno IN ('||i_empno_tx||')'; EXECUTE IMMEDIATE v_sql_tx INTO v_out_nr; END IF; RETURN v_out_nr; END; Passing a collection (TABLE OF NUMBER) FUNCTION f_getSumSal_nr (i_tt id_tt) RETURN NUMBER IS v_out_nr NUMBER:=0; BEGIN IF i_tt IS NOT NULL AND i_tt.count>0 THEN SELECT sum(sal) INTO v_out_nr FROM emp WHERE empno IN (SELECT t.column_value FROM TABLE(CAST(i_tt as id_tt)) t); END IF; RETURN v_out_nr; 23 of 24 END; Conclusions The #1 critical success factor for any web development is effective utilization of the database. PL/SQL is not irrelevant (and it continues to improve). Code that needs to access the database is faster if it is placed in the database. 24 of 24 Contact Information Rosenblum – [email protected] Blog – wonderingmisha.blogspot.com Website – www.dulcian.com Michael Developer Advanced Forms & Reports Designer Handbook Available now! Expert PL/SQL Practices 25 of 24