/
An Oracle White Paper March 2009 Introduction to Groovy Support in JDe An Oracle White Paper March 2009 Introduction to Groovy Support in JDe

An Oracle White Paper March 2009 Introduction to Groovy Support in JDe - PDF document

tawny-fly
tawny-fly . @tawny-fly
Follow
450 views
Uploaded On 2015-08-01

An Oracle White Paper March 2009 Introduction to Groovy Support in JDe - PPT Presentation

Oracle White Paper ID: 98412

Oracle White Paper

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "An Oracle White Paper March 2009 Introdu..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

 An Oracle White Paper March 2009 Introduction to Groovy Support in JDeveloper and Oracle ADF 11 Oracle White Paper— Introduction to Groovy support in JDeveloper and Oracle ADF 11g Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g  Introduction.......................................................................................2 Introduction to Groovy.......................................................................2 Groovy in JDeveloper and Oracle ADF..............................................2 Groovy expressions in ADF Business Components Entity Objects....3 Referencing attributes in the same entity.......................................3 Referencing custom methods in the EntityImpl class.....................3 Referencing base class methods in the EntityImpl class................4 Using Groovy expressions in error messages................................6 Referencing attribtues in other entities...........................................7 Referencing built-in calls................................................................9 Entity object Groovy diagram.......................................................13 Groovy Expressions in ADF Business Components View Objects...13 Conclusion......................................................................................14 Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 2 Introduction Oracle JDeveloper and Oracle ADF 11g introduce support for the Groovy scripting language, allowing Groovy expressions to be used in attribute validation and as a source for attribute values. This paper gives and overview and examples of the support. Introduction to Groovy   \n  \r\n  \n  \r\r    \n\r \r  \r\n\r \n  \r \r\n \n   \n \r    \r  \r\r \r\n     \r\n  !\r\n  \n  \n  \r \n\r \r\r \n  \r \r\r\r\r \n\r \r\r \r\r\n \r \n  \r  "\r \n\n \r \r #\r\r   \n\r\r$\r \n %\n\r\r    \r\r \n  \n\r\n\r$  \r% \n\n\r\r&' \n \n \r\r\r  \r\n\n\r\n  \r( \n \r    \r \n  \r) \r \n  \r\r  * \r \n\r\n\r\n \n  \r\r\r \r\n\r\r\r\n\r +  \r, \r\n \n#--  \r   -\r\n . \r.\r Groovy in JDeveloper and Oracle ADF. /\r\r\r\n\n\n0  \r12+!\n\r3\n\r\n\r \n  \r\r \r\r\r\n0  \r12+,\r  \r\n\r   \n\r\r \r \r\n  \n  \n +\r\r\r \r\n\r\r\r \n\r \n\r\r \r \r    \n4\r   \r \n   \n  4\r\n\r \r\n \n\r4 \n\r\n0  \r12+,\r   \r\r)'2* "\r \n\r  \r    \n\r\r \n \r\n   \n \r\n \r\r\n\n\r \r\r\r\n\n \n\r\r\n \n\r\r   \n 0  \r12+\r \n\r\r\r\n\r  \r\n\n \n\r#· & \r\r \n\r\n5\r \r· &  \n \r\n\r\n5\r \r· 6\r\n\r\r \r Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 3 · & \r\r5\r\n   \r· &\r5\r \n\r\n \r  \n Groovy expressions in ADF Business Components Entity Objects \r\r\n \n\r \r\n \n\r\r\r\n \r\n12+!\n\r3\n\r\n +\r \n    \r  \n \r\n\r\n \n\r5\r \r \r \n\r\n5\r  \n  Referencing attributes in the same entity "\r \r\r  \r\r\r\r\n\r \r\n\r \r\r\n \r \n\r\n \r \r\n\r \r\r\n\r\r  \r#Sal * 12 7 \n \r \r\r\n    \n\r \r  \n\r\n\r   \r \n \r   \r \n8999#if (Job == "SALESMAN") {return newValue 1000} else return true /\r\n\r\r\r\n\r \n \r\n   \r \r \r\r   \r\r\r\r\n\r \r\r\n   \r    \n\r\r \r) \r\r\n\r\n\r \n  \r\r\r\r \r\r* \r \n \n\r\r\r\n\r \r\r\r\r\r\n \n  :\n\r\n12+!\n\r3\n\r\n \n  \r\n\r \r\r\r 5\n 7 \n \r \r  \r\n\r \r\r\r  \n \r  Referencing custom methods in the EntityImpl class : \r\r\n\r \r\n6\n:  \r\n \n\r \r  \r\r\n \n \r\r  #adf.object.getDefaultSalaryForGrade() ;\n \r\r\n\r\r\r\n\n  \n \r\r\r\n5\r \n\r\n\r \r\r\r\n\n \r \r\n \r\r\n\r\r\r\n\n  \r \r\r\r\r\r\r\n \radf.object  Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 4 : \n\r\r\r\n\r\r \r\r    \r\r\rsource\r source.getDefaultSalaryForGrade() +\r  \r \r\r \n \r\r\n \r\n \r\r   \r \n if (Job == "SALESMAN") { return newValue source.getMaxSalaryForGrade(Job) } else return true Referencing base class methods in the EntityImpl class :\n\r\r\r  \r\r\r\r\r\r\n\n \n\r\n\r6\n:   7 \n \r\r\r\n\r \r \r  \r\r\n \r \n\r6\n: +\r  \r\n\r  \r  \n\r\r   \r \r\r\n\r\n\r\r\r\r\r   \r  Figure 1. Setting employeeId from a database sequence Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 5 "\n\r\n\r6\n: \r \n  \r\r\n\r5\r \n\r\n \n    = \n\n \r8"\r \r  \n\r \r\n  \r\r\n \r \r\r  \r \r#(new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ", adf.object.getDBTransaction())). getSequenceNumber() .10;霰\r  \r\r\r\r\r \n \r\r )        * \n  \r  \r\r\r\n\r\r6\n: 0\r\n \r \r \r \n6\n: \r \r\r#protected oracle.jbo.domain.Number nextVal(String sequenceName) { SequenceImpl s = new SequenceImpl(sequenceName,getDBTransaction()); return s.getSequenceNumber(); } "\r\n\r \r\r\n \n5\r#adf.object.nextVal("YOUR_SEQUENCE_NAME")  \n\r  \n\r6\n:  \n \r \r\n  \n\r\r)   \n\r*\r  \r \n\n \r\r \r \n \r\r \r  \n\r \r ;\n \r \n \r \r \n \r6\n: \r \n \r\n \r \r \n \r\r  \r \n \n \r \r  \n  \n\n \r \r  adf.object.setEmail(adf.object.getAttributeHints("LastName").getLabel(adf.object.getDBTransaction().getSession().getLocaleContext())) ?\r\r\r\r  \n\r  \r\n \r \r\n \n#adf.object.hints.LastName.label "\r\r \r!  \r  \r\r6\n: \n \n\r "\r\r"\r\r   \r \n\r \r\r \r\n \r" \r!  " \r\r\r\n\r \n\r \n\r\n # @\r\r \n' 5\r\r\r\n\rA\r \r\r\nA\n\r\r\n  \r \r \n \r \r!  "$  \r\r\n\n\r\n' \n \rA@ .10;霰 \rA \n\r'  \r;:\n    \r   \r  \n \r \n' \r\r\n\r\r \r\r\n\n\r\r\n  \r \r \n \r  Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 6 \r!  "$   \r\r\n\n\r\r!  "$ ' \r\rA \r A 7 \n \r \r#adf.object.hints.LastName.label   \r \r\n#getAttributeHints("LastName").getLabel(getDBTransaction().getSession().getLocaleContext()); Using Groovy expressions in error messages 1 \r  \n \n\r\n5\r \n\r\n\r \r \r\n\r\r\r \r  \r\r  \r \r\r\n \r  \r \n\r\r\r\n\r\r \r  \n  \r      \n\r\r \r \r \r \n\r\r \r \r \r #$"\n   \rBC +\r \n\r\rBC %"\r \r \n \r\r\r\n) \n\r\r\r* #source.getAttributeHints("HireDate").getLabel(source.getDBTransaction().getSession().getLocaleContext()) source.getAttributeHints("HireDate").getTooltip(source.getDBTransaction().getSession().getLocaleContext())\n \r\r\r\n \n#source.hints.HireDate.label source.hints.HireDate.tooltip" \n\r\n% \r  \n\r\r\r \r \r\r  \n\r \r  \r\r\r \r  Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 7 Figure 2. Customizing an error message by calling an entity attribute control hint Referencing attribtues in other entities 7 \n \r\r\r\n\r \r\n\r\r\n\r +\r  \r \n\r\r \r\r,\r     \r \n \r\r\n\n \n\r  \n \r getDefaultSalaryForGrade  \r\r \r\n  \n  \n " \r\r\r\r\r\n\n \r \r\n\r\r\n  \n " \r\r\r\n\r\r \r\r\r\n5\r$  %\r \r\r \r\n\r\n +\r  \r#  object.getDefaultSalaryForGrade(Dept.Loc)  \n   \r-\r  \r \n\r\r\r\n\r \r\n \n\r \r\r\r\r\n \r\r  \r    \r6 \r\r6\n: \r \n \n\r \r$ \r \r �\r \r\n\r\r\r\n\n \r\n \r\r\r\n)2\r*5 \r\n\r \r  \r\n\r\r\r\r\n \n\r\r\n \r   \r\r\n \r\r  \n  \n2\r \n6 \r&'    \n\r \r \r \r  \n "\n\n \rD  Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 8 Figure 3. Entity association ?\r\r\r\r \n \r\r\n \r\r\r \r (  \n\n \rE\r\n\r  \r#adf.object.getDefaultSalaryForGrade(DeptContainingEmps.Loc) Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 9 Figure 4. Entity association using a different name for the accessor \r\n \r\r \r  \n \r\r\r\n$ %\r\r \n\r\r\r\n5\r �\r \r\r\r\n \r\n\r \r \n\r  \n \r\n\r \r\n \r \n \r \r\r\r\n  \r\n  \r\r\n \n \r \n \r\n \r)\n  \n\r    \r\n \r*\r\n  \r \n  \n \r\r\r\r\n \r Referencing built-in calls "\r\r \r  \n\r$ \n%\r \r  \n\r\r\r\n\r  Date and time adf.currentDate adf.currentDateTime "\r\r\n\r\r\n   \n\r\r \r\r \r\r  \r \r \n\r\r \r\r\r\r\n\r  , \r  \r\n\r\r\r\r\n #adf.currentDate Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 10 : \n\r \r\r \r \n\r\r \r\r\r\r , \r \r   \n% \r  #return (newValue adf.currentDate) Aggregate functions 12+!\n\r3\n\r\n\r \r \r\n\n  Accessor&#x-2.2;犇.sum(Groovyexpression) Accessor&#x-2.2;犇.count(Groovyexpression) Accessor&#x-2.2;犇.avg(Groovyexpression) Accessor&#x-2.2;犇.min(Groovyexpression) Accessor&#x-2.2;犇.max(Groovyexpression) \r2\r\r\n5\r   \n\r \n\r\n \r  \r \r \r\r, \n \r \r\n Emp.sum("Sal") 1 \r\n  \r\n\r\r\n\r \r\n \r\n \r\r \r)6*\r\r\r\n\r\r\r \r\r \r\r \r\n + \n \r \r61\r  \r \n  \n   \n \n\r\r\n#EmpAccessor.sum("Sal + 20") :\n\r\r  \r\r\n \r \r  \r\n\r)*\n\n\n\r\r\r\n\r\n\r\r \r  \r\n\n\r \r\n\r\r\n \n \r\r\r\n\n\r2\r\r\n5\r\r  \r\r\r\n \n\r\r\r\r \r\r6\r\n "\r \n  \n\r\r\n\r\r \n \n \r\r\r\r\r\n\r \r\n\r6\r\n : \n\r\r\r \r\r\r \n  \n\r \r2\r\r\n   \r\r  \r\r \r\r\n \r \r\n "\r  \n\r  \r\n\r \r \r\r,  \r\r\n\r  \r\r\r\n\r 5 \r "\r\r\r\r \n \r\r\n \r \r \n \r\n\r2\r\r\n5\r#EmpAccessor.sum("Sal + adf.object.getBenefitsValue(Job)") Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 11 Figure 5. Business components diagram showing the object structure + \rF \r\r\n\n\r2\r\r\n)\r  *\r \r61\r$ %\r2\r\r\n\r6\r\n +\n\n\r\n\r\n\n\r6\r\n \n   !  \r\r\r\n\r\n\r66\n: \n\r \r) \r\r\r\n\r\r6\r\n5\r  Walking objects using the dot notation " \n \r\r\n\r\n\r\r\r \n\r \r$ % \n\n\r\n\r\n\r\n 3\n\r  \r\r  2\r \n6\r\r \n\r\n\r  \r  \n\r \r\r\r \r \r \n\r\r \r\n\n 7  \r \n6  \n\n #return newValue � DeptContainingEmps.Emp.min("Sal")"\r\r   \r \r \n \r5\r\r\r\r \r2\r \n\r\n  \n \r \r\n\n\n\r\r    \r\n \r\n6 0\r\n\n  \r\r\r\r\r\n \n\r \r\r \r\r \n \r \r \n \n\r \r\r\r\n\r \n  Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 12 Ternary Operators 1\n \r\r \n\r,\r\n \r  "\r  \n  \r\r\n\r \n\r\n\r \r\n (Conditional expression&#x-2.2;牸 ? action&#x-2.2;爗 : else-action&#x-2.2;爗) +\r  \r# (Job != "SALESMAN" ? newValue &#x-2.2;爗 100 : newValue &#x-2.2;爗 0) " \n\r\r  $5\n 1@6'1&#x-2.2;爗\r\n\r\n\r \r\r \r \r \r \n899\r \r \r \r \n9 " \n\r\r \r\r\n \r \r\n\n\r\n\r\n,  \r\n #EmpAccessor.sum("Comm != null ? Comm : 0") 0 \n\r\n\n \r\r \r\r \n\n\n \n\rD99 #EmpAccessor.count("Comm != null && Comm &#x-2.2;爗 300 ? Comm : null") Raising exceptions and warnings +   \n \r\n \n\r\n \r \n\r \r\r\n\r\r\r\r \n\r  \n\n \r \r \r \r\n \r \n \r\r\n#adf.error.raise("THIS_IS_AN_ERROR_MESSAGE") adf.error.warn("THIS_IS_A_WARNING_MESSAGE") \r \r\r  \n\r\n\r  \r   \r\n \r\r\r\n8999 \nF999    \n\n 1\n \r  \r   \n\r \n\r\r\r\n\r\r\r if (newValue .10;霰 1000) { if (newValue .10;霰 5000) {adf.error.raise("SALARY_TOO_HIGH_ERROR") return false} adf.error.warn("SALARY_LIMIT_WARNING") return true } Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 13 else { return true Entity object Groovy diagram + \rG 4\r\r5\r\r\n \r\r\n\n\r\n5\r  Figure 6. Object structure for Groovy expressions in entity objects Groovy Expressions in ADF Business Components View Objects 12+!\n\r3\n\r\n\r5\r \r\r  \r\r\r\n 1\r\n5\r\r5\r \n#· \r\r\r\n\n  \r\n\r \r\r5\r· \r\r\r\n\n  \r\n\r\r5\r· " \n\r\n \r  \n Oracle White Paper—Introduction to Groovy support in JDeveloper and Oracle ADF 11g 14 · \r\r\r\n\n \r\n\r     \r\r5\r· \r\r\r\n\n  \n   \n&\r5\r  \r\r\n\r\r\n\n   \r ?\r\r\r\n \n   \r\r\n \r  \r\r\r\n\n\n\r \r\r   \r \r5\rH\n   \r\r\n \r  \r\r\n\r\n\r\r&\r05\r:   \r \n  \r)\r  \r\r\r5\r* \r\n    \r 1\n\r \n \r\n\r     \r\r5\r "\r\n \n\r \r\r\n5\r\r6\n:   :\n \r5\r\r&\r: \n\r&\r:   \n\r\r\r\r\n\r "\r6\n:  \n\r&\r: \r\r\n\r:   "\r\r\r\r\n\r\r \r&\r05\r:  \n5\r \r\r\r\n\r\r \n  \r  \r\r\r\r\n \n \r\r\r \n &\r: \n \n\r\r\n\r\r\r  Conclusion "\r\n  \n  \r \r \r \r  \r  \n\r\n \r\r\r   \n  \r\n    \r\r  \n \r\n\r\r \r\r0  \r12+ / \r0  \r12+\r  \r \r \n   \r \r\r\r \r\r\n \r\r\r\r \r\r  \r  \r\n \n  \r\r\r \r\n \n\n\r  Introduction to Groovy Support in JDeveloper and Oracle ADF 11g March] 2009 Author: Grant Ronald Contributing Authors: Oracle Corporation World Headquarters 500 Oracle Parkway Redwood Shores, CA 94065 U.S.A. Worldwide Inquiries: Phone: +1.650.506.7000 Fax: +1.650.506.7200 oracle.com Copyright © 2009, Oracle and/or its affiliates. All rights reserved. This document is provided for information purposes only and the contents hereof are subject to change without notice. This document is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or implied in law, including implied warranties and conditions of merchantability or fitness for a particular purpose. We specifically disclaim any liability with respect to this document and no contractual obligations are formed either directly or indirectly by this document. This document may not be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without our prior written permission. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. 0109