KickJava   Java API By Example, From Geeks To Geeks.

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


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.metainfo.lib.BasicMetaObject;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 /**
31  * Implementation of the RdbJoin interface. It represents the structure of a join
32  * between an external table and its corresponding main table.
33  * The join relationship requires two columns represented by
34  * primaryTableColumnName and externalTableColumnName.
35  * As a meta-object the parent is the external table. The main table is retrieved
36  * through the external table.
37  * @see RdbClassMultiMapping
38  */

39 public class RdbJoin extends BasicMetaObject implements Comparable JavaDoc {
40     /**
41      * Column names of the primary table involved in the join.
42      */

43     private ArrayList JavaDoc ptJoinColumnNames;
44
45     /**
46      * Column names of the external table involved in the join.
47      */

48     private ArrayList JavaDoc etJoinColumnNames;
49
50     private String JavaDoc name;
51     /**
52      * Builds a new BasicRdbJoin object between an external table and its
53      * asociated main table. The list of joined columns is given afterwhile by
54      * calling the addJoinColumnNames.
55      *
56      * @param externalTable the external table of the join.
57      * @param name the name given to the join meta-object
58      */

59     public RdbJoin(RdbExternalTable externalTable, String JavaDoc name) {
60         super(externalTable);
61         this.name = name;
62         this.ptJoinColumnNames = new ArrayList JavaDoc();
63         this.etJoinColumnNames = new ArrayList JavaDoc();
64     }
65
66     /**
67      * Returns the external table involved in the join.
68      * @return the external table involved in the join.
69      */

70
71     public RdbExternalTable getExternalTable() {
72         return (RdbExternalTable) parent;
73     }
74
75     /**
76      * Returns the main table involved in the join. Retrieved through the external
77      * table.
78      * @return the external table involved in the join.
79      */

80     public RdbTable getMainTable() {
81         return getExternalTable().getMainTable();
82     }
83     /**
84      * Compares the join to another join. Join meta-object are equal if their names
85      * are equal.
86      * @param o the join meta-object to which comparing this join meta-object
87      * @return true is join mata-objects have the same names
88      */

89     public int compareTo(Object JavaDoc o) {
90         return name.compareTo(((RdbJoin) o).getName());
91     }
92
93     /**
94      * Returns the list of the column names of the primary (main) table
95      * involved in the join. If main T1 and ext T2 joined through
96      * T1.c11 == T2.c21 ... T1.c1n == T2.c2n,
97      * then this method returns (c11, ..., c1n)
98      * @return the list of the column names of the primary (main) table
99      * involved in the join.
100      */

101     public List JavaDoc getPTJoinColumnNames() {
102         return ptJoinColumnNames;
103     }
104
105     /**
106      * Returns the list of the column names of the primary (main) table
107      * involved in the join. If main T1 and ext T2 joined through
108      * T1.c11 == T2.c21 ... T1.c1n == T2.c2n,
109      * then this method returns (c21, ..., c2n)
110      * @return the list of the column names of the primary (main) table
111      * involved in the join.
112      */

113     public List JavaDoc getETJoinColumnNames() {
114         return etJoinColumnNames;
115     }
116
117     /**
118      * Adds two join column names
119      */

120     public void addJoinColumnNames(String JavaDoc ptJoinColumnName,
121                                    String JavaDoc etJoinColumnName) {
122         if (! ptJoinColumnNames.contains( ptJoinColumnName)) {
123             if (! etJoinColumnNames.contains( etJoinColumnName)) {
124                 ptJoinColumnNames.add(ptJoinColumnName);
125                 etJoinColumnNames.add(etJoinColumnName);
126             }
127         }
128     }
129
130     public String JavaDoc getName() {
131         return name;
132     }
133
134     public void setName(String JavaDoc name) {
135         this.name = name;
136     }
137 }
138
Popular Tags