00001 00002 #ifndef oOrient_h 00003 #define oOrient_h 1 00004 //------------------------------------------------------------------------------ 00005 00006 #include "cTypes.h" 00007 #include "oSessionManager.h" 00008 #include "oObjectStreamCache.h" 00009 #include "oThread.h" 00010 #include "oLicense.h" 00011 00012 #include "oCurrMutex.h" 00013 //------------------------------------------------------------------------------ 00014 00015 /** 00016 * oOrient is the main class of the Orient ODBMS environment. 00017 * 00018 * ORIENT ENVIRONMENT: 00019 * Before to use Orient ODBMS the client application must initialize the Orient 00020 * ODBMS engine. 00021 * 00022 * In Windows® systems this operation is executed automatically at startup of 00023 * the application before the main() function, when the user client application 00024 * links the Orient ODBMS library. On application ending the library is 00025 * detached and the shutdown procedure of the Orient ODBMS environment is 00026 * called automatically. 00027 * 00028 * In other platforms the client application must explicitly initialize and 00029 * deinitialize the Orient environment before to use any Orient ODBMS APIs. 00030 * To initialize the Orient ODBMS environment the user application had to call 00031 * the oOrient::init() static method. When the application ends to use Orient 00032 * ODBMS can call the oOrient::deinit() static method to free Orient resources. 00033 * 00034 * The simpler method is defining a variable of type oOrient as first thing 00035 * inside the main() function. The oOrient constructor calls init() and the 00036 * destructor calls deinit(). In this way the Orient environment will be 00037 * initialized when the variable will be out-of-scope. 00038 * 00039 * For more information see the example below. 00040 * 00041 * CLIENT CACHE: 00042 * Each client application that use Orient has a local object cache. The 00043 * default size of the cache is of 512 objects. Is possible to modify the 00044 * client cache size calling oOrient::setCacheSize(). This permits a major 00045 * reuse of objects already loaded. 00046 * 00047 * MULTI-SESSION MANAGEMENT: 00048 * In the multi-thread version of Orient ODBMS client libraries are available 00049 * sessions to handle parallel multi-threads access to Orient ODBMS engine. 00050 * 00051 * oOrient is entry-point the class for Session management. 00052 * 00053 * USAGE: 00054 * oOrient orient_env; 00055 * 00056 * Where: 00057 * 00058 * <orient_env>: Is the name of variable of type oOrient. 00059 * 00060 * EXAMPLES: 00061 * int main( int argc, char* argv[] ) 00062 * { 00063 * * START THE ORIENT ENVIRONMENT (OPTIONAL IN WIN32 SYSTEMS) 00064 * * WHEN THE VARIABLE WILL BE OUT OF SCOPE THE ENVIRONMENT 00065 * * WILL BE DEINITIALIZED. 00066 * oOrient orient_env; 00067 * 00068 * ... 00069 * } 00070 * 00071 * ODMG: 00072 * Extension 00073 */ 00074 00075 class _ODLL oOrient 00076 { 00077 public: 00078 /** 00079 * Default constructor. 00080 * 00081 * Initializes the Orient ODBMS environment calling the init() method. 00082 */ 00083 oOrient (); 00084 00085 /** 00086 * Destructor. 00087 * 00088 * Deinitializes the Orient ODBMS environment calling the deinit() method. 00089 */ 00090 ~oOrient(); 00091 00092 /** 00093 * Initializes the Orient ODBMS environment. 00094 * 00095 * Must be called before to use any Orient ODBMS APIs. 00096 * 00097 * SEE ALSO: oOrient(), deinit() 00098 */ 00099 static void init (); 00100 00101 /** 00102 * Shutdowns Orient ODBMS environment. 00103 * 00104 * Must be called after the use of Orient ODBMS. It's useful to free 00105 * Orient ODBMS resources (local object cache, etc). 00106 * 00107 * SEE ALSO: ~oOrient(), init() 00108 */ 00109 static void deinit (); 00110 00111 /** 00112 * Check the status of Orient ODBMS engine. 00113 * 00114 * It returns true if the Orient ODBMS environment is initialized, 00115 * otherwise false. 00116 * 00117 * SEE ALSO: check_ready() 00118 */ 00119 static bool is_ready(); 00120 00121 /** 00122 * Check the status of Orient ODBMS engine. 00123 * 00124 * It throws a d_Error_OrientNotInit exception if the Orient ODBMS 00125 * environment is not yet initialized. 00126 * 00127 * SEE ALSO: is_ready() 00128 */ 00129 static void check_ready(); 00130 00131 /** 00132 * Sets the Local Client Cache size. 00133 * 00134 * Sets the Local Client Cache size to <iSize> objects. By default is 512. 00135 * This permits a major reuse of objects already loaded. 00136 * 00137 * The user application can change at run-time the cache size. 00138 * 00139 * SEE ALSO: getCacheSize(), d_Object::pin(), d_Object::unpin() 00140 */ 00141 static void setCacheSize (oUInt4 iSize); 00142 00143 /** 00144 * Returns the Local Client Cache size in objects. 00145 * 00146 * By default is equals to 512. 00147 * 00148 * SEE ALSO: setCacheSize(), d_Object::pin(), d_Object::unpin() 00149 */ 00150 static oUInt4 getCacheSize (); 00151 00152 /** 00153 * Set the cache policy for new objects created. By default is unpinned 00154 * that means that all objects will be created as unpinned. 00155 * 00156 * The user application can change at run-time the cache policy. 00157 * 00158 * SEE ALSO: getCachePolicy() 00159 */ 00160 static void setCachePolicy (const oObjectStreamCache::cachePolicies iPolicy); 00161 00162 /** 00163 * Get the current cache policy. By default is unpinned 00164 * 00165 * SEE ALSO: setCachePolicy() 00166 */ 00167 static oObjectStreamCache::cachePolicies getCachePolicy (); 00168 00169 /** 00170 * Creates a new session. 00171 * 00172 * Creates a new session called <iName>. This method creates a new thread 00173 * associated to the session. The thread starts at <iEntryPoint> function 00174 * passing <iArg> as argument. 00175 * 00176 * Optional flags can be specified for the new thread. Now are supported 00177 * these flags: 00178 * 00179 * flagDetached: create the thread as detached. In this the thread (and 00180 * therefore the session) cannot be waited. The benefits 00181 * of detached threads are that can be instanced much more 00182 * rather than "joinable" threads. 00183 * 00184 * This method returns the new session created. 00185 * 00186 * This method returns immediately after that the new session is created, 00187 * because the new session is executed asynchronously in a new thread. 00188 * 00189 * SEE ALSO: waitSessions () 00190 */ 00191 static oSession* createSession( d_String iName, oThread::tEntry iEntryPoint, oThread::tArgument iArg, oUInt2 iFlag = 0 ); 00192 00193 /** 00194 * Wait for one or more session to finish. 00195 * 00196 * Wait for one or more session called <iSessionName> to finish. 00197 * 00198 * If <iSessionName> is empty, then are waited all the session registered. 00199 * 00200 * If not specified any name, are waited all the sessions registered. 00201 * 00202 * SEE ALSO: createSession () 00203 */ 00204 static bool waitSessions( d_String iSessionName = "" ); 00205 00206 // Internal. 00207 static void setTransMaxObjs (oUInt4 iSize); 00208 // Internal. 00209 static oUInt4 getTransMaxObjs (); 00210 00211 static char getType( void ); 00212 00213 private: 00214 // Internal. 00215 static void registerSysTypes(); 00216 // Internal. 00217 static void registerSysClasses (); 00218 // Internal. 00219 //static void registerSysFactory(); 00220 00221 // INSTALL THE APPLICATION SIGNALS TO MAKE A "SOFT" SHUTDOWN AVOIDING LOSS 00222 // OF DATA 00223 static void installSignal( void ); 00224 00225 // CATCH AN APPLICATION SIGNAL TO MAKE A "SOFT" SHUTDOWN AVOIDING LOSS OF DATA 00226 static void catchSignal( int iSignal ); 00227 00228 // INTERNAL. 00229 static void checkLicense( void ); 00230 00231 // INTERNAL 00232 static oLicense::information license; 00233 00234 // Internal. 00235 static bool ready; 00236 00237 // Internal. 00238 static OCURRMUTEX _lock; 00239 00240 // FRIENDSHIPS 00241 friend class oSegment; 00242 friend class oSessionManager; 00243 }; 00244 //------------------------------------------------------------------------------ 00245 inline bool oOrient::is_ready() 00246 { 00247 return ready; 00248 } 00249 //------------------------------------------------------------------------------ 00250 inline void oOrient::check_ready() 00251 { 00252 if( !ready ) 00253 // ERROR: ORIENT ENVIRONMENT IS NOT YET INITIALIZED 00254 OERROR( d_Error_OrientNotInit, "" ) 00255 } 00256 //------------------------------------------------------------------------------ 00257 //------------------------------------------------------------------------------ 00258 00259 #endif 00260
1.3-rc1