长事务

长事务用于支持 AutoCAD 参照编辑功能,对于 ObjectARX 应用程序非常有用。这些类和函数为应用程序提供了一种方案,用于签出实体以进行编辑并将其签回其原始位置。此操作会将原始对象替换为已编辑的对象。有三种类型的长期交易结帐:

  • 从同一图形中的普通块
  • 从图形的外部参照 (外部参照)
  • 从不相关的临时数据库

长事务类和函数概述

主要的长事务类和函数是

  • AcDbLongTransaction.class
  • AcDbLongTransWorkSetIterator.class
  • AcApLongTransactionReactor.class
  • AcApLongTransactionManager.class
  • wblockCloneObject.class

AcDbLongTransaction Class

AcDbLongTransaction是包含跟踪长事务所需信息的类。该类AcDbLongTransactionManager负责创建AcDbLongTransaction对象并将其追加到数据库。然后它返回对象AcDbLongTransaction的AcDbObjectId。与所有其他驻留在数据库的对象一样,其销毁由数据库处理。

注意:AcDbLongTransaction对象在处于活动状态时添加到数据库中,并在事务完成后擦除。它们不存储在 DWG 或 DXF 文件中,因此不是持久性的。

AcDbLongTransWorkSetIterator Class

AcDbLongTransWorkSetIterator提供对工作集中对象的只读访问权限。在构造AcDbLongTransaction::newWorkSetIterator()期间,可以将其设置为仅包含活动工作集,或者包括添加到工作集的对象,因为它们被工作集中的对象(辅助对象)引用。它还可以处理从工作集中移除的对象,无论是通过擦除AcDbLongTransaction::removeFromWorkSet()还是被擦除。

AcApLongTransactionReactor Class

AcApLongTransactionReactor提供特定于长事务操作的通知。它旨在与也将发送的深层克隆通知结合使用,但会因正在执行的签出/签入类型而异。要将这些通知与深层克隆通知连接起来,可以通过调用AcDbLongTransaction::activeIdMap()函数来检索用于克隆的对象AcDbIdMapping。

AcApLongTransactionManager Class

AcApLongTransactionManager是用于启动和控制多头事务的管理器。每个 AutoCAD 会话只有一个acapLongTransactionManager,可通过对象返回的指针进行访问。

AcDbDatabase::wblockCloneObjects() Function

wblockCloneObjects()函数是AcDbDatase的成员。它将对象从一个数据库深度克隆到另一个数据库,并遵循硬引用,以便所有依赖对象也被克隆。当发现重复项时,符号表记录的行为由类型参数确定。下图显示了符号表类型 (enum DuplicateRecordCloning) 和深层克隆类型 (enum DeepCloneType) 之间的关系。

Relationship between DeepCloneTypes and DuplicateRecordCloning for different commands and functions

Command or API Function

DeepCloneType

DuplicateRecordCloning

命令或 API 函数

深度克隆类型

复制记录克隆

copy

kDcCopy

kDrcNotApplicable

explode

kDcExplode

kDrcNotApplicable

block

kDcBlock

kDrcNotApplicable

INSERT/BIND

kDcXrefInsert

kDrcIgnore

XRESOLVE

kDcSymTableMerge

kDrcXrefMangleName

INSERT

kDcInsert

kDrcIgnore

insert()

kDcInsertCopy

kDrcIgnore

WBLOCK

kDcWblock

kDrcNotApplicable

deepCloneObjects()

kDcObjects

kDrcNotApplicable

wblockObjects()

kDcObjects

kDrcIgnore

wblockObjects()

kDcObjects

kDrcReplace

wblockObjects()

kDcObjects

kDrcMangleName

wblockObjects()

kDcObjects

kDrcUnmangleName

长事务示例

这个简单的示例演示如何从另一个数据库中签出实体,在当前数据库中修改它们,然后将其签回原始数据库。作为长事务过程一部分的调用以粗体显示。

void
refEditApiExample()
{
AcDbObjectId transId;
AcDbDatabase* pDb;
TCHAR *fname;
struct resbuf *rb;
// Get a dwg file from the user.
//
rb = acutNewRb(RTSTR);
int stat = acedGetFileD(_T("Pick a drawing"), NULL, _T("dwg"),
0, rb);
if ((stat != RTNORM) || (rb == NULL)) {
acutPrintf(_T("\nYou must pick a drawing file.")); return; }
fname = (TCHAR*)acad_malloc((_tcslen(rb->resval.rstring) + 1) *
sizeof(TCHAR));
_tcscpy(fname, rb->resval.rstring);
acutRelRb(rb);
// Open the dwg file.
//
pDb = new AcDbDatabase(Adesk::kFalse);
if (pDb->readDwgFile(fname) != Acad::eOk) {
acutPrintf(_T("\nSorry, that drawing is probably already
open."));
return;
}
// Get the Block Table and then the model space record.
//
AcDbBlockTable *pBlockTable;
pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pOtherMsBtr;
pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr,
AcDb::kForRead);
pBlockTable->close();
// Create an iterator.
//
AcDbBlockTableRecordIterator *pIter;
pOtherMsBtr->newIterator(pIter);
// Set up an object ID array.
//
AcDbObjectIdArray objIdArray;
// Iterate over the model space BTR. Look specifically
// for lines and append their object ID to the array.
//
for (pIter->start(); !pIter->done(); pIter->step()) {
AcDbEntity *pEntity;
pIter->getEntity(pEntity, AcDb::kForRead);
// Look for only AcDbLine objects and add them to the
// object ID array.
//
if (pEntity->isKindOf(AcDbLine::desc())) {
objIdArray.append(pEntity->objectId());
}
pEntity->close();
}
delete pIter;
pOtherMsBtr->close();
if (objIdArray.isEmpty()) {
acad_free(fname);
acutPrintf(_T("\nYou must pick a drawing file that contains
lines."));
return;
}
// Now get the current database and the object ID for the
// current database's model space BTR.
//
AcDbBlockTable *pThisBlockTable;
acdbHostApplicationServices()->workingDatabase()->
getSymbolTable(pThisBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pThisMsBtr;
pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr,
AcDb::kForWrite);
pThisBlockTable->close();
AcDbObjectId id = pThisMsBtr->objectId();
pThisMsBtr->close();
// Create the long transaction. This will check all the entities
// out of the external database.
//
AcDbIdMapping errorMap;
acapLongTransactionManagerPtr()->checkOut(transId, objIdArray,
id, errorMap);
// Now modify the color of these entities.
//
int colorIndex;
acedGetInt(_T("\nEnter color number to change entities to: "),
&colorIndex);
AcDbObject* pObj;
if (acdbOpenObject(pObj, transId, AcDb::kForRead) == Acad::eOk) {
// Get a pointer to the transaction.
//
AcDbLongTransaction* pLongTrans =
AcDbLongTransaction::cast(pObj);
if (pLongTrans != NULL) {
// Get a work set iterator.
//
AcDbLongTransWorkSetIterator* pWorkSetIter;
pLongTrans->newWorkSetIterator(pWorkSetIter);
// Iterate over the entities in the work set and change
// the color.
for (pWorkSetIter->start(); !pWorkSetIter->done();
pWorkSetIter->step()) {
AcDbEntity *pEntity;
acdbOpenAcDbEntity(pEntity, pWorkSetIter->objectId(),
AcDb::kForWrite);
pEntity->setColorIndex(colorIndex);
pEntity->close();
}
delete pWorkSetIter;
}
pObj->close();
}
// Pause to see the change.
//
TCHAR str[132];
acedGetString(0, _T("\nSee the new colors. Press return to check
the object into the original database"), str);
// Check the entities back in to the original database.
//
acapLongTransactionManagerPtr()->checkIn(transId, errorMap);
// Save the original database, since we have made changes.
//
pDb->saveAs(fname);
// Close/Delete the database
//
delete pDb;
pDb = NULL;
acad_free(fname);
}

长事务 (Long Transactions)的更多相关文章

  1. ogg-01027(长事务)

    OGG-01027(长事务) 示例9-25: WARNING OGG-01027  Long Running Transaction: XID 82.4.242063, Items 0,  Extra ...

  2. mysql 监控长事务

    mysql> desc information_schema.innodb_trx -> ; +----------------------------+----------------- ...

  3. redis学习之——Redis事务(transactions)

    Redis事务:可以一次执行多个命令,本质是一组命令的集合.一个事务中的,所有命令都会序列化,按顺序地串行化执行而不会被其它命令插入,不许加塞. 常用命令:MULTI  开启事务  EXEC 提交事务 ...

  4. SQL Server 查出未提交事务(长事务)SQL

    ),value )); INSERT INTO @tab EXEC('DBCC OPENTRAN WITH TABLERESULTS'); SELECT name,CAST(value AS DATE ...

  5. ogg:Extract 进程遇长事务执行 Forcestop 引发的惨案

    http://www.linuxidc.com/Linux/2015-04/115777.htm SQL> select t.addr,t.START_DATE from v$transacti ...

  6. oracle事务和锁

    数据库事务概括 1. 说明 一组SQL,一个逻辑工作单位,执行时整体修改或者整体回退. 2.事务相关概念 1)事务的提交和回滚:COMMIT/ROLLBACK 2)事务的开始和结束 开始事务:连接到数 ...

  7. oracle事务和锁(转)

    If you use a SET TRANSACTION statement, then it must be the first statement in your transaction. How ...

  8. MySQL 事务与锁机制

    下表展示了本人安装的MariaDB(10.1.19,MySQL的分支)所支持的所有存储引擎概况,其中支持事务的有InnoDB.SEQUENCE,另外InnoDB还支持XA事务,MyISAM不支持事务. ...

  9. mysql 分库分表 ~ 柔性事务

    一 定义 TCC方案是可能是目前最火的一种柔性事务方案二 具体 内容 TCC=try(预设)-confrim(应用确认)-canal(回滚取消)三 目的 解决跨服务调用场景下的分布式事务问题,避免使用 ...

随机推荐

  1. tty的crash分析

    crash> btPID: 410629 TASK: ffff883fea379fa0 CPU: 10 COMMAND: "jupyter-lab"#0 [ffff8823c ...

  2. Java 在PDF中添加水印

    在日常工作和学习中,PDF的普及给人们带来了极大的便利,但同时也出现了很多问题. PDF文件容易复制和传播,版权难以保护. 在海量文件中也很难区分信息,例如,你有没有打开一个文件夹,里面有这么多同名的 ...

  3. 【MySQL】从入门到精通8-SQL数据库编程

    上期:[MySQL]从入门到精通7-设计多对多数据库 第零章:Mac用户看这里: mac终端写MySQL和windows基本相同,除了配置环境变量和启动有些许不同以外. 先配置环境变量,在终端输入vi ...

  4. KingbaseES R6 主备流复制集群创建级联复制案例

    案例环境: 数据库: test=# select version(); version -------------------------------------------------------- ...

  5. 创建多个节点的集群 - Elastic Stack 8.0

    文章转载自:https://mp.weixin.qq.com/s/k6u9Q2nebW9qgZMghQwJng 详述如何安装3个节点的 Elasticsearch 集群.我将使用 Docker 来进行 ...

  6. kubernetes给容器生命周期设置操作事件

    Kubernetes支持预启动和预结束事件. Kubernetes在容器启动的时候发送预启动事件,在容器结束的时候发送预结束事件. 定义预启动和预结束事件操作 下面是Pod的配置文件: # cat l ...

  7. 使用工具SecureCRT通过ssh远程连接Windows server 2019

    Windows Server 2019 开通SSH Server服务 在需要安裝的ws2019开启powershell,执行安装 openssh server 指令 Add-WindowsCapabi ...

  8. @property装饰器和property()函数

    @property装饰器 Python内置的@property装饰器可以把类的方法伪装成属性调用的方式.也就是本来是Foo.func()的调用方法,变成Foo.func的方式. class Peopl ...

  9. Linux+Wine玩火影忍者究极风暴3指南

    如果你的系统没有Wine先装Wine,Wine在各大发行版的源都能找到.记住32位和64位的Wine都要装 去https://www.playonlinux.com/wine/binaries/pho ...

  10. 邻接矩阵dfs

    #include<bits/stdc++.h> using namespace std; int a[11][11]; bool visited[11]; void store_graph ...