| 195 | } |
| 196 | |
| 197 | ThreadSafeDatabase::ThreadSafeDatabase(ConnectionRecordType connectionRecordType, |
| 198 | std::string connectionRecordString, |
| 199 | int apiVersion) { |
| 200 | // Allocate memory for the Database from this thread (so the pointer is known for subsequent method calls) |
| 201 | // but run its constructor on the main thread |
| 202 | DatabaseContext* db = this->db = DatabaseContext::allocateOnForeignThread(); |
| 203 | |
| 204 | onMainThreadVoid([db, connectionRecordType, connectionRecordString, apiVersion]() { |
| 205 | try { |
| 206 | Reference<IClusterConnectionRecord> connectionRecord = |
| 207 | connectionRecordType == ConnectionRecordType::FILE |
| 208 | ? Reference<IClusterConnectionRecord>(ClusterConnectionFile::openOrDefault(connectionRecordString)) |
| 209 | : Reference<IClusterConnectionRecord>( |
| 210 | new ClusterConnectionMemoryRecord(ClusterConnectionString(connectionRecordString))); |
| 211 | |
| 212 | Database::createDatabase(connectionRecord, apiVersion, IsInternal::False, LocalityData(), db).extractPtr(); |
| 213 | } catch (Error& e) { |
| 214 | new (db) DatabaseContext(e); |
| 215 | } catch (...) { |
| 216 | new (db) DatabaseContext(unknown_error()); |
| 217 | } |
| 218 | }); |
| 219 | } |
| 220 | |
| 221 | ThreadSafeDatabase::~ThreadSafeDatabase() { |
| 222 | DatabaseContext* db = this->db; |
nothing calls this directly
no test coverage detected