KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > mappeddata > data > MappedData


1 /*
2  * Copyright (c) 2006 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: MappedData.java,v 1.6 2007/01/28 06:54:51 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.patterns.mappeddata.data;
23
24 import java.sql.Timestamp JavaDoc;
25
26 import org.opensubsystems.core.data.DataConstant;
27 import org.opensubsystems.core.data.ModifiableDataObject;
28
29 /**
30  * Mapped data object represents relationship between two data objects by
31  * identifying the two data objects in the relationship, the type of relationship
32  * as well as storing any additional data connected with this relationship..
33  *
34  * @version $Id: MappedData.java,v 1.6 2007/01/28 06:54:51 bastafidli Exp $
35  * @author Julian Legeny
36  * @code.reviewer Miro Halas
37  * @code.reviewed 1.2 2006/06/29 00:26:42 jlegeny
38  */

39 public class MappedData extends ModifiableDataObject
40 {
41    // Constants ////////////////////////////////////////////////////////////////
42

43    /**
44     * Code for table column.
45     */

46    public static final int COL_MAPPEDDATA_ID = DataConstant.MAPPEDDATA_DATA_TYPE + 1;
47
48    /**
49     * Object code for table column.
50     */

51    public static final Integer JavaDoc COL_MAPPEDDATA_ID_OBJ = new Integer JavaDoc(COL_MAPPEDDATA_ID);
52
53    /**
54     * Code for table column.
55     */

56    public static final int COL_MAPPEDDATA_ID1 = DataConstant.MAPPEDDATA_DATA_TYPE + 2;
57
58    /**
59     * Object code for table column.
60     */

61    public static final Integer JavaDoc COL_MAPPEDDATA_ID1_OBJ = new Integer JavaDoc(COL_MAPPEDDATA_ID1);
62
63    /**
64     * Code for table column.
65     */

66    public static final int COL_MAPPEDDATA_ID2 = DataConstant.MAPPEDDATA_DATA_TYPE + 3;
67
68    /**
69     * Object code for table column.
70     */

71    public static final Integer JavaDoc COL_MAPPEDDATA_ID2_OBJ = new Integer JavaDoc(COL_MAPPEDDATA_ID2);
72
73    /**
74     * Code for table column.
75     */

76    public static final int COL_MAPPEDDATA_MAPPING_TYPE = DataConstant.MAPPEDDATA_DATA_TYPE + 4;
77
78    /**
79     * Object code for table column.
80     */

81    public static final Integer JavaDoc COL_MAPPEDDATA_MAPPED_TYPE_OBJ
82                                = new Integer JavaDoc(COL_MAPPEDDATA_MAPPING_TYPE);
83
84    /**
85     * Code for table column.
86     */

87    public static final int COL_MAPPEDDATA_CUSTOM_DATA = DataConstant.MAPPEDDATA_DATA_TYPE + 5;
88
89    /**
90     * Object code for table column.
91     */

92    public static final Integer JavaDoc COL_MAPPEDDATA_CUSTOM_DATA_OBJ
93                                   = new Integer JavaDoc(COL_MAPPEDDATA_CUSTOM_DATA);
94
95    /**
96     * Code for table column.
97     */

98    public static final int COL_MAPPEDDATA_CREATION_DATE = DataConstant.MAPPEDDATA_DATA_TYPE + 6;
99
100    /**
101     * Code for table column.
102     */

103    public static final int COL_MAPPEDDATA_MODIFICATION_DATE = DataConstant.MAPPEDDATA_DATA_TYPE + 7;
104
105    /**
106     * Static variable for array of all columns codes.
107     * The order is important since it is used to retrieve all data from the
108     * persistence store efficiently so do not modify it unless you make
109     * changes to other places as well.
110     */

111    public static final int[] ALL_MAPPEDDATA_COLUMNS = {COL_MAPPEDDATA_ID,
112                                                        COL_MAPPEDDATA_ID1,
113                                                        COL_MAPPEDDATA_ID2,
114                                                        COL_MAPPEDDATA_MAPPING_TYPE,
115                                                        COL_MAPPEDDATA_CUSTOM_DATA,
116                                                        COL_MAPPEDDATA_CREATION_DATE,
117                                                        COL_MAPPEDDATA_MODIFICATION_DATE,
118                                                       };
119
120    /**
121     * List of columns which should be retrieved from persistence store by default.
122     * These should be only columns visible to user on the screen and not any
123     * internal columns. Also the columns should be retrievable efficiently so
124     * that the default view is very quick.
125     */

126    public static final int[] DEFAULT_LIST_COLUMNS = {COL_MAPPEDDATA_ID1,
127                                                      COL_MAPPEDDATA_ID2,
128                                                      COL_MAPPEDDATA_MAPPING_TYPE,
129                                                      COL_MAPPEDDATA_MODIFICATION_DATE,
130                                                     };
131
132    /**
133     * Mapping type of domain-survey schema that identify selfregistration data.
134     * TODO: For Julo: This doesn't belong here: This should be in DomainSurvey
135     * object or controller which uses it..
136     */

137    public static final int MAPPING_TYPE_SELFREG = 1;
138
139    // Cached values ////////////////////////////////////////////////////////////
140

141    /**
142     * Maximal length of the custom data field.
143     * The value depends on the underlying persistence mechanism and it is set
144     * once the persistance layer is initialized.
145     */

146    protected static int s_iCustomDataMaxLength;
147
148    // Attributes ///////////////////////////////////////////////////////////////
149

150    /**
151     * Generated serial version id for this class.
152     */

153    private static final long serialVersionUID = -6781584072783366066L;
154
155    /**
156     * Id of the first data object in the relation.
157     */

158    protected int m_iMappedId1;
159
160    /**
161     * Id of the second data object in the relation.
162     */

163    protected int m_iMappedId2;
164
165    /**
166     * Mapping type. By specifying different values it is possible to create
167     * multiple different relations between the same dataobjects.
168     */

169    protected int m_iMappingType;
170
171    /**
172     * Custom data to store together with the relation. This could be data further
173     * classifying the relation between the specified data objects.
174     */

175    protected String JavaDoc m_strCustomData;
176
177    // Constructors /////////////////////////////////////////////////////////////
178

179    /**
180     * Empty mapped data initialized to default parameters
181     *
182     * Note: We do not allow to specify domain id because mapped data doesn't
183     * exist in domain.
184     */

185    public MappedData(
186    )
187    {
188       this(NEW_ID, NEW_ID, NEW_ID, 0, "", null, null);
189    }
190
191    /**
192     * Create mapped data from a given parameters.
193     *
194     * Note: We do not allow to specify domain id because mapped data doesn't
195     * exist in domain.
196     *
197     * @param iId - Unique ID identifying this mapped data.
198     * @param iMappedId1 - Mapped ID 1.
199     * @param iMappedId2 - Mapped ID 2.
200     * @param iMappedType - Mapped type.
201     * @param strCustomData - Custom data.
202     * @param creationTimestamp - Timestamp when the mapped data was created
203     * @param modificationTimestamp - Timestamp when the mapped data was last time modified
204     *
205     */

206    public MappedData(
207       int iId,
208       int iMappedId1,
209       int iMappedId2,
210       int iMappedType,
211       String JavaDoc strCustomData,
212       Timestamp JavaDoc creationTimestamp,
213       Timestamp JavaDoc modificationTimestamp
214    )
215    {
216       super(iId, NEW_ID, creationTimestamp, modificationTimestamp);
217
218       m_iMappedId1 = iMappedId1;
219       m_iMappedId2 = iMappedId2;
220       m_iMappingType = iMappedType;
221       m_strCustomData = strCustomData;
222    }
223
224    /**
225     * @return int
226     */

227    public int getMappedId1()
228    {
229       return m_iMappedId1;
230    }
231
232    /**
233     * @param mappedId1 - new mapped ID 1
234     */

235    public void setMappedId1(
236       int mappedId1
237    )
238    {
239       m_iMappedId1 = mappedId1;
240    }
241
242    /**
243     * @return int
244     */

245    public int getMappedId2()
246    {
247       return m_iMappedId2;
248    }
249
250    /**
251     * @param mappedId2 - new mapped ID 2
252     */

253    public void setMappedId2(
254       int mappedId2
255    )
256    {
257       m_iMappedId2 = mappedId2;
258    }
259
260    /**
261     * @return int
262     */

263    public int getMappingType()
264    {
265       return m_iMappingType;
266    }
267
268    /**
269     * @param mappingType - new mapped type
270     */

271    public void setMappingType(
272       int mappingType
273    )
274    {
275       m_iMappingType = mappingType;
276    }
277
278    /**
279     * @return String
280     */

281    public String JavaDoc getCustomData()
282    {
283       return m_strCustomData;
284    }
285
286    /**
287     * @param customData - new cutom data for mapped table
288     */

289    public void setCustomData(
290       String JavaDoc customData
291    )
292    {
293       m_strCustomData = customData;
294    }
295
296    /**
297     * @return int
298     */

299    public int getCustomDataMaxLength()
300    {
301       return s_iCustomDataMaxLength;
302    }
303
304    /**
305     * @return int
306     */

307    public static int getCustomDataMaxLengthStatic()
308    {
309       return s_iCustomDataMaxLength;
310    }
311
312    /**
313     * Maximal length for custom data.
314     *
315     * @param iCustomData - maximal length of the custom data in the persistence
316     * store
317     */

318    public static void setCustomDataMaxLength(
319       int iCustomData
320    )
321    {
322       s_iCustomDataMaxLength = iCustomData;
323    }
324
325    /**
326     * {@inheritDoc}
327     */

328    public boolean isSame(
329       Object JavaDoc oObject
330    )
331    {
332       boolean bReturn = false;
333       MappedData help;
334
335       if (oObject == this)
336       {
337          bReturn = true;
338       }
339       else
340       {
341          if (oObject != null && oObject instanceof MappedData)
342          {
343             // cast Object to Mapped Data
344
help = (MappedData) oObject;
345             // check all data attributes for equals
346
bReturn = (((m_strCustomData == null) && (help.m_strCustomData == null))
347                          || ((m_strCustomData != null)
348                             && (m_strCustomData.equals(help.m_strCustomData))))
349                       && help.getMappedId1() == m_iMappedId1
350                       && help.getMappedId2() == m_iMappedId2
351                       && help.getMappingType() == m_iMappingType;
352          }
353       }
354       return bReturn;
355    }
356 }
357
Popular Tags