IConverter.hpp 6.64 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/******************************************************************************
 *                      IConverter.hpp
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 *
 *
 * @author Sebastien Ponce
 *****************************************************************************/

26
#pragma once
27
28

// Include Files
Sebastien Ponce's avatar
Sebastien Ponce committed
29
#include <vector>
30
31
32
#include <map>

// Local Includes
33
#include "castor/exception/Exception.hpp"
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

namespace castor {

  // Forward Declarations
  class IAddress;
  class IObject;

  /**
   * abstract interface for all converters and conversion
   * services
   */
  class IConverter {

  public:

49
50
51
52
53
    /**
     * virtual destructor
     */
    virtual ~IConverter(){};

54
55
56
57
    /**
     * gets the object type, that is the type of
     * object this converter can convert
     */
58
    virtual unsigned int objType() const = 0;
59
60
61
62
63

    /**
     * gets the representation type, that is the type of
     * the representation this converter can deal with
     */
64
    virtual unsigned int repType() = 0;
65
66
67
68
69
70

    /**
     * create foreign representation from a C++ Object
     * @param address where to store the representation of
     * the object
     * @param object the object to deal with
71
     * @param endTransaction whether the changes to the database
72
     * should be commited or not
73
74
75
     * @param type if not OBJ_INVALID, the ids representing
     * the links to objects of this type will not set to 0
     * as is the default.
76
77
78
79
     * @exception Exception throws an Exception in case of error
     */
    virtual void createRep(IAddress* address,
                           IObject* object,
80
                           bool endTransaction,
81
                           unsigned int type)
82
       = 0;
83
    
Sebastien Ponce's avatar
Sebastien Ponce committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    /**
     * create foreign representations from a set of C++ Object
     * @param address where to store the representation of
     * the objects
     * @param objects the list of objects to deal with
     * @param endTransaction whether the changes to the database
     * should be commited or not
     * @param type if not OBJ_INVALID, the ids representing
     * the links to objects of this type will not set to 0
     * as is the default.
     * @exception Exception throws an Exception in case of error
     */
    virtual void bulkCreateRep(IAddress* address,
                               std::vector<IObject*> &objects,
			       bool endTransaction,
			       unsigned int type)
100
       = 0;
Sebastien Ponce's avatar
Sebastien Ponce committed
101
    
102
103
104
105
106
    /**
     * Updates foreign representation from a C++ Object.
     * @param address where the representation of
     * the object is stored
     * @param object the object to deal with
107
     * @param endTransaction whether the changes to the database
108
     * should be commited or not
Sebastien Ponce's avatar
Sebastien Ponce committed
109
     * @exception Exception throws an Exception in case of error
110
111
112
     */
    virtual void updateRep(IAddress* address,
                           IObject* object,
113
                           bool endTransaction)
114
       = 0;
115
116
117
118
119
120

    /**
     * deletes foreign representation of a C++ Object
     * @param address where the representation of
     * the object is stored
     * @param object the object to deal with
121
     * @param endTransaction whether the changes to the database
122
123
124
125
126
     * should be commited or not
     * @exception Exception throws an Exception in case of error
     */
    virtual void deleteRep(IAddress* address,
                           IObject* object,
127
                           bool endTransaction)
128
       = 0;
129
130
131
132
133

    /**
     * create C++ object from foreign representation
     * @param address the place where to find the foreign
     * representation
Sebastien Ponce's avatar
Sebastien Ponce committed
134
     * @return the C++ object created from its representation
135
136
     * or 0 if unsuccessful. Note that the caller is responsible
     * for the deallocation of the newly created object
Sebastien Ponce's avatar
Sebastien Ponce committed
137
     * @exception Exception throws an Exception in case of error
138
     */
139
    virtual IObject* createObj(IAddress* address)
140
       = 0;
141

Sebastien Ponce's avatar
Sebastien Ponce committed
142
143
144
145
146
147
148
149
150
151
    /**
     * create C++ objects from foreign representations
     * @param address the place where to find the foreign
     * representations
     * @return the C++ objects created from the representations
     * or empty vector if unsuccessful. Note that the caller is
     * responsible for the deallocation of the newly created objects
     * @exception Exception throws an Exception in case of error
     */
    virtual std::vector<IObject*> bulkCreateObj(IAddress* address)
152
       = 0;
Sebastien Ponce's avatar
Sebastien Ponce committed
153

154
155
156
157
158
    /**
     * Updates C++ object from its foreign representation.
     * @param object the object to deal with
     * @exception Exception throws an Exception in case of error
     */
159
    virtual void updateObj(IObject* object)
160
       = 0;
161

162
163
164
165
166
167
168

    /**
     * Fill the foreign representation with some of the objects
     * refered by a given C++ object.
     * @param address the place where to find the foreign representation
     * @param object the original C++ object
     * @param type the type of the refered objects to store
169
     * @param endTransaction whether the changes to the database
170
171
172
173
174
175
     * should be commited or not
     * @exception Exception throws an Exception in case of error
     */
    virtual void fillRep(castor::IAddress* address,
                         castor::IObject* object,
                         unsigned int type,
176
                         bool endTransaction = false)
177
       = 0;
178
179
180
181
182
183
184
    
    /**
     * Retrieve from the foreign representation some of the
     * objects refered by a given C++ object.
     * @param address the place where to find the foreign representation
     * @param object the original object
     * @param type the type of the refered objects to retrieve
185
     * @param endTransaction whether the lock taken on the database
186
     * should be released or not
187
188
189
190
     * @exception Exception throws an Exception in case of error
     */
    virtual void fillObj(castor::IAddress* address,
                         castor::IObject* object,
191
                         unsigned int type,
192
                         bool endTransaction = false)
193
       = 0;
194

195
196
197
198
  };

} // end of namespace castor