Gnizr Architecture (for developers)

1,679 views

Published on

How WebWork and Spring function in gnizr. For developers who want to extend gnizr.

Published in: Technology, Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,679
On SlideShare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
30
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Gnizr Architecture (for developers)

  1. 1. Gnizr Architecture Dr. Harry Chen CMSC 491S/691S February 25, 2008
  2. 2. Agenda <ul><li>Design patterns in gnizr </li></ul><ul><li>WebWork and Spring configurations </li></ul><ul><li>HelloWorldDemo revisit </li></ul>
  3. 3. Design Patterns Found in Gnizr <ul><li>Data Access Object (DAO) </li></ul><ul><li>Inversion of Control (IoC) </li></ul><ul><ul><li>a.k.a Dependency Injection </li></ul></ul><ul><li>Singleton </li></ul><ul><li>Interceptor </li></ul>
  4. 4. Gnizr Architecture What’s DAO?
  5. 5. What’s DAO? <ul><li>A design pattern that allows developers to abstract and encapsulate the access to the data source. </li></ul>User DB (MySQL) User Registration <ul><li>- add(user) </li></ul><ul><li>delete(user) </li></ul><ul><li>update(user) </li></ul><ul><li>lookup(user) </li></ul><ul><li>User record </li></ul><ul><li>is OP okay? </li></ul>How do you design your program to do these?
  6. 6. Why use DAO? <ul><li>Hide SQL statements from the high-level program. Don’t want to write the same SQL multiple times in different class files </li></ul><ul><li>Allow high-level programs to access DB records without knowing how the DB schema is designed </li></ul>
  7. 7. Tight-coupling is a bad idea Do you really want to write SQL every time you need to access the “customers” DB? Fetching data from “ResultSet” is complicated – it’s column-driven . Not natural for OO programming
  8. 8. DAO Design Pattern http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
  9. 9. DAO Example
  10. 10. DAO Example User Registration User DB (MySQL) User (class) UserDAO <ul><li>UserDao implements… </li></ul><ul><li>addUser(User): int </li></ul><ul><li>deleteUser(User): boolean </li></ul><ul><li>updateUser(User): boolean </li></ul><ul><li>getUser(id): User </li></ul>
  11. 11. Gnizr DAO package <ul><li>Let’s scan through gnizr DAO API </li></ul><ul><ul><li>Bookmark </li></ul></ul><ul><ul><li>User </li></ul></ul><ul><ul><li>Tag </li></ul></ul><ul><ul><li>Link </li></ul></ul><ul><ul><li>Etc. </li></ul></ul><ul><li>http://dev.gnizr.com/javadocs/2.3.0/ </li></ul>
  12. 12. Gnizr DAO Classes <ul><li>Let’s walkthough some DAO class implementation in gnizr </li></ul><ul><ul><li>UserDao.java (interface) </li></ul></ul><ul><ul><ul><li>UserDBDao.java (class impl) </li></ul></ul></ul><ul><ul><li>BookmarkDao.java (interface) </li></ul></ul><ul><ul><ul><li>BookmarkDBDao.java (class impl) </li></ul></ul></ul><ul><li>[Switching to Eclipse…] </li></ul>
  13. 13. How Gnizr Business Logic is Created When are these objects created? What’s the life span of these objects? How are JDBC connections initialized?
  14. 14. Inversion of Control (IoC) <ul><li>IoC is a principle that encourage the decoupling of code. </li></ul><ul><ul><li>A.K.A. Dependency Injection. </li></ul></ul>Problem : The use of “MovieFinderImpl” is hardwired into “MovieLister”. Change this logic will require code rewrite and re-compile “MovieFinderImpl” Read: http://martinfowler.com/articles/injection.html
  15. 15. Spring IoC <ul><li>A framework that can be coupled with WebWork to provide Dependency Injection. </li></ul>Spring IoC implements a flexible “Assembler”. Developers can tell this “Assembler” how to perform “<create>” via XML configuration. http://static.springframework.org/spring/docs/2.0.x/reference/beans.html
  16. 16. IoC in Gnizr <ul><li>How to create “hocks” for </li></ul><ul><ul><li>Connecting DAO objects to Gnizr Core class objects </li></ul></ul><ul><ul><li>Connecting Gnizr Core class objects to WebWork action objects </li></ul></ul><ul><ul><li>Injecting application configuration at runtime </li></ul></ul><ul><li>[Switching to Eclipse…] </li></ul>
  17. 17. Design Pattern: Singleton <ul><li>A design pattern that restricts the instantiation of a class to one object. </li></ul><ul><li>Singleton is used when you want exactly one object to be created in the system. </li></ul><ul><li>Singletons in gnizr, for example, </li></ul><ul><ul><li>GnizrBasicDataSource (holds JDBC settings) </li></ul></ul><ul><ul><li>All DAO objects (not Transport objects) </li></ul></ul><ul><ul><li>Gnizr Core class objects </li></ul></ul>
  18. 18. WebWork Actions are not Singletons <ul><li>99% of times, you should not define WebWork actions as Singletons. </li></ul><ul><li>Because…. </li></ul>
  19. 19. Actions are not Singleton <ul><li>WebWork actions are not singletons because multiple action objects are needed to serve multiple user sessions. </li></ul>user session action DAO MySQL Singleton is okay under what condition?
  20. 20. WebWork Actions in gnizr <ul><li>Let’s review some Action class in gnizr </li></ul><ul><li>[switching to Eclipse…] </li></ul>
  21. 21. WebWork Interceptors <ul><li>Interceptors are classes that can be defined to pre-process request or post-process response. </li></ul><ul><ul><li>Validate parameter value (e.g., password length must 8, no symbols are allowed) </li></ul></ul><ul><ul><li>Map HTTP parameter values to Beans and call “set” methods. </li></ul></ul><ul><ul><li>Create HTTP session automatically </li></ul></ul><ul><ul><li>… </li></ul></ul>
  22. 22. Interceptor http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.html
  23. 23. Interceptor http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.html
  24. 24. Gnizr WebWork configuration <ul><li>Let’s review Gnizr’s webwork configuration. </li></ul><ul><li>[switching to Eclipse] </li></ul>
  25. 25. WebWork Result Types <ul><li>Result Types are classes that determine what happens after an Action executes and a Result is returned. </li></ul>
  26. 26. Which Result Type to Choose <ul><li>The “name” of the result determines which Result Type to apply after an Action executes </li></ul><ul><ul><li>The “name” maybe “success”, “error” or any string that you choose return in your “execute()” method, or “go()” if you extends the “AbstractAction” class. </li></ul></ul>
  27. 27. Gnizr Result Type Examples <ul><li>Let’s review some example of Action configuration in gnizr, and see how different Result Types play a role in the application </li></ul><ul><ul><li>File: gnizr-useradmin.xml </li></ul></ul><ul><ul><li>File: gnizr-bookmark.xml </li></ul></ul><ul><ul><li>File: gnizr-json.xml (searchproxy action) </li></ul></ul><ul><li>[swithcing to Eclipse…] </li></ul>

×