simpleorm.quickstart

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » SimpleORM » simpleorm.quickstart 
simpleorm.quickstart
SimpleORMGenerator

SimpleORMGenerator provides a simple way of generating the SimpleORM class files for an existing database. Since SimpleORMGenerator uses the meta data extracted from the database the class files produced should exactly match the database's schema.

Class files produced

Every table produces two class files, a base class that contains the field definitions and a public class that extends the base class.

Example given table EMPLOYEE

file Employee_base.java
class Employee_base {
   //all table fields are defined here
}

File Employee.java
public class Employee extends Employee_base{
   //place your business rules in this class.
}

The Employee_base class is defined as package private, which means that it can't be seen from outside of the package. All interaction to the database table has to pass through Employee and therefore through any business rules that you add.

The base class is regenerated every time SimpleORMGenerator is run, while the public class is only generated if it does not exit. This allows you to edit the pubic class to your hearts content and still be easily update your classes with any changes made to the database.

Getters and Setters

SimpleORMGenerator produces getters and setters for every field in the table. As these methods are creates automatically there is no method maintenance is required. Having getters and setters makes it easy to insure that the correct data type is passed to a field at compile time instead of runtime.

Example

public String get_NAME(){
   return getString(NAME);
}
public void set_NAME( String value){
   setString( NAME,value);
}

Foreign references key fields.

SimpleORMGenerator does generate code that uses SFieldReference fields to represent foreign keys. This is because SfieldReference fields represent links between tables in a conceptual model of the database. Trying to re-engineer these conceptual links from a physical model has not proved very successful. The mapping is complex and it appears that SimpleORM may contain a number of bugs in this area.

To get around this problem SimpleORMGenerator uses a simple solution - getters and setters for reference fields.

Example (simplified)

public Department get_DEPARTMENT(){
   return Department.findOrCreate(get_DEPT_ID());
}
public void set_DEPARTMENT( Department value){
   set_DEPT_ID( value.get_DEPT_ID());
}

One side effect of this approach is that if the classes are to generate database tables, the foreign keys between tables will be lost. The pay off is that there is no type casting required when getting a record!

Find or Create methods.

SimpleORMGenerator creates a set of static FindOrCreate methods for the classes. These are far simple to use that provided by the meta object as the parameters are implicitly defined.

Example

public static Employee findOrCreate( String _EMPEE_ID ){
   return (Employee) meta.findOrCreate( new Object[]{_EMPEE_ID});
}

If a foreign key appears in the primary keys of the table then additional FindOrCreate method will be generated with the foreign key as one of its parameters

Example

public static PaySlip findOrCreate( Employee _ref, long _YEAR, long _PERIOD){
   return findOrCreate( _ref.get_EMPEE_ID(), _YEAR, _PERIOD);
}
Naming of fields

SimpleORMGenerator uses a version of adapter pattern to allow uses to implement their own field name strategy. When running SimpleORMGenerator a class that implements interface simpleorm.quickstart.IniceNameFormatter. This class can then implement the required field naming algorithm. See simpleorm.quickstart.SimpleORMNiceNameFormatter for an example.

Running SimpleORMGenerator.

The required system properties must be set. Create an instance of SimpleORMGenerator and then call the execute() method. Or do what I do and simply edit the code in the main() method!

Java Source File NameTypeComment
AParam.javaClass
ColumnGenerate.javaClass
DefaultFormatter.javaClass This is the standard name conversion used by SimpleORMGenerator.
ForeignKeyGenerate.javaClass
INiceNameFormatter.javaInterface Interface to convert the database table or column name to your names.
SimpleORMGenerate must be created with an object that instanciates this interface.

Typically you should simple algrothem to return a nice name (like DefaultFormatter), but the code could be complex as you feel like (like SimpleORMNiceNameFormatter).

SimpleORMGenerator.javaClass This class generates the SimpleORM mapping files for a (in this example) Sybase schema.
SimpleORMNiceNameFormatter.javaClass
TableGenerate.javaClass
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.