KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > sessions > DatabaseRecord


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.sessions;
23
24 import java.util.*;
25 import oracle.toplink.essentials.exceptions.ValidationException;
26 import oracle.toplink.essentials.internal.helper.DatabaseField;
27 import oracle.toplink.essentials.internal.sessions.AbstractRecord;
28
29 /**
30  * <p>
31  * <b>Purpose</b>: Define a representation of a database row as field=>value pairs.
32  * This is the database row implementation class, the Record or java.util.Map interfaces
33  * should be used to access this class instead of the implemention class.
34  * <p>
35  * <b>Responsibilities</b>: <ul>
36  * <li> Implement the common hashtable collection protocol.
37  * <li> Allow get and put on the field or field name.
38  * </ul>
39  * @see DatabaseField
40  * @see Record
41  * @see java.util.Map
42  */

43 public class DatabaseRecord extends AbstractRecord {
44
45     /**
46      * INTERNAL:
47      * Returns a record (of default size).
48      */

49     public DatabaseRecord() {
50         super();
51     }
52
53     /**
54      * INTERNAL:
55      * Returns a record of the given initial capacity.
56      * @param initialCapacity
57      */

58     public DatabaseRecord(int initialCapacity) {
59         super(initialCapacity);
60     }
61
62     /**
63      * INTERNAL:
64      * Builds row from database result fields and values.
65      * Note: the entire database result will share the same fields vector.
66      * @param fields Vector of fields
67      * @param values Vector of values
68      */

69     public DatabaseRecord(Vector fields, Vector values) {
70         super(fields, values);
71     }
72
73     /**
74      * PUBLIC:
75      * Clears the contents of the database row, both fields and values.
76      */

77     public void clear() {
78         super.clear();
79     }
80
81     /**
82      * PUBLIC:
83      * Checks if the given Object value is contained in the values held
84      * in the database row.
85      * @param value the Object to be considered
86      * @return boolean - true if the Object value is in the row.
87      */

88     public boolean contains(Object JavaDoc value) {
89         return super.containsValue(value);
90     }
91
92     /**
93      * PUBLIC:
94      * Checks if a key (ie. the field) is contained in the database row.
95      * Conforms to a hashtable interface.
96      * @param key an Object, either String or DatabaseField
97      * @return boolean - true if the row with the corresponding key is in the row.
98      */

99     public boolean containsKey(Object JavaDoc key) {
100         return super.containsKey(key);
101     }
102
103     /**
104      * PUBLIC:
105      * Checks if a given field is contained in the database row.
106      * @param key String, the DatabaseField name
107      * @return boolean - true if the row contains the key with the corresponding fieldName.
108      */

109     public boolean containsKey(String JavaDoc fieldName) {
110         return super.containsKey(fieldName);
111     }
112
113     /**
114      * PUBLIC:
115      * Checks if the given Object value is contained in the values held
116      * in the database row.
117      * @param value the Object under consideration
118      * @return boolean - true if the row contains the Object as a value
119      */

120     public boolean containsValue(Object JavaDoc value) {
121         return super.containsValue(value);
122     }
123
124     /**
125      * PUBLIC:
126      * Returns an Enumeration of the values in the database row.
127      * @return Enumeration
128      */

129     public Enumeration elements() {
130         return super.elements();
131     }
132
133     /**
134      * PUBLIC:
135      * Returns a set of map entries (ie. field-value pairs)in the database row
136      * with the DatabaseFields as keys and the value Objects as values.
137      * @see java.util.Map#entrySet()
138      * @return Set - the set of all the field-value entries (see java.util.Map.Entry)
139      */

140     public Set entrySet() {
141         return super.entrySet();
142     }
143
144     /**
145      * PUBLIC:
146      * Retrieves the value for the given key.
147      * A field is constructed with the key to check the hash table.
148      * If missing, null is returned.
149      * @param key Object, either String or DatabaseField
150      * @return Object
151      */

152     public Object JavaDoc get(Object JavaDoc key) {
153         return super.get(key);
154     }
155
156     /**
157      * PUBLIC:
158      * Retrieves the value with the given name of the DatabaseField.
159      * A field is constructed on the name to check the hash table.
160      * If missing, null is returned.
161      * @param fieldName String, the DatabaseField name
162      * @return Object - the value
163      */

164     public Object JavaDoc get(String JavaDoc fieldName) {
165        return super.get(fieldName);
166     }
167
168     /**
169      * PUBLIC:
170      * Retrieves the value with the given field name.
171      * A field is constructed on the name to check the hash table.
172      * If missing, DatabaseRow.noEntry is returned.
173      * @param fieldName String, the DatabaseField name
174      * @return Object - the value
175      */

176     public Object JavaDoc getIndicatingNoEntry(String JavaDoc fieldName) {
177        return super.getIndicatingNoEntry(fieldName);
178     }
179     
180     /**
181      * PUBLIC:
182      * Returns the Object associated with the given key
183      * (null if the key does not map to an Object.)
184      * @param key DatabaseField
185      * @return Object - the value associated with the key
186      */

187     public Object JavaDoc getValues(DatabaseField key) {
188         return super.get(key);
189     }
190
191     /**
192      * PUBLIC:
193      * Returns the Object associated with the given key
194      * (null if the key does not map to an Object.)
195      * @param key String
196      * @return Object - the value associated with the key
197      */

198     public Object JavaDoc getValues(String JavaDoc key) {
199         return super.get(key);
200     }
201
202     /**
203      * PUBLIC:
204      * Checks if the database row is empty (ie. there are no field-value pairs.)
205      * @return boolean - true if the database row is empty
206      */

207     public boolean isEmpty() {
208         return super.isEmpty();
209     }
210
211     /**
212      * PUBLIC:
213      * Returns an Enumeration of the DatabaseField Objects.
214      * @return Enumeration
215      */

216     public Enumeration keys() {
217         return super.keys();
218     }
219
220     /**
221      * PUBLIC:
222      * Returns a set of the keys, the DatabaseField Objects, for the database row.
223      * @return Set of the keys
224      */

225     public Set keySet() {
226         return super.keySet();
227     }
228     
229     /**
230      * PUBLIC:
231      * Adds a field-value pair to the row.
232      * @param key Object, either String or DatabaseField
233      * @param value Object
234      * @return Object - the previous Object with that key, could be null
235      * @throws ValidationException if inappropriate key is used
236      */

237     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) throws ValidationException {
238         return super.put(key, value);
239     }
240
241     /**
242      * PUBLIC:
243      * Adds a field-value pair to the row.
244      * @param key String
245      * @param value Object
246      * @return Object - the previous Object with that key, could be null
247      */

248     public Object JavaDoc put(String JavaDoc key, Object JavaDoc value) {
249         return super.put(key, value);
250     }
251
252     /**
253      * PUBLIC:
254      * Adds all of the elements in the given map to the database row.
255      * @param map Map of all the field-value elements to be added
256      */

257     public void putAll(Map map){
258         super.putAll(map);
259     }
260
261     /**
262      * PUBLIC:
263      * Returns the number of field-value pairs in the database row.
264      * @return int
265      */

266     public int size() {
267         return super.size();
268     }
269
270     /**
271      * PUBLIC:
272      * Returns a collection of the values held in the database row.
273      * @return Collection of value Objects
274      */

275     public Collection values() {
276         return super.values();
277     }
278 }
279
Popular Tags