Xenogenetics for PL/SQLInfusing with Java Best Practices and Design Patterns<br />
Blogger<br />Presenter<br />Author<br />
Blogger<br />Presenter<br />
Xenogenetics for PL/SQLInfusing with Java Best Practices and Design Patterns<br />
Zĕn'ə-jə-nĕt'ĭks for PL/SQLInfusing with Java Best Practices and Design Patterns<br />
Show of hands:<br /><ul><li> DBA
 Developer
 Biologist</li></li></ul><li>Source: www.answers.com<br />
Design Patterns<br />
solutionsforgenericproblems<br />
“Someone has already solved your problems”<br />
Design by Contract<br />EncapsulationDecouplingAssertion<br />
specification<br />body<br />Encapsulation<br />
specification<br />specification<br />body<br />body<br />Decoupling<br />
procedure proc (p_name     in varchar2<br />               ,p_sal      in number<br />               ,p_hiredate in date<b...
Expectation regarding Valid Input<br />procedure proc (p_name     in varchar2<br />               ,p_sal      in number<br...
package dbc<br />is<br />AssertFail   exception;<br />c_AssertFail constant integer := -20999;<br />pragmaexception_init (...
procedure assert (p_check in boolean<br />                 ,p_msg   in varchar2 := null<br />                 )<br />is<br...
Validate Input<br />procedure proc (...)<br />is<br />begin<br />dbc.assert (p_name is not null          <br />           ...
-- Description of this procedure<br />--<br />-- %paramp_name Name of an Employee<br />--  {*} Requirement Name must be pr...
Allround Automations Plugin PLSQLDOC<br />
(aka Inversion of Control)<br />Advanced Decoupling<br />Dependency Injection<br />
PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />HTTP<br />Logger<br />
PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />HTTP<br />Logger<br />
Dependency Injection- Traditional Approach Central Package instead of hard-coding<br />c_mailserverc_interest_ratec_vat_ra...
True Injection<br />Configuration Values<br />property<br />package<br />value<br />After Logon trigger<br />mailserverint...
From mere Value Injection to Interface Injection<br />A component can specify it requires some simple configuration values...
Interface Injection“If you give me a logger, I will write logging”<br />Dependency_Injector<br />LOGGER<br />log_message( ...
Interface Injection“If you give me a logger, I will write logging”<br />Dependency_Injector<br />HRM_SALARY_RULES<br />/* ...
Reusability<br />
JSON<br />Cross Session Communication<br />
Why?<br />process<br />process<br />process<br />
Why?<br />process<br />process<br />process<br />
session<br />session<br />CentralCache<br />session<br />session<br />
session<br />session<br />
session<br />session<br />
Q<br />session<br />session<br />
ApplicationContext<br />session<br />session<br />
namespace<br />Name : Value<br />Name : Value<br />Name : Value<br />Name : Value<br />Name : Value<br />Name : Value<br /...
JavaScript Object Notation<br />Lightweight data-interchange format<br />
Name : Value<br />
Name : Value,<br />Name : Value,<br />Name : Value<br />
Name : Value,<br />Name : Value,<br />Name : Value<br />Name : Value,<br />Name : Value,<br />Name : Value<br />Name : Val...
{"ACCOUNTING" : {<br />    "EMPLOYEES" : [<br />    {"ENAME" : "KING",<br />      "JOB" : "PRESIDENT",<br />      "SAL" : ...
<department name="ACCOUNTING"><br />  <employees><br />    <employee><br />      <ename>KING</ename><br />      <job>PRESI...
context2.sql<br />
Caching session<br />Cache<br />package<br />session<br />session<br />session<br />
Caching session<br />Cache<br />package<br />key<br />value<br />Alert<br />Listener<br />
Worker<br />Session<br />Worker<br />Session<br />Package (single session)<br />client<br />Worker<br />Session<br />dbms_...
Java Stored Procedure<br />Unlocking the World<br />
Challenges<br />
Challenges<br />Lack of Interaction<br />Humans<br />External Systems<br />PL/SQL is limited<br />
Q<br />
1<br /><ul><li>Write Functional Java</li></ul>2<br /><ul><li>Wrap with PL/SQL</li></ul>3<br /><ul><li>Load into Database</...
From Xenophobia to Xenogenetics<br />Established best practices in languages like Java can help improve use of PL/SQL<br /...
From Xenophobia to Xenogenetics<br />De-facto standards – such as JSON – may make sense in a PL/SQL context<br />And open ...
Upcoming SlideShare
Loading in …5
×

Xenogenetics for PL/SQL - infusing with Java best practices

2,823
-1

Published on

Xenogenetics for PL/SQL- Infusing with Java Best Practices and Design Patterns - PL/SQL is a venerable programming language that is both vital and very much alive. This session will discuss how we further rejuvenate and enhance the way we create PL/SQL programs. We'll tap into the world of .NET, Java, and other modern programming language to do some cherry picking: what are the very best practices, concepts, and design patterns and how can we apply them to PL/SQL? We'll explain and demonstrate dependency injection, the observer pattern based on listeners, aspect-oriented programming (AOP), the decorator and template pattern, use of user-defined nested types, and collections.

Published in: Technology
1 Comment
3 Likes
Statistics
Notes
  • http://dbmanagement.info/Tutorials/PLSQL.htm
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
2,823
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide
  • … 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 &amp; 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, ..)
  • Xenogenetics for PL/SQL - infusing with Java best practices

    1. 1.
    2. 2. Xenogenetics for PL/SQLInfusing with Java Best Practices and Design Patterns<br />
    3. 3. Blogger<br />Presenter<br />Author<br />
    4. 4. Blogger<br />Presenter<br />
    5. 5. Xenogenetics for PL/SQLInfusing with Java Best Practices and Design Patterns<br />
    6. 6. Zĕn'ə-jə-nĕt'ĭks for PL/SQLInfusing with Java Best Practices and Design Patterns<br />
    7. 7. Show of hands:<br /><ul><li> DBA
    8. 8. Developer
    9. 9. Biologist</li></li></ul><li>Source: www.answers.com<br />
    10. 10.
    11. 11. Design Patterns<br />
    12. 12. solutionsforgenericproblems<br />
    13. 13.
    14. 14. “Someone has already solved your problems”<br />
    15. 15.
    16. 16.
    17. 17.
    18. 18.
    19. 19. Design by Contract<br />EncapsulationDecouplingAssertion<br />
    20. 20. specification<br />body<br />Encapsulation<br />
    21. 21. specification<br />specification<br />body<br />body<br />Decoupling<br />
    22. 22.
    23. 23. procedure proc (p_name in varchar2<br /> ,p_sal in number<br /> ,p_hiredate in date<br /> )<br />
    24. 24. Expectation regarding Valid Input<br />procedure proc (p_name in varchar2<br /> ,p_sal in number<br /> ,p_hiredate in date<br /> )<br />Agreed Contract<br />
    25. 25. package dbc<br />is<br />AssertFail exception;<br />c_AssertFail constant integer := -20999;<br />pragmaexception_init (AssertFail, -20999);<br /> procedure assert (p_check in boolean<br /> ,p_msg in varchar2 := null<br /> );<br />end dbc;<br />
    26. 26. procedure assert (p_check in boolean<br /> ,p_msg in varchar2 := null<br /> )<br />is<br />begin<br /> if not nvl(p_check,false) -- fail on null input<br /> then<br />raise_application_error<br /> ( c_AssertFail, 'Assertion Fail'<br /> ||': '||substr( nvl(p_msg, 'No Message')<br /> , 1, 200) <br /> );<br /> end if;<br />end assert;<br />
    27. 27. Validate Input<br />procedure proc (...)<br />is<br />begin<br />dbc.assert (p_name is not null <br /> ,'The Name must be Filled' <br /> );<br />dbc.assert ((p_sal is not null and p_sal > 0)<br /> ,'The Salary must be greater than zero'<br /> );<br />dbc.assert (p_hiredate >= trunc (sysdate)<br /> ,'Hiredate must be in the Future'<br /> );<br /> ...<br />end proc;<br />proc.sql<br />
    28. 28. -- Description of this procedure<br />--<br />-- %paramp_name Name of an Employee<br />-- {*} Requirement Name must be provided<br />--<br />-- %paramp_sal Salary of the Employee<br />-- {*} Requirement Salary must be greater than zero<br />--<br />-- %paramp_hiredateHiredate<br />-- {*} Requirement Hiredate must be in the Future<br />--<br />-- %raises DBC.AssertFail<br />-- When a Parameter does not match the requirement<br />
    29. 29. Allround Automations Plugin PLSQLDOC<br />
    30. 30.
    31. 31. (aka Inversion of Control)<br />Advanced Decoupling<br />Dependency Injection<br />
    32. 32.
    33. 33.
    34. 34. PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />HTTP<br />Logger<br />
    35. 35. PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />PL/SQL Package<br />HTTP<br />Logger<br />
    36. 36. Dependency Injection- Traditional Approach Central Package instead of hard-coding<br />c_mailserverc_interest_ratec_vat_ratec_file_in_namec_log_level<br />APP_CONSTANTS<br />Package<br />Package<br />Package<br />
    37. 37. True Injection<br />Configuration Values<br />property<br />package<br />value<br />After Logon trigger<br />mailserverinterest_ratevat_ratefile_in_namelog_levelurl_proxy<br />emailertax_calctax_calcloggerloggerrss_reader<br />amislin324.517.6app_log_xdebugamisvm2…<br />setMailServer<br />EMAILER<br />setFileInName<br />setLogLevel<br />LOGGER<br />setUrlProxy<br />RSS_READER<br />Dependency_Injector<br />TAX_CALC<br />setInterestRate<br />setVatRate<br />
    38. 38. From mere Value Injection to Interface Injection<br />A component can specify it requires some simple configuration values to be injected<br />directory name, email address, discount percentage<br />It can also stipulate that it wants some ‘helpers’<br />complete functional components<br />for example: a Logger, an Emailer, a Discount Calculation Service, an Order Validation , etc.<br />The component will prescribe the interface the injected helper must have<br />Reuse is promoted through injected dependencies<br />
    39. 39. Interface Injection“If you give me a logger, I will write logging”<br />Dependency_Injector<br />LOGGER<br />log_message( p_log_level in varchar2 , p_log_origin in varchar2 , p_log_message in varchar2<br />);<br />set_loglevel_threshold( p_log_level in varchar2);set_file_writer( p_file_writer in varchar2<br />HRM_SALARY_RULES<br />/* Logger interface:<br />p_log_level in varchar2 , p_log_origin in varchar2 , p_log_message in varchar2<br />*/<br />set_logger (p_logger in varchar2)<br />
    40. 40. Interface Injection“If you give me a logger, I will write logging”<br />Dependency_Injector<br />HRM_SALARY_RULES<br />/* Logger interface:<br />p_log_level in varchar2 , p_log_origin in varchar2 , p_log_message in varchar2<br />*/<br />set_logger (p_logger in varchar2)<br />NEW_LOGGER_IMPL<br />Write_trace_message( p_log_level in varchar2 , p_log_origin in varchar2 , p_log_message in varchar2<br />);<br />
    41. 41. Reusability<br />
    42. 42. JSON<br />Cross Session Communication<br />
    43. 43. Why?<br />process<br />process<br />process<br />
    44. 44. Why?<br />process<br />process<br />process<br />
    45. 45.
    46. 46. session<br />session<br />CentralCache<br />session<br />session<br />
    47. 47. session<br />session<br />
    48. 48. session<br />session<br />
    49. 49. Q<br />session<br />session<br />
    50. 50. ApplicationContext<br />session<br />session<br />
    51. 51. namespace<br />Name : Value<br />Name : Value<br />Name : Value<br />Name : Value<br />Name : Value<br />Name : Value<br />context1.sql<br />
    52. 52. JavaScript Object Notation<br />Lightweight data-interchange format<br />
    53. 53. Name : Value<br />
    54. 54. Name : Value,<br />Name : Value,<br />Name : Value<br />
    55. 55. Name : Value,<br />Name : Value,<br />Name : Value<br />Name : Value,<br />Name : Value,<br />Name : Value<br />Name : Value,<br />Name : Value,<br />Name : Value<br />,<br />,<br />
    56. 56. {"ACCOUNTING" : {<br /> "EMPLOYEES" : [<br /> {"ENAME" : "KING",<br /> "JOB" : "PRESIDENT",<br /> "SAL" : 5000<br /> },<br /> {"ENAME" : "MILLER",<br /> "JOB" : "CLERK",<br /> "SAL" : 1300<br /> }]<br /> }<br />}<br />
    57. 57. <department name="ACCOUNTING"><br /> <employees><br /> <employee><br /> <ename>KING</ename><br /> <job>PRESIDENT</job><br /> <sal>5000</sal><br /> </employee><br /> <employee><br /> <ename>MILLER</ename><br /> <job>CLERK</job><br /> <sal>1300</sal><br /> </employee><br /> </employees><br /></department><br />
    58. 58.
    59. 59. context2.sql<br />
    60. 60. Caching session<br />Cache<br />package<br />session<br />session<br />session<br />
    61. 61. Caching session<br />Cache<br />package<br />key<br />value<br />Alert<br />Listener<br />
    62. 62. Worker<br />Session<br />Worker<br />Session<br />Package (single session)<br />client<br />Worker<br />Session<br />dbms_job<br />Worker<br />Session<br />Worker<br />Session<br />
    63. 63. Java Stored Procedure<br />Unlocking the World<br />
    64. 64. Challenges<br />
    65. 65. Challenges<br />Lack of Interaction<br />Humans<br />External Systems<br />PL/SQL is limited<br />
    66. 66.
    67. 67. Q<br />
    68. 68.
    69. 69.
    70. 70. 1<br /><ul><li>Write Functional Java</li></ul>2<br /><ul><li>Wrap with PL/SQL</li></ul>3<br /><ul><li>Load into Database</li></ul>4<br /><ul><li>Set appropriate Privs</li></ul>5<br /><ul><li>Invoke JSP via PL/SQL Interface</li></li></ul><li>Summary<br />
    71. 71.
    72. 72.
    73. 73. From Xenophobia to Xenogenetics<br />Established best practices in languages like Java can help improve use of PL/SQL<br />Design by Contract, Encapsulation, Assertion, Reduced Impact of Changes<br />Dependency Injection, Decoupling, Reuse<br />Technical concepts in Java can have a meaningful counterpart in PL/SQL<br />Data and Interaction across sessions<br />
    74. 74. From Xenophobia to Xenogenetics<br />De-facto standards – such as JSON – may make sense in a PL/SQL context<br />And open source PL/SQL libraries may exist<br />Through Java Stored Procedures, PL/SQL can leverage Java capabilities & libraries<br />To interact through additional channels<br />To calculate, process, generate, interpret<br />
    75. 75.
    76. 76. Lucas.Jellema@amis.nl<br />Alex.Nuijten@amis.nl<br />technology.amis.nl<br />

    ×