00001 /* 00002 00003 Copyright (c) 2002-2005, Yauheni Akhotnikau 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are met: 00008 00009 - Redistributions of source code must retain the above copyright notice, this 00010 list of conditions and the following disclaimer. 00011 00012 - Redistributions in binary form must reproduce the above copyright notice, this 00013 list of conditions and the following disclaimer in the documentation and/or 00014 other materials provided with the distribution. 00015 00016 - The name of the author may not be used to endorse or promote products derived 00017 from this software without specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00020 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00021 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 00022 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00024 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00026 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00027 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00028 OF SUCH DAMAGE. 00029 00030 */ 00031 00036 #if !defined( _OESS_1__DB__STORAGE__IMPL__STD_STREAM_STORAGE_HPP_ ) 00037 #define _OESS_1__DB__STORAGE__IMPL__STD_STREAM_STORAGE_HPP_ 00038 00039 #include <map> 00040 00041 #include <auto_ptr_3/h/obj_ptr.hpp> 00042 00043 #include <oess_1/db/storage/h/chain_storage.hpp> 00044 #include <oess_1/db/storage/h/stream_storage.hpp> 00045 00046 #include <oess_1/db/storage/impl/h/stream_storage_dir.hpp> 00047 00048 namespace oess_1 { 00049 00050 namespace db { 00051 00052 namespace storage { 00053 00054 namespace impl { 00055 00056 /* 00057 ** std_stream_storage_t 00058 */ 00059 00063 class std_stream_storage_t 00064 : public stream_storage_t 00065 { 00066 public : 00068 std_stream_storage_t( 00071 const std::string & physic_name, 00076 std::auto_ptr< chain_storage_t > storage, 00078 const chain_id_t & meta_info_id, 00080 oess_1::io::istream_t & meta_info_stream ); 00081 virtual ~std_stream_storage_t(); 00082 00085 virtual void 00086 trans_start(); 00087 00088 virtual void 00089 trans_commit(); 00090 00091 virtual void 00092 trans_rollback(); 00093 00094 virtual void 00095 stream_create( 00096 const std::string & name ); 00097 00098 virtual bool 00099 stream_is_exists( 00100 const std::string & name ) const; 00101 00102 virtual void 00103 stream_destroy( 00104 const std::string & name ); 00105 00106 virtual std::set< std::string > 00107 stream_names() const; 00108 00109 virtual entity_stream_t & 00110 stream_get( 00111 const std::string & name ); 00112 00113 virtual entity_stream_t & 00114 stream_get( 00115 const oess_1::uint_t & id ); 00116 00117 virtual chain_storage_t & 00118 chain_storage(); 00120 00121 private : 00124 const std::string m_physic_name; 00125 00127 std::auto_ptr< chain_storage_t > m_storage; 00128 00130 chain_id_t m_meta_info_id; 00131 00133 stream_storage_dir_t m_dir; 00134 00136 bool m_is_ok; 00137 00139 typedef std::map< oess_1::uint_t, ref_entity_stream_t > 00140 entity_stream_map_t; 00141 00143 entity_stream_map_t m_streams; 00144 00147 void 00148 lo_stream_create( 00149 const std::string & name ); 00150 00151 void 00152 lo_stream_destroy( 00153 const std::string & name ); 00154 00155 entity_stream_t & 00156 lo_stream_get( 00157 const oess_1::uint_t & id ); 00159 00161 00164 void 00165 ensure_all_right() const; 00166 00169 00173 void 00174 parse_meta_info( 00177 oess_1::io::istream_t & meta_info_stream ); 00178 00181 void 00182 create_entity_stream_objects(); 00183 00186 void 00187 reload_meta_info_on_rollback(); 00188 00190 void 00191 save_meta_info(); 00192 }; 00193 00194 } /* namespace impl */ 00195 00196 } /* namespace storage */ 00197 00198 } /* namespace db */ 00199 00200 } /* namespace oess_1 */ 00201 00202 #endif