JavaOne2010 Groovy/Spring Roo

1,603 views

Published on

Presented in JJUG CCC 2010 Fall at 2010-10-18

Published in: Technology, Business
  • Be the first to comment

JavaOne2010 Groovy/Spring Roo

  1. 1. 1
  2. 2. 2
  3. 3. 3
  4. 4. 4
  5. 5. 5
  6. 6. 5
  7. 7. 6
  8. 8. 6
  9. 9. 6
  10. 10. 7
  11. 11. 7
  12. 12. List
list
=
[1,
2,
3] Map
map
=
[“a”:1,
“b”:2,
“c”:3] //
key Map
map
=
[a:1,
b:2,
c:3] 8
  13. 13. [1,
2,
3].collect
{
num
‐>
num
*
2
} //
=>
[2,
4,
6] //
 it [1,
2,
3].collect
{
it
*
2
} //
=>
[2,
4,
6] [1,
2,
3].each
{
print
it
} //
=>
1 //
=>
2 //
=>
3 [1,
2,
3].findAll{
num
%
2
!=
0
} //
=>
[1,
3] 9
  14. 14. //
 Ivy @Grab(group='log4j',
module='log4j',
version='1.2.9') import
org.apache.log4j.* Logger
log
=
Logger.getLogger(this.class) log.setLevel(Level.ALL) def
layout
=
new
SimpleLayout() def
appender
=
new
ConsoleAppender(layout) log.addAppender(appender) log.debug
"Hello,
Grape!" log.info

"Hello,
Grape!" log.warn

"Hello,
Grape!" log.error
"Hello,
Grape!" log.fatal
"Hello,
Grape!" 10
  15. 15. 11
  16. 16. 12
  17. 17. 13
  18. 18. 14
  19. 19. 15
  20. 20. //
 Object.metaClass. 
= 

Object.metaClass. 
= 


{
clos
‐>
clos.call(delegate)
} 
=
{
it
} 
=
{
println
it
} 
=
{
Math.sqrt(it)
} //
 
100
 
 
 
 //
=>
10.0 16
  21. 21. 17
  22. 22. 18
  23. 23. 19
  24. 24. 20
  25. 25. 21
  26. 26. 22
  27. 27. import groovy.swing.SwingBuilder import javax.swing.* count = 0 def frame = new SwingBuilder().frame(title:'Frame', defaultCloseOperation:JFrame.EXIT_ON_CLOSE, pack:true, show:true) { vbox { def textlabel = label("Click the button!") button( text:'Click Me', actionPerformed: { count++ textlabel.text = "Clicked ${count} time(s)." println "Clicked!" } ) } } 23
  28. 28. 24
  29. 29. $ cat build.gradle file apply plugin:'groovy' repositories { mavenCentral() } dependencies { groovy 'org.codehaus.groovy:groovy:1.7.4' testCompile 'junit:junit:4.8.1' } $ gradle clean test .... 25
  30. 30. 26
  31. 31. // 10 GParsPool.withPool(10) { assert (1..10).findAllParallel { it % 2 == 0 } == [2, 4, 6, 8, 10] } // Map/Reduce // filter map // xxxxParallel GParsPool.withPool { assert (1..10).parallel.filter{ it % 2 == 0 }.map{ it }.collection == [2, 4, 6, 8, 10] assert (1..10).parallel.filter{ it % 2 == 0 }.map{ it }.sum() == 30 } 27
  32. 32. 28
  33. 33. 29
  34. 34. // 0 9 4 def list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] assert list.findAll{ it % 2 == 0 }.size() == 4 30
  35. 35. // 0 9 4 def list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] assert list.findAll{ it % 2 == 0 }.size() == 4 








↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ Caught:
Assertion
failed:
 assert
list.findAll{
it
%
2
==
0
}.size()
==
4 






|



|





















|





| 






|



[0,
2,
4,
6,
8]







5





false 






[0,
1,
2,
3,
4,
5,
6,
7,
8,
9] 30
  36. 36. 31
  37. 37. 32
  38. 38. 33
  39. 39. 34
  40. 40. 35
  41. 41. 36
  42. 42. $
mkdir
contacts $
cd
contacts $
roo 



____

____

____

 


/
__
/
__
/
__

 

/
/_/
/
/
/
/
/
/
/
 
/
_,
_/
/_/
/
/_/
/

 /_/
|_|____/____/



1.1.0.M3
[rev
e66e029] Welcome
to
Spring
Roo.
For
assistance
press
TAB
or
type
"hint"
then
hit
ENTER. roo>
project
‐‐topLevelPackage
sample sample
roo>
persistence
setup
‐‐provider
HIBERNATE
‐‐database
 HYPERSONIC_IN_MEMORY
 sample
roo>
entity
‐‐class
~.domain.Contact
‐‐testAutomatically
 ~.domain.Contact
roo>
field
string
‐‐fieldName
firstName ~.domain.Contact
roo>
field
string
‐‐fieldName
lastName
‐‐notNull
‐‐sizeMin
3 ~.domain.Contact
roo>
field
number
‐‐fieldName
phone
‐‐type
java.lang.Long ~.domain.Contact
roo>
perform
eclipse roo>
controller
all
‐‐package
~.web roo>
perform
eclipse roo>
exit $
mvn
tomcat:run 37
  43. 43. 38
  44. 44. 39
  45. 45. 40
  46. 46. 41
  47. 47. 42
  48. 48. 43
  49. 49. 44
  50. 50. FIN

×