KickJava   Java API By Example, From Geeks To Geeks.

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


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-2004 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@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.mapper.rdb.metainfo;
25
26 import org.objectweb.jorm.metainfo.api.MetaObject;
27 import org.objectweb.jorm.metainfo.api.PrimitiveElement;
28 import org.objectweb.jorm.metainfo.api.PrimitiveElementMapping;
29 import org.objectweb.jorm.metainfo.lib.BasicMappingStructure;
30 import org.objectweb.jorm.api.PException;
31
32 import java.util.Map JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.TreeMap JavaDoc;
35
36 /**
37  * Description
38  */

39 public class RdbPrimitiveElementMapping extends BasicMappingStructure
40         implements PrimitiveElementMapping, Comparable JavaDoc {
41     /**
42      * The name of the column
43      */

44     private String JavaDoc name;
45
46     /**
47      * The sql type of the column
48      */

49     private String JavaDoc type;
50
51     /**
52      * Indicates if the column can be null or not
53      */

54     private boolean notNull;
55
56     private Map JavaDoc join2pe;
57
58     /**
59      * Builds a new BasicRdbPrimitiveElementMapping.
60      * @param name the name of the column
61      * @param type the sql type of the column
62      * @param notNull true, if the column can not be null, else false.
63      * @param parent the parent of the current object
64      */

65     public RdbPrimitiveElementMapping(String JavaDoc name,
66                                            String JavaDoc type,
67                                            boolean notNull,
68                                            MetaObject linkedMO,
69                                            MetaObject parent) {
70         super(parent, linkedMO);
71         this.name = name;
72         this.type = type;
73         this.notNull = notNull;
74         this.join2pe = new TreeMap JavaDoc();
75     }
76
77     /**
78      * Builds a new BasicRdbPrimitiveElementMapping.
79      * @param name the name of the column
80      * @param type the sql type of the column
81      * @param notNull true, if the column can not be null, else false.
82      * @param parent the parent of the current object
83      */

84     public RdbPrimitiveElementMapping(String JavaDoc name,
85                                            String JavaDoc type,
86                                            boolean notNull,
87                                            MetaObject linkedMO,
88                                            MetaObject parent,
89                                            RdbJoin join) {
90         this(name, type, notNull, linkedMO, parent);
91         join2pe.put(join, linkedMO);
92     }
93
94     public int compareTo(Object JavaDoc o) {
95         return name.compareTo(((RdbPrimitiveElementMapping) o).getName());
96     }
97
98
99     ///////////////////////////////////////////////////////////////////
100
// from RdbPrimitiveElementMapping interface
101
///////////////////////////////////////////////////////////////////
102

103     /**
104      * Returns the name of the current column.
105      * @return the string representation of column name
106      */

107     public String JavaDoc getName() {
108         return name;
109     }
110
111     /**
112      * Returns the SQL type of the current object.
113      * @return the string representation of the sql type
114      */

115     public String JavaDoc getType() {
116         return type;
117     }
118
119     /**
120      * Returns an RdbFilter object.
121      * @return an RdbFilter object.
122      */

123     public RdbFilter getRdbFilter() {
124         RdbFilter filter = ((RdbClassMapping) getParent().getParent()).getRdbFilter();
125         return filter;
126     }
127
128     /**
129      * Indicates if the column is used as a filter column
130      * @return true, if the column is a filter column, else false
131      */

132     public boolean isFilter() {
133         RdbFilter filter = getRdbFilter();
134         if (filter == null) {
135             return false;
136         }
137         return filter.isFilter((PrimitiveElement) linkedMO);
138     }
139
140     /**
141      * Returns the predicate value associated with the column.
142      * If the predicate does not correspond to an equal operator, a PException is raised.
143      * @return the predicate value associated with the column.
144      */

145     public String JavaDoc getEqualPredicateValue() throws PException {
146         RdbFilter filter = getRdbFilter();
147         return filter.getEqualPredicateValue(((PrimitiveElement)linkedMO).getName());
148      }
149
150     /**
151      * Allows to know if the column is null or not.
152      * @return true, if the column is null, else false
153      */

154     public boolean isNotNull() {
155         return notNull;
156     }
157
158     public void setName(String JavaDoc columnName) {
159         this.name = columnName;
160     }
161
162     public void setType(String JavaDoc sqlType) {
163         this.type = sqlType;
164     }
165
166     public void setIsNotNull(boolean isNotNull) {
167         this.notNull = isNotNull;
168     }
169
170     public void bindPrimitiveElement(RdbJoin join, PrimitiveElement pe) {
171         join2pe.put(join, pe);
172     }
173
174     public PrimitiveElement lookupPrimitiveElement(RdbJoin join) {
175         return (PrimitiveElement) join2pe.get(join);
176     }
177
178     public Map JavaDoc getPrimitiveElementByRdbJoin() {
179         return join2pe;
180     }
181
182     public RdbJoin getJoinByPrimitiveElement(PrimitiveElement pe) {
183         RdbJoin join = null;
184         if (!(join2pe.keySet().isEmpty())) {
185             Iterator JavaDoc joinIterator = join2pe.keySet().iterator();
186             while (joinIterator.hasNext()) {
187                 RdbJoin currentJoin = (RdbJoin) joinIterator.next();
188                 if (join2pe.get(currentJoin) == pe) {
189                     join = currentJoin;
190                     return join;
191                 }
192             }
193         }
194         return join;
195     }
196
197 }
198
Popular Tags