1 /* 2 bdb2d is BerkeleyDB for D language 3 It is part of unDE project (http://unde.su) 4 5 Copyright (C) 2009-2014 Nikolay (unDEFER) Krivchenkov <undefer@gmail.com> 6 7 This program is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 module berkeleydb.dblogc; 22 23 import berkeleydb.c; 24 import berkeleydb.dbexception; 25 import berkeleydb.dbenv; 26 import berkeleydb.dbt; 27 import std.stdint; 28 import std.string; 29 30 class DbLogc 31 { 32 private: 33 DB_LOGC *dblogc = null; 34 DbEnv dbenv; 35 int opened; 36 37 package: 38 @property DB_LOGC *_DB_LOGC() {return dblogc;} 39 @property int _opened() {return opened;} 40 41 this(DB_LOGC *dblogc, DbEnv dbenv) 42 { 43 this.dblogc = dblogc; 44 this.dbenv = dbenv; 45 opened = 1; 46 } 47 48 public: 49 ~this() 50 { 51 if (opened > 0) close(); 52 } 53 54 void close(uint32_t flags = 0) 55 { 56 if (opened < 0) { 57 throw new DbWrongUsingException("Closing closed DbLogc"); 58 } 59 auto ret = dblogc.close(dblogc, flags); 60 opened = -1; 61 DbRetCodeToException(ret, dbenv); 62 assert(ret == 0); 63 } 64 65 int get(DbLsn *lsn, Dbt *data, uint32_t flags = 0) 66 { 67 if (opened < 0) { 68 throw new DbWrongUsingException("Operation on closed DbLogc"); 69 } 70 auto ret = dblogc.get(dblogc, lsn, &data.dbt, flags); 71 DbRetCodeToException!"DbLogc.get"(ret, dbenv, data); 72 return DbRetCodeToException!"DbLogc.get"(ret, dbenv); 73 } 74 }