长事务

长事务用于支持 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. what the difference betweent pin page and lock page ?

    以前在项目中,大家为了避免自己使用的page被换出,使用的方式是mlock,从mlock的实现的看,它限制了page被swap, 然后在一个swap off的系统中,这样其实和mlock调用与否没有关 ...

  2. C# 开发过程中常见错误记录及解决说明

    1.异常了类型: 1.1.1.1 异常错误信息:An error occurred while updating the entries. See the inner exception for de ...

  3. 第十三篇:axios网络通信

    好了这事一个非常艰巨的任务  解释以下的全部代码 <template> <div class="hello"> <p style="colo ...

  4. 3款知名RTMP推流模块比较:OBS VS SmartPublisher VS Flash Media Live Encoder

    OBS 功能强大,几乎所有你想要的场景它都有,用起来很顺手.可以将桌面.摄像头.程序窗口通过rtmp推送到流媒体服务器上. 当然如果你是开发者,想基于OBS做二次开发,实现二次产品化的化,难度比较大, ...

  5. 如何为 SAST 工具设置误报基准?

    许多 SAST 工具都无法避免误报的问题.这些工具经常报告一些实际不存在的漏洞,这种不准确性让安全团队耗费大量时间来对误报进行分类和处理,这时设置误报基准就显得十分必要. 通过设置误报基准,安全团队可 ...

  6. 微信小程序-云函数、云存储

    云函数是运行在服务器端的 创建一个目录cloud project.config.json配置云函数目录 cloud目录有个云朵.代表云函数 初始化成功了 新建一个云函数 cloud目录右击 新建一个N ...

  7. Redis基本数据结构ZipList

    为什么要有ziplist 有两点原因: 普通的双向链表,会有两个指针,在存储数据很小的情况下,我们存储的实际数据的大小可能还没有指针占用的内存大,是不是有点得不偿失?而且Redis是基于内存的,而且是 ...

  8. ProxySQL(11):链式规则( flagIN 和 flagOUT )

    文章转载自:https://www.cnblogs.com/f-ck-need-u/p/9350631.html 理解链式规则 在mysql_query_rules表中,有两个特殊字段"fl ...

  9. 9. Ceph 基础篇 - Crush Maps

    文章转载自:https://mp.weixin.qq.com/s?__biz=MzI1MDgwNzQ1MQ==&mid=2247485302&idx=1&sn=00a3a204 ...

  10. logstash知识点

    Logstash是位于Data和Elasticsearch之间的一个中间件.Logstash是一个功能强大的工具,可与各种部署集成. 它提供了大量插件. 它从数据源实时地把数据进行采集,可帮助您解析, ...