Apache Transaction:以事务方式写入文件 - 如何使用 resourceId
如果有人实施了事务写入文件,请帮助我。
相关主题已在之前的线程中讨论过(事务写入)。
用例如下:
如果写入日志文件失败,则应回滚相应的数据库事务。
因此,应以事务方式执行写入文件。
我选择了 Apache Commons Transaction lib。
并且有问题,这不允许我进一步讨论,因为还没有找到适当的文档或示例。
我已经创建了 FileResourceManager 的实例:
FileResourceManager frm = 新 FileResourceManager("c:\cur", "c:\cur", true, 记录器);
据我从这个 Apache Commons Transaction 教程中了解到,我应该实施以下步骤:
开始交易:
frm.start();
获取交易它的 ID:
transactionId = frm. generatedUniqueTxId();
调用方法,这是需要的,例如 writeResource 与 transactionId 和资源Id:
frm.writeResource(transactionId, resourceId);
这里有歧义:
a) 如何将 resourceId
与真实资源连接起来,我应该以事务方式编写?
b) 我现在将以事务方式编写的关于 resourceId
的文件如何?
谢谢你的建议。
If anybody implemented transactional writing to file,please, assist me.
Related topic was discussed in earlier thread(transactional write).
Use case is following:
if writing to log file is failed,that appropriate DB transaction shoud be rolled back.
So the writinig to file should be performed in transactional way.
I've chosen Apache Commons Transaction lib.
And have issue,that doesn't let me go further,because haven't found appropriate documentation or examples.
I have created instance of FileResourceManager:
FileResourceManager frm = new
FileResourceManager("c:\cur",
"c:\cur", true, logger);
As I understand from this Apache Commons Transaction tutorial,i should implement following steps:
start transaction:
frm.start();
get transaction Id for it:
transactionId = frm.generatedUniqueTxId();
call method, that is needed, e.g. writeResource with transactionId and resourceId:
frm.writeResource(transactionId, resourceId);
And here is ambiguity:
a) how can I connect resourceId
with real resource,that I should write transactioanally?
b) how do my file,that I will write transactionally will now about resourceId
?
Thank you for advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止没有人回答,我尝试根据我的最新经验这样做。
有用的文档:
example2(.ppt)
简化算法看起来像(实际上,如示例2所示):
1.初始化FileResourceManager
2.启动FileResourceManager
3.从FileResourceManager实例获取事务Id
4. 使用第 3 步中的交易 ID 开始交易
5.编写您需要的资源 - 这里提到以事务方式编写
,所以看起来这是主要的一步!
6.提交或回滚事务
注意:resourceId,关于我在我的问题中提出的问题,只是 事务文件的名称。
这个命名并没有很好地描述这个属性。
代码,我用过:
As far nobody answers, I try do that from my latest experience.
Useful documentataion:
example2(.ppt)
Simplified algorithm looks like(actually,depicted in example2):
1. initialize FileResourceManager
2. start FileResourceManager
3. get transaction Id from FileResourceManager instance
4. start transaction with transaction Id from step 3
5. write resource you need - here is mentioned write it transactionally
,so looks like it's the major step!
6. commit or rollback transaction
Note: resourceId,about i asked in ,my question, is simply name of transactional file.
This naming doesn't depict very good this attribute.
Code, I used: