KickJava   Java API By Example, From Geeks To Geeks.

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


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.api.MetaObject;
26 import org.objectweb.jorm.metainfo.lib.BasicGenClassMapping;
27
28 import java.util.List JavaDoc;
29 import java.util.Collection JavaDoc;
30
31 /**
32  * Description
33  */

34 public class RdbGenClassMapping extends BasicGenClassMapping
35         implements RdbMappingInfos {
36     /**
37      * The primary table
38      */

39     private RdbTable table;
40
41     /**
42      * List of external table names
43      */

44     List JavaDoc tableNames = null;
45
46     /**
47      * List of RdbExternalTable objects
48      */

49     List JavaDoc tables = null;
50
51     /**
52      * Builds a new BasicRdbGenClassMapping object.
53      * This object contains the mapping structure of the class it refers to.
54      * The parent object is a Mapping object that contains the mapper name.
55      * @param ruleName the name of the rule used to map the class,
56      * linkedMo the GenClassRef object referenced by the current object,
57      * ruleName the name of the rule used to map the class,
58      * parent the parent of the current object.
59      */

60     public RdbGenClassMapping(String JavaDoc ruleName, MetaObject linkedMO,
61                                    MetaObject parent) {
62         super(ruleName,linkedMO, parent);
63         table = null;
64         /*
65         GenClassRef genClassRef = (GenClassRef) linkedMO;
66         if (getLogger().isLoggable(BasicLevel.DEBUG)) {
67             getLogger().log(BasicLevel.DEBUG,
68                     "create a new BasicRdbGenClassMapping for the current "+
69                     "GenClassRef ("+ genClassRef.getName() + ")");
70             getLogger().log(BasicLevel.DEBUG,"ruleName= " + ruleName);
71         }
72         */

73     }
74
75     ///////////////////////////////////////////////////////////////////
76
// from RdbGenClassMapping interface
77
///////////////////////////////////////////////////////////////////
78

79
80     /**
81      * Sets the name of the primary table
82      * @param tablename the name of the primary table
83      */

84     public RdbTable createRdbTable(String JavaDoc tablename) {
85         if (table == null) {
86             table = new RdbTable(this, getLinkedMO(), tablename);
87             table.setLogger(getLogger());
88             table.setLoggerFactory(getLoggerFactory());
89         }
90         return table;
91     }
92
93     /**
94      * Returns the name of the primary table.
95      * @return a String object, the name of the primary table
96      */

97     public RdbTable getRdbTable() {
98         return table;
99     }
100
101     public RdbExternalTable createRdbExternalTable(String JavaDoc tableName) {
102         int idx = tableNames.indexOf(tableName);
103         RdbExternalTable t;
104         if (idx == -1) {
105             t = new RdbExternalTable(this, getLinkedMO(), tableName);
106             t.setLogger(getLogger());
107             t.setLoggerFactory(getLoggerFactory());
108             tableNames.add(tableName);
109             tables.add(t);
110         }
111         else {
112             t = (RdbExternalTable) tables.get(idx);
113         }
114         return t;
115     }
116
117     public RdbExternalTable removeRdbExternalTable(String JavaDoc tableName) {
118         int idx = tableNames.indexOf(tableName);
119         if (idx != -1) {
120             tableNames.remove(idx);
121             return (RdbExternalTable) tables.remove(idx);
122         }
123         return null;
124     }
125
126     public Collection JavaDoc getRdbExternalTables() {
127         return tables;
128     }
129
130     public RdbExternalTable getRdbExternalTable(String JavaDoc tableName) {
131         int idx = tableNames.indexOf(tableName);
132         if (idx != -1) {
133             return (RdbExternalTable) tables.get(idx);
134         }
135         return null;
136     }
137     public RdbTable getMainTable() {
138         return table;
139     }
140
141     public List JavaDoc getExternalTables() {
142         return tables;
143     }
144
145     public List JavaDoc getExternalTableNames() {
146         return tableNames;
147     }
148
149 }
150
Popular Tags