Revision 855d34f9 include/DefaultQuotas.h

View differences:

include/DefaultQuotas.h
18 18
#define DEFAULT_QUOTAS_H_
19 19

  
20 20
#include "Quotas.h"
21
#include "SqlDB.h"
22
#include "ObjectSQL.h"
21 23

  
22
class DefaultQuotas : public Quotas
24
class DefaultQuotas : public Quotas, ObjectSQL
23 25
{
24 26
public:
25 27
    DefaultQuotas(
......
54 56
    string& to_xml(string& xml) const;
55 57

  
56 58
    /**
59
     *  Writes the quotas in the database.
60
     *    @param db pointer to the db
61
     *    @return 0 on success
62
     */
63
    int insert(SqlDB *db, string& error_str)
64
    {
65
        return insert_replace(db, false, error_str);
66
    };
67

  
68
    /**
69
     *  Writes/updates the quotas data fields in the database.
70
     *    @param db pointer to the db
71
     *    @return 0 on success
72
     */
73
    int update(SqlDB *db)
74
    {
75
        string error_str;
76
        return insert_replace(db, true, error_str);
77
    };
78

  
79
    /**
80
     *  Reads the Quotas from the database.
81
     *    @param db pointer to the db
82
     *    @return 0 on success
83
     */
84
    int select(SqlDB *db);
85

  
86
    /**
87
     *  Bootstraps the database table(s) associated to the default quotas
88
     *    @return 0 on success
89
     */
90
    static int bootstrap(SqlDB * db);
91

  
92
private:
93
    const char * root_elem;
94

  
95
    // *************************************************************************
96
    // DataBase implementation
97
    // *************************************************************************
98

  
99
    static const char * db_names;
100

  
101
    static const char * db_bootstrap;
102

  
103
    static const char * table;
104

  
105
    /**
106
     *  Execute an INSERT or REPLACE Sql query.
107
     *    @param db The SQL DB
108
     *    @param replace Execute an INSERT or a REPLACE
109
     *    @param error_str Returns the error reason, if any
110
     *    @return 0 one success
111
     */
112
    int insert_replace(SqlDB *db, bool replace, string& error_str);
113

  
114
    /**
115
     *  Callback function to unmarshall a PoolObjectSQL
116
     *    @param num the number of columns read from the DB
117
     *    @param names the column names
118
     *    @param vaues the column values
119
     *    @return 0 on success
120
     */
121
    int select_cb(void *nil, int num, char **values, char **names)
122
    {
123
        if ( (!values[0]) || (num != 1) )
124
        {
125
            return -1;
126
        }
127

  
128
        return from_xml(values[0]);
129
    };
130

  
131
    /**
57 132
     *  Builds quota object from an ObjectXML
58 133
     *    @param xml The xml-formatted string
59
     *    @return 0 if success
134
     *    @return 0 on success
60 135
     */
61 136
    int from_xml(const string& xml);
62 137

  
63
private:
64
    const char * root_elem;
138
    /**
139
     *  Removes the Quotas from the database.
140
     *    @param db pointer to the db
141
     *    @return 0 on success
142
     */
143
    int drop(SqlDB * db)
144
    {
145
        return -1;  // Not supported
146
    };
65 147
};
66 148

  
67 149
#endif /*DEFAULT_QUOTAS_H_*/

Also available in: Unified diff