88d5d7627a98c31fba2458086f1cc9ad4f2684cd
[platform/upstream/libzypp.git] / zypp / cache / CacheInitializer.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9
10 #ifndef ZYPP_CacheInitializer_H
11 #define ZYPP_CacheInitializer_H
12
13 #include <iosfwd>
14 #include <string>
15
16 #include "zypp/base/PtrTypes.h"
17 #include "zypp/base/ReferenceCounted.h"
18 #include "zypp/base/NonCopyable.h"
19 #include "zypp/Pathname.h"
20 #include "zypp/cache/sqlite3x/sqlite3x.hpp"
21
22 #define ZYPP_CACHE_SCHEMA_VERSION 1002
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27   ///////////////////////////////////////////////////////////////////
28   namespace cache
29   { /////////////////////////////////////////////////////////////////
30
31     ///////////////////////////////////////////////////////////////////
32     //
33     //  CLASS NAME : CacheInitializer
34     //
35     class CacheInitializer
36     {
37       friend std::ostream & operator<<( std::ostream & str, const CacheInitializer & obj );
38
39     public:
40       /**
41        * Tries to initialize the source cache if it was not
42        * \throws Exception When cant initialize
43        */
44       CacheInitializer( const Pathname &root_r, const Pathname &db_file );
45       virtual ~CacheInitializer();
46
47       /**
48        * \short Has the cache been reinitialized?
49        *
50        * only true when cache was not initialized before
51        * and was just initialized with success
52        */
53       bool justInitialized() const;
54       
55       /**
56        * \short Has the cache been reinitialized?
57        *
58        * This is true when the cache was already initialized
59        * but an old schema was detected, so the cache
60        * was reinitialized in order to get the new schema
61        */
62       bool justReinitialized() const;
63       
64     protected:
65       bool tablesCreated() const;
66                         void createTables();
67       /** Overload to realize stream output. */
68       virtual std::ostream & dumpOn( std::ostream & str ) const;
69     private:
70        /** Implementation. */
71       class Impl;
72       /** Pointer to implementation. */
73       RW_pointer<Impl> _pimpl;
74     };
75     ///////////////////////////////////////////////////////////////////
76
77     /** \relates CacheInitializer Stream output */
78     inline std::ostream & operator<<( std::ostream & str, const CacheInitializer & obj )
79     { return obj.dumpOn( str ); }
80
81
82     /////////////////////////////////////////////////////////////////
83   } // namespace cache
84   ///////////////////////////////////////////////////////////////////
85   /////////////////////////////////////////////////////////////////
86 } // namespace zypp
87 ///////////////////////////////////////////////////////////////////
88 #endif // ZYPP_SOURCE_CacheInitializer_H