- add messages
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 11 Jun 2007 16:32:15 +0000 (16:32 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 11 Jun 2007 16:32:15 +0000 (16:32 +0000)
- dont throw if record is not found, allow to specify default value
- fix duplicated size attr in messageIf

zypp/CMakeLists.txt
zypp/cache/ResolvableQuery.cc
zypp/cache/ResolvableQuery.h
zypp/detail/MessageImplIf.cc
zypp/detail/MessageImplIf.h
zypp/repo/cached/MessageImpl.cc [new file with mode: 0644]
zypp/repo/cached/MessageImpl.h [new file with mode: 0644]

index d165d1d..24aab7e 100644 (file)
@@ -1084,6 +1084,7 @@ SET( zypp_repository_cached_SRCS
   repo/cached/PatchImpl.cc
   repo/cached/PatternImpl.cc
   repo/cached/ProductImpl.cc
+  repo/cached/MessageImpl.cc
 )
 
 SET( zypp_repository_cached_HEADERS
@@ -1092,6 +1093,7 @@ SET( zypp_repository_cached_HEADERS
   repo/cached/PatchImpl.h
   repo/cached/PatternImpl.h
   repo/cached/ProductImpl.h
+  repo/cached/MessageImpl.h
 )
 
 SET( zypp_repository_data_SRCS
index a2d9312..2ecc632 100644 (file)
@@ -80,46 +80,98 @@ struct ResolvableQuery::Impl
 
   std::string queryStringAttribute( const data::RecordId &record_id,
                                     const std::string &klass,
-                                    const std::string &name )
+                                    const std::string &name,
+                                    const std::string &default_value )
   {
     sqlite3_connection con((_dbdir + "zypp.db").asString().c_str());
-    return queryStringAttributeTranslationInternal( con, record_id, Locale(), klass, name);
+    
+    string value;
+    try {
+      value = queryStringAttributeTranslationInternal( con, record_id, Locale(), klass, name);
+    }
+    catch ( const Exception &e )
+    {
+      ZYPP_CAUGHT(e);
+      return default_value;
+    }
+    
+    return value;
   }
 
 
   std::string queryStringAttributeTranslation( const data::RecordId &record_id,
                                                const Locale &locale,
                                                const std::string &klass,
-                                               const std::string &name )
+                                               const std::string &name,
+                                               const std::string &default_value )
   {
     sqlite3_connection con((_dbdir + "zypp.db").asString().c_str());
-    return queryStringAttributeTranslationInternal( con, record_id, locale, klass, name );
+    string value;
+    try {
+      value = queryStringAttributeTranslationInternal( con, record_id, locale, klass, name );
+    }
+    catch ( const Exception &e )
+    {
+      ZYPP_CAUGHT(e);
+      return default_value;
+    }
+    return value;
   }
 
 
   TranslatedText queryTranslatedStringAttribute( const data::RecordId &record_id,
                                                  const std::string &klass,
-                                                 const std::string &name )
+                                                 const std::string &name,
+                                                 const TranslatedText &default_value )
   {
     sqlite3_connection con((_dbdir + "zypp.db").asString().c_str());
-    return queryTranslatedStringAttributeInternal( con, record_id, klass, name );
+    TranslatedText value;
+    try {
+      value = queryTranslatedStringAttributeInternal( con, record_id, klass, name );
+    }
+    catch ( const Exception &e )
+    {
+      ZYPP_CAUGHT(e);
+      return default_value;
+    }
+    return value;
   }
 
 
   bool queryBooleanAttribute( const data::RecordId &record_id,
-                                        const std::string &klass,
-                                        const std::string &name )
+                              const std::string &klass,
+                              const std::string &name,
+                              bool default_value )
   {
     sqlite3_connection con((_dbdir + "zypp.db").asString().c_str());
-    return ( queryNumericAttributeInternal( con, record_id, klass, name) != 0 );
+    bool value;
+    try {
+      value = queryNumericAttributeInternal( con, record_id, klass, name);
+    }
+    catch ( const Exception &e )
+    {
+      ZYPP_CAUGHT(e);
+      return default_value;
+    }
+    return value;
   }
       
   int queryNumericAttribute( const data::RecordId &record_id,
-                                 const std::string &klass,
-                                 const std::string &name )
+                             const std::string &klass,
+                             const std::string &name,
+                             int default_value )
   {
     sqlite3_connection con((_dbdir + "zypp.db").asString().c_str());
-    return queryNumericAttributeInternal( con, record_id, klass, name);
+    int n;
+    try {
+      n = queryNumericAttributeInternal( con, record_id, klass, name);
+    }
+    catch ( const Exception &e )
+    {
+      ZYPP_CAUGHT(e);
+      return default_value;
+    }
+    return n;
   }
 
 private:
@@ -223,24 +275,27 @@ void ResolvableQuery::query( const std::string &s, ProcessResolvable fnc  )
 
 int ResolvableQuery::queryNumericAttribute( const data::RecordId &record_id,
                                             const std::string &klass,
-                                            const std::string &name )
+                                            const std::string &name,
+                                            int default_value )
 {
-  return _pimpl->queryNumericAttribute(record_id, klass, name);
+  return _pimpl->queryNumericAttribute(record_id, klass, name, default_value);
 }
 
 bool ResolvableQuery::queryBooleanAttribute( const data::RecordId &record_id,
                                              const std::string &klass,
-                                             const std::string &name )
+                                             const std::string &name,
+                                             bool default_value )
 {
-  return _pimpl->queryNumericAttribute(record_id, klass, name);
+  return _pimpl->queryNumericAttribute(record_id, klass, name, default_value);
 }
 
 
 std::string ResolvableQuery::queryStringAttribute( const data::RecordId &record_id,
                                                    const std::string &klass,
-                                                   const std::string &name )
+                                                   const std::string &name,
+                                                   const std::string &default_value )
 {
-  return _pimpl->queryStringAttribute(record_id, klass, name);
+  return _pimpl->queryStringAttribute(record_id, klass, name, default_value);
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -248,18 +303,20 @@ std::string ResolvableQuery::queryStringAttribute( const data::RecordId &record_
 std::string ResolvableQuery::queryStringAttributeTranslation( const data::RecordId &record_id,
                                                               const Locale &locale,
                                                               const std::string &klass,
-                                                              const std::string &name )
+                                                              const std::string &name,
+                                                              const std::string &default_value )
 {
-  return _pimpl->queryStringAttributeTranslation(record_id, locale, klass, name);
+  return _pimpl->queryStringAttributeTranslation(record_id, locale, klass, name, default_value );
 }
 
 //////////////////////////////////////////////////////////////////////////////
 
 TranslatedText ResolvableQuery::queryTranslatedStringAttribute( const data::RecordId &record_id,
                                                                 const std::string &klass,
-                                                                const std::string &name )
+                                                                const std::string &name,
+                                                                const TranslatedText &default_value )
 {
-  return _pimpl->queryTranslatedStringAttribute(record_id, klass, name);
+  return _pimpl->queryTranslatedStringAttribute(record_id, klass, name, default_value );
 }
 
 //////////////////////////////////////////////////////////////////////////////
index 9b3bf0d..16759df 100644 (file)
@@ -61,12 +61,13 @@ namespace zypp
        * \param klass Attribute Class
        * \param name Attribute Name
        *
-       * \return The attribute or 0 if
+       * \return The attribute or -1 if
        * no record is found.
        */
       int queryNumericAttribute( const data::RecordId &record_id,
                                  const std::string &klass,
-                                 const std::string &name );
+                                 const std::string &name,
+                                 int default_value = -1 );
 
 
       /**
@@ -81,7 +82,8 @@ namespace zypp
        */
       bool queryBooleanAttribute( const data::RecordId &record_id,
                                   const std::string &klass,
-                                  const std::string &name );
+                                  const std::string &name,
+                                  bool default_value = false );
 
 
       /**
@@ -96,7 +98,8 @@ namespace zypp
        */
       std::string queryStringAttribute( const data::RecordId &record_id,
                                         const std::string &klass,
-                                        const std::string &name );
+                                        const std::string &name,
+                                        const std::string &default_value = std::string() );
       
       /**
        * Queries a specifc attribute translation
@@ -113,7 +116,8 @@ namespace zypp
       std::string queryStringAttributeTranslation( const data::RecordId &record_id,
                                                    const Locale &locale,
                                                    const std::string &klass,
-                                                   const std::string &name );
+                                                   const std::string &name,
+                                                   const std::string &default_value = std::string() );
       
       /**
        * Queries all translations for a specific attribute
@@ -128,7 +132,8 @@ namespace zypp
        */
       TranslatedText queryTranslatedStringAttribute( const data::RecordId &record_id,
                                                      const std::string &klass,
-                                                     const std::string &name );
+                                                     const std::string &name,
+                                                     const TranslatedText &default_vaue = TranslatedText() );
       
       /**
        * Queries for a specific container attribute
@@ -138,8 +143,8 @@ namespace zypp
        * \param klass Attribute Class
        * \param name Attribute Name
        *
-       * \return the attribute or a empty 
-       * \ref _Container if no record is found.
+       * The results are filled to the provided
+       * \ref _OutputIterator
        */
       template<class _OutputIterator>
       void queryStringContainerAttribute( const data::RecordId &record_id,
index 252bae5..b8f9cdc 100644 (file)
@@ -26,9 +26,6 @@ namespace zypp
       TranslatedText MessageImplIf::text() const
       { return TranslatedText(); }
 
-      ByteCount MessageImplIf::size() const
-      { return ResObjectImplIf::size(); }
-
       /** Patch the message belongs to - if any */
       Patch::constPtr MessageImplIf::patch() const
       { return Patch::constPtr(); }
index 784fca0..68a8c0d 100644 (file)
@@ -39,8 +39,6 @@ namespace zypp
     public:
       /** Get the text of the message */
       virtual TranslatedText text() const PURE_VIRTUAL;
-      /** */
-      virtual ByteCount size() const;
       /** Patch the message belongs to - if any */
       virtual Patch::constPtr patch() const; // TODO make it abstract = 0;
     };
diff --git a/zypp/repo/cached/MessageImpl.cc b/zypp/repo/cached/MessageImpl.cc
new file mode 100644 (file)
index 0000000..c9b0d21
--- /dev/null
@@ -0,0 +1,134 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#include "zypp/TranslatedText.h"
+#include "zypp/base/String.h"
+#include "zypp/base/Logger.h"
+#include "zypp/repo/RepositoryImpl.h"
+#include "MessageImpl.h"
+
+
+using namespace std;
+using namespace zypp::detail;
+using namespace::zypp::repo;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp { namespace repo { namespace cached {
+
+///////////////////////////////////////////////////////////////////
+//
+//        CLASS NAME : MessageImpl
+//
+///////////////////////////////////////////////////////////////////
+
+/** Default ctor
+*/
+MessageImpl::MessageImpl (const data::RecordId &id, cached::RepoImpl::Ptr repository_r)
+    : _repository (repository_r),
+      _id(id)
+{}
+
+Repository
+MessageImpl::repository() const
+{
+  return _repository->selfRepository();
+}
+
+///////////////////////////////////////////////////
+// ResObject Attributes
+///////////////////////////////////////////////////
+
+TranslatedText MessageImpl::summary() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "summary" );
+}
+
+TranslatedText MessageImpl::description() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "description" );
+}
+
+TranslatedText MessageImpl::insnotify() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "insnotify" );
+}
+
+TranslatedText MessageImpl::delnotify() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "delnotify" );
+}
+
+TranslatedText MessageImpl::licenseToConfirm() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "ResObject", "licenseToConfirm" );
+}
+
+Vendor MessageImpl::vendor() const
+{
+  return _repository->resolvableQuery().queryStringAttribute( _id, "ResObject", "vendor" );
+}
+
+
+ByteCount MessageImpl::size() const
+{
+  return _repository->resolvableQuery().queryNumericAttribute( _id, "ResObject", "size" );
+}
+
+ByteCount MessageImpl::archivesize() const
+{
+  return _repository->resolvableQuery().queryNumericAttribute( _id, "ResObject", "archivesize" );
+}
+
+bool MessageImpl::installOnly() const
+{
+  return _repository->resolvableQuery().queryBooleanAttribute( _id, "ResObject", "installOnly" );
+}
+
+Date MessageImpl::buildtime() const
+{
+  return _repository->resolvableQuery().queryNumericAttribute( _id, "ResObject", "buildtime" );
+}
+
+Date MessageImpl::installtime() const
+{
+  return Date();
+}
+
+//////////////////////////////////////////
+// DEPRECATED
+//////////////////////////////////////////
+
+Source_Ref MessageImpl::source() const
+{
+  return Source_Ref::noSource;
+}
+
+unsigned MessageImpl::sourceMediaNr() const
+{
+  return 1;
+}
+
+//////////////////////////////////////////
+// MESSAGE
+/////////////////////////////////////////
+
+TranslatedText MessageImpl::text() const
+{
+  return _repository->resolvableQuery().queryTranslatedStringAttribute( _id, "Message", "text" );
+}
+
+Patch::constPtr MessageImpl::patch() const
+{
+  return 0;
+}
+    
+/////////////////////////////////////////////////////////////////
+} } } // namespace zypp::repo::cached
+///////////////////////////////////////////////////////////////////
+
diff --git a/zypp/repo/cached/MessageImpl.h b/zypp/repo/cached/MessageImpl.h
new file mode 100644 (file)
index 0000000..3225128
--- /dev/null
@@ -0,0 +1,65 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#ifndef zypp_repo_cached_MessageImpl_H
+#define zypp_repo_cached_MessageImpl_H
+
+#include "zypp/detail/MessageImpl.h"
+#include "zypp/repo/cached/RepoImpl.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+namespace repo
+{ /////////////////////////////////////////////////////////////////
+namespace cached
+{ /////////////////////////////////////////////////////////////////
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //        CLASS NAME : MessageImpl
+  //
+  class MessageImpl : public detail::MessageImplIf
+  {
+  public:
+
+    MessageImpl( const data::RecordId &id, repo::cached::RepoImpl::Ptr repository_r );
+    
+    virtual TranslatedText summary() const;
+    virtual TranslatedText description() const;
+    virtual TranslatedText insnotify() const;
+    virtual TranslatedText delnotify() const;
+    virtual TranslatedText licenseToConfirm() const;
+    virtual Vendor vendor() const;
+    virtual ByteCount size() const;
+    virtual ByteCount archivesize() const;
+    virtual bool installOnly() const;
+    virtual Date buildtime() const;
+    virtual Date installtime() const;
+    
+    virtual Source_Ref source() const;
+    virtual unsigned sourceMediaNr() const;
+    
+    // MESSAGE
+    virtual TranslatedText text() const;
+    virtual Patch::constPtr patch() const;
+    
+    virtual Repository repository() const;
+    
+  protected:
+    repo::cached::RepoImpl::Ptr _repository;
+    data::RecordId _id;
+  };
+  /////////////////////////////////////////////////////////////////
+} // namespace cached
+} // namespace repository
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZMD_BACKEND_DBSOURCE_DBPACKAGEIMPL_H
+