24. Expectation regarding Valid Input procedure proc (p_name in varchar2 ,p_sal in number ,p_hiredate in date ) Agreed Contract
25. package dbc is AssertFail exception; c_AssertFail constant integer := -20999; pragmaexception_init (AssertFail, -20999); procedure assert (p_check in boolean ,p_msg in varchar2 := null ); end dbc;
26. procedure assert (p_check in boolean ,p_msg in varchar2 := null ) is begin if not nvl(p_check,false) -- fail on null input then raise_application_error ( c_AssertFail, 'Assertion Fail' ||': '||substr( nvl(p_msg, 'No Message') , 1, 200) ); end if; end assert;
27. Validate Input procedure proc (...) is begin dbc.assert (p_name is not null ,'The Name must be Filled' ); dbc.assert ((p_sal is not null and p_sal > 0) ,'The Salary must be greater than zero' ); dbc.assert (p_hiredate >= trunc (sysdate) ,'Hiredate must be in the Future' ); ... end proc; proc.sql
28. -- Description of this procedure -- -- %paramp_name Name of an Employee -- {*} Requirement Name must be provided -- -- %paramp_sal Salary of the Employee -- {*} Requirement Salary must be greater than zero -- -- %paramp_hiredateHiredate -- {*} Requirement Hiredate must be in the Future -- -- %raises DBC.AssertFail -- When a Parameter does not match the requirement
36. Dependency Injection- Traditional Approach Central Package instead of hard-coding c_mailserverc_interest_ratec_vat_ratec_file_in_namec_log_level APP_CONSTANTS Package Package Package
38. From mere Value Injection to Interface Injection A component can specify it requires some simple configuration values to be injected directory name, email address, discount percentage It can also stipulate that it wants some ‘helpers’ complete functional components for example: a Logger, an Emailer, a Discount Calculation Service, an Order Validation , etc. The component will prescribe the interface the injected helper must have Reuse is promoted through injected dependencies
39. Interface Injection“If you give me a logger, I will write logging” Dependency_Injector LOGGER log_message( p_log_level in varchar2 , p_log_origin in varchar2 , p_log_message in varchar2 ); set_loglevel_threshold( p_log_level in varchar2);set_file_writer( p_file_writer in varchar2 HRM_SALARY_RULES /* Logger interface: p_log_level in varchar2 , p_log_origin in varchar2 , p_log_message in varchar2 */ set_logger (p_logger in varchar2)
40. Interface Injection“If you give me a logger, I will write logging” Dependency_Injector HRM_SALARY_RULES /* Logger interface: p_log_level in varchar2 , p_log_origin in varchar2 , p_log_message in varchar2 */ set_logger (p_logger in varchar2) NEW_LOGGER_IMPL Write_trace_message( p_log_level in varchar2 , p_log_origin in varchar2 , p_log_message in varchar2 );
73. From Xenophobia to Xenogenetics Established best practices in languages like Java can help improve use of PL/SQL Design by Contract, Encapsulation, Assertion, Reduced Impact of Changes Dependency Injection, Decoupling, Reuse Technical concepts in Java can have a meaningful counterpart in PL/SQL Data and Interaction across sessions
74. From Xenophobia to Xenogenetics De-facto standards – such as JSON – may make sense in a PL/SQL context And open source PL/SQL libraries may exist Through Java Stored Procedures, PL/SQL can leverage Java capabilities & libraries To interact through additional channels To calculate, process, generate, interpret
… and you don’t want to be sitting here [animation] when someone down here [animation] has already written this solution.
ENCAPSULATION (hide implementation from consumers)Encapsulation: wijziging van implementatiezonderuiterlijkegevolgen; netter organiserenDecoupling: views, pl/sqlapiAssertion: verifieren van afgesproken contract
When developing stored procedures, you agreed upon a specific interface, the signature of the stored procedure. Implicitly you agreed upon a contract. One using the Stored Procedure will know which parameters to supply and what will be returned by the stored procedure.In order to implement the stored procedure you make certain assumption about the supplied values for the parameters.Using Assertions you can make sure that the user of the Stored Procedures is faithful to the contract.Talen: webservices, javaElementen in contractDatatype (aantal, type, eisenaaninhoud)ExceptionsReturn SLA elementen: side effects – transactions/ nietbeschikbaarFunctionelebeschrijving
Deel van assertions is er, datatype
Do nothing or Complain Loudly
This is
Nice and optimistic interpretation:We do not want to burden you with the task(s) ofcalling us, keeping up to date with our latest contact details, being familiar with our internal procedures Let us handle the nitty gritty and just tell you what you need to know when you should know it
EmailDirectoryurllogging
EmailDirectoryurllogging
Background parallel processing; information exchange between different processesWhy would you want cross session communication?Background processes for parallel processingSharing cache resultsInter-user communication…?
Background parallel processing; information exchange between different processes
Javakoffie
Communication across sessions: Options: DBMS_PIPE – serialized in case of Public Pipes, only one session gets the informationQueueing – quite heavy Tables – always need transaction mechanism Application Context- no transaction neededApplication Context: storing name-value pairsKunnenalleen strings in
Communication across sessions: Options: DBMS_PIPE – serialized in case of Public Pipes, only one session gets the informationQueueing – quite heavy Tables – always need transaction mechanism Application Context- no transaction neededApplication Context: storing name-value pairsKunnenalleen strings in
Communication across sessions: Options: DBMS_PIPE – serialized in case of Public Pipes, only one session gets the informationQueueing – quite heavy Tables – always need transaction mechanism Application Context- no transaction neededApplication Context: storing name-value pairsKunnenalleen strings in
Communication across sessions: Options: DBMS_PIPE – serialized in case of Public Pipes, only one session gets the informationQueueing – quite heavy Tables – always need transaction mechanism Application Context- no transaction neededApplication Context: storing name-value pairsKunnenalleen strings in
JavascriptPhpWeb wereld
Very compact, with lots of information.
Same information, now represented in XML – lot more text
Available Open Source projects for JSON in combination with PL/SQL
Available Open Source projects for JSON in combination with PL/SQL
Usually, jobs can only be used for batch programming (no synchronous response). However: a task can be divided up over various jobs – where each job does part of the work – and all jobs report back their result to the original thread (session) through a pipe
The job is scheduled to run every minuteIt calls upon the Java Stored Procedure to retrieve the newly arrived email-messages – in a specific accountFor each message, an email event is enqueue in the AQ Queue. The new email-messages are subsequently removed.A queue listener has been registered on the queue with email eventsEvery email (event) is dequeued and processedThe email can contain query statements – in some form – that the processor knows how to handleThe reply to the query is then sent in an email message that forms the response to the original email messageNote: other listeners could dequeue the email events and process them in other waysIncoming messages from other sources could be retrieved and processed in a similar way as email messages (VOIP, SMS, IM/Chat, Twitter)The database can both send and retrieve messages from such serversNote: Java is much better equipped than plain PL/SQL (that really only has utl_http, utl_tcp, utl_smtp) for customized, flexible, advanced interaction with a wide range of infrastructures and technologies.
Screenshot:Frank sends email to Maggie – with a query on EmployeesAfter some time, a response is sent to this particular email – by the queue listener using the JSP to send(list of employee data, corresponding with “query”)
Java is much better equipped than plain PL/SQL (that really only has utl_http, utl_tcp, utl_smtp) for customized, flexible, advanced interaction with a wide range of infrastructures and technologies.Java libraries can help to generate PDF, create and/or read Word and Excel etc.Through JMS – external Java applications can be accessed in a decoupled way. For example: Complex Event Processor
Write functional JavaFor example in JDeveloperUsing the full richness of the IDE and of the Java Language (and libraries)Wrap with PL/SQL Map Java & PL/SQL data types Load into DatabaseCustom classes and libraries (JAR-files)Set appropriate privilegesInvoke JSP through a normal PL/SQL interface
Look around youThink out of the the boxKeep an open mind
Leverage Java – without the need to buy/install/maintain (middletier) additional infrastructureChannels: receiving emails, Instant Messaging (chatting)Processing/Generating (statistics, Excel, PDF, images, ..)