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
00029
00030
00031
00038 #if !defined( _OESS_1__DB__STORAGE__CHAIN_STORAGE_HPP_ )
00039 #define _OESS_1__DB__STORAGE__CHAIN_STORAGE_HPP_
00040
00041 #include <memory>
00042
00043 #include <cpp_util_2/h/nocopy.hpp>
00044
00045 #include <oess_1/defs/h/types.hpp>
00046
00047 #include <oess_1/io/h/stream.hpp>
00048 #include <oess_1/io/h/mem_buf.hpp>
00049
00050 #include <oess_1/stdsn/h/ent_std.hpp>
00051
00052 #include <oess_1/db/h/declspec.hpp>
00053
00054 #include <oess_1/db/storage/h/chain_id.hpp>
00055 #include <oess_1/db/storage/h/config.hpp>
00056
00057 namespace oess_1 {
00058
00059 namespace db {
00060
00061 namespace storage {
00062
00063
00064
00065
00066
00075 const oess_1::uint_t no_chain_length_limit =
00076 static_cast< oess_1::uint_t >( -1 );
00077
00078
00079
00080
00081
00092 class OESS_1__DB__TYPE chain_storage_t
00093 : private cpp_util_2::nocopy_t
00094 {
00095 public :
00096 virtual ~chain_storage_t();
00097
00101
00105 virtual void
00106 trx_start() = 0;
00107
00109
00112 virtual void
00113 trx_commit() = 0;
00114
00116
00119 virtual void
00120 trx_rollback() = 0;
00122
00126
00129 virtual chain_id_t
00130 chain_create(
00132 oess_1::io::istream_t & from,
00134 oess_1::uint_t length ) = 0;
00135
00137 virtual void
00138 chain_destroy(
00140 const chain_id_t & chain ) = 0;
00141
00143
00148 virtual void
00149 chain_load(
00151 const chain_id_t & chain,
00153 oess_1::io::ostream_t & to,
00155 oess_1::uint_t max_length ) = 0;
00156
00158
00162 virtual void
00163 chain_update(
00165 const chain_id_t & chain,
00167 oess_1::io::istream_t & from,
00169 oess_1::uint_t length ) = 0;
00171 };
00172
00175
00176
00177
00178
00179
00195 OESS_1__DB__FUNC(std::auto_ptr< chain_storage_t >)
00196 create_chain_storage(
00198 const std::string & physic_name,
00200 const config_t & config,
00202 oess_1::io::istream_t & from,
00205 oess_1::uint_t length,
00207 chain_id_t & first_chain );
00208
00209
00210
00211
00212
00233 OESS_1__DB__FUNC(std::auto_ptr< chain_storage_t >)
00234 open_chain_storage(
00236 const std::string & physic_name,
00238 const config_t & config,
00240 bool is_read_only,
00242 bool is_auto_repair_enabled,
00244 oess_1::io::ostream_t & to,
00247 oess_1::uint_t length,
00249 chain_id_t & first_chain );
00250
00251
00252
00253
00254
00263 OESS_1__DB__FUNC(bool)
00264 is_chain_storage_exists(
00266 const std::string & physic_name );
00267
00268
00269
00270
00271
00279 OESS_1__DB__FUNC(void)
00280 destroy_chain_storage(
00282 const std::string & physic_name );
00283
00285
00290
00291 template< class T >
00292 chain_id_t
00293 create_in_storage(
00294 chain_storage_t & storage, const T & what )
00295 {
00296 oess_1::io::mem_buf_t stream;
00297 oess_1::stdsn::oent_std_t oent( stream );
00298 oent << what;
00299 stream.set_pos( 0 );
00300
00301 return storage.chain_create( stream, stream.size() );
00302 }
00303
00305 template< class T >
00306 void
00307 load_from_storage(
00308 chain_storage_t & storage,
00309 const chain_id_t & chain,
00310 T & what,
00311 oess_1::uint_t length = no_chain_length_limit )
00312 {
00313 oess_1::io::mem_buf_t stream;
00314 storage.chain_load( chain, stream, length );
00315
00316 stream.set_pos( 0 );
00317 oess_1::stdsn::ient_std_t ient( stream );
00318 ient >> what;
00319 }
00320
00322 template< class T >
00323 void
00324 update_in_storage(
00325 chain_storage_t & storage,
00326 const chain_id_t & chain,
00327 const T & what )
00328 {
00329 oess_1::io::mem_buf_t stream;
00330 oess_1::stdsn::oent_std_t oent( stream );
00331 oent << what;
00332 stream.set_pos( 0 );
00333
00334 return storage.chain_update( chain, stream, stream.size() );
00335 }
00336
00339 }
00340
00341 }
00342
00343 }
00344
00345 #endif
00346