| 280 | } |
| 281 | |
| 282 | class Item : public Task::WorkItem |
| 283 | { |
| 284 | public: |
| 285 | Item(IndexCreateTask* task) : Task::WorkItem(task), |
| 286 | m_inuse(false), |
| 287 | m_ownAttach(true), |
| 288 | m_tra(NULL), |
| 289 | m_sort(NULL), |
| 290 | m_ppSequence(0) |
| 291 | {} |
| 292 | |
| 293 | virtual ~Item() |
| 294 | { |
| 295 | if (m_sort) |
| 296 | { |
| 297 | delete m_sort; |
| 298 | m_sort = NULL; |
| 299 | } |
| 300 | |
| 301 | if (!m_ownAttach || !m_attStable) |
| 302 | return; |
| 303 | |
| 304 | Attachment* att = NULL; |
| 305 | { |
| 306 | AttSyncLockGuard guard(*m_attStable->getSync(), FB_FUNCTION); |
| 307 | |
| 308 | att = m_attStable->getHandle(); |
| 309 | if (!att) |
| 310 | return; |
| 311 | fb_assert(att->att_use_count > 0); |
| 312 | } |
| 313 | |
| 314 | FbLocalStatus status; |
| 315 | if (m_tra) |
| 316 | { |
| 317 | BackgroundContextHolder tdbb(att->att_database, att, &status, FB_FUNCTION); |
| 318 | TRA_commit(tdbb, m_tra, false); |
| 319 | } |
| 320 | WorkerAttachment::releaseAttachment(&status, m_attStable); |
| 321 | } |
| 322 | |
| 323 | bool init(thread_db* tdbb) |
| 324 | { |
| 325 | FbStatusVector* status = tdbb->tdbb_status_vector; |
| 326 | Attachment* att = NULL; |
| 327 | |
| 328 | if (m_ownAttach && !m_attStable.hasData()) |
| 329 | m_attStable = WorkerAttachment::getAttachment(status, getTask()->m_dbb); |
| 330 | |
| 331 | if (m_attStable) |
| 332 | att = m_attStable->getHandle(); |
| 333 | |
| 334 | if (!att) |
| 335 | { |
| 336 | if (!status->hasData()) |
| 337 | Arg::Gds(isc_bad_db_handle).copyTo(status); |
| 338 | |
| 339 | return false; |