2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
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 $ */
29 * tt_db_object.h - Declare the TT DB server object class. This class defines the
30 * object properties interface to the DB server.
32 * Copyright (c) 1992 by Sun Microsystems, Inc.
35 #ifndef _TT_DB_OBJECT_H
36 #define _TT_DB_OBJECT_H
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"
45 class _Tt_db_object : public _Tt_object {
47 // Instantiates a _Tt_object without any connection to an existing
48 // spec or the database.
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);
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;
61 // Creates the in memory version of the object spec and returns the
63 _Tt_string create (const _Tt_string &file);
64 _Tt_string create (const _Tt_string &file, const _Tt_string &key);
66 // Writes the spec to the database.
67 _Tt_db_results write ();
69 // Refreshes the properties in memory with whatever is currently out
71 _Tt_db_results refresh ();
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);
78 // Copys the object spec to the new file
79 _Tt_string copy (const _Tt_string &new_file);
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);
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
92 _Tt_db_results setProperty (const _Tt_db_property_ptr &property);
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);
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
106 _Tt_db_results addProperty (const _Tt_db_property_ptr &property,
107 bool_t unique=FALSE);
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
113 _Tt_db_results deleteProperty (const _Tt_db_property_ptr &property);
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);
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 ();
124 // Sets and gets the otype of the specified object.
125 _Tt_db_results setType (const _Tt_string &otype);
126 _Tt_string getType ();
128 // Gets the file of the object.
129 _Tt_string getFile ();
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 ();
135 // Returns the object ID of this object.
136 const _Tt_string& getObjectID () const
141 // Returns the key porition of this object's object ID.
142 _Tt_string getObjectKey () const;
144 // Gets the results of the last database operation made with this object.
145 _Tt_db_results getDBResults () const
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;
166 void setTtDBObjectDefaults ();
167 _Tt_db_results createMemoryObject (const _Tt_string&, const _Tt_string&);
168 void getDBObjectHostnameFromID ();
169 _Tt_db_results createDBObject ();
172 // Sets the internal object ID to a new ID and checks to see if the
173 // object is in the database.
175 _Tt_db_results setObjectID (const _Tt_string&);
177 _Tt_string makeEquivalentObjectID (const _Tt_string&,
179 bool_t isObjectInDatabase (bool_t force = FALSE);
180 _Tt_db_results internalRefresh ();
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.
189 _Tt_db_results processDBResults ();
191 void setCurrentDBAccess ()
193 if (!dbObjectDatabase.is_null()) {
194 dbObjectDatabase->setCurrentAccess(dbObjectCurrentAccess);
199 #endif // _TT_DB_OBJECT_H