You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2006/07/27 01:41:49 UTC
svn commit: r425906 -
/db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java
Author: arminw
Date: Wed Jul 26 16:41:49 2006
New Revision: 425906
URL: http://svn.apache.org/viewvc?rev=425906&view=rev
Log:
PATCH: forward engineering tool by Tom Antony, see OJB-112
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java?rev=425906&r1=425905&r2=425906&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/tools/org/apache/ojb/tools/mapping/forward/RepositoryXmlProcessor.java Wed Jul 26 16:41:49 2006
@@ -48,7 +48,7 @@
* one for each of the associated table. The primary key will be a combination of the foreign
* keys for both of the associated tables.
*
- * @author Tom Antony
+ * @author Tom Antony <to...@yahoo.com>
* @version 1.0, 03-MAY-2006.
*/
public class RepositoryXmlProcessor
@@ -263,14 +263,34 @@
}
/*
- * Returns set of names of tables mapped to multiple classes.
+ * Returns set of names of tables mapped to multiple classes. This includes tables used as indirection tables
+ * betwen two entities in addition to having explicit mappings.
*/
private Set duplicateTables(Document doc)
{
Set workingSet = new HashSet();
Set duplicateSet = new HashSet();
- NodeList clsDescList = doc.getElementsByTagName("class-descriptor");
+ NodeList clsDescList = doc.getElementsByTagName("class-descriptor");
+
+ /* First collect all indirection tables into the working set. */
+ for(int i = 0; i < clsDescList.getLength(); i++)
+ {
+ Element clsDescElem = (Element) clsDescList.item(i);
+
+ NodeList colDescList = clsDescElem.getElementsByTagName("collection-descriptor");
+
+ for(int j = 0; j < colDescList.getLength(); j++)
+ {
+ Element colDescElem = (Element) colDescList.item(j);
+ String indirectionTableName = colDescElem.getAttribute("indirection-table");
+ if(StringUtils.isNotBlank(indirectionTableName))
+ {
+ workingSet.add(indirectionTableName);
+ }
+ }
+ }
+
for(int i = 0; i < clsDescList.getLength(); i++)
{
Element clsDescElem = (Element) clsDescList.item(i);
@@ -341,7 +361,7 @@
{
try
{
- /*
+ /*
* If table has multiple class mappings, keep the table structure in the deferred
* list and keep merging later definitions we encounter.
*/
@@ -398,7 +418,7 @@
column.name = columnName;
foreignKey.localColumns.add(columnName);
- /*
+ /*
* Foreign keys pointing to current table in the <collection-descriptor>
* element should match primary keys of current table in the same sequence.
* Match attributes for indirection columns with corresponding primary key columns.
@@ -443,10 +463,30 @@
}
}
- // Generate deferred tables at the end.
-
+ /*
+ * Deferred tables also includes tables which are also used as indirection tables in addition to
+ * having explicit mapping. So merge them with the corresponding indirection table if any.
+ */
Set defKeySet = deferredTables.keySet();
- Iterator defKeysItr = defKeySet.iterator();
+ Iterator defKeysItr = defKeySet.iterator();
+ while(defKeysItr.hasNext())
+ {
+ String tableName = (String) defKeysItr.next();
+
+ Table defferedTable = (Table) deferredTables.get(tableName);
+ Table indirectionTable = (Table) indirectionTables.get(tableName);
+
+ if(indirectionTable != null)
+ {
+ mergeTables(defferedTable, indirectionTable);
+ }
+
+ }
+
+ /* Generate deferred tables at the end. */
+
+ defKeySet = deferredTables.keySet();
+ defKeysItr = defKeySet.iterator();
while(defKeysItr.hasNext())
{
String tableName = (String) defKeysItr.next();
@@ -456,10 +496,10 @@
fwr.write(tableStr);
}
- /*
- * Generate tables for indirection tables at the end. Table structure for an
- * indirection table gets filled up after processing both of the association tables.
- */
+ /*
+ * Generate tables for indirection tables at the end. Table structure for an
+ * indirection table gets filled up after processing both of the association tables.
+ */
Set indKeySet = indirectionTables.keySet();
Iterator indKeysItr = indKeySet.iterator();
@@ -467,10 +507,10 @@
{
String tableName = (String) indKeysItr.next();
- /*
- * Sometimes there can be explicit mappings for indirection tables. In such cases
- * skip the auto generation of indirection table.
- */
+ /*
+ * Sometimes there can be explicit mappings for indirection tables. In such cases
+ * skip the auto generation of indirection table.
+ */
if(allTables.contains(tableName))
continue;
@@ -485,8 +525,8 @@
}
/**
- Return bean descriptor for a class descriptor element.
- This method always returns an empty list for inner classes.
+ * Return bean descriptor for a class descriptor element.
+ * This method always returns an empty list for inner classes.
*/
private BeanDescriptor getBeanDescriptor(Element clsDescElem)
{
@@ -574,10 +614,8 @@
ArrayList innerClasses = new ArrayList();
- BeanDescriptor descriptor = new BeanDescriptor(packageName, className, baseClass, null,
- attributes, types, innerClasses);
-
- return descriptor;
+ return new BeanDescriptor(packageName, className, baseClass, null,
+ attributes, types, innerClasses);
}
/**
@@ -589,7 +627,7 @@
public void generateJavaCode() throws Exception
{
/*
- First form a mapping of inner classes to their parent classes, with parent class as the key
+ First form a mapping of inner classes to their outer classes, with outer class as the key
and a list of inner class names as the value.
*/
HashMap innerOuterClassMap = new HashMap();
@@ -667,8 +705,7 @@
BeanDescriptor innerDescriptor = (BeanDescriptor) innerDescriptionsMap.get(innerClass);
- if(descriptor != null)
- innerDescriptors.add(innerDescriptor);
+ innerDescriptors.add(innerDescriptor);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org