KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 package org.objectweb.jorm.mapper.rdb.metainfo;
25
26 import org.objectweb.jorm.metainfo.api.Class;
27 import org.objectweb.jorm.metainfo.api.ClassMapping;
28 import org.objectweb.jorm.metainfo.api.MappingPrinter;
29 import org.objectweb.jorm.metainfo.api.MappingStructure;
30 import org.objectweb.jorm.metainfo.api.PrimitiveElementMapping;
31 import org.objectweb.jorm.metainfo.api.PrimitiveElement;
32 import org.objectweb.jorm.metainfo.api.GenClassMapping;
33 import org.objectweb.jorm.metainfo.api.GenClassRef;
34 import org.objectweb.jorm.metainfo.lib.MetaInfoPrinter;
35
36 import java.io.PrintStream JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.Map JavaDoc;
39
40 /**
41  * @author S.Chassande-Barrioz
42  */

43 public class RdbMappingPrinter extends MappingPrinter {
44     public void print(String JavaDoc p, ClassMapping _cm, PrintStream JavaDoc out) {
45         RdbClassMapping cm = (RdbClassMapping) _cm;
46         boolean isMulti = cm instanceof RdbClassMultiMapping;
47         out.println((isMulti ? "RdbClassMultiMapping: '" : "RdbClassMapping: '")
48                     + ((Class JavaDoc) cm.getLinkedMO()).getFQName() + "'");
49         print(p, cm.getRdbTable(), out);
50         if (isMulti) {
51             RdbClassMultiMapping rcm = (RdbClassMultiMapping) cm;
52             Iterator JavaDoc it = rcm.getRdbExternalTables().iterator();
53             while (it.hasNext()) {
54                 print(p, (RdbTable) it.next(), out);
55             }
56         }
57         super.print(p, _cm, out);
58     }
59
60     public void print(String JavaDoc p, GenClassMapping _gcm, PrintStream JavaDoc out) {
61         RdbGenClassMapping gcm = (RdbGenClassMapping) _gcm;
62         out.println("RdbGenClassMapping: '" + ((GenClassRef) gcm.getLinkedMO()).getGenClassId() + "'");
63         print(p, gcm.getRdbTable(), out);
64         super.print(p, gcm, out);
65     }
66
67     public void print(String JavaDoc p, PrimitiveElementMapping pem, PrintStream JavaDoc out) {
68         RdbPrimitiveElementMapping rpem = (RdbPrimitiveElementMapping) pem;
69         Map JavaDoc m = rpem.getPrimitiveElementByRdbJoin();
70         PrimitiveElement pe;
71         if (m == null || m.size() <= 1) {
72             pe = (PrimitiveElement) pem.getLinkedMO();
73             out.println(p + "Column '" + rpem.getName() + "' / field '" + pe.getName());
74         } else {
75             out.print(p + "Column '" + rpem.getName() + "'");
76             Iterator JavaDoc it = m.entrySet().iterator();
77             String JavaDoc sep = " / ";
78             while (it.hasNext()) {
79                 Map.Entry JavaDoc me = (Map.Entry JavaDoc) it.next();
80                 RdbJoin j = (RdbJoin) me.getKey();
81                 pe = (PrimitiveElement) me.getValue();
82                 out.print(sep + "(field:" + pe.getName() + ", join:" + j.getName() + ")");
83                 sep = ", ";
84             }
85             out.println();
86         }
87     }
88
89     public boolean canPrint(MappingStructure ms) {
90         return true;//ms.getMapperName().startsWith("rdb");
91
}
92
93     public void print(String JavaDoc p, RdbTable t, PrintStream JavaDoc out) {
94         boolean isExternal = t instanceof RdbExternalTable;
95         out.println(p + (isExternal ? "External" : "Main")
96                     + " table: " + t.getName()
97                     + " colocated:" + t.isColocated()
98                     + " colocatedMaster:" + t.isColocatedMaster()
99                     + " readOnly:" + t.isReadOnly()
100         );
101         Iterator JavaDoc it = t.getPrimitiveElementMappings().iterator();
102         while (it.hasNext()) {
103             print(p + MetaInfoPrinter.TAB,
104                   (PrimitiveElementMapping) it.next(), out);
105         }
106         if (isExternal) {
107             it = ((RdbExternalTable) t).getRdbJoins().iterator();
108             while (it.hasNext()) {
109                 RdbJoin j = (RdbJoin) it.next();
110                 out.println(p + "Join '" + j.getName() + "': " + j.getPTJoinColumnNames() + " == " + j.getETJoinColumnNames());
111             }
112         }
113     }
114 }
115
Popular Tags