Statistics
| Branch: | Tag: | Revision:

one / include / GroupPool.h @ ae53d437

History | View | Annotate | Download (4.29 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2011, 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_POOL_H_
18
#define GROUP_POOL_H_
19

    
20
#include "Group.h"
21
#include "SqlDB.h"
22

    
23
using namespace std;
24

    
25

    
26
class GroupPool : public PoolSQL
27
{
28
public:
29
    GroupPool(SqlDB * db);
30

    
31
    ~GroupPool(){};
32

    
33
    /**
34
     *  Cluster name for the default cluster
35
     */
36
    static const string DEFAULT_GROUP_NAME;
37

    
38
    /* ---------------------------------------------------------------------- */
39
    /* Methods for DB management                                              */
40
    /* ---------------------------------------------------------------------- */
41

    
42
    /**
43
     *  Allocates a new group, writting it in the pool database. No memory is
44
     *  allocated for the object.
45
     *    @param uid user id (the owner of the Object)
46
     *    @param name Group name
47
     *    @param oid the id assigned to the Group
48
     *    @param error_str Returns the error reason, if any
49
     *
50
     *    @return the oid assigned to the object, -1 in case of failure
51
     */
52
    int allocate(int                      uid,
53
                 string                   name,
54
                 int *                    oid,
55
                 string&                  error_str);
56

    
57
    /**
58
     *  Function to get a group from the pool, if the object is not in memory
59
     *  it is loaded from the DB
60
     *    @param oid group unique id
61
     *    @param lock locks the group mutex
62
     *    @return a pointer to the group, 0 if the group could not be loaded
63
     */
64
    Group * get(int oid, bool lock)
65
    {
66
        return static_cast<Group *>(PoolSQL::get(oid,lock));
67
    };
68

    
69
    /**
70
     *  Gets an object from the pool (if needed the object is loaded from the
71
     *  database).
72
     *   @param name of the object
73
     *   @param uid id of owner
74
     *   @param lock locks the object if true
75
     *
76
     *   @return a pointer to the object, 0 in case of failure
77
     */
78
    Group * get(const string& name, int uid, bool lock)
79
    {
80
        return static_cast<Group *>(PoolSQL::get(name,uid,lock));
81
    };
82

    
83
    /** Update a particular Group
84
     *    @param user pointer to Group
85
     *    @return 0 on success
86
     */
87
    int update(Group * group)
88
    {
89
        return group->update(db);
90
    };
91

    
92
    /**
93
     *  Drops the Group from the data base. The object mutex SHOULD be
94
     *  locked.
95
     *    @param group a pointer to the object
96
     *    @return 0 on success.
97
     */
98
    int drop(Group * group);
99

    
100
    /**
101
     *  Bootstraps the database table(s) associated to the Group pool
102
     */
103
    static void bootstrap(SqlDB * _db)
104
    {
105
        Group::bootstrap(_db);
106
    };
107

    
108
    /**
109
     *  Dumps the Group pool in XML format. A filter can be also added to the
110
     *  query
111
     *  @param oss the output stream to dump the pool contents
112
     *  @param where filter for the objects, defaults to all
113
     *
114
     *  @return 0 on success
115
     */
116
    int dump(ostringstream& oss, const string& where)
117
    {
118
        return PoolSQL::dump(oss, "GROUP_POOL", Group::table, where);
119
    };
120

    
121
private:
122

    
123
    /**
124
     *  Factory method to produce objects
125
     *    @return a pointer to the new object
126
     */
127
    PoolObjectSQL * create()
128
    {
129
        return new Group(-1,-1,"");
130
    };
131
};
132

    
133
#endif /*GROUP_POOL_H_*/