ICnvSvc.hpp 7.86 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
/******************************************************************************
 *                      ICnvSvc.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
29
30
#include "castor/IService.hpp"
#include "castor/Constants.hpp"
31
#include "castor/exception/Exception.hpp"
Sebastien Ponce's avatar
Sebastien Ponce committed
32
#include <vector>
33
34
35
36
37
38
39
40

namespace castor {

  // Forward Declaration
  class IConverter;
  class IAddress;
  class IObject;

41
42
43
44
  namespace db {
      class IDbStatement;
  }

45
46
47
48
49
50
  /**
   * Abstract interface for services dealing with conversion
   */
  class ICnvSvc : public virtual IService {

  public:
51
52
53
54
55
56

    /**
     * virtual destructor
     */
    virtual ~ICnvSvc(){};

57
58
59
60
61
62
63
    /** Retrieve converter from list
     *  @param id the id of the converter
     *  @return the converter corresponding to id or 0 if non was found
     */
    virtual IConverter* converter(const unsigned int id) = 0;

    /**
64
     * create foreign representation from a C++ Object.
65
66
67
     * @param address where to store the representation of
     * the object
     * @param object the object to deal with
68
     * @param endTransaction whether the changes to the database
69
     * should be commited or not
70
71
72
     * @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.
73
     * @exception Exception throws an Exception in case of error
74
75
76
     */
    virtual void createRep(IAddress* address,
                           IObject* object,
77
                           bool endTransaction,
78
                           unsigned int type = castor::OBJ_INVALID)
79
       = 0;
80

Sebastien Ponce's avatar
Sebastien Ponce committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
    /**
     * 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 = castor::OBJ_INVALID)
97
       = 0;
Sebastien Ponce's avatar
Sebastien Ponce committed
98
    
99
100
101
102
103
    /**
     * Updates foreign representation from a C++ Object.
     * @param address where the representation of
     * the object is stored
     * @param object the object to deal with
104
     * @param endTransaction whether the changes to the database
105
     * should be commited or not
106
     * @exception Exception throws an Exception in case of error
107
108
109
     */
    virtual void updateRep(IAddress* address,
                           IObject* object,
110
                           bool endTransaction)
111
       = 0;
112
113
114
115
116
117

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

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

Sebastien Ponce's avatar
Sebastien Ponce committed
139
140
141
142
143
144
145
146
147
148
    /**
     * 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)
149
       = 0;
Sebastien Ponce's avatar
Sebastien Ponce committed
150

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

159
160
161
162
163
164
    /**
     * 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
165
     * @param endTransaction whether the changes to the database
166
167
168
169
170
171
     * 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,
172
                         bool endTransaction = false)
173
       = 0;
174
175
176
177
178
179
180
    
    /**
     * 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
181
     * @param endTransaction whether the lock taken on the database
182
     * should be released or not
183
184
185
186
     * @exception Exception throws an Exception in case of error
     */
    virtual void fillObj(castor::IAddress* address,
                         castor::IObject* object,
187
                         unsigned int type,
188
                         bool endTransaction = false)
189
       = 0;
190

191
192
193
194
195
    /**
     * Forces the commit of the last changes.
     * @exception Exception throws an Exception in case of error
     */
    virtual void commit()
196
       = 0;
197
198
199
200
201
202

    /**
     * Forces the rollback of the last changes
     * @exception Exception throws an Exception in case of error
     */
    virtual void rollback()
203
       = 0;
204

205
206
207
208
209
210
    /**
     * Creates a prepared statement wrapped with the
     * db-independent CDBC API
     * @param stmt the string statement to be prepared 
     */
    virtual castor::db::IDbStatement* createStatement(const std::string& stmt)
211
       = 0;
212
	  
213
214
215
216
217
218
219
    /**
     * Deletes foreign representation of a C++ Object without
     * needing the object. The cost of this method is higher
     * than the cost of deleteRep since it needs to call
     * createObj first
     * @param address where the representation of
     * the object is stored
220
     * @param endTransaction whether the changes to the database
221
     * should be commited or not
Sebastien Ponce's avatar
Sebastien Ponce committed
222
     * @exception Exception throws an Exception in case of error
223
     */
224
    virtual void deleteRepByAddress(IAddress* address,
225
                                    bool endTransaction = true)
226
       = 0;
227

228
229
230
231
  };

} // end of namespace castor