KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sql > CloneableDO


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: CloneableDO.java,v 1.1 2004/09/03 13:42:37 sinisa Exp $
22  */

23 package com.lutris.appserver.server.sql;
24
25 import java.sql.ResultSet JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import org.enhydra.dods.DODS;
28
29 /**
30  * Base class from which the data objects are created.
31  * Provides functionality for cloning data objects. The cloned
32  * data object will have a unique object identifier.
33  *
34  * @version $Revision: 1.1 $
35  * @since LBS1.8
36  * @author Kyle Clark
37  */

38 abstract public class CloneableDO extends CoreDO implements Cloneable JavaDoc {
39
40     /**
41      * Public constructor.
42      */

43     public CloneableDO() {
44         super();
45     }
46     
47     /**
48      * Public constructor.
49      * @param rs a result set.
50      * @exception SQLException if an error occurs while instantiating this
51      * object from the result set.
52      * @exception ObjectIdException if the object id for this object is
53      * invalid.
54      */

55     public CloneableDO(ResultSet JavaDoc rs) throws SQLException JavaDoc, ObjectIdException {
56         super(rs);
57     }
58
59     /**
60      * Creates a clone of the object, but ensures that
61      * a new and unique object id is created for the object
62      * and that the version number is set to zero.
63      * @exception DatabaseManagerException if an error occurs while
64      * allocation a new object id from the default logical database.
65      * @exception ObjectIdException if a new object id could not be
66      * allocated.
67      */

68     public synchronized Object JavaDoc cloneUnique()
69         throws DatabaseManagerException, ObjectIdException {
70         CloneableDO dataObj = (CloneableDO) clone();
71
72         dataObj.set_OId(DODS.getDatabaseManager().allocateObjectId());
73         dataObj.set_Version(0);
74         dataObj.setPersistent(false);
75         return dataObj;
76     }
77
78     /**
79      * Will clone the existing object keeping a fields
80      * the same, including the object id.
81      */

82     protected Object JavaDoc clone() {
83         Object JavaDoc obj = this;
84
85         try {
86             obj = super.clone();
87         } catch (CloneNotSupportedException JavaDoc ex) {// Should not happen
88
}
89         return obj;
90     }
91 }
92
Popular Tags