KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > mapper > rdb > metainfo > RdbClassMapping


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23 package org.objectweb.jorm.mapper.rdb.metainfo;
24
25 import org.objectweb.jorm.naming.api.NamingFilterKeyProvider;
26 import org.objectweb.jorm.metainfo.api.*;
27 import org.objectweb.jorm.metainfo.api.Class;
28 import org.objectweb.jorm.metainfo.lib.BasicClassMapping;
29 import org.objectweb.jorm.metainfo.lib.FieldComparator;
30 import org.objectweb.jorm.metainfo.lib.BasicParentClassMapping;
31 import org.objectweb.jorm.type.api.PType;
32 import org.objectweb.medor.expression.api.Expression;
33 import org.objectweb.medor.expression.api.ExpressionException;
34 import org.objectweb.medor.expression.api.ParameterOperand;
35 import org.objectweb.medor.expression.api.Operator;
36 import org.objectweb.medor.expression.lib.BasicOperand;
37 import org.objectweb.medor.expression.lib.BasicParameterOperand;
38 import org.objectweb.medor.expression.lib.BasicVariableOperand;
39 import org.objectweb.medor.expression.lib.Equal;
40 import org.objectweb.medor.expression.lib.ExpressionPrinter;
41 import org.objectweb.util.monolog.api.BasicLevel;
42
43 import java.util.Iterator JavaDoc;
44 import java.util.ArrayList JavaDoc;
45 import java.util.Collection JavaDoc;
46 import java.util.List JavaDoc;
47 import java.util.Collections JavaDoc;
48 import java.util.Set JavaDoc;
49 import java.util.HashSet JavaDoc;
50 import java.text.DateFormat JavaDoc;
51 import java.text.ParseException JavaDoc;
52 import java.math.BigDecimal JavaDoc;
53 import java.math.BigInteger JavaDoc;
54
55 /**
56  * This class defines information on the mapping of a class to relational structures
57  * In the case of inheritance, one must defines how the mapping definitions are
58  * inherited, and how to distinguish instances of the class to instances of
59  * super or sub classes.
60  * Following the partitionning schemes in relational database we defines three
61  * ways to inherit the mapping of its parent.
62  *
63  *
64  * In the case of multi-inheritance, all combinations are valid. One can map new
65  * fields relative to class A to new columns or tables (to-extended or to-added rules)
66  * while the resulting stuctures being completely redefined relatively to the ones
67  * of another class B (to-new rule). One class can also inherits with a to-added
68  * or to-extended rule from class A and also with a to-added or to-exended rule from
69  * another class B provided they map their id the same way, which implies that
70  * they have the same main table.
71  *
72  * One limitation is relative to the "abscractness" of the classes. In fact,
73  * the inheritance rules are those of Java. That is, a class cannot inherit
74  * from more than one concrete class (the 'extends' keyword is limited to only
75  * one class). Note that Jorm support abstract classes inheriting from concrete
76  * classes, even though this has no sense from a persistance point of view. The
77  * reason is that Jorm is used to map Java classes to persistant ones, that
78  * Java authorizes abstract classes deriving from concrete classes by defining
79  * new abstract methods. Even though methods are not translated in a persistance point
80  * of view since they do not represent fields (exception made of accessors),
81  * we need to represent the abstract classes since there may exist references
82  * of this abstract class.
83  *
84  */

85 public class RdbClassMapping extends BasicClassMapping {
86     /**
87      * Specifies that the structures and the mapping of the parent is inherited,
88      * the structures are extended (i.e. new columns are defined in existing tables)
89      * and the new fields are mapped to this extension. This merely corresponds to
90      * a 'filtered' case but can cover the case of concrete classes where a filter
91      * can be defined, and the case of abstract classes where only the mapping
92      * is extended and no filter is defined. This implies that concrete classes
93      * having this inheritance rule MUST define a filter.
94      * Note that when no parent class mapping is defined, a default one is created with this
95      * rule, with no new mapping and no filters. That is, the mapping and structures
96      * are inherited as is, unchanged. This prevent us from defining a new 'unchanged'
97      * rule.
98      */

99     public final static String JavaDoc MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES = "to-extended-structures";
100
101     /**
102      * Specifies that the structures and the mapping of the parent is inherited,
103      * new structures are added (i.e. new tables are added) and the some of new fields
104      * are mapped to this new structures. Note that this rule 'extends' the previous one,
105      * that is, some of the new fields may be mapped to new columns of inherited tables
106      * This merely corresponds to a 'vertical' case supporting the definition of a filter (for efficiency reasons).
107      */

108     public final static String JavaDoc MAP_NEW_FIELDS_TO_ADDED_STRUCTURES = "to-added-structures";
109
110     /**
111      * Specifies that neither the structures nor the mapping is inherited,
112      * structures are completely redefined (i.e. new tables are defined)
113      * and ALL the fields (defined in the class or previously defined in super
114      * classes are remapped to this new structures. This merely corresponds to
115      * a 'horizontal' case.
116      */

117     public final static String JavaDoc REMAP_FIELDS_TO_NEW_STRUCTURES = "to-new-structures";
118
119     /**
120      * ==== NOT USED ANYMORE ====
121      * Specifies the structures and the mapping are left unchanged.
122      * The class is necessarily abstract, and if it defines new fields, they are
123      * not defined here. This is the default case when no mapping rule is defined.
124      * Classes that are gathering of other classes (that their extent is the
125      * union of its subclasses' extents) comes into this category.
126      */

127  // public final static String MAPPING_UNCHANGED = "unchanged";
128

129     /**
130      * The (main) table of which the fields are mapped
131      */

132     RdbTable table = null;
133
134     /**
135      *
136      */

137     RdbFilter filter = null;
138
139
140     /**
141      *
142      */

143     RdbInheritanceQuery inheritanceQuery = null;
144     
145     /**
146      * Builds a new BasicRdbClassMapping object.
147      *
148      * This object contains the mapping structure of the class it refers to.
149      * The parent object is a Mapping object that contains the mapper name.
150      *
151      * @param ruleName the name of the rule used to map the class,
152      * linkedMo the Class object referenced by the current object,
153      * parent the parent of the current object.
154      */

155     public RdbClassMapping(String JavaDoc ruleName, MetaObject linkedMO,
156                                 MetaObject parent) {
157         super(ruleName, linkedMO, parent);
158     }
159
160     ///////////////////////////////////////////////////////////////////
161
// from RdbClassMapping interface
162
///////////////////////////////////////////////////////////////////
163
public List JavaDoc getAllPrimitiveElementMappings() {
164         List JavaDoc pems = super.getAllPrimitiveElementMappings();
165         List JavaDoc pcms = (List JavaDoc) getParentClassMappings();
166         int i;
167         for(i = pcms.size()-1; i>=0; i--) {
168             ParentClassMapping pcm = (ParentClassMapping) pcms.get(i);
169             if ((MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES.equalsIgnoreCase(pcm.getRuleName())) ||
170                     (MAP_NEW_FIELDS_TO_ADDED_STRUCTURES.equalsIgnoreCase(pcm.getRuleName()))) {
171                 //Add the the pem of the super class
172
Class JavaDoc superClass = pcm.getMOClass();
173                 ClassProject cp = superClass.getClassProject(getProjectName());
174                 if (cp != null) {
175                     Mapping m = cp.getMapping(getMapperName());
176                     if (m != null) {
177                         //fetch the PEMs of the super class (Recusrive call)
178
pems.addAll(m.getClassMapping().getAllPrimitiveElementMappings());
179                     }
180                 }
181             }
182         }
183         if (i == -1) {
184             Collections.sort(pems, FieldComparator.instance);
185         }
186         return pems;
187     }
188     
189     public RdbTable createRdbTable(String JavaDoc tableName) {
190         if (table == null) {
191             table = new RdbTable(this, getLinkedMO(), tableName);
192             table.setLogger(getLogger());
193             table.setLoggerFactory(getLoggerFactory());
194         } else {
195             table.setName(tableName);
196         }
197         return table;
198     }
199
200     public RdbTable getRdbTable() {
201         return table;
202     }
203     /**
204      * Get the main table (tables ??).
205      * OL: Gets the RdbTable meta-objects relative to the main tables of
206      * ancestors while it is the same main table (which is the case
207      * with 'extended' and 'added' inheritance rules)
208      * @param res the list of RdbTable meta-object in ancestors relative to the
209      * the main table of the class
210      */

211     public void getMainRdbTableOld(ArrayList JavaDoc res) {
212         if ( !getParentClassMappings().isEmpty()) {
213             for (Iterator JavaDoc it = getParentClassMappings().iterator(); it.hasNext();) {
214                 ParentClassMapping pcm = (ParentClassMapping) it.next();
215                 String JavaDoc ruleName = pcm.getRuleName();
216                 //System.out.println("rule-name = " + ruleName);
217
if (MAP_NEW_FIELDS_TO_ADDED_STRUCTURES.equals(ruleName) ||
218                         MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES.equals(ruleName)) {
219                     Class JavaDoc parentClass = pcm.getMOClass();
220                     RdbClassMapping classmapping =
221                             (RdbClassMapping) parentClass.getClassMapping(getProjectName(),getMapperName());
222                     classmapping.getMainRdbTableOld(res);
223                 } else {
224                     // new tables at this level (horizontal)
225
res.add(table);
226                 }
227             }
228         } else {
229             // There is no extension.
230
//logger.log(BasicLevel.DEBUG, "no extension");
231
res.add(table);
232         }
233     }
234
235     public RdbTable getMainRdbTable() {
236         // if main table is null (this can happen if the classmapping is implicit)
237
// gets the main table of the super class
238
if (table == null) {
239             // get a super class (one among all since they should be the same)
240
ParentClassMapping aPcm = (ParentClassMapping)
241                     parentClassMappings.get(0);
242             Class JavaDoc aSuperClass = aPcm.getMOClass();
243             RdbClassMapping aSuperCm =
244                     (RdbClassMapping) aSuperClass.getClassMapping(getProjectName(),
245                             getMapperName());
246             table = aSuperCm.getMainRdbTable();
247         }
248         return table;
249     }
250
251     public RdbFilter createRdbFilter() {
252        filter = new RdbFilter(this);
253        return filter;
254     }
255
256     public RdbFilter getRdbFilter() {
257         return filter;
258     }
259     
260     public RdbInheritanceQuery getRdbInheritanceQuery() {
261         if(inheritanceQuery == null)
262             createRdbInheritanceQuery();
263         return inheritanceQuery;
264     }
265
266     public RdbInheritanceQuery createRdbInheritanceQuery() {
267         if(inheritanceQuery == null)
268             inheritanceQuery = new RdbInheritanceQuery(this);
269         return inheritanceQuery;
270     }
271         
272     public Expression getMappingFilterFromNamingFilter()
273         throws ExpressionException {
274         return getMappingFilterFromNamingFilter(null);
275     }
276     public Expression getMappingFilterFromNamingFilter(NamingFilterKeyProvider nfkp)
277             throws ExpressionException {
278         if (debug) {
279             logger.log(BasicLevel.DEBUG,
280                 "getMappingFilterFromNamingFilter: class "
281                 + ((Class JavaDoc) linkedMO).getFQName());
282         }
283         NameDef nd = getIdentifierMapping().getNameDef();
284         if (nd == null) {
285             if (debug) {
286                 logger.log(BasicLevel.DEBUG,
287                     "getMappingFilterFromNamingFilter: null NameDef");
288             }
289             return null;
290         }
291         Class JavaDoc clazz = getJormClass();
292         Expression namingFilter = null;
293         namingFilter = clazz.getInheritanceFilter(nd);
294         Object JavaDoc key;
295         if (nfkp != null) {
296             //fetch the key value from the NamingFilterKeyProvider
297
// This case happens when the key value is calculated at runtime for
298
// example.
299
key = nfkp.getNamingFilterKey();
300         } else {
301             //Fetch the key value from the meta information
302
key = clazz.getInheritanceNamingKey(nd);
303         }
304         if (debug) {
305             logger.log(BasicLevel.DEBUG,
306                 "getMappingFilterFromNamingFilter: key=" + key
307                 + " / namingFilter=" + namingFilter);
308         }
309         if (key != null) { //A key value is specified on the current class ==> FKPNC
310
if (namingFilter == null) {
311                 logger.log(BasicLevel.DEBUG, "Find the naming filter on ancestors");
312                 ArrayList JavaDoc al = new ArrayList JavaDoc(clazz.getSuperClasses());
313                 while (namingFilter == null && !al.isEmpty()) {
314                     Class JavaDoc superClass = (Class JavaDoc) al.remove(0);
315                     logger.log(BasicLevel.DEBUG, "Ancestor " + superClass.getFQName());
316                     namingFilter = superClass.getInheritanceFilter(nd);
317                     if (namingFilter == null) {
318                         al.addAll(superClass.getSuperClasses());
319                     }
320                 }
321                 if (namingFilter == null) {
322                     logger.log(BasicLevel.DEBUG, "No the naming filter found on ancestors");
323                     //not found ==> no filter
324
return null;
325                 } else {
326                     logger.log(BasicLevel.DEBUG, "Naming filter found on ancestors: " + ExpressionPrinter.e2str(namingFilter));
327                 }
328             } // else the filter is also on the current class
329

330             logger.log(BasicLevel.DEBUG, "Compute the key filter with key value");
331             //the filter is based on key principle => add the equality between
332
// the key value and the expression
333
BasicVariableOperand keyexp = new BasicVariableOperand(namingFilter.getType());
334             if (key instanceof String JavaDoc) {
335                 assignKey(keyexp, (String JavaDoc) key);
336             } else {
337                 keyexp.setValue(key);
338             }
339             namingFilter = new Equal(keyexp, namingFilter);
340             logger.log(BasicLevel.DEBUG, "Naming filter changed into Equal: " + ExpressionPrinter.e2str(namingFilter));
341
342         } else { // no key define on the current class ==> FPNC
343
if (namingFilter == null) {
344                 return null;
345             }
346         }
347         //changes are done here!!
348
Expression res = cloneAndReplaceLeaves(namingFilter);
349         if (debug) {
350             logger.log(BasicLevel.WARN, "Filter=" + ExpressionPrinter.e2str(res));
351         }
352         return res;
353     }
354
355     private void assignKey(BasicVariableOperand keyexp,
356                            String JavaDoc str) throws ExpressionException {
357         switch (keyexp.getType().getTypeCode()) {
358         case PType.TYPECODE_BYTE:
359             keyexp.setValue(Byte.parseByte(str));
360             break;
361         case PType.TYPECODE_CHAR:
362             keyexp.setValue(str.charAt(0));
363             break;
364         case PType.TYPECODE_SHORT:
365             keyexp.setValue(Short.parseShort(str));
366             break;
367         case PType.TYPECODE_INT:
368             keyexp.setValue(Integer.parseInt(str));
369             break;
370         case PType.TYPECODE_LONG:
371             keyexp.setValue(Long.parseLong(str));
372             break;
373         case PType.TYPECODE_OBJBYTE:
374             keyexp.setValue(Long.valueOf(str));
375             break;
376         case PType.TYPECODE_OBJCHAR:
377             keyexp.setValue(new Character JavaDoc(str.charAt(0)));
378             break;
379         case PType.TYPECODE_OBJSHORT:
380             keyexp.setValue(Short.valueOf(str));
381             break;
382         case PType.TYPECODE_OBJINT:
383             keyexp.setValue(Integer.valueOf(str));
384             break;
385         case PType.TYPECODE_OBJLONG:
386             keyexp.setValue(Long.valueOf(str));
387             break;
388         case PType.TYPECODE_DATE:
389             try {
390                 keyexp.setValue(DateFormat.getInstance().parse(str));
391             } catch (ParseException JavaDoc e) {
392                 throw new ExpressionException("Impossible to parse the date " + str, e);
393             }
394             break;
395         case PType.TYPECODE_STRING:
396             keyexp.setValue(str);
397             break;
398         case PType.TYPECODE_BIGDECIMAL:
399             keyexp.setValue(new BigDecimal JavaDoc(str));
400             break;
401         case PType.TYPECODE_BIGINTEGER:
402             keyexp.setValue(new BigInteger JavaDoc(str));
403             break;
404         default:
405             throw new ExpressionException("Umanaged key type: "
406                 + keyexp.getType().getJavaName());
407         }
408     }
409
410
411     /**
412      * Clones an Expression, where leaves which point to naming fields are
413      * replaced with leaves pointing to class fields.
414      * @param exp
415      * @return
416      * @throws ExpressionException
417      */

418     private Expression cloneAndReplaceLeaves(Expression exp)
419         throws ExpressionException {
420         if (exp instanceof ParameterOperand) {
421             //field to replace
422
NameDef nd = getIdentifierMapping().getNameDef();
423             String JavaDoc classFieldName = null;
424             if (nd.isFieldName()) {
425                 if (debug) {
426                     logger.log(BasicLevel.DEBUG, "nd.getFieldName = " + nd.getFieldName()
427                         + " while exp.getName = " + ((ParameterOperand) exp).getName());
428                 }
429                 return exp;
430             } else if (nd.isNameRef()) {
431                 classFieldName = (String JavaDoc) nd.getNameRef().getProjection().get(
432                     ((ParameterOperand) exp).getName());
433                 //if the field is not part of the namedef, just keep the original name
434
if (classFieldName == null) {
435                     return exp;
436                 }
437                 if (debug) {
438                     logger.log(BasicLevel.DEBUG, "nref.getFieldName = " + classFieldName
439                         + " while exp.getName = " + ((ParameterOperand) exp).getName());
440                 }
441             } else {
442                 throw new ExpressionException("Naming type not managed: " + nd);
443             }
444             return new BasicParameterOperand(exp.getType(), classFieldName);
445         } else if (exp instanceof BasicVariableOperand) {
446             //constant
447
return new BasicVariableOperand((BasicOperand) exp);
448         } else if (exp instanceof BasicOperand) {
449             //constant
450
return new BasicOperand((BasicOperand) exp);
451
452         } else if (exp instanceof Operator) {
453             Operator oldop = (Operator) exp;
454             Operator newop = null;
455             try {
456                 newop = (Operator) exp.getClass().newInstance();
457             } catch (Exception JavaDoc e) {
458                 throw new ExpressionException(
459                     "Impossible to clone the operator "
460                     + exp.getClass().getName() + ": ", e);
461             }
462             for(int i=(oldop.getOperandNumber() - 1); i>=0; i--) {
463                 //recursion using clone of operator and clones of children
464
newop.setExpression(i, cloneAndReplaceLeaves(oldop.getExpression(i)));
465             }
466             return newop;
467         } else {
468             throw new ExpressionException("UnManaged expression: " + exp);
469         }
470     }
471
472     protected Collection JavaDoc getChildren() {
473         Collection JavaDoc col = super.getChildren();
474         if (table != null) {
475             col.add(table);
476         }
477         return col;
478     }
479
480     public ParentClassMapping createImplicitParentClassMapping(Class JavaDoc superClass) {
481         BasicParentClassMapping pcm =
482                 new BasicParentClassMapping(MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES,
483                         superClass, this);
484         addParentClassMapping(pcm);
485         return pcm;
486     }
487
488     /**
489      * The creation of tables cannot be done until all columns are known and those
490      * columns can be defined in the super and subclasses with wich there is
491      * a 'to-extended' or a 'to-added' inheritance rule.
492      *
493      */

494     public void addImplicitDependencies() {
495
496         // treat inheritance with its super classes
497
Class JavaDoc clazz = (Class JavaDoc) getLinkedMO();
498         for (Iterator JavaDoc itPcm = getParentClassMappings().iterator(); itPcm.hasNext();) {
499             ParentClassMapping parentClassMapping = (ParentClassMapping) itPcm.next();
500             // The creation the structures of a class requires that the structures are completely
501
// defined. In case of 'added' and 'extended' inheritance rules, structures (i.e. table) are
502
// shared, so the definition of the columns mapping fields of its super classes must be done.
503
if (inheritsStructures(parentClassMapping)) {
504                 Class JavaDoc superClass = (Class JavaDoc) parentClassMapping.getLinkedMO();
505                 if (debug) {
506                     logger.log(BasicLevel.DEBUG, "Add dependency: " +
507                             clazz.getName() + " -> " + superClass.getName());
508                 }
509                 addDependency(superClass.getFQName());
510             }
511
512         }
513
514         // treat inheritance with its sub classes
515
for (Iterator JavaDoc itClass = clazz.getSubClasses().iterator(); itClass.hasNext();) {
516             Class JavaDoc subClass = (Class JavaDoc) itClass.next();
517             ClassMapping subClassMapping = subClass.getClassMapping(getProjectName(), getMapperName());
518             if (subClassMapping == null) {
519                 throw new InternalError JavaDoc("Cannot find class mapping of "
520                         + subClass.getName() + "<" + getProjectName() + ","
521                         + getMapperName() + ">" +
522                         " when adding implicit dependencies to " + clazz.getName());
523             }
524             ParentClassMapping parentClassMapping = subClassMapping.getParentClassMapping(clazz.getFQName());
525             // The creation of the structures of a class requires that the structures
526
// of ALL its subclasses are created, and, therefore, defined. This is required because
527
// the creation of the extents of its full-extent will required that the
528
// structures of the subclasses are defined before.
529
// Hence, we do not test the inheritency rule.
530
// String inheritanceRule = parentClassMapping.getRuleName();
531
if (debug) {
532                 logger.log(BasicLevel.DEBUG, "Add dependency: " +
533                         clazz.getName() + " -> " + subClass.getName());
534             }
535             addDependency(subClass.getFQName());
536         }
537     }
538     
539     /**
540      * Check if any (hidden) field defined in the class (or its supers) has
541      * a defined mapping (defined in the class mapping or in it supers)
542      * @return true if there is at least one (hidden) field whch is unmapped
543      */

544     public boolean hasUnmappedPrimitiveElements(Collection JavaDoc pes) {
545         Class JavaDoc clazz = (Class JavaDoc) linkedMO;
546         // search if there is a field which is not mapped
547
for (Iterator JavaDoc itPE = pes.iterator(); itPE.hasNext();) {
548                 PrimitiveElement pe = (PrimitiveElement) itPE.next();
549                 PrimitiveElementMapping pem = getPrimitiveElementMapping(pe.getName(), true);
550                 if (pem == null) {
551                     return true;
552                 }
553             }
554         return false;
555     }
556
557     /**
558      * Returns the parent class mappings having a inheritance rule in a
559      * set of inheritance rules.
560      * @param inheritanceRules the set of inheritance rule names
561      * @return the parent class mappings
562      */

563     public Set JavaDoc getParentClassMapping(Set JavaDoc inheritanceRules) {
564         HashSet JavaDoc res = new HashSet JavaDoc();
565         for (Iterator JavaDoc it = parentClassMappings.iterator(); it.hasNext();) {
566             ParentClassMapping pcm = (ParentClassMapping) it.next();
567             if (inheritanceRules.contains(pcm.getRuleName())) {
568                 res.add(pcm);
569             }
570         }
571         return res;
572     }
573
574     /**
575      * Returns the parent class mappings having an extened or added inheritance
576      * rule.
577      * @return the parent class mappings having an extened or added inheritance
578      * rule.
579      */

580     public Set JavaDoc getAddedOrExtendedParentClassMapping() {
581         HashSet JavaDoc res = new HashSet JavaDoc();
582         for (Iterator JavaDoc it = parentClassMappings.iterator(); it.hasNext();) {
583             ParentClassMapping pcm = (ParentClassMapping) it.next();
584             if (inheritsStructures(pcm)) {
585                 res.add(pcm);
586             }
587         }
588         return res;
589     }
590
591     public boolean inheritsStructures(ParentClassMapping pcm) {
592         return (RdbClassMapping.MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES.
593                     equalsIgnoreCase(pcm.getRuleName()) ||
594                     RdbClassMapping.MAP_NEW_FIELDS_TO_ADDED_STRUCTURES.
595                     equalsIgnoreCase(pcm.getRuleName()));
596     }
597
598     public boolean inheritsStructures() {
599         for(Iterator JavaDoc it= getParentClassMappings().iterator(); it.hasNext();) {
600         ParentClassMapping pcm = (ParentClassMapping) it.next();
601             if (inheritsStructures(pcm)) {
602                 return true;
603             }
604         }
605         return false;
606     }
607     
608     public PrimitiveElementMapping getPrimitiveElementMapping(String JavaDoc fieldName,
609             boolean searchInSuper) {
610         PrimitiveElementMapping pem = getPrimitiveElementMapping(fieldName);
611         if ((pem == null) && searchInSuper) {
612             Mapping mapping = (Mapping) getParent();
613             String JavaDoc mapperName = mapping.getMapperName();
614             String JavaDoc projectName = ((ClassProject) mapping.getParent()).getProjectName();
615             for (Iterator JavaDoc itPcm = parentClassMappings.iterator(); itPcm.hasNext();) {
616                 ParentClassMapping pcm = (ParentClassMapping) itPcm.next();
617                 // remap inheritance rule does no inherits mappings
618
if (RdbClassMapping.REMAP_FIELDS_TO_NEW_STRUCTURES.equals(pcm.getRuleName())) {
619                     continue;
620                 }
621                 Class JavaDoc superClass = (Class JavaDoc) pcm.getLinkedMO();
622                 BasicClassMapping superClassMapping =
623                     (BasicClassMapping) superClass.getClassMapping(projectName, mapperName);
624                 pem = superClassMapping.getPrimitiveElementMapping(fieldName, searchInSuper);
625                 if (pem != null) break;
626             }
627         }
628         return pem;
629     }
630
631 }
632
Popular Tags