00001 //------------------------------------------------------------------------------ 00002 #ifndef d_Extent_h 00003 #define d_Extent_h 1 00004 00005 //------------------------------------------------------------------------------ 00006 #include "d_Iterator.h" 00007 00008 //------------------------------------------------------------------------------ 00009 template <class T> class _ODLL d_Varray; 00010 template <class T> class _ODLL d_Ref; 00011 class oRefSeg; 00012 class _ODLL d_Database; 00013 class _ODLL oStorage; 00014 class _ODLL oQueryEngine; 00015 //------------------------------------------------------------------------------ 00016 00017 /** 00018 * The class Extent is a virtual collection of all objects of a class updated 00019 * automatically by the Orient engine. 00020 * 00021 * QUERIES: 00022 * Making a query on an Extent means to query all the objects of a class. 00023 * 00024 * LOCATION: 00025 * d_Extent.h 00026 * 00027 * USAGE: 00028 * d_Extent< <pers-class-name> > <variable-name>; 00029 * 00030 * Where: 00031 * 00032 * <pers-class-name>: persistent class to use 00033 * <variable-name>: is the name of d_Extent object 00034 * 00035 * EXAMPLES: 00036 * d_Ref<Customer> objCustomer; 00037 * d_Iterator< d_Ref<Customer> > itCustomer; 00038 * d_Extent<Customer> customers( &db ); 00039 * 00040 * itCustomer = customers.select( "Customer.code = 1" ); 00041 * 00042 * while( itCustomer.next( objCustomer ) ) 00043 * { 00044 * * DISPLAY OBJECT 00045 * printf( "\nCode......: %d", objCustomer->code ); 00046 * printf( "\nName......: %s", objCustomer->name.c_str() ); 00047 * printf( "\nSurname...: %s", objCustomer->surname.c_str() ); 00048 * printf( "\nAge.......: %d", objCustomer->age ); 00049 * printf( "\nNotes.....: %s", objCustomer->notes.c_str() ); 00050 * } 00051 * 00052 * SEE ALSO: 00053 * d_Iterator 00054 * 00055 * ODMG: 00056 * Compliant 00057 */ 00058 00059 template <class T> 00060 class _ODLL d_Extent 00061 { 00062 public: 00063 00064 /** 00065 * Create an d_Extent object. 00066 * 00067 * Creates an extent for class specified as template argument (<> bracets) 00068 * of database <iDb>. Parameter <iSubClasses> is not used but available 00069 * for ODMG compatibility. 00070 * 00071 * ODMG : Compliant 00072 */ 00073 d_Extent (const d_Database* iDb, d_Boolean iSubClasses = d_True); 00074 00075 /** 00076 * Destructor. 00077 * 00078 * ODMG : Compliant 00079 */ 00080 ~d_Extent(); 00081 00082 00083 /** 00084 * Returns total number of object in the extent. 00085 * 00086 * This is equal to the total of objects present in the database for that 00087 * class. 00088 * 00089 * ODMG : Compliant 00090 */ 00091 unsigned long cardinality () const; 00092 00093 /** 00094 * Returns true if the extent doesn't contain objects. 00095 * 00096 * ODMG : Compliant 00097 */ 00098 d_Boolean is_empty () const; 00099 00100 /** 00101 * Returns always false. It's maintained for compatibility with collection 00102 * classes. 00103 * 00104 * ODMG : Compliant 00105 */ 00106 d_Boolean allows_duplicates () const; 00107 00108 /** 00109 * Returns always false. It's maintained for compatibility with collection 00110 * classes. 00111 * 00112 * ODMG : Compliant 00113 */ 00114 d_Boolean is_ordered () const; 00115 00116 /** 00117 * Creates an iterator that points to the first element of extent and 00118 * returns it. 00119 * 00120 * SEE ALSO: d_Iterator, begin() 00121 * ODMG : Compliant 00122 */ 00123 d_Iterator< d_Ref<T> > create_iterator (); 00124 00125 /** 00126 * Creates an iterator that points to the first element of extent and 00127 * returns it. 00128 * 00129 * It works like create_iterator() member and is maintained for 00130 * compatibility with C++ STL containers. 00131 * 00132 * SEE ALSO: d_Iterator, create_iterator() 00133 * ODMG : Compliant 00134 */ 00135 d_Iterator< d_Ref<T> > begin (); 00136 00137 /** 00138 * Creates an iterator that points to the last element of extent and 00139 * returns it. 00140 * 00141 * Is maintained for compatibility with C++ STL containers. 00142 * 00143 * SEE ALSO: d_Iterator, begin() 00144 * ODMG : Compliant 00145 */ 00146 d_Iterator< d_Ref<T> > end (); 00147 00148 /** 00149 * Makes a query on the extent. 00150 * 00151 * <iTextQuery> is the text of query to execute. It returns a reference 00152 * to the object that matches the query predicate. 00153 * 00154 * If more than one object matches the query, then only the first one 00155 * object scanned is returned. 00156 * 00157 * For best performance use this method instead of general select() 00158 * method when the field of research is unique and doesn't contain 00159 * duplicates. In this way the research will stop after the first, 00160 * and unique, match. 00161 * 00162 * SEE ALSO: d_Ref, select() 00163 * ODMG : Compliant 00164 */ 00165 d_Ref<T> select_element (const char* iTextQuery) const; 00166 00167 /** 00168 * Makes a query on the extent. 00169 * 00170 * <iTextQuery> is the text of query to execute. 00171 * 00172 * It returns an iterator that point to the first object that matches 00173 * the query predicate. To browse the result set use d_Iterator object. 00174 * 00175 * SEE ALSO: d_Iterator, d_Ref, select_element() 00176 * ODMG : Compliant 00177 */ 00178 d_Iterator< d_Ref<T> > select (const char* iTextQuery); 00179 00180 /** 00181 * Delete objects that satisfy query predicate. 00182 * 00183 * <iTextQuery> is the text of query to execute. 00184 * 00185 * SEE ALSO: select() 00186 * ODMG : Extension 00187 */ 00188 void deleteObjects (const char* iTextQuery); 00189 00190 /** 00191 * Counts the number of objects that matches the query predicate. 00192 * 00193 * SEE ALSO: select(), cardinality() 00194 * ODMG : Compliant 00195 */ 00196 unsigned long count (const char* iTextQuery); 00197 00198 /** 00199 * 00200 * SEE ALSO: d_Iterator, d_Ref, select_element() 00201 * ODMG : Compliant 00202 */ 00203 int query (d_Collection<d_Ref<T> >& iColl, const char* iTextQuery) const; 00204 00205 /** 00206 * Returns true if there is at least one object that matches the query 00207 * predicate. 00208 * 00209 * SEE ALSO: select_element(), select() 00210 * ODMG : Compliant 00211 */ 00212 d_Boolean exists_element (const char* iTextQuery) const; 00213 00214 /** 00215 * Set query language engine. This allow the user to change the language 00216 * for query at run-time just calling this method. 00217 * 00218 * Query engine must be previously registered in the oQueryEngineManager 00219 * object taken by oQueryEngineManager::getInstance() method. 00220 * 00221 * SEE ALSO: oQueryEngineManager 00222 * ODMG : Extension 00223 */ 00224 void setQueryEngine( const char* iQueryEngineName ); 00225 00226 00227 protected: 00228 // Avoid copy constructor. 00229 d_Extent (const d_Extent<T>& iSource); 00230 // Avoid copy assignment. 00231 d_Extent<T>& operator = (const d_Extent<T>& iSource); 00232 00233 private: 00234 // Internal. 00235 oQueryEngine* queryEngine; 00236 // Internal. 00237 oStorage* storage; 00238 // Internal. 00239 oClass* refClass; 00240 // Internal. 00241 d_Varray< d_Ref<T> > result; 00242 // Internal. 00243 d_Boolean subClasses; 00244 // Internal. 00245 bool queryExecuted; 00246 }; 00247 //------------------------------------------------------------------------------ 00248 template <class T> 00249 inline d_Boolean d_Extent<T>::is_empty () const 00250 { 00251 return ( cardinality() ? false : true ); 00252 } 00253 //------------------------------------------------------------------------------ 00254 template <class T> 00255 inline d_Boolean d_Extent<T>::allows_duplicates () const 00256 { 00257 return false; 00258 } 00259 //------------------------------------------------------------------------------ 00260 template <class T> 00261 inline d_Boolean d_Extent<T>::is_ordered () const 00262 { 00263 return false; 00264 } 00265 //------------------------------------------------------------------------------ 00266 #include "d_Extent.cti" 00267 //------------------------------------------------------------------------------ 00268 //------------------------------------------------------------------------------ 00269 00270 #endif 00271
1.3-rc1