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 |