summaryrefslogtreecommitdiffstats
path: root/sdo-cpp/tags/cpp-sdo-1.0.incubating-M3/runtime/core/src/commonj/sdo/ChangeSummaryImpl.h
blob: 61375323152de4e963aa7252e18a6fa79453ee0a (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/* $Rev$ $Date$ */

#ifndef _CHANGESUMMARYIMPL_H_
#define _CHANGESUMMARYIMPL_H_

#include "commonj/sdo/disable_warn.h"


#include "commonj/sdo/ChangedDataObjectListImpl.h"
#include "commonj/sdo/SettingList.h"
#include "commonj/sdo/ChangeSummary.h"
#include "commonj/sdo/RefCountingPointer.h"
#include "commonj/sdo/SDOXMLString.h"

#include <map>

namespace commonj{
namespace sdo {


    /** 
     * ChangeLogItem is a part of a change summary.
     * The change summary consisists of change items, 
     * deletion items and creation items. They are held in three
     * lists as they have slightly different contents.
     * The change log items hold old values for all the changes to
     * properties of the data object concerned.
     */

    class changeLogItem {

    public:

        changeLogItem(const Type& tp, const Property& prop,SequencePtr seq, 
            DataObjectImpl* cont = 0 );
        changeLogItem(const changeLogItem& cin); 
        ~changeLogItem();
        DataObjectImpl* getOldContainer();
        const Property& getOldContainmentProperty();
        const Type& getOldType();
        SettingList& getSettings();
        SequencePtr getSequence();

    private:

        const Property& theOldContainmentProperty;
        DataObjectImpl* theOldContainer;
        const Type& theType;
        SettingList theSettings;
        SequencePtr theSequence;
    };

    /** 
     * CreateLogItem is a part of a change summary.
     * The change summary consisists of change items, 
     * deletion items and creation items. They are held in three
     * lists as they have slightly different contents.
     * The create log items hold the data object itself,
     * and details of its container.
     */


    class createLogItem {

    public:

        createLogItem(const Type& tp, const Property& prop, DataObjectImpl* cont = 0);


        DataObjectImpl* getOldContainer();
        const Property& getOldContainmentProperty();
        const Type& getOldType();

    private:

        const Property& theOldContainmentProperty;
        DataObjectImpl* theOldContainer;
        const Type& theType;
    };

    /** 
     * DeleteLogItem is a part of a change summary.
     * The change summary consisists of change items, 
     * deletion items and creation items. They are held in three
     * lists as they have slightly different contents.
     * The delete log items hold the old data object , and
     * details of the properties as they were before deletion
     */

    class deleteLogItem {

    public:


        deleteLogItem(DataObject* dob,  const Property& prop,
                        SequencePtr seq,const char *oldpath,
                        DataObjectImpl* cont = 0);


        deleteLogItem(const deleteLogItem& cin); 
        ~deleteLogItem();
        DataObjectImpl* getOldContainer();
        const Property& getOldContainmentProperty();
        const Type& getOldType();
        const char* getOldXpath();
        SettingList& getSettings();
        SequencePtr getSequence();
        void setSequence(SequencePtr s);

    private:

        const Property& theOldContainmentProperty;
        DataObjectImpl* theOldContainer;

        /** theActualObject
         * A counting pointer to the object is held, such that the 
         * object is not freed, even if deleted. This rcp will not
         * be used to refer to the object, but makes sure that the
         * object does not reuse a memory address of a previously
         * deleted object until the change summary is destroyed.
         */

        RefCountingPointer<DataObject> theActualObject;
        const Type& theType;
        SettingList theSettings;
        SequencePtr theSequence;
        char * theOldXpath;
    };


    /** ChangeSummaryImpl implements the abstract class ChangeSummary.
     * The change summary consisists of change items, 
     * deletion items and creation items. They are held in three
     * lists as they have slightly different contents.
     */
 
    class ChangeSummaryImpl : public ChangeSummary
    {
      public:
        ChangeSummaryImpl();

        virtual ~ChangeSummaryImpl();

    /** 
    * The new and modified objects in the list are references to objects that
    * are associated with this change summary. 
    * The deleted objects in the list are references to copies of the objects 
    * as they appeared at the time that event logging was enabled; 
    * if the deleted objects have references to other objects, 
    * the references will also refer to copies of the target objects.
    * Return a list of changed data objects.
       */
    
    virtual ChangedDataObjectList&  getChangedDataObjects();


    /** getOldSettings returns a list of settings.
    * Returns a list of Settings 
    * that represent the property values of the given dataObject
    * at the point when logging began.
    * In the case of a deleted object, 
    * the list will include Settings for all the properties.
    * An old value Setting indicates the value at the
    * point logging begins.  A setting is only produced for 
    * modified objects if either the old value differs from the current value or
    * if the isSet differs from the current value. 
    * No Settings are produced for created objects.
    * Param dataObject the object in question.
    * Return a list of settings.
      */
    virtual SettingList& getOldValues(DataObjectPtr dataObject);

    /**  getOldXpath returns the old path before the setting.
     *
     * Returns a path where the object was located before the setting took place.
       */
    virtual const char* getOldXpath(RefCountingPointer<commonj::sdo::DataObject> dol);


    /**  beginLogging() sets the change summary in logging mode.
     *
     * The change summary is initially inactive. Setting it to logging mode
     * starts the process of recording all the settings made.
     */
    
    virtual void beginLogging();

     /**  endLogging() stops logging.
     *
     * This method stops logging, but does not clear out the change summary.
     * The changes are valid until the summary is next set to logging, at which time
     * all old settings are lost.
     */
    virtual void endLogging();

  
  
    /**  isLogging() returns true if logging is enabled.
     *
     * Indicates whether change logging is on (true) or off (false).
       */

    virtual bool isLogging();


  
   /**  isCreated() returns true if the object was created during logging.
    *
    * Returns whether or not the specified data object was created while logging.
    * Any object that was added to the data graph
    * but was not in the data graph when logging began, 
    * will be considered created.
    * Param dataObject the data object in question.
    * Return true if the specified data object was created.
     */
    virtual bool isCreated(DataObjectPtr dataObject);

    /**  isDeleted() - true if the object was deleted during logging.
     *
     * Returns whether or not the specified data object was deleted while logging.
     * Any object that is not contained by the data graph will be considered 
     * deleted.
     * Param dataObject the data object in question.
     * Return true if the specified data object was deleted.
      */
    virtual bool isDeleted(DataObjectPtr dataObject);


     /**  isModified() - true if the object was changed during logging.
     *
     * Returns whether or not the specified data object was updated while logging.
     * An object that was contained in the data graph when logging began, 
     * and remains in the graph when logging ends will be considered for changes.
     * An object considered modified must have at least one old value Setting.
     * Param dataObject the data object in question.
     * Return true if the specified data object was modified.
      */
    virtual bool isModified(DataObjectPtr dataObject);   

    /**  getOldValue() gets the setting showing the old value.
     *
     * Returns a setting for the specified property
     * representing the property value of the given dataObject
     * at the point when logging began.
     * Returns null if the property has not changed and 
     * has not been deleted. 
     * Param dataObject the object in question.
     * Param property the property of the object.
     * Return the Setting for the specified property.
      */

    virtual const Setting& getOldValue(DataObjectPtr dataObject, const Property& property);

     /**  getOldContainer() gets the container before the setting.
     *
     * Returns the value of the container data object
     * at the point when logging began.
     * Param dataObject the object in question.
     * Return the old container data object.
        */
    virtual DataObjectPtr getOldContainer(DataObjectPtr dataObject);

    /**  getOldContainmentProperty() - gives the property before setting.
     *
     * Returns the value of the containment property data object property
     * at the point when logging began.
     * Param dataObject the object in question.
     * Return the old containment property.
     */
    virtual const Property& getOldContainmentProperty(DataObjectPtr dataObject);  

     /**  undoChanges() - Not Implemented.
     *
     * NOT IMPLEMENTED
     *
     * Undoes all changes in the log to restore the tree of 
     * DataObjects to its original state when logging began.
     * isLogging() is unchanged.  The log is cleared.
      */
    virtual void undoChanges();

    /**  getOldSequence() - Not Implemented.
     *
     * NOT IMPLEMENTED
     *
     * This method gives back the sequence of a data object as it
     * appeared when logging was switched on. The data object may be
     * a deleted data object or a changed data object. If the
     * data object was not sequenced, this returns null.
      */

    virtual SDO_API SequencePtr getOldSequence(DataObjectPtr dataObject);

    bool isInCreatedMap(DataObjectImpl* ob);

    void logDeletion(DataObjectImpl* ob,
                     DataObjectImpl* cont, const Property&  prop,
                     const char* oldpath,
                     bool loggingChildren = true
                     );

    void logCreation(DataObjectImpl* ob,
                    DataObjectImpl* cont, const Property& prop
                    );

    void logChange(DataObjectImpl* ob, const Property& prop
                    );


    SDO_API void debugPrint();

    void removeFromChanges(DataObjectImpl* ob);


    /**
    * appendToCreations is used by deserialization
    * This method helps to rebuild a change summary by populating the 
    * lists without the changes actually being logged.
    */

    void appendToCreations(const Property& p, 
                            DataObjectPtr    dob,
                            DataObjectPtr    cont);


    /**
    * appendToDeletions is used by deserialization
    * This method helps to rebuild a change summary by populating the 
    * lists without the changes actually being logged.
    */
    void appendToDeletions(const Property& p,
                            DataObjectPtr dob, 
                            DataObjectPtr cont,
                            const char* oldpath);


    unsigned int stringConvert(
                            char** value, 
                            const char* c, 
                            const Property& p);

    /**
    * appendToChangesis used by deserialization
    * This method helps to rebuild a change summary by populating the 
    * lists without the changes actually being logged.
    */

    void appendToChanges(const Property& p, 
                            DataObjectPtr dob, 
                            SDOXMLString value,
                            int index);

    void appendToChanges(const Property& p, 
                            DataObjectPtr dob, 
                            DataObjectPtr pdob,
                            int index);

    DataObjectPtr matchDeletedObject(SDOXMLString path);


    private:


        void setPropValue(void** value, unsigned int *len, DataObjectImpl* ob, const Property& prop);
        void setManyPropValue(void** value, unsigned int *len, DataObjectImpl* ob, 
            DataObjectImpl* listob, const Property& prop);
        bool logging;

        typedef std::map<DataObjectImpl*, createLogItem>    CREATELOG_MAP;
        typedef std::map<DataObjectImpl*, deleteLogItem>    DELETELOG_MAP;
        typedef std::map<DataObjectImpl*, changeLogItem>    CHANGELOG_MAP;

        CHANGELOG_MAP changedMap;
        CREATELOG_MAP createdMap;
        DELETELOG_MAP deletedMap;

        ChangedDataObjectListImpl changedDataObjects;





};
};
};
#endif //_CHANGESUMMARYIMPL_H_