Java Doc for JDBCSchemaReader.java in  » J2EE » Jaffa » org » jaffa » tools » domainmeta » jdbc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 » J2EE » Jaffa » org.jaffa.tools.domainmeta.jdbc 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.jaffa.tools.domainmeta.jdbc.JDBCSchemaReader

JDBCSchemaReader
public class JDBCSchemaReader (Code)
This tool is used to reverse enginer a database schema and generate Jaffa based domain object XML meta data. This can then be used by the app builder to build a working CRUD application (See Jaffa's BaseLine project for more details)

This reads the table definitions and all the fields. It looks at the primary key definitions, and rejects any table that does not have one. It then looks at each table and infers (by field name, datatype, and field length) if this table has any foreign keys by looking at all the other tables Primary keys. If a match is found, then it assumes these object are related. If they have the same primary key, it assumes it is a one-to-one relationship. All relationships are created as associations.

There is at present no logic to look at table constraints to infer relationships as not everyone puts the contraints in the database, at present we just rely on primary keys.

This is based on generated domain objects for the v1.1 pattern

This is an example of how it can be used to reverse enginer the default 'Northwind' that codes wih Microsoft SQL Server 2000


 public static void main(String[] args) {
 try {
 JDBCSchemaReader s = new JDBCSchemaReader();
 s.setSourceDriverString("com.microsoft.jdbc.sqlserver.SQLServerDriver");
 s.setSourceConnection("jdbc:microsoft:sqlserver://localhost:1433;SelectMethod=cursor;databasename=Northwind");
 s.setSourceUser("sa");
 s.setSourcePassword("sa");
 s.setSourceSchema("%");
 s.setAppName("Microsoft");
 s.setFullPackageNames(false);
 s.setModuleName("Northwind");
 s.setOutputDirectory("C:/sandbox.sf/northwind");
 s.setPackagePrefix("com");
 s.process();
 if(!s.save())
 System.out.println("****SAVE ERROR!!!!");
 } catch (Exception e) {
 e.printStackTrace(System.out);
 }
 }
 

This is an example of one of the XML files this tool generated. This is the 'Customers' table from 'Northwind'.


 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE Root PUBLIC "-//JAFFA//DTD Domain Creator Meta 1.1//EN" "http://jaffa.sourceforge.net/DTD/domainCreatorMeta_1_1.dtd">
 <Root>
 <DomainObject>Customers</DomainObject>
 <DomainPackage>com.microsoft.northwind.domain</DomainPackage>
 <DatabaseTable>Customers</DatabaseTable>
 <MappingPackage>resources/jdbcengine</MappingPackage>
 <PatternTemplate>patterns/library/domain_creator_1_1/DomainCreatorPattern.xml</PatternTemplate>
 <Description>Reverse Engineered on 05/05/2004</Description>
 <LabelToken>[label.Microsoft.Northwind.Customers]</LabelToken>
 <Fields>
 <Field>
 <Name>CustomerID</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>CUSTOMERID</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>T</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.CustomerID]</LabelToken>
 <Mandatory>T</Mandatory>
 <IntSize>5</IntSize>
 <CaseType>UpperCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>CompanyName</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>COMPANYNAME</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.CompanyName]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>40</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>ContactName</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>CONTACTNAME</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.ContactName]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>30</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>ContactTitle</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>CONTACTTITLE</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.ContactTitle]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>30</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>Address</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>ADDRESS</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.Address]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>60</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>City</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>CITY</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.City]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>15</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>Region</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>REGION</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.Region]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>15</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>PostalCode</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>POSTALCODE</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.PostalCode]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>10</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>Country</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>COUNTRY</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.Country]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>15</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>Phone</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>PHONE</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.Phone]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>24</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 <Field>
 <Name>Fax</Name>
 <DataType>java.lang.String</DataType>
 <DatabaseFieldName>FAX</DatabaseFieldName>
 <DatabaseDataType>STRING</DatabaseDataType>
 <PrimaryKey>F</PrimaryKey>
 <LabelToken>[label.Microsoft.Northwind.Customers.Fax]</LabelToken>
 <Mandatory>F</Mandatory>
 <IntSize>24</IntSize>
 <CaseType>MixedCase</CaseType>
 <Ignore>false</Ignore>
 </Field>
 </Fields>
 <Relationships>
 <Relationship>
 <ToDomainObject>CustomerCustomerDemo</ToDomainObject>
 <ToDomainPackage>com.microsoft.northwind.domain</ToDomainPackage>
 <FromCardinality>1</FromCardinality>
 <ToCardinality>0..*</ToCardinality>
 <Type>association</Type>
 <FromFields>
 <RelationshipField><Name>CustomerID</Name></RelationshipField>
 </FromFields>
 <ToFields>
 <RelationshipField><Name>CustomerID</Name></RelationshipField>
 </ToFields>
 </Relationship>
 <Relationship>
 <ToDomainObject>Orders</ToDomainObject>
 <ToDomainPackage>com.microsoft.northwind.domain</ToDomainPackage>
 <FromCardinality>1</FromCardinality>
 <ToCardinality>0..*</ToCardinality>
 <Type>association</Type>
 <FromFields>
 <RelationshipField><Name>CustomerID</Name></RelationshipField>
 </FromFields>
 <ToFields>
 <RelationshipField><Name>CustomerID</Name></RelationshipField>
 </ToFields>
 </Relationship>
 </Relationships>
 </Root>
 

author:
   paule
version:
   1.0

Inner Class :class Key



Method Summary
public  StringgetAppName()
     Getter for property appName.
public  StringgetMappingPackage()
     Getter for property mappingPackage.
public  StringgetModuleName()
     Getter for property moduleName.
public  StringgetOutputDirectory()
     Getter for property m_outputDirectory.
public  StringgetPackagePrefix()
     Getter for property packagePrefix.
public  StringgetSourceConnection()
     Getter for property sourceConnection.
public  StringgetSourceDriverString()
     Getter for property sourceDriverString.
public  StringgetSourcePassword()
     Getter for property sourcePassword.
public  StringgetSourceSchema()
     Getter for property sourceSchema.
public  StringgetSourceUser()
     Getter for property sourceUser.
public  StringgetTableExcludePattern()
     Getter for property tableExcludePattern.
public  StringgetTableFilter()
     Getter for property tableFilter.
public  CollectiongetTables()
    
public  booleanisFullPackageNames()
     Getter for property fullPackageNames.
public  booleanisInferMandatory()
     Getter for property inferMandatory.
public  voidprocess()
     Run the reverse engineer process.
public  booleansave()
     This will write out each of the TableBean objects to an XML based domain object file.
public  voidsetAppName(String appName)
     Setter for property appName.
public  voidsetFullPackageNames(boolean fullPackageNames)
     Setter for property fullPackageNames.
public  voidsetInferMandatory(boolean inferMandatory)
     Setter for property inferMandatory.
public  voidsetMappingPackage(String mappingPackage)
     Setter for property mappingPackage.
public  voidsetModuleName(String moduleName)
     Setter for property moduleName.
public  voidsetOutputDirectory(String outputDirectory)
     Setter for property outputDirectory.
public  voidsetPackagePrefix(String packagePrefix)
     Setter for property packagePrefix.
public  voidsetSourceConnection(String sourceConnection)
     Setter for property sourceConnection.
public  voidsetSourceDriverString(String sourceDriverString)
     Setter for property sourceDriverString.
public  voidsetSourcePassword(String sourcePassword)
     Setter for property sourcePassword.
public  voidsetSourceSchema(String sourceSchema)
     Setter for property sourceSchema.
public  voidsetSourceUser(String sourceUser)
     Setter for property sourceUser.
public  voidsetTableExcludePattern(String tableExcludePattern)
     Setter for property tableExcludePattern.
public  voidsetTableFilter(String tableFilter)
     Setter for property tableFilter.



Method Detail
getAppName
public String getAppName()(Code)
Getter for property appName. Value of property appName.



getMappingPackage
public String getMappingPackage()(Code)
Getter for property mappingPackage. Value of property mappingPackage.



getModuleName
public String getModuleName()(Code)
Getter for property moduleName. Value of property moduleName.



getOutputDirectory
public String getOutputDirectory()(Code)
Getter for property m_outputDirectory. Value of property m_outputDirectory.



getPackagePrefix
public String getPackagePrefix()(Code)
Getter for property packagePrefix. Value of property packagePrefix.



getSourceConnection
public String getSourceConnection()(Code)
Getter for property sourceConnection. Value of property sourceConnection.



getSourceDriverString
public String getSourceDriverString()(Code)
Getter for property sourceDriverString. Value of property sourceDriverString.



getSourcePassword
public String getSourcePassword()(Code)
Getter for property sourcePassword. Value of property sourcePassword.



getSourceSchema
public String getSourceSchema()(Code)
Getter for property sourceSchema. Value of property sourceSchema.



getSourceUser
public String getSourceUser()(Code)
Getter for property sourceUser. Value of property sourceUser.



getTableExcludePattern
public String getTableExcludePattern()(Code)
Getter for property tableExcludePattern. Value of property tableExcludePattern.



getTableFilter
public String getTableFilter()(Code)
Getter for property tableFilter. Value of property tableFilter.



getTables
public Collection getTables()(Code)
Get the list of processed tables A collection of tables, this is in a list sorted by table name



isFullPackageNames
public boolean isFullPackageNames()(Code)
Getter for property fullPackageNames. Value of property fullPackageNames.



isInferMandatory
public boolean isInferMandatory()(Code)
Getter for property inferMandatory. Value of property inferMandatory.



process
public void process() throws Exception(Code)
Run the reverse engineer process. This reads the database schema and create an array of TableBean objects, each containing an array of FieldBean objects, and an array of related TableBean objects.
throws:
  Exception - General Exception thrown if there is a processing error. Typically theunderlying exception is an SQLException.



save
public boolean save()(Code)
This will write out each of the TableBean objects to an XML based domain object file. The files will be written to the folder specified by setOutputDirectory(). This folder must exist. It also writes out the related ApplicationResources.pfragment file with all the labels as used in the domain object xml files Returns true if the save works, false if there were errors. In the event of anyerror only some files may be written.



setAppName
public void setAppName(String appName)(Code)
Setter for property appName. Default is "MyApp"
Parameters:
  appName - New value of property appName.



setFullPackageNames
public void setFullPackageNames(boolean fullPackageNames)(Code)
Setter for property fullPackageNames. Default is false
Parameters:
  fullPackageNames - New value of property fullPackageNames.



setInferMandatory
public void setInferMandatory(boolean inferMandatory)(Code)
Setter for property inferMandatory.
Parameters:
  inferMandatory - New value of property inferMandatory.



setMappingPackage
public void setMappingPackage(String mappingPackage)(Code)
Setter for property mappingPackage. Default is "resources/jdbcengine"
Parameters:
  mappingPackage - New value of property mappingPackage.



setModuleName
public void setModuleName(String moduleName)(Code)
Setter for property moduleName. Default is "MyModule"
Parameters:
  moduleName - New value of property moduleName.



setOutputDirectory
public void setOutputDirectory(String outputDirectory)(Code)
Setter for property outputDirectory. Default is "c:/temp"
Parameters:
  outputDirectory - New value of property outputDirectory.



setPackagePrefix
public void setPackagePrefix(String packagePrefix)(Code)
Setter for property packagePrefix. Default is "org.jaffa"
Parameters:
  packagePrefix - New value of property packagePrefix.



setSourceConnection
public void setSourceConnection(String sourceConnection)(Code)
Setter for property sourceConnection. Default value is "jdbc:oracle:thin:@localhost:1521:my_sid"
Parameters:
  sourceConnection - New value of property sourceConnection.



setSourceDriverString
public void setSourceDriverString(String sourceDriverString)(Code)
Setter for property sourceDriverString. Default value is "oracle.jdbc.driver.OracleDriver"
Parameters:
  sourceDriverString - New value of property sourceDriverString.



setSourcePassword
public void setSourcePassword(String sourcePassword)(Code)
Setter for property sourcePassword. Default value is "tiger"
Parameters:
  sourcePassword - New value of property sourcePassword.



setSourceSchema
public void setSourceSchema(String sourceSchema)(Code)
Setter for property sourceSchema. Default is to get all schemas
Parameters:
  sourceSchema - New value of property sourceSchema.



setSourceUser
public void setSourceUser(String sourceUser)(Code)
Setter for property sourceUser. Default value is "scott"
Parameters:
  sourceUser - New value of property sourceUser.



setTableExcludePattern
public void setTableExcludePattern(String tableExcludePattern)(Code)
Setter for property tableExcludePattern. Default is to exclude nothing. This expects a regular expression to use as an exclude table filter
Parameters:
  tableExcludePattern - New value of property tableExcludePattern.



setTableFilter
public void setTableFilter(String tableFilter)(Code)
Setter for property tableFilter. Default is to get all tables
Parameters:
  tableFilter - New value of property tableFilter.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.