Utilized code generation to save our efforts in SAP Integration  Albert Guo [email_address]
Agenda <ul><li>Scenario </li></ul><ul><li>SAP Implementation </li></ul><ul><li>Data Access Object Pattern </li></ul><ul><l...
Scenario
Scenario
SAP Implementation
SAP Implementation But including the connectivity and data access code within these components  introduces a tight couplin...
Data Access Object Pattern
Data Access Object <ul><li>Data Access Object (DAO) is an  object  that provides an abstract  interface  to some type of  ...
DAO Structure © 2006 PTC The BusinessObject represents the data client.  It is the object that requires access to the data...
Participants and Responsibilities © 2006 PTC Create Read Update, Delete
Strategies - Automatic DAO Code Generation Strategy <ul><li>Automatic  DAO Code Generation Strategy </li></ul><ul><ul><li>...
Strategies - Automatic DAO Code Generation Strategy <ul><li>which will generate the following java source files: </li></ul...
Advatnages <ul><li>The advantage of using data access objects is the relatively simple and rigorous separation between two...
Implementation Steps Squirrel SQL Client and DAO4J can generate these codes, so we does not need to do from the scratch. W...
Squirrel SQL Client and DAO4J
Definition <ul><li>Squirrel SQL Client </li></ul><ul><ul><li>SQuirreL SQL Client is a graphical Java program that will all...
Demo
Demo Select specific table. Right click, then select  Generate DAO . 1
Demo Define code gen  to where Define package name for each class Refer to database specific properties file in dao4jconf 2
Demo
Class Diagram DAO Interface DTO Class The DTO Class which contains only  the PK fields and can be used as the key of HashM...
Class Diagram We does not need to know the detail method operation,  just call create method if we need to insert data int...
Source code snippet . . We just need to focus on how to retrieve all the necessary attributes, and set values to DTO Provi...
ATTENTATION – Poor Exception Handling We need to add catch clause before finally clause
ATTENTATION – Poor Exception Handling
Summary
Benefits <ul><li>Enables Transparency </li></ul><ul><ul><li>Business objects can use the data source without knowing the s...
Summary Code Generation We can focus on workflow design,  and retrieve required value and  call DAO method.
Upcoming SlideShare
Loading in …5
×

Utilized Code Gen To Save Our Efforts In Sap Integration

1,147 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
1,147
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
38
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Utilized Code Gen To Save Our Efforts In Sap Integration

  1. 1. Utilized code generation to save our efforts in SAP Integration Albert Guo [email_address]
  2. 2. Agenda <ul><li>Scenario </li></ul><ul><li>SAP Implementation </li></ul><ul><li>Data Access Object Pattern </li></ul><ul><li>Squirrel SQL Client and DAO4J </li></ul><ul><li>Summary </li></ul>
  3. 3. Scenario
  4. 4. Scenario
  5. 5. SAP Implementation
  6. 6. SAP Implementation But including the connectivity and data access code within these components introduces a tight coupling between the components and the data source implementation. Such code dependencies in components make it difficult and tedious to do modification if requirement change.
  7. 7. Data Access Object Pattern
  8. 8. Data Access Object <ul><li>Data Access Object (DAO) is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database. </li></ul><ul><li>This isolation separates the concerns of what data accesses the application needs, in terms of domain-specific objects and data types (the public interface of the DAO), and how these needs can be satisfied with a specific DBMS, database schema, etc. (the implementation of the DAO). </li></ul><ul><li>This design pattern is equally applicable to most programming languages, most types of software with persistence needs and most types of database, but it is traditionally associated with J2EE applications and with relational databases accessed via the JDBC API because of its origin in Sun Microsystems' best practice guidelines (&quot;Core J2EE Patterns&quot;) for that platform. </li></ul>
  9. 9. DAO Structure © 2006 PTC The BusinessObject represents the data client. It is the object that requires access to the data source to obtain and store data. The DataAccessObject is the primary object of this pattern. The DataAccessObject abstracts the underlying data access implementation for the BusinessObject to enable transparent access to the data source This represents a Transfer Object used as a data carrier This represents a data source implementation. A data source could be a database such as an RDBMS, OODBMS, XML repository, flat file system, and so forth. A data source can also be another system (legacy/mainframe), service (B2B service or credit card bureau), or some kind of repository (LDAP).
  10. 10. Participants and Responsibilities © 2006 PTC Create Read Update, Delete
  11. 11. Strategies - Automatic DAO Code Generation Strategy <ul><li>Automatic DAO Code Generation Strategy </li></ul><ul><ul><li>Since each BusinessObject corresponds to a specific DAO, it is possible to establish relationships between the BusinessObject, DAO, and underlying implementations (such as the tables in an RDBMS). Once the relationships are established, it is possible to write a simple application-specific code-generation utility that generates the code for all DAOs required by the application. </li></ul></ul>© 2006 PTC DAO, DTO Classes SQL Client Code Gen Tool Generated Results
  12. 12. Strategies - Automatic DAO Code Generation Strategy <ul><li>which will generate the following java source files: </li></ul><ul><ul><li>DTO (Data Transfer Objects): This is the DTO Class </li></ul></ul><ul><ul><li>DAO Interface </li></ul></ul><ul><ul><li>DAO Impl Class </li></ul></ul>© 2006 PTC DAO Interface DAO Impl DTO
  13. 13. Advatnages <ul><li>The advantage of using data access objects is the relatively simple and rigorous separation between two important parts of an application which can and should know almost nothing of each other, and which can be expected to evolve frequently and independently. </li></ul><ul><li>Changing business logic can rely on the same DAO interface, while changes to persistence logic do not affect DAO clients as long as the interface remains correctly implemented. </li></ul><ul><li>In the specific context of the Java , Data Access Objects can be used to insulate an application from the particularly numerous, complex and varied Java persistence technologies , which could be JDBC , JDO , EJB CMP , TopLink , Hibernate , iBATIS , or many others. </li></ul><ul><li>Using Data Access Objects means the underlying technology can be upgraded or swapped without changing other parts of the application. </li></ul>
  14. 14. Implementation Steps Squirrel SQL Client and DAO4J can generate these codes, so we does not need to do from the scratch. We can take it as black box. We just need to focus on workflow design and author business objects. We don’t need to know how to do CRUD.
  15. 15. Squirrel SQL Client and DAO4J
  16. 16. Definition <ul><li>Squirrel SQL Client </li></ul><ul><ul><li>SQuirreL SQL Client is a graphical Java program that will allow you to view the structure of a JDBC compliant database, browse the data in tables, issue SQL commands etc. The minimum version of Java supported is 1.5.x as of SQuirreL version 2.4. </li></ul></ul><ul><ul><li>http://squirrel-sql.sourceforge.net </li></ul></ul><ul><ul><li>For more features and screenshots, you can go to http://squirrel-sql.sourceforge.net/index.php?page=screenshots </li></ul></ul><ul><li>DAO4J </li></ul><ul><ul><li>DAO4J can generate clear and efficient Java source files to populate Database tables via standard JDBC. </li></ul></ul><ul><ul><li>http://freehost04.websamba.com/dao4j/ </li></ul></ul>© 2006 PTC
  17. 17. Demo
  18. 18. Demo Select specific table. Right click, then select Generate DAO . 1
  19. 19. Demo Define code gen to where Define package name for each class Refer to database specific properties file in dao4jconf 2
  20. 20. Demo
  21. 21. Class Diagram DAO Interface DTO Class The DTO Class which contains only the PK fields and can be used as the key of HashMap This table has more than 80-column, I’ll not show all attributes in class diagram DAO Impl DTO Class
  22. 22. Class Diagram We does not need to know the detail method operation, just call create method if we need to insert data into ERP interface table.
  23. 23. Source code snippet . . We just need to focus on how to retrieve all the necessary attributes, and set values to DTO Provide DTO and connection to create method. Then, everything is done.
  24. 24. ATTENTATION – Poor Exception Handling We need to add catch clause before finally clause
  25. 25. ATTENTATION – Poor Exception Handling
  26. 26. Summary
  27. 27. Benefits <ul><li>Enables Transparency </li></ul><ul><ul><li>Business objects can use the data source without knowing the specific details of the data source's implementation. Access is transparent because the implementation details are hidden inside the DAO. </li></ul></ul><ul><ul><li>Reduces Code Complexity in Business Objects </li></ul></ul><ul><ul><li>Because the DAOs manage all the data access complexities, it simplifies the code in the business objects and other data clients that use the DAOs. All implementation-related code (such as SQL statements) is contained in the DAO and not in the business object. This improves code readability and development productivity. </li></ul></ul><ul><ul><li>Centralizes All Data Access into a Separate Layer </li></ul></ul><ul><ul><li>Because all data access operations are now delegated to the DAOs, the separate data access layer can be viewed as the layer that can isolate the rest of the application from the data access implementation. This centralization makes the application easier to maintain and manage. </li></ul></ul>© 2006 PTC
  28. 28. Summary Code Generation We can focus on workflow design, and retrieve required value and call DAO method.

×