- Don't use enums for values anymore. The values are dynamic in the
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 11 May 2007 16:15:29 +0000 (16:15 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 11 May 2007 16:15:29 +0000 (16:15 +0000)
  database.
- Port CachedSource to ths change
- Start implementing the text attributes in the database

tests/cache/CacheStore_test.cc
tests/cache/SimplePackagesParser.cc
zypp2/cache/CacheStore.cpp
zypp2/cache/CacheStore.h
zypp2/cache/schema/schema.sql
zypp2/repository/cached/CachedRepositoryImpl.cc
zypp2/repository/cached/CachedRepositoryImpl.h

index 47ff05d..a7035c3 100644 (file)
@@ -14,6 +14,7 @@
 #include "zypp/capability/CapabilityImpl.h"
 #include "zypp/data/ResolvableData.h"
 #include "zypp2/cache/CacheStore.h"
+#include "zypp2/repository/cached/CachedRepositoryImpl.h"
 #include "zypp/Url.h"
 #include "zypp/NVRA.h"
 #include "zypp/PathInfo.h"
 
 using namespace std;
 using namespace zypp;
+using namespace zypp::repository;
+using namespace zypp::repository::cached;
 using namespace boost::unit_test;
 
 void cache_write_test(const string &dir)
 {
-  Pathname nvra_list = Pathname(dir) + "package-set.txt.gz";
-  list<MiniResolvable> res_list;
-  
-  parse_mini_file( nvra_list, res_list );
-  
   filesystem::TmpDir tmpdir;
-  cache::CacheStore store(tmpdir.path());
-  
-  data::RecordId catalog_id = store.lookupOrAppendCatalog( Url("http://novell.com"), "/");
-  
-  zypp::debug::Measure cap_parse_timer("store resolvables");
-  for ( list<MiniResolvable>::iterator it = res_list.begin(); it != res_list.end(); it++)
   {
-    data::RecordId id = store.appendResolvable( catalog_id,
-                                       ResTraits<Package>::kind,
-                                       (*it).nvra,
-                                       (*it).deps );
+    Pathname nvra_list = Pathname(dir) + "package-set.txt.gz";
+    list<MiniResolvable> res_list;
+    
+    parse_mini_file( nvra_list, res_list );
+    
+    cache::CacheStore store(tmpdir.path());
+    
+    data::RecordId catalog_id = store.lookupOrAppendCatalog( Url("http://novell.com"), "/");
+    
+    zypp::debug::Measure cap_parse_timer("store resolvables");
+    for ( list<MiniResolvable>::iterator it = res_list.begin(); it != res_list.end(); it++)
+    {
+      data::RecordId id = store.appendResolvable( catalog_id,
+                                        ResTraits<Package>::kind,
+                                        (*it).nvra,
+                                        (*it).deps );
+    }
+  }
+  {
+    MIL << "now read resolvables" << endl;
+    
+    CachedRepositoryImpl *repositoryImpl = new CachedRepositoryImpl(tmpdir.path());
+    //RepositoryFactory factory;
+    //Repository_Ref repository = factory.createFrom(repositoryImpl);
+    repositoryImpl->createResolvables();
+    ResStore dbres = repositoryImpl->resolvables();
+        
+    MIL << dbres.size() << " resolvables" << endl;
   }
 }
 
index bf223b6..1e20de6 100644 (file)
@@ -39,7 +39,7 @@ static void read_deps( ifgzstream &ifs, data::DependencyList &list, int &line, c
     {
       capability::CapabilityImpl::Ptr cap = capability::parse( ResTraits<Package>::kind, buffer);
       if (cap)
-        list.push_back(cap);
+        list.insert(cap);
     }
     catch( const Exception  &e )
     {
index 44be993..17b8f26 100644 (file)
@@ -58,6 +58,9 @@ struct CacheStore::Impl
   sqlite3_command_ptr select_file_cmd;
   sqlite3_command_ptr insert_file_cmd;
 
+  sqlite3_command_ptr select_type_cmd;
+  sqlite3_command_ptr insert_type_cmd;
+  
   //sqlite3_command_ptr insert_dependency_entry_cmd;
 
   sqlite3_command_ptr append_file_dependency_cmd;
@@ -69,6 +72,7 @@ struct CacheStore::Impl
   sqlite3_command_ptr append_resolvable_cmd;
 
   map<string, data::RecordId> name_cache;
+  map< pair<string,string>, data::RecordId> type_cache;
   int name_cache_hits;
 };
 
@@ -113,6 +117,10 @@ CacheStore::CacheStore( const Pathname &dbdir )
   _pimpl->select_file_cmd.reset( new sqlite3_command( _pimpl->con, "select id from files where dir_name_id=:dir_name_id and file_name_id=:file_name_id;" ));
   _pimpl->insert_file_cmd.reset( new sqlite3_command( _pimpl->con, "insert into files (dir_name_id,file_name_id) values (:dir_name_id,:file_name_id);" ));
 
+  _pimpl->select_type_cmd.reset( new sqlite3_command( _pimpl->con, "select id from types where class=:class and name=:name;" ));
+  _pimpl->insert_type_cmd.reset( new sqlite3_command( _pimpl->con, "insert into types (class,name) values (:class,:name);" ));
+
+  
   //_pimpl->insert_dependency_entry_cmd.reset( new sqlite3_command( _pimpl->con, "insert into capabilities ( resolvable_id, dependency_type, refers_kind ) values ( :resolvable_id, :dependency_type, :refers_kind );" ));
   _pimpl->append_file_dependency_cmd.reset( new sqlite3_command( _pimpl->con, "insert into file_capabilities ( resolvable_id, dependency_type, refers_kind, file_id ) values ( :resolvable_id, :dependency_type, :refers_kind, :file_id );" ));
   _pimpl->append_named_dependency_cmd.reset( new sqlite3_command( _pimpl->con, "insert into named_capabilities ( resolvable_id, dependency_type, refers_kind, name_id, version, release, epoch, relation ) values ( :resolvable_id, :dependency_type, :refers_kind, :name_id, :version, :release, :epoch, :relation );" ));
@@ -154,8 +162,8 @@ data::RecordId CacheStore::appendResolvable( const data::RecordId &catalog_id,
   _pimpl->append_resolvable_cmd->bind( ":version", nvra.edition.version() );
   _pimpl->append_resolvable_cmd->bind( ":release", nvra.edition.release() );
   _pimpl->append_resolvable_cmd->bind( ":epoch", static_cast<int>( nvra.edition.epoch() ) );
-  _pimpl->append_resolvable_cmd->bind( ":arch", zypp_arch2db_arch(nvra.arch) );
-  _pimpl->append_resolvable_cmd->bind( ":kind", zypp_kind2db_kind(kind) );
+  _pimpl->append_resolvable_cmd->bind( ":arch", lookupOrAppendType("arch", nvra.arch.asString()) );
+  _pimpl->append_resolvable_cmd->bind( ":kind", lookupOrAppendType("kind", kind.asString()) );
   _pimpl->append_resolvable_cmd->bind( ":catalog_id", catalog_id );
 
   _pimpl->append_resolvable_cmd->executenonquery();
@@ -255,15 +263,15 @@ void CacheStore::appendNamedDependency( const data::RecordId &resolvable_id, zyp
   data::RecordId name_id = lookupOrAppendName(cap->name());
 
   _pimpl->append_named_dependency_cmd->bind( ":resolvable_id", resolvable_id );
-  _pimpl->append_named_dependency_cmd->bind( ":dependency_type", zypp_deptype2db_deptype(deptype) );
-  _pimpl->append_named_dependency_cmd->bind( ":refers_kind", zypp_kind2db_kind(cap->refers()) );
+  _pimpl->append_named_dependency_cmd->bind( ":dependency_type", lookupOrAppendType("deptype", deptype.asString()) );
+  _pimpl->append_named_dependency_cmd->bind( ":refers_kind", lookupOrAppendType("kind", cap->refers().asString()) );
 
   //_pimpl->append_named_dependency_cmd->bind( ":capability_id", capability_id);
   _pimpl->append_named_dependency_cmd->bind( ":name_id", name_id);
   _pimpl->append_named_dependency_cmd->bind( ":version", cap->edition().version() );
   _pimpl->append_named_dependency_cmd->bind( ":release", cap->edition().release() );
   _pimpl->append_named_dependency_cmd->bind( ":epoch", static_cast<int>( cap->edition().epoch() ) );
-  _pimpl->append_named_dependency_cmd->bind( ":relation", zypp_rel2db_rel( cap->op() ) );
+  _pimpl->append_named_dependency_cmd->bind( ":relation", lookupOrAppendType("rel", cap->op().asString()) );
   _pimpl->append_named_dependency_cmd->executenonquery();
 
   //delete cmd;
@@ -277,13 +285,13 @@ void CacheStore::appendModaliasDependency( const data::RecordId &resolvable_id,
     ZYPP_THROW(Exception("Null modalias capability"));
 
   _pimpl->append_modalias_dependency_cmd->bind( ":resolvable_id", resolvable_id );
-  _pimpl->append_modalias_dependency_cmd->bind( ":dependency_type", zypp_deptype2db_deptype(deptype) );
-  _pimpl->append_modalias_dependency_cmd->bind( ":refers_kind", zypp_kind2db_kind(cap->refers()) );
+  _pimpl->append_modalias_dependency_cmd->bind( ":dependency_type", lookupOrAppendType("deptype", deptype.asString()) );
+  _pimpl->append_modalias_dependency_cmd->bind( ":refers_kind", lookupOrAppendType("kind", cap->refers().asString()) );
 
   //_pimpl->append_modalias_dependency_cmd->bind( ":capability_id", capability_id);
   _pimpl->append_modalias_dependency_cmd->bind( ":name", cap->name());
   _pimpl->append_modalias_dependency_cmd->bind( ":value", cap->value());
-  _pimpl->append_modalias_dependency_cmd->bind( ":relation", zypp_rel2db_rel( cap->op() ) );
+  _pimpl->append_modalias_dependency_cmd->bind( ":relation", lookupOrAppendType("rel", cap->op().asString()) );
 
   _pimpl->append_modalias_dependency_cmd->executenonquery();
   //delete cmd;
@@ -297,13 +305,13 @@ void CacheStore::appendHalDependency( const data::RecordId &resolvable_id,
     ZYPP_THROW(Exception("Null HAL capability"));
 
   _pimpl->append_hal_dependency_cmd->bind( ":resolvable_id", resolvable_id );
-  _pimpl->append_hal_dependency_cmd->bind( ":dependency_type", zypp_deptype2db_deptype(deptype) );
-  _pimpl->append_hal_dependency_cmd->bind( ":refers_kind", zypp_kind2db_kind(cap->refers()) );
+  _pimpl->append_hal_dependency_cmd->bind( ":dependency_type", lookupOrAppendType("deptype", deptype.asString()) );
+  _pimpl->append_hal_dependency_cmd->bind( ":refers_kind", lookupOrAppendType("kind", cap->refers().asString()) );
 
   //_pimpl->append_hal_dependency_cmd->bind( ":capability_id", capability_id);
   _pimpl->append_hal_dependency_cmd->bind( ":name", cap->name());
   _pimpl->append_hal_dependency_cmd->bind( ":value", cap->value());
-  _pimpl->append_hal_dependency_cmd->bind( ":relation", zypp_rel2db_rel( cap->op() ) );
+  _pimpl->append_hal_dependency_cmd->bind( ":relation", lookupOrAppendType("rel", cap->op().asString()) );
 
   _pimpl->append_hal_dependency_cmd->executenonquery();
   //delete cmd;
@@ -319,8 +327,8 @@ void CacheStore::appendFileDependency( const data::RecordId &resolvable_id, zypp
   data::RecordId file_id = lookupOrAppendFile(cap->filename());
 
   _pimpl->append_file_dependency_cmd->bind( ":resolvable_id", resolvable_id );
-  _pimpl->append_file_dependency_cmd->bind( ":dependency_type", zypp_deptype2db_deptype(deptype) );
-  _pimpl->append_file_dependency_cmd->bind( ":refers_kind", zypp_kind2db_kind(cap->refers()) );
+  _pimpl->append_file_dependency_cmd->bind( ":dependency_type", lookupOrAppendType("deptype", deptype.asString()) );
+  _pimpl->append_file_dependency_cmd->bind( ":refers_kind", lookupOrAppendType("kind", cap->refers().asString()) );
 
   //_pimpl->append_file_dependency_cmd->bind( ":capability_id", capability_id);
   _pimpl->append_file_dependency_cmd->bind( ":file_id", file_id);
@@ -337,8 +345,8 @@ void CacheStore::appendUnknownDependency( const data::RecordId &resolvable_id,
     ZYPP_THROW(Exception("Null unknown capability"));
 
   _pimpl->append_other_dependency_cmd->bind( ":resolvable_id", resolvable_id );
-  _pimpl->append_other_dependency_cmd->bind( ":dependency_type", zypp_deptype2db_deptype(deptype) );
-  _pimpl->append_other_dependency_cmd->bind( ":refers_kind", zypp_kind2db_kind(cap->refers()) );
+  _pimpl->append_other_dependency_cmd->bind( ":dependency_type", lookupOrAppendType("deptype", deptype.asString()) );
+  _pimpl->append_other_dependency_cmd->bind( ":refers_kind", lookupOrAppendType("kind", cap->refers().asString()) );
   _pimpl->append_other_dependency_cmd->bind( ":value", cap->encode());
 
   _pimpl->append_hal_dependency_cmd->executenonquery();
@@ -423,6 +431,34 @@ data::RecordId CacheStore::lookupOrAppendCatalog( const Url &url, const Pathname
   return static_cast<data::RecordId>(id);
 }
 
+data::RecordId CacheStore::lookupOrAppendType( const string &klass, const string &name )
+{
+  pair<string, string> thetype = make_pair(klass,name);
+  if ( _pimpl->type_cache.find(thetype) != _pimpl->type_cache.end() )
+  {
+    //_pimpl->name_cache_hits++;
+    return _pimpl->type_cache[thetype];
+  }
+  
+  _pimpl->select_type_cmd->bind(":class", klass);
+  _pimpl->select_type_cmd->bind(":name", name);
+  long long id = 0;
+  try {
+    id = _pimpl->select_type_cmd->executeint64();
+    _pimpl->type_cache[thetype] = id;
+  }
+  catch ( const sqlite3x::database_error &e )
+  {
+    // does not exist
+    _pimpl->insert_type_cmd->bind(":class", klass);
+    _pimpl->insert_type_cmd->bind(":name", name);
+    _pimpl->insert_type_cmd->executenonquery();
+    id = _pimpl->con.insertid();
+    return id;
+  }
+  return id;
+}
+
 data::RecordId CacheStore::lookupOrAppendName( const std::string &name )
 {
   if ( _pimpl->name_cache.find(name) != _pimpl->name_cache.end() )
index e8298c7..2afee20 100644 (file)
@@ -228,7 +228,22 @@ namespace zypp
       void appendUnknownDependency( const data::RecordId &resolvable_id,
                                           zypp::Dep deptype,
                                           capability::CapabilityImpl::Ptr cap );
-
+      
+      /**
+       * Returns the record id of a type
+       *
+       * Types are mostly used internally. To give concepts
+       * a record id to associate with.
+       * Examples could be arch::i386, lang::en_US
+       * Packages::summary, rel:>, kind::Package
+       *
+       * \note If the type entry does not exist, it will
+       * be created and the new inserted entry's id will
+       * be returned.
+       */
+      data::RecordId lookupOrAppendType( const std::string &klass,
+                                         const std::string &name );
+      
       /**
        * Returns the record id of a catalog (Source) \a path
        *
index 2ff2955..6d1eb75 100644 (file)
@@ -69,6 +69,16 @@ CREATE TABLE db_info (
 );
 
 ------------------------------------------------
+-- Basic types like archs, attributes, languages
+------------------------------------------------
+
+CREATE TABLE types (
+    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
+  , class TEXT NOT NULL
+  , name TEXT NOT NULL
+);
+
+------------------------------------------------
 -- Knew catalogs. They existed some day.
 ------------------------------------------------
 
@@ -120,8 +130,8 @@ CREATE TABLE resolvables (
   , version TEXT
   , release TEXT
   , epoch INTEGER
-  , arch INTEGER
-  , kind INTEGER
+  , arch INTEGER REFERENCES types(id)
+  , kind INTEGER REFERENCES types(id)
   , catalog_id INTEGER REFERENCES catalogs(id)
   ,  installed_size INTEGER
   , archive_size INTEGER
@@ -131,33 +141,11 @@ CREATE TABLE resolvables (
 );
 
 -- Resolvables translated strings
-CREATE TABLE resolvable_ttext_attributes (
+CREATE TABLE text_attributes (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-  , lang_code INTEGER
-  , summary TEXT
-  , description TEXT
-  , insnotify TEXT
-  , delnotify TEXT
-  , license_to_confirm
-);
-
--- Association between ttext attributes and resolvables
-CREATE TABLE resolvable_resolvable_ttext_attributes (
-    resolvable_id INTEGER REFERENCES resolvable(id)
-  , ttext_attribute_id INTEGER REFERENCES resolvable_ttext_attributes(id)
-  , PRIMARY KEY ( resolvable_id, ttext_attribute_id )
-);
-
--- Resolvables untranslated strings
-CREATE TABLE resolvable_text_attributes (
-    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-);
-
--- Association between text attributes and resolvables
-CREATE TABLE resolvable_resolvable_text_attributes (
-    resolvable_id INTEGER REFERENCES resolvable(id)
-  , text_attribute_id INTEGER REFERENCES text_attribute(id)
-  , PRIMARY KEY ( resolvable_id, text_attribute_id )
+  , lang INTEGER REFERENCES types(id)
+  , attr INTEGER REFERENCES types(id)
+  , text TEXT
 );
 
 ------------------------------------------------
@@ -169,24 +157,6 @@ CREATE TABLE message_details (
   , text TEXT
 );
 
--- messages translated strings
-CREATE TABLE message_ttext_attributes (
-    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-  , lang_code INTEGER
-  , summary TEXT
-  , description TEXT
-  , insnotify TEXT
-  , delnotify TEXT
-  , license_to_confirm
-);
-
--- Association between ttext attributes and messages
-CREATE TABLE message_message_ttext_attributes (
-    message_id INTEGER REFERENCES message(id)
-  , ttext_attribute_id INTEGER REFERENCES message_ttext_attributes(id)
-  , PRIMARY KEY ( message_id, ttext_attribute_id )
-);
-
 CREATE TABLE patch_details (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
   , resolvable_id INTEGER REFERENCES resolvables(id)
@@ -198,20 +168,6 @@ CREATE TABLE patch_details (
 
 );
 
--- patchs translated strings
-CREATE TABLE patch_text_attributes (
-    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-  , patch_id TEXT
-  , category TEXT
-);
-
--- Association between ttext attributes and patchs
-CREATE TABLE patch_patch_text_attributes (
-    patch_id INTEGER REFERENCES patch(id)
-  , text_attribute_id INTEGER REFERENCES patch_text_attributes(id)
-  , PRIMARY KEY ( patch_id, text_attribute_id )
-);
-
 CREATE TABLE pattern_details (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
   , resolvable_id INTEGER REFERENCES resolvables(id)
@@ -229,41 +185,6 @@ CREATE TABLE product_details (
   , resolvable_id INTEGER REFERENCES resolvables(id)
 );
 
--- products translated strings
-CREATE TABLE product_ttext_attributes (
-    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-  , lang_code INTEGER
-  , short_name TEXT
-);
-
--- Association between ttext attributes and products
-CREATE TABLE product_product_ttext_attributes (
-    product_id INTEGER REFERENCES product(id)
-  , ttext_attribute_id INTEGER REFERENCES product_ttext_attributes(id)
-  , PRIMARY KEY ( product_id, ttext_attribute_id )
-);
-
--- products translated strings
-CREATE TABLE product_text_attributes (
-    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-  , category TEXT
-  , distribution_name TEXT
-  , distribution_edition TEXT
-  , vendor TEXT
-  , release_notes_url TEXT
-  , update_urls TEXT
-  , extra_urls TEXT
-  , optional_urls TEXT
-  , flags TEXT
-  , short_name TEXT
-);
-
--- Association between ttext attributes and products
-CREATE TABLE product_product_text_attributes (
-    product_id INTEGER REFERENCES product(id)
-  , text_attribute_id INTEGER REFERENCES product_text_attributes(id)
-  , PRIMARY KEY ( product_id, text_attribute_id )
-);
 
 CREATE TABLE script_details (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
@@ -276,26 +197,6 @@ CREATE TABLE script_ttext_attributes (
   , lang_code INTEGER
 );
 
--- Association between ttext attributes and scripts
-CREATE TABLE script_script_ttext_attributes (
-    script_id INTEGER REFERENCES script(id)
-  , ttext_attribute_id INTEGER REFERENCES script_ttext_attributes(id)
-  , PRIMARY KEY ( script_id, ttext_attribute_id )
-);
-
--- scripts translated strings
-CREATE TABLE script_text_attributes (
-    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-  , do_script TEXT
-  , undo_script TEXT
-);
-
--- Association between ttext attributes and scripts
-CREATE TABLE script_script_text_attributes (
-    script_id INTEGER REFERENCES script(id)
-  , text_attribute_id INTEGER REFERENCES script_text_attributes(id)
-  , PRIMARY KEY ( script_id, text_attribute_id )
-);
 
 CREATE TABLE package_details (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
@@ -320,43 +221,6 @@ CREATE TABLE package_details (
 );
 CREATE INDEX package_details_resolvable_id ON package_details (resolvable_id);
 
--- packages translated strings
-CREATE TABLE package_ttext_attributes (
-    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-  , lang_code INTEGER
-  , short_name TEXT
-);
-
--- Association between ttext attributes and packages
-CREATE TABLE package_package_ttext_attributes (
-    package_id INTEGER REFERENCES package(id)
-  , ttext_attribute_id INTEGER REFERENCES package_ttext_attributes(id)
-  , PRIMARY KEY ( package_id, ttext_attribute_id )
-);
-
--- packages translated strings
-CREATE TABLE package_text_attributes (
-    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-  , category TEXT
-  , distribution_name TEXT
-  , distribution_edition TEXT
-  , vendor TEXT
-  , release_notes_url TEXT
-  , update_urls TEXT
-  , extra_urls TEXT
-  , optional_urls TEXT
-  , flags TEXT
-  , short_name TEXT
-);
-
--- Association between ttext attributes and packages
-CREATE TABLE package_package_text_attributes (
-    package_id INTEGER REFERENCES package(id)
-  , text_attribute_id INTEGER REFERENCES package_text_attributes(id)
-  , PRIMARY KEY ( package_id, text_attribute_id )
-);
-
-
 ------------------------------------------------
 -- Do we need those here?
 ------------------------------------------------
index fc8fa5a..25baced 100644 (file)
@@ -8,10 +8,11 @@
 \---------------------------------------------------------------------*/
 
 #include <iostream>
+#include <map>
+
 #include "zypp/base/Logger.h"
 #include "zypp/base/Measure.h"
-#include <sqlite3.h>
-#include "zypp2/cache/sqlite3x/sqlite3x.hpp"
+
 #include "zypp2/cache/QueryFactory.h"
 #include "zypp2/cache/CapabilityQuery.h"
 #include "zypp2/cache/sqlite_detail/CacheSqlite.h"
@@ -27,7 +28,6 @@
 
 using namespace zypp::detail;
 using namespace zypp::cache;
-using std::endl;
 using namespace std;
 using namespace sqlite3x;
 
@@ -60,6 +60,56 @@ void CachedRepositoryImpl::factoryInit()
 
 void read_capabilities( sqlite3_connection &con, map<data::RecordId, NVRAD> &nvras );
 
+Rel CachedRepositoryImpl::relationFor( const data::RecordId &id )
+{
+  Rel rel;
+  std::map<data::RecordId, Rel>::const_iterator it;
+  if ( (it = _rel_cache.find(id) ) != _rel_cache.end() )
+    rel = it->second;
+  else
+    ZYPP_THROW(Exception("Inconsistent Rel"));
+  
+  return rel;
+
+}
+
+Resolvable::Kind CachedRepositoryImpl::kindFor( const data::RecordId &id )
+{
+  Resolvable::Kind kind;
+  std::map<data::RecordId, Resolvable::Kind>::const_iterator it;
+  if ( (it = _kind_cache.find(id) ) != _kind_cache.end() )
+    kind = it->second;
+  else
+    ZYPP_THROW(Exception("Inconsistent Kind"));
+  
+  return kind;
+}
+
+Dep CachedRepositoryImpl::deptypeFor( const data::RecordId &id )
+{
+  std::map<data::RecordId, string>::const_iterator it;
+  if ( (it = _deptype_cache.find(id) ) != _deptype_cache.end() )
+    return Dep(it->second);
+  else
+  {
+    ERR << "deptype: " << id << endl;
+    ZYPP_THROW(Exception("Inconsistent deptype"));
+  }
+}
+
+Arch CachedRepositoryImpl::archFor( const data::RecordId &id )
+{
+   
+  Arch arch;
+  std::map<data::RecordId, Arch>::const_iterator it;
+  if ( (it = _arch_cache.find(id) ) != _arch_cache.end() )
+    arch = it->second;
+  else
+    ZYPP_THROW(Exception("Inconsistent Arch"));
+  
+  return arch;
+}
+
 void CachedRepositoryImpl::createResolvables()
 {
   debug::Measure m("create resolvables");
@@ -68,21 +118,44 @@ void CachedRepositoryImpl::createResolvables()
     sqlite3_connection con((_dbdir + "zypp.db").asString().c_str());
     con.executenonquery("PRAGMA cache_size=8000;");
     con.executenonquery("BEGIN;");
+    
+    // get all types
+    sqlite3_command select_types_cmd( con, "select id,class,name from types;");
+    sqlite3_reader reader = select_types_cmd.executereader();
+    
+    while(reader.read())
+    {
+      data::RecordId id = reader.getint64(0);
+      string klass = reader.getstring(1);
+      string name = reader.getstring(2);
+      if ( klass == "arch" )
+        _arch_cache[id] = Arch(name);
+      if ( klass == "rel" )
+        _rel_cache[id] = Rel(name);
+      if ( klass == "kind" )
+        _kind_cache[id] = Resolvable::Kind(name);
+      if ( klass == "deptype" )
+        _deptype_cache[id] = name;
+    }
+    
+    MIL << "archs: " << _arch_cache.size() << endl;
+    MIL << "rel  : " << _rel_cache.size() << endl;
+    MIL << "kind : " << _kind_cache.size() << endl;
+    MIL << "deptype : " << _deptype_cache.size() << endl;
+    
     sqlite3_command cmd( con, "select id,name,version,release,epoch,arch,kind from resolvables;");
     map<data::RecordId, NVRAD> nvras;
     
-    sqlite3_reader reader = cmd.executereader();
+    reader = cmd.executereader();
     while(reader.read())
     {
       long long id = reader.getint64(0);
       Dependencies deps;
       
-      Arch arch = db_arch2zypp_arch( static_cast<db::Arch>(reader.getint(5)));
-      
       // Collect basic Resolvable data
       nvras[id] = NVRAD( reader.getstring(1),
                        Edition( reader.getstring(2), reader.getstring(3), reader.getint(4) ),
-                       arch,
+                       archFor(reader.getint(5)),
                        deps
                      );
     }
@@ -106,11 +179,15 @@ void CachedRepositoryImpl::createResolvables()
    
 }
 
-void read_capabilities( sqlite3_connection &con, map<data::RecordId, NVRAD> &nvras )
+void CachedRepositoryImpl::read_capabilities( sqlite3_connection &con, map<data::RecordId, NVRAD> &nvras )
 {
   CapFactory capfactory;
+  
+  
   // precompile statements
   
+  
+  
 //   map<data::RecordId, capability::CapabilityImpl::Ptr> named_caps;
 //   sqlite3_command select_named_cmd( con, "select v.id, c.refers_kind, n.name, v.version, v.release, v.epoch, v.relation named_capabilities v, capabilities c, names n where v.name_id=n.id and c.id=ncc.capability_id and ncc.named_capability_id=v.id;");
 //   {
@@ -129,21 +206,22 @@ void read_capabilities( sqlite3_connection &con, map<data::RecordId, NVRAD> &nvr
     sqlite3_reader reader = select_named_cmd.executereader();
     while  ( reader.read() )
     {
-      Resolvable::Kind refer = db_kind2zypp_kind( static_cast<db::Kind>(reader.getint(0)) );
-      zypp::Rel rel = db_rel2zypp_rel( static_cast<db::Rel>(reader.getint(5)) );
+      
+      Resolvable::Kind refer = kindFor(reader.getint(0));
+      Rel rel = relationFor(reader.getint(5));
+      
       data::RecordId rid = reader.getint64(7);
   
       if ( rel == zypp::Rel::NONE )
       {
         capability::NamedCap *ncap = new capability::NamedCap( refer, reader.getstring(1) );
-        zypp::Dep deptype = db_deptype2zypp_deptype( static_cast<db::DependencyType>(reader.getint(5)) );
-        
+        zypp::Dep deptype = deptypeFor(reader.getint(6));  
         nvras[rid][deptype].insert( capfactory.fromImpl( capability::CapabilityImpl::Ptr(ncap) ) ); 
       }
       else
       {
         capability::VersionedCap *vcap = new capability::VersionedCap( refer, reader.getstring(1), /* rel */ rel, Edition( reader.getstring(2), reader.getstring(3), reader.getint(4) ) );
-        zypp::Dep deptype = db_deptype2zypp_deptype( static_cast<db::DependencyType>(reader.getint(5)) );
+        zypp::Dep deptype = deptypeFor(reader.getint(6));
         nvras[rid][deptype].insert( capfactory.fromImpl( capability::CapabilityImpl::Ptr(vcap) ) ); 
       }
     }
@@ -154,9 +232,9 @@ void read_capabilities( sqlite3_connection &con, map<data::RecordId, NVRAD> &nvr
     sqlite3_reader reader = select_file_cmd.executereader();
     while  ( reader.read() )
     {
-      Resolvable::Kind refer = db_kind2zypp_kind( static_cast<db::Kind>(reader.getint(0)) );
+      Resolvable::Kind refer = kindFor(reader.getint(0));
       capability::FileCap *fcap = new capability::FileCap( refer, reader.getstring(1) + "/" + reader.getstring(2) );
-      zypp::Dep deptype = db_deptype2zypp_deptype( static_cast<db::DependencyType>(reader.getint(3)) );
+      zypp::Dep deptype = deptypeFor(reader.getint(3));
       data::RecordId rid = reader.getint64(4);
       nvras[rid][deptype].insert( capfactory.fromImpl( capability::CapabilityImpl::Ptr(fcap) ) ); 
     }
index 2b4683a..16157b1 100644 (file)
 #define ZYPP_CachedRepositoryImpl_H
 
 #include <iosfwd>
+#include <map>
+#include "zypp/Arch.h"
+#include "zypp/Rel.h"
 #include "zypp/Pathname.h"
+#include "zypp/data/RecordId.h"
 #include "zypp2/repository/RepositoryImpl.h"
 #include "zypp/ResStore.h"
 
+#include <sqlite3.h>
+#include "zypp2/cache/sqlite3x/sqlite3x.hpp"
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -51,16 +58,32 @@ namespace zypp
         virtual std::string type() const
         { return typeString(); }
 
+        const ResStore & resolvables() const
+        { return _store; }
+        
+        virtual void createResolvables();
       private:
         /** Ctor substitute.
          * Actually get the metadata.
          * \throw EXCEPTION on fail
         */
         virtual void factoryInit();
-        virtual void createResolvables();
+        
         
         zypp::Pathname _dbdir;
         ResStore _store;
+        
+        Rel relationFor( const data::RecordId &id );
+        Resolvable::Kind kindFor( const data::RecordId &id );
+        Dep deptypeFor( const data::RecordId &id );
+        Arch archFor( const data::RecordId &id );
+        
+        void read_capabilities( sqlite3x::sqlite3_connection &con, std::map<data::RecordId, NVRAD> &nvras );
+        
+        std::map<data::RecordId, Rel> _rel_cache;
+        std::map<data::RecordId, Resolvable::Kind> _kind_cache;
+        std::map<data::RecordId, std::string> _deptype_cache;
+        std::map<data::RecordId, Arch> _arch_cache;
       };
       ///////////////////////////////////////////////////////////////////