Statistics
| Branch: | Tag: | Revision:

one / include / Group.h @ ae53d437

History | View | Annotate | Download (3.42 KB)

1
/* ------------------------------------------------------------------------ */
2
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)           */
3
/*                                                                          */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may  */
5
/* not use this file except in compliance with the License. You may obtain  */
6
/* a copy of the License at                                                 */
7
/*                                                                          */
8
/* http://www.apache.org/licenses/LICENSE-2.0                               */
9
/*                                                                          */
10
/* Unless required by applicable law or agreed to in writing, software      */
11
/* distributed under the License is distributed on an "AS IS" BASIS,        */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
13
/* See the License for the specific language governing permissions and      */
14
/* limitations under the License.                                           */
15
/* -------------------------------------------------------------------------*/
16

    
17
#ifndef GROUP_H_
18
#define GROUP_H_
19

    
20
#include "PoolSQL.h"
21

    
22
using namespace std;
23

    
24
/**
25
 *  The Group class.
26
 */
27
class Group : public PoolObjectSQL
28
{
29
public:
30
    /**
31
     *  Function to write a Group on an output stream
32
     */
33
     friend ostream& operator<<(ostream& os, Group& group);
34

    
35
    /**
36
     * Function to print the Group object into a string in XML format
37
     *  @param xml the resulting XML string
38
     *  @return a reference to the generated string
39
     */
40
    string& to_xml(string& xml) const;
41

    
42
    /**
43
     *  Rebuilds the object from an xml formatted string
44
     *    @param xml_str The xml-formatted string
45
     *
46
     *    @return 0 on success, -1 otherwise
47
     */
48
    int from_xml(const string &xml_str);
49

    
50
private:
51

    
52
    // -------------------------------------------------------------------------
53
    // Friends
54
    // -------------------------------------------------------------------------
55

    
56
    friend class GroupPool;
57

    
58
    // *************************************************************************
59
    // Constructor
60
    // *************************************************************************
61

    
62
    Group(int id, int uid, const string& name);
63

    
64
    virtual ~Group();
65

    
66
    // *************************************************************************
67
    // DataBase implementation (Private)
68
    // *************************************************************************
69

    
70
    static const char * db_names;
71

    
72
    static const char * db_bootstrap;
73

    
74
    static const char * table;
75

    
76
    /**
77
     *  Execute an INSERT or REPLACE Sql query.
78
     *    @param db The SQL DB
79
     *    @param replace Execute an INSERT or a REPLACE
80
     *    @return 0 one success
81
    */
82
    int insert_replace(SqlDB *db, bool replace);
83

    
84
    /**
85
     *  Bootstraps the database table(s) associated to the Group
86
     */
87
    static void bootstrap(SqlDB * db)
88
    {
89
        ostringstream oss(Group::db_bootstrap);
90

    
91
        db->exec(oss);
92
    };
93

    
94
    /**
95
     *  Writes the Group in the database.
96
     *    @param db pointer to the db
97
     *    @return 0 on success
98
     */
99
    int insert(SqlDB *db, string& error_str);
100

    
101
    /**
102
     *  Writes/updates the Group's data fields in the database.
103
     *    @param db pointer to the db
104
     *    @return 0 on success
105
     */
106
    int update(SqlDB *db);
107
};
108

    
109
#endif /*GROUP_H_*/