Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / db / tt_db_object.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: tt_db_object.h /main/3 1995/10/23 10:03:53 rswiston $                                                        */
28 /*
29  * tt_db_object.h - Declare the TT DB server object class.  This class defines the
30  *                  object properties interface to the DB server.
31  *
32  * Copyright (c) 1992 by Sun Microsystems, Inc.
33  */
34
35 #ifndef _TT_DB_OBJECT_H
36 #define _TT_DB_OBJECT_H
37
38 #include "util/tt_object.h"
39 #include "util/tt_string.h"
40 #include "db/tt_db_file.h"
41 #include "db/tt_db_hostname_global_map_ref.h"
42 #include "db/tt_db_access_utils.h"
43 #include "db/tt_db_property_utils.h"
44
45 class _Tt_db_object : public _Tt_object {
46 public:
47   // Instantiates a _Tt_object without any connection to an existing
48   // spec or the database.
49   _Tt_db_object ();
50
51   // If the specified ID is an existing spec in the database, then
52   // the database is connected to and the spec is loaded into memory.
53   _Tt_db_object (const _Tt_string &objid);
54
55   ~_Tt_db_object ();
56
57   // Sets and gets the access mode of this object spec.
58   void              setCurrentAccess (const _Tt_db_access_ptr &access);
59   _Tt_db_access_ptr getCurrentAccess () const;
60
61   // Creates the in memory version of the object spec and returns the
62   // new object ID.
63   _Tt_string create (const _Tt_string &file);
64   _Tt_string create (const _Tt_string &file, const _Tt_string &key);
65
66   // Writes the spec to the database.
67   _Tt_db_results write ();
68
69   // Refreshes the properties in memory with whatever is currently out
70   // in the database.
71   _Tt_db_results refresh ();
72
73   // Removes the spec from the database and/or memory and leaves the specified
74   // forward pointer in its place.
75   _Tt_db_results remove ();
76   _Tt_db_results remove (const _Tt_string &forward_pointer);
77
78   // Copys the object spec to the new file
79   _Tt_string copy (const _Tt_string &new_file);
80
81   // Moves the object spec to the new file.  After the move is done,
82   // this object actually contains the information of the new location.
83   // However, to prevent any weird race conditions due to someone else
84   // doing a move shortly after this move, it is best to just instantiate
85   // a new _Tt_db_object with the new objid.
86   _Tt_string move (const _Tt_string &new_file);
87
88   // Writes the specified object property to memory.  All values of the
89   // the object property with the same name are overwritten.  If the value of
90   // the property is empty, this deletes all properties with the same name
91   // from the database.
92   _Tt_db_results setProperty (const _Tt_db_property_ptr &property);
93
94   // Writes the specified object properties to memory.  All values of
95   // the object properties with the same names are overwritten.  If the value
96   // of some of the properties are empty, this deletes all properties with the
97   // same name from the database.
98   _Tt_db_results setProperties (const _Tt_db_property_list_ptr &properties);
99
100   // Adds an object property to the list of values of the object property
101   // with the same name in memory.  If the property does not already exist,
102   // then the property is created.  If the "unique" argument is TRUE, then
103   // the property name and value combination is guaranteed to be unique
104   // and will not be added to the list of values if the combination already
105   // exists.
106   _Tt_db_results addProperty (const _Tt_db_property_ptr &property,
107                               bool_t                     unique=FALSE);
108   
109   // Deletes the object property value with the same name and value from the
110   // DB.  If the value is left empty, then all values of the property are
111   // deleted.  The deletion is not cached.  The deletion is immediately
112   // executed on disk.
113   _Tt_db_results deleteProperty (const _Tt_db_property_ptr &property); 
114  
115   // Gets the values of the object property with the specified name from the
116   // memory cache.  If the property does not exist in memory, then the value
117   // is obtained from the DB.
118   _Tt_db_property_ptr      getProperty (const _Tt_string &name);
119
120   // Gets a list of all of the object properties currently written to the DB.
121   // If the object has never been written to the DB, then an error is returned. 
122   _Tt_db_property_list_ptr getProperties ();
123
124   // Sets and gets the otype of the specified object.
125   _Tt_db_results setType (const _Tt_string &otype);
126   _Tt_string     getType ();
127
128   // Gets the file of the object.
129   _Tt_string getFile ();
130
131   // Sets and gets the access mode of the specified object.
132   _Tt_db_results    setAccess (const _Tt_db_access_ptr &access);
133   _Tt_db_access_ptr getAccess ();
134  
135   // Returns the object ID of this object.
136   const _Tt_string& getObjectID () const
137     {
138       return dbObjectID;
139     }
140
141   // Returns the key porition of this object's object ID.
142   _Tt_string getObjectKey () const;
143
144   // Gets the results of the last database operation made with this object. 
145   _Tt_db_results getDBResults () const
146     {
147       return dbResults;
148     }
149
150 private:
151   bool_t                         checkedDatabase;
152   _Tt_db_hostname_global_map_ref dbHostnameGlobalMapRef;
153   _Tt_db_access_ptr              dbObjectAccess;
154   _Tt_db_access_ptr              dbObjectCurrentAccess;
155   _Tt_db_client_ptr              dbObjectDatabase;
156   _Tt_string                     dbObjectFile;
157   _Tt_string                     dbObjectHostname;
158   _Tt_string                     dbObjectID;
159   _Tt_db_property_list_ptr       dbObjectProperties;
160   int                            dbObjectPropertiesCacheLevel;
161   _Tt_string                     dbObjectType;
162   _Tt_db_results                 dbResults;
163   bool_t                         forwardPointerFlag;
164   bool_t                         memoryObjectCreated;
165
166   void           setTtDBObjectDefaults ();
167   _Tt_db_results createMemoryObject (const _Tt_string&, const _Tt_string&);
168   void           getDBObjectHostnameFromID ();
169   _Tt_db_results createDBObject ();
170
171   //
172   // Sets the internal object ID to a new ID and checks to see if the
173   // object is in the database.
174   //
175   _Tt_db_results setObjectID (const _Tt_string&);
176
177   _Tt_string     makeEquivalentObjectID (const _Tt_string&,
178                                          const _Tt_string&);
179   bool_t         isObjectInDatabase (bool_t force = FALSE);
180   _Tt_db_results internalRefresh ();
181
182   //
183   // Does some special results processing for any public member functions
184   // that do some database server operations.  It should be used to get
185   // the final results for all such member functions.  Member functions
186   // that are not public or that only work on the memory copy of the
187   // object should not call processDBResults.
188   //
189   _Tt_db_results processDBResults (); 
190
191   void setCurrentDBAccess ()
192     {
193       if (!dbObjectDatabase.is_null()) {
194         dbObjectDatabase->setCurrentAccess(dbObjectCurrentAccess);
195       }
196     }
197 };
198
199 #endif // _TT_DB_OBJECT_H