1 /****************************************************************************** 2 * $Id: ogremulatedtransaction.h b55a33407a80673ec314b165c82f47dd02e9dc9c 2020-04-27 20:37:55 +0200 Even Rouault $ 3 * 4 * Project: OpenGIS Simple Features Reference Implementation 5 * Purpose: Defines OGRDataSourceWithTransaction class 6 * Author: Even Rouault, even dot rouault at spatialys dot com 7 * 8 ****************************************************************************** 9 * Copyright (c) 2015, Even Rouault <even dot rouault at spatialys dot com> 10 * 11 * Permission is hereby granted, free of charge, to any person obtaining a 12 * copy of this software and associated documentation files (the "Software"), 13 * to deal in the Software without restriction, including without limitation 14 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 * and/or sell copies of the Software, and to permit persons to whom the 16 * Software is furnished to do so, subject to the following conditions: 17 * 18 * The above copyright notice and this permission notice shall be included 19 * in all copies or substantial portions of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 * DEALINGS IN THE SOFTWARE. 28 ****************************************************************************/ 29 30 #ifndef OGREMULATEDTRANSACTION_H_INCLUDED 31 #define OGREMULATEDTRANSACTION_H_INCLUDED 32 33 #include "ogrsf_frmts.h" 34 35 /** IOGRTransactionBehaviour is an interface that a driver must implement 36 * to provide emulation of transactions. 37 * 38 * @since GDAL 2.0 39 */ 40 class CPL_DLL IOGRTransactionBehaviour 41 { 42 public: 43 virtual ~IOGRTransactionBehaviour(); 44 45 /** Start a transaction. 46 * 47 * The implementation may update the poDSInOut reference by closing 48 * and reopening the datasource (or assigning it to NULL in case of error). 49 * In which case bOutHasReopenedDS must be set to TRUE. 50 * 51 * The implementation can for example backup the existing files/directories 52 * that compose the current datasource. 53 * 54 * @param poDSInOut datasource handle that may be modified 55 * @param bOutHasReopenedDS output boolean to indicate if datasource has been closed 56 * @return OGRERR_NONE in case of success 57 */ 58 virtual OGRErr StartTransaction(OGRDataSource*& poDSInOut, 59 int& bOutHasReopenedDS) = 0; 60 61 /** Commit a transaction. 62 * 63 * The implementation may update the poDSInOut reference by closing 64 * and reopening the datasource (or assigning it to NULL in case of error). 65 * In which case bOutHasReopenedDS must be set to TRUE. 66 * 67 * The implementation can for example remove the backup it may have done 68 * at StartTransaction() time. 69 * 70 * @param poDSInOut datasource handle that may be modified 71 * @param bOutHasReopenedDS output boolean to indicate if datasource has been closed 72 * @return OGRERR_NONE in case of success 73 */ 74 virtual OGRErr CommitTransaction(OGRDataSource*& poDSInOut, 75 int& bOutHasReopenedDS) = 0; 76 77 /** Rollback a transaction. 78 * 79 * The implementation may update the poDSInOut reference by closing 80 * and reopening the datasource (or assigning it to NULL in case of error). 81 * In which case bOutHasReopenedDS must be set to TRUE. 82 * 83 * The implementation can for example restore the backup it may have done 84 * at StartTransaction() time. 85 * 86 * @param poDSInOut datasource handle that may be modified 87 * @param bOutHasReopenedDS output boolean to indicate if datasource has been closed 88 * @return OGRERR_NONE in case of success 89 */ 90 virtual OGRErr RollbackTransaction(OGRDataSource*& poDSInOut, 91 int& bOutHasReopenedDS) = 0; 92 }; 93 94 /** Returns a new datasource object that adds transactional behavior to an existing datasource. 95 * 96 * The provided poTransactionBehaviour object should implement driver-specific 97 * behavior for transactions. 98 * 99 * The generic mechanisms offered by the wrapper class do not cover concurrent 100 * updates (though different datasource connections) to the same datasource files. 101 * 102 * There are restrictions on what can be accomplished. For example it is not 103 * allowed to have a unreleased layer returned by ExecuteSQL() before calling 104 * StartTransaction(), CommitTransaction() or RollbackTransaction(). 105 * 106 * Layer structural changes are not allowed after StartTransaction() if the 107 * layer definition object has been returned previously with GetLayerDefn(). 108 * 109 * @param poBaseDataSource the datasource to which to add transactional behavior. 110 * @param poTransactionBehaviour an implementation of the IOGRTransactionBehaviour interface. 111 * @param bTakeOwnershipDataSource whether the returned object should own the 112 * passed poBaseDataSource (and thus destroy it 113 * when it is destroyed itself). 114 * @param bTakeOwnershipTransactionBehavior whether the returned object should own 115 * the passed poTransactionBehaviour 116 * (and thus destroy it when 117 * it is destroyed itself). 118 * @return a new datasource handle 119 * @since GDAL 2.0 120 */ 121 OGRDataSource CPL_DLL* OGRCreateEmulatedTransactionDataSourceWrapper( 122 OGRDataSource* poBaseDataSource, 123 IOGRTransactionBehaviour* poTransactionBehaviour, 124 int bTakeOwnershipDataSource, 125 int bTakeOwnershipTransactionBehavior); 126 127 #endif // OGREMULATEDTRANSACTION_H_INCLUDED 128