KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > mapper > rdb > generator > RdbGenJoin


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.generator;
24
25 import org.objectweb.jorm.api.PException;
26 import org.objectweb.jorm.mapper.rdb.metainfo.RdbJoin;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  *
33  * @author S.Chassande-Barrioz
34  */

35 public class RdbGenJoin {
36
37     public RdbGenTable mainTable = null;
38     public RdbGenTable table = null;
39     public int joinIdx = 0;
40
41     /**
42      * The list of columns used to join with the reference table.
43      * null for the reference table. These columns belongs to one of the other
44      * tables used in this mapping.
45      */

46     public List JavaDoc joinColumnsInMain = null;
47
48     /**
49      * Along with this list, we define the position the column of this table
50      * with which these external columns join.
51      */

52     public List JavaDoc joinColumnsInExt = null;
53
54     public int getJoinIdx() {
55         return joinIdx;
56     }
57
58     public List JavaDoc getJoinColumnsInMain() {
59         return joinColumnsInMain;
60     }
61
62     public List JavaDoc getJoinColumnsInExt() {
63         return joinColumnsInExt;
64     }
65
66     public RdbGenTable getMainTable() {
67         return mainTable;
68     }
69
70     public RdbGenTable getTable() {
71         return table;
72     }
73
74     public RdbGenJoin(RdbGenTable mainTable,
75                       RdbGenTable extTable,
76                       RdbJoin j,
77                       int idx) throws PException {
78         this.joinIdx = idx;
79         //System.out.println("Define a join:");
80
this.table = extTable;
81         this.mainTable = mainTable;
82         //Define the join between the main extTable and the slave extTable
83
List JavaDoc pcns = j.getPTJoinColumnNames();
84         List JavaDoc ecns = j.getETJoinColumnNames();
85         joinColumnsInMain = new ArrayList JavaDoc(pcns.size());
86         joinColumnsInExt = new ArrayList JavaDoc(pcns.size());
87         for (int i = 0; i < pcns.size(); i++) {
88             String JavaDoc pcn = (String JavaDoc) pcns.get(i);
89             String JavaDoc ecn = (String JavaDoc) ecns.get(i);
90             //System.out.println("between: " + mainTable.tableName + "." + pcn + " and " + extTable.tableName + "." + ecn);
91
RdbGenColumn pjcol = mainTable.getColumn(pcn);
92             if (pjcol == null) {
93                 throw new PException("In the join between tables "
94                         + mainTable.tableName + " and " + extTable.tableName + ", " +
95                         "the column '" + pcn + "' was not found in extTable "
96                         + mainTable.tableName);
97             }
98             joinColumnsInMain.add(pjcol);
99             RdbGenColumn ejcol = extTable.getColumn(ecn);
100             if (ejcol == null) {
101                 ejcol = new RdbGenColumn();
102                 ejcol.columnName = ecn;
103                 ejcol.joinCol = pjcol;
104                 ejcol.columnType = pjcol.columnType;
105                 ejcol.columnSqlType = pjcol.columnSqlType;
106                 ejcol.table = extTable;
107                 ejcol.fieldName = pjcol.fieldName;
108                 ejcol.columnNotNull = pjcol.columnNotNull;
109                 ejcol.joins = null;
110                 ejcol.pes = null;
111             }
112             joinColumnsInExt.add(ejcol);
113             extTable.columns.add(ejcol);
114         }
115     }
116
117 }
118
Popular Tags