KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > data > ModifiableDataObject


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ModifiableDataObject.java,v 1.7 2007/01/07 06:14:17 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.core.data;
23
24 import java.sql.Timestamp JavaDoc;
25
26 import org.opensubsystems.core.util.HashCodeUtils;
27
28 /**
29  * Base class for all data objects, which can be modified and therefore want to
30  * track when they were last modified.
31  *
32  * @version $Id: ModifiableDataObject.java,v 1.7 2007/01/07 06:14:17 bastafidli Exp $
33  * @author Miro Halas
34  * @code.reviewer Miro Halas
35  * @code.reviewed 1.5 2005/08/22 06:29:10 bastafidli
36  */

37 public abstract class ModifiableDataObject extends BasicDataObject
38 {
39    // Attributes ///////////////////////////////////////////////////////////////
40

41    /**
42     * Modification timestamp when the data object was last time modified.
43     */

44    protected Timestamp JavaDoc m_modificationTimestamp;
45
46    // Constructors /////////////////////////////////////////////////////////////
47

48    /**
49     * Default constructor.
50     */

51    public ModifiableDataObject(
52    )
53    {
54       this(DataObject.NEW_ID);
55    }
56
57    /**
58     * Simple constructor creating new data object in particular domain.
59     *
60     * @param iDomainId - domain this data object belongs to
61     */

62    public ModifiableDataObject(
63       int iDomainId
64    )
65    {
66       this(DataObject.NEW_ID, iDomainId, null, null);
67    }
68
69    /**
70     * Full constructor.
71     *
72     * @param iId - id of this data object
73     * @param iDomainId - domain this data object belongs to
74     * @param creationTimestamp - timestamp when the data object was created.
75     * @param modificationTimestamp - timestamp when the data object was last
76     * time modified.
77     */

78    public ModifiableDataObject(
79       int iId,
80       int iDomainId,
81       Timestamp JavaDoc creationTimestamp,
82       Timestamp JavaDoc modificationTimestamp
83    )
84    {
85       super(iId, iDomainId, creationTimestamp);
86       
87       m_modificationTimestamp = modificationTimestamp;
88    }
89    
90    // Accessors ////////////////////////////////////////////////////////////////
91

92    /**
93     * Get modification timestamp when the data object was last time modified.
94     *
95     * @return Timestamp
96     */

97    public Timestamp JavaDoc getModificationTimestamp()
98    {
99       return m_modificationTimestamp;
100    }
101    
102    /**
103     * Set modification timestamp when the data object was last time modified.
104     *
105     * @param modificationTimestamp - new modification timestamp
106     */

107    public void setModificationTimestamp(
108       Timestamp JavaDoc modificationTimestamp
109    )
110    {
111       m_modificationTimestamp = modificationTimestamp;
112    }
113    
114    /**
115     * {@inheritDoc}
116     */

117    public boolean equals(
118       Object JavaDoc oObject
119    )
120    {
121       boolean bReturn = false;
122       ModifiableDataObject helper;
123
124       if (oObject == this)
125       {
126          bReturn = true;
127       }
128       else if ((oObject != null) && (oObject instanceof ModifiableDataObject))
129       {
130          helper = (ModifiableDataObject) oObject;
131          bReturn = (((m_modificationTimestamp == null)
132                       && (helper.getModificationTimestamp() == null))
133                       || ((m_modificationTimestamp != null))
134                          && (m_modificationTimestamp.equals(
135                               helper.getModificationTimestamp())))
136                    && (super.equals(oObject));
137       }
138
139       return bReturn;
140    }
141
142    /**
143     * {@inheritDoc}
144     */

145    public int hashCode()
146    {
147       int iResult = HashCodeUtils.SEED;
148       if (m_modificationTimestamp != null)
149       {
150          iResult = HashCodeUtils.hash(iResult, m_modificationTimestamp.getTime());
151       }
152       else
153       {
154          iResult = HashCodeUtils.hash(iResult, "null");
155       }
156       iResult = HashCodeUtils.hash(iResult, super.hashCode());
157       return iResult;
158    }
159
160    // Helper methods ///////////////////////////////////////////////////////////
161

162    /**
163     * Restore all values from specified values. This is here to reinitialize
164     * object in case it needs to be reused or reconstructed (e.g. when rollback
165     * is issued).
166     *
167     * @param iId - id of this data object
168     * @param iDomainId - domain this data object belongs to
169     * @param creationTimestamp - timestamp when the data object was created.
170     * @param modificationTimestamp - timestamp when the data object was last
171     * time modified.
172     */

173    protected void restore(
174       int iId,
175       int iDomainId,
176       Timestamp JavaDoc creationTimestamp,
177       Timestamp JavaDoc modificationTimestamp
178    )
179    {
180       super.restore(iId, iDomainId, creationTimestamp);
181       
182       m_modificationTimestamp = modificationTimestamp;
183    }
184 }
185
Popular Tags