00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _terimber_varobj_h_
00029 #define _terimber_varobj_h_
00030
00031 #include "smart/varvalue.h"
00032 #include "base/vector.h"
00033 #include "base/list.h"
00034 #include "base/stack.h"
00035 #include "base/map.h"
00036 #include "base/memory.h"
00037 #include "smart/byterep.h"
00038 #include "smart/varmap.h"
00039 #include "xml/xmlaccss.h"
00040 #include "fuzzy/fuzzyaccess.h"
00041
00042 BEGIN_TERIMBER_NAMESPACE
00043 #pragma pack(4)
00044
00047 class var_property_schema
00048 {
00049 public:
00050 vt_types _type;
00051 const char* _name;
00052 bool _is_searchable;
00053 bool _is_fuzzy_match;
00054 };
00055
00058 typedef _list< size_t > list_returns_index_t;
00059
00062 class pk_column
00063 {
00064 public:
00066 pk_column( size_t pk,
00067 size_t col
00068 ) :
00069 _pk(pk),
00070 _col(col)
00071 {
00072 }
00073
00075 inline
00076 bool
00077 operator<(const pk_column& x) const
00078 {
00079
00080 return _col != x._col ? _col < x._col : _pk < x._pk;
00081 }
00083 inline
00084 bool
00085 operator==(const pk_column& x) const
00086 {
00087 return _col == x._col && _pk == x._pk;
00088 }
00089
00090 size_t _pk;
00091 size_t _col;
00092 };
00093
00096 class var_container
00097 {
00098 public:
00101
00102 typedef byte_allocator sorted_container_allocator_t;
00105 typedef _map< size_t, bool, sorted_container_allocator_t > sorted_container_data_t;
00106
00107
00108 public:
00110 var_container( sorted_container_allocator_t& all
00111 ) :
00112 _allocator(all)
00113 {
00114 }
00115
00117 void
00118 intersect( const var_container& x
00119 );
00121 void
00122 combine( const var_container& x
00123 );
00125 static
00126 inline
00127 size_t
00128 clean_key( const pk_column& x
00129 )
00130 {
00131 return x._pk;
00132 }
00133
00135 static
00136 inline
00137 pk_column
00138 compound_key( size_t x,
00139 const pk_column& c
00140 )
00141 {
00142 return pk_column(x, c._col);
00143 }
00144
00145
00146 sorted_container_allocator_t& _allocator;
00147 sorted_container_data_t _container;
00148 };
00149
00152 typedef varmap< pk_column, var_container > var_object_map_t;
00155 typedef _vector< var_property_schema > var_object_schema;
00158 typedef _vector< var_value > var_object_values;
00159
00162 typedef _list< pk_column > var_unique_key_t;
00163
00166 class var_object_repository
00167 {
00168 public:
00171 typedef array_allocator< var_object_map_t::mainmap_iter_t > iter_vec_allocator_t;
00174 typedef _vector< var_object_map_t::mainmap_iter_t, iter_vec_allocator_t > iter_vector_t;
00177 typedef node_allocator< _map< size_t, iter_vector_t >::_node > object_map_allocator_t;
00180 typedef _map< size_t, iter_vector_t, object_map_allocator_t > object_map_data_t;
00181
00183 var_object_repository(const var_object_repository& x);
00185 var_object_repository& operator=(const var_object_repository& x);
00186
00187 public:
00189 var_object_repository(const var_object_schema& schema
00190 );
00192 ~var_object_repository();
00193
00195 void
00196 reset();
00197
00199 size_t
00200 count() const;
00201
00203 bool
00204 process_query( xml_designer* parser,
00205 var_container::sorted_container_allocator_t& all,
00206 byte_allocator& tmp,
00207 byte_allocator& inl
00208 );
00209
00210
00211
00212
00215 bool
00216 select_object(size_t pk,
00217 var_object_values& row,
00218 byte_allocator& tmp
00219 ) const;
00220
00223 bool
00224 select_object(const var_object_values& key,
00225 var_object_values& row,
00226 byte_allocator& tmp,
00227 var_container::sorted_container_allocator_t& conall,
00228 size_t& pk
00229 ) const;
00230
00234 size_t
00235 insert_object( const var_object_values& values,
00236 byte_allocator& tmp,
00237 byte_allocator& inl,
00238 string_t& err
00239 );
00240
00242 bool
00243 delete_object( size_t pk,
00244 byte_allocator& tmp,
00245 string_t& err
00246 );
00247
00249 bool
00250 delete_object( const var_object_values& key,
00251 byte_allocator& tmp,
00252 byte_allocator& inl,
00253 string_t& err
00254 );
00255
00257 bool
00258 update_object( size_t pk,
00259 const var_object_values& values,
00260 byte_allocator& tmp,
00261 byte_allocator& inl,
00262 string_t& err
00263 );
00264
00266 bool
00267 find_by_conditions( const xml_designer* parser,
00268 var_container& container,
00269 byte_allocator& tmp,
00270 byte_allocator& inl,
00271 string_t& err
00272 ) const;
00273
00275 bool
00276 find_by_condition( const xml_designer* parser,
00277 var_container& container,
00278 byte_allocator& tmp,
00279 byte_allocator& inl,
00280 string_t& err
00281 ) const;
00282
00284 bool
00285 find_by_row( const var_object_values& values,
00286 var_container& container,
00287 byte_allocator& tmp
00288 ) const;
00289
00290 private:
00292 vt_types
00293 cast_to_common_type(vt_types type,
00294 const var_value& in,
00295 var_value& out,
00296 byte_allocator& tmp
00297 ) const;
00299 vt_types
00300 map_type( vt_types type
00301 ) const;
00302
00304 bool
00305 process_returns(const xml_designer* parser,
00306 list_returns_index_t& container,
00307 byte_allocator& tmp,
00308 byte_allocator& inl,
00309 string_t& err
00310 ) const;
00312 bool
00313 process_values( const xml_designer* parser,
00314 var_object_values& container,
00315 byte_allocator& tmp,
00316 byte_allocator& inl,
00317 string_t& err
00318 ) const;
00320 bool
00321 process_where( const xml_designer* parser,
00322 var_container& container,
00323 byte_allocator& tmp,
00324 byte_allocator& inl,
00325 string_t& err
00326 ) const;
00328 bool
00329 process_condition(const xml_designer* parser,
00330 var_container& container,
00331 bool intersect,
00332 byte_allocator& tmp,
00333 byte_allocator& inl,
00334 string_t& err
00335 ) const;
00337 bool
00338 process_group( const xml_designer* parser,
00339 var_container& container,
00340 bool intersect,
00341 byte_allocator& tmp,
00342 byte_allocator& inl,
00343 string_t& err
00344 ) const;
00345
00347 bool
00348 process_error( xml_designer* parser,
00349 const char* err
00350 ) const;
00351
00353 const var_object_map_t*
00354 get_v_object_pointer(vt_types type,
00355 bool searchable
00356 ) const;
00357
00359 var_object_map_t*
00360 get_v_object_pointer(vt_types type,
00361 bool searchable
00362 );
00363
00364 private:
00365 const var_object_schema& _schema;
00366 unique_key_generator _key_generator;
00367 variant_factory _var_factory;
00368 var_object_map_t _uint32_type_map;
00369 var_object_map_t _double_type_map;
00370 var_object_map_t _uint64_type_map;
00371 var_object_map_t _string_type_map;
00372 var_object_map_t _searchable_string_type_map;
00373 var_object_map_t _fuzzy_string_type_map;
00374 var_object_map_t _numeric_type_map;
00375 var_object_map_t _binary_type_map;
00376 var_object_map_t _guid_type_map;
00377 object_map_allocator_t _objs_all;
00378 iter_vec_allocator_t _iter_vec_all;
00379 object_map_data_t _objs_map;
00380 fuzzy_matcher* _fuzzy_engine;
00381 };
00382
00383 #pragma pack()
00384 END_TERIMBER_NAMESPACE
00385
00386 #endif