Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Devoxx 2011 - Scaffolding with Telosys
1. A pragmatic scaffolding approach
to build Java Web Applications
Laurent Guérin
Telosys Project Leader
Sogeti & OW2 Consortium
2. Introduction
Sogeti : Company Capgemini : Company
belongs to
: Plateform
Laurent Guérin : Person Telosys : Project
leads
laurent.guerin@sogeti.com
: IDE
located in
hosts
OW2 : Consortium
: License
France : Country
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 2
5. Model Driven
• "Model-First" approach ( MDD, MDA, … )
• Code generation from an existing model
• "Model Driven" => You need a model !
• Model => substantial initial investment
• Process : keep the model up to date !
MODEL Split !
XMI
Service
name
+port 0..n
( XML )
Port Binding Port Type
1
+binding name
name name Param
1 +type
name
StartWithExtensions
+output 0..1 +operation 0..n +operation 0..n
+input Input
0..1 +input
BindingOperation Operation
0..1
Code
name name
1 0..1 Output
+output
+message 1
+fault 0..n +fault 0..n
Message
Fault +message
BindingFault name
name
1 1
+part 0..n
Part
name
TOOL
Template
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 5
6. Scaffolding
• "Database-first" approach
Database
• Very efficient
• No customization between the database Metadata
metadata and the generator
TOOL
• Not enough information …
– Java field name Template
– Java field type
– Validation rules : min, max, regexp, … Code
– Boolean storage values ( 1/0, "T"/"F", … )
– etc …
• Cannot store/reuse further information
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 6
7. Wizards
• Code generation without model / DB “Java Model”
org.eclipse.jdt.core
• IDE tool => Needs user inputs Workspace
files
I.D.E.
• Can also use existing artefacts
as input
– Java class Java class
– WSDL file Java classes
• Efficient only for a few kinds of
targets
Code
• Can only be considered as Bulk
generation
"development accelerators"
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 7
9. Telosys approach
• What we want …
– to be able to generate code quickly for entities
management (like scaffolding) with a simple tool
– to add and keep specific information about entities
=> we need a repository to store them (kind of model)
• What we don’t want …
– to spend a lot of time to build a model
– to input further information for each generation
• What we must have …
– a database (“database first”) Metadata
DB
+
– an IDE (Eclipse) that is the developer’s daily tool
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 9
10. Telosys approach
• The 3 steps …
Template
Database updates customizes
Metadata
modify
& add
information Code
Repository Code
generator generator
generates
Repository
(Lightweight
updates model)
1 2 3
Use the Customize the Generate
“Database-first” “lightweight model” the code
approach to build
a “lightweight model”
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 10
11. The tripod of success
What a Method ( agile )
development
project needs…
Tools Framework
( code generation ) ( global & simple )
• The framework is self-sufficient to build a
complete Web application
( "global" / "full stack" framework )
• The tools are provided as Eclipse plugins in
order to make the programmer's life easier
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 11
12. Project’s philosophy
• “Keep it simple and stupid”
( KISP ? )
– lightweight framework
– small tools (easy to install & to use)
• “Conform with the standards”
– servlet/JSP/JSPX, JDBC, JPA, http, XML, …
• “Remain open”
– Open Source (hosted by OW2 consortium)
– Open Format (lightweight model = XML)
– Customizable templates different targets :
Telosys fwk + other Java Frameworks, Flex, PHP, …
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 12
14. The framework
• Global framework “all in one“
• Only one jar (+ JDBC) => no "jar hell" !
• Designed for "data centric" web applications
• Light (just needs a servlet container and a
database) & based on simple concepts
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 14
15. The "global effect"
One framework
that covers all the application layers
Authenti-
cation
Presentation Application Business Persistence
Services
Screen Java Beans
Maps ( POJO ) DAO
XML conv
"VO" SQL
JSP + taglib Screen
AJAX Managers
Framework
Services Thin persistence
Javascript layer
Very simple objects
Natively AJAX Commons, logging, I18N, … ( "Pure POJO" )
• “Global” means … less “glue”, less objects
(less memory footprint), less configuration, …
=> Coherence & Efficiency
• “Modular” (modules usable separately)
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 15
16. The "client-server" paradigm
• Once the screen is loaded in the browser, it
converses with the server via AJAX requests
( XML / http )
Client-side http Server-side
<request screen-name="Employee"
screen-id="0" action="get" >
</request> Screen
Manager
Action
<response screen-name="Employee"
screen-id="0" action="get" >
<return code="0" message="Ok" >
</return>
Framework
JavaScript
<data>
<employee id="23" lastName="Wayne"
firstName="John" manager="0" email="" />
</data>
</response>
Service
Service
http://myhost:8080/.../Add.svc?p1=2&p2=6
<response service-name="Add">
<return code="0" message="Ok" />
<values> <value result="8" /> </values>
<data> </data>
</response>
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 16
17. The "Data Objects"
• VO Bean (POJO = “entity record”) Code
• VO List (selectable/sortable list of POJO)
generator
• DataSet (grid of objects)
Book
.java
BookDAO
BookConv VO Bean .java
.java
Data
Database
XML XML Access
<…>
VO List Layer Book
</ … >
Table
Con- BookList
verters .java
DataSet Parsers
Files
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 17
18. The "Data Access Layer"
• Why another persistence framework ?
ORM : JPA (or Hibernate) …
High level & "Object Oriented"
Java objects
Hides the complexity rule the persistence
Sometimes misunderstood by the developers
( "lazy/eager" loading, cache effects, DB
"attached/detached" entities,
"owning side"/"inverse side" links, … ) new new
Telosys DAL (based on DAO pattern)
Intermediate level & "Record Oriented" Database records
One Bean = One Record rule the persistence
The developer keeps the control
No links, no cache, no byte-code enhancement
DB
Very simple API : load, save, insert, update,
exists, loadList, updateList, … new legacy
JDBC API Both are useful,
Low level You have the choice …
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 18
19. "Record Persistence" examples
A "record" = a bean (POJO)
Each bean is managed by a dedicated DAO
EmployeeDAO dao = getDAO();
Employee employee = new Employee();
employee.setCode( "123" ); // primary key
int r = dao.load(employee, db);
The developer decides…
if ( r > 0 ) { // if found . What to do
// update
employee.setFirstName("Bill"); . How to do it
dao.update(employee, db);
} . When to do it
else {
// create
employee.setLastName("Wayne"); EmployeeList list = new EmployeeList();
employee.setFirstName("John"); ListQuery query = dao.createQuery(…);
employee.setEmail("jwayne@cinema.com"); int count = dao.count(query, db);
dao.insert(employee, db); dao.loadList(query, list, db);
} dao.updateList(list, db);
if (dao.exists(employee,db)){...}
dao.delete(employee, db); db.commit();
db.rollback();
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 19
20. Links or no links ?
• You have the choice …
• Links can be generated if an “object graph
approach” is chosen (ie with JPA persistence)
Bean
@ManyToOne Code
@OneToMany generator
@ManyToMany
@OneToOne
• With a “record approach” : no need to manage
links between beans, the framework uses
“aggregations” to assemble required beans
Code
Bean generator
Aggregation
(composite) DAO
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 20
21. The screens
Code
generator
request BookMgr BookProc
ScreenMap .java .java
response ScreenManager ScreenProcedure
V C
AJAX acts on …
BookData
.java Book (bean) M
ScreenData
AuthorList
Book.jsp (aggregation
( or .jspx)
0 .. N objects) Shop (bean)
Book.js DataSet
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 21
23. Conventions
• "Framework" => "Frame" !
• "CoC" ( Conventions over Configuration )
– The developers know where the files are
– The tools know where to generate files
• Example : 1 Java package 1 web folder
1 screen =
+
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 23
24. What is a Telosys project ?
• Just a standard Java Web Application project
src (server side)
TelosysTools (+) deployment
WebContent (client side) .war
• It can be organized for Maven, or not…
• In Eclipse :
That’s all !
1) Create a new "Web Dynamic project" The project is ready
for development and
2) Import the "Telosys Starter Kit“ code generation
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 24
25. Demo
• How to create a Telosys project …
1) Create a Dynamic
Web Project 2) Import the
Telosys starter kit
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 25
26. Demo (cont’d)
• Test and initialize the Telosys project …
3) Test the
project
( run it )
4) Define the
conventions
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 26
28. The big picture
Everything can be
done in Eclipse
Editors Wizards Properties
Repository Repository Template
Database .dbrep .vm
Meta-data generator ( XML )
Code
.java
generator
Context .jsp / .jspx
.js
Velocity
other …
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 28
29. The demo
• Connection to the database
• Repository generation
• Repository customization
• Basic objects generation (Bean, List, DAO, Conv.)
• Screens generation (server side & client side)
• Template customization
• Links management
• Beans generation for JPA & Validators
• New specific template See demo screenshots at
the end of this presentation
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 29
31. Conclusion
Database Repository Tools Initial code
and the project is
on the rails…
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 31
32. In the future …
• Main goals in the 2012 roadmap
– Repository
• Extendable/unlimited information for
each entity and each Java field
– Screens design
• Official release of the Screen Builder
plugin (WYSIWYG)
Still a lot
– Java Portals of work to
• JSR-168 portlet to embed
screen maps in a portal page
improve
– NoSQL
the rails …
• DAO for GAE/BigTable & Cassandra
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 32
43. Demo (cont’d)
• Generator templates
– The generator is based on "Velocity"
– The templates ( ".vm" files ) can be modified in order
to conform with each project requirements
• coding style
• comments
• etc… i.e. :
add/remove
serialization
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 43
44. Demo (cont’d)
• Entities links
– The foreign keys can be used to generate
links between entities
–Useful for JPA beans generation
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 44
45. Demo (cont’d)
• Generator project’s variables
– Each project can
define its own
specific variables…
… and use them
in the templates
#if ( $bean_jpa == "1" )
$link.jpaAnnotations(4)
#end
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 45
46. Demo (cont’d)
• Adding a new specific template
– 1) create the new “.vm” file vo_doc_html.vm
– 2) add it in the “templates.cfg” file
HTML documentation ; ${BEANNAME}.html ; doc/html ; vo_doc_html.vm
Title File Folder Template
–3) use it in the tool …
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 46
47. Demo (cont’d)
• Using wizards
New …
Devoxx 2011 – Laurent Guérin – JAVA scaffolding with Telosys ( http://www.telosys.org ) 47