管理无状态(Web)DB4O应用程序中的唯一ID
我正在尝试使用 DB4O 构建一个新的 Web 应用程序 - 充满乐趣并且学到了一些非常有趣的东西。我正在努力解决的一件事是 DB4O 目前缺乏对无状态应用程序(即大多数 Web 应用程序)的支持以及对自动生成 ID 的需求。
我发现了许多富有创意且有趣的方法,挂钩 DB4O 的事件,使用 GUID比数字 ID 或出于任何原因完全避免使用任何 ID 系统。
虽然每种方法都有其优点,但我想知道不太优雅的方法是否同样是最合适的。考虑下面的伪代码:
If ID == 0 or null
Set ID = (typeof(myObject)).Count
myObject.Save
这似乎是一个非常简单的方法,通常在这里我开始思考,“我错过了一些非常明显的东西”。我有吗?
I'm playing around with building a new web application using DB4O - piles of fun and some really interesting stuff learned. The one thing I'm struggling with is DB4O's current lack of support for stateless applications (i.e. web apps, mostly) and the need for automatically-generated IDs.
There are a number of creative and interesting approaches that I've been able to find that hook into DB4O's events, use GUIDs rather than numeric IDs or for whatever reason avoid using any system of ID at all.
While each approach has its merits, I'm wondering if the less-elegant approach might equally be the best fit. Consider the following pseudo-code:
If ID == 0 or null
Set ID = (typeof(myObject)).Count
myObject.Save
It seems like such a blindingly simple approach, it's usually about here that I start thinking, "I've missed something really obvious". Have I?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在计数之前锁定 myObject 的插入和删除,直到保存之后
you need to lock inserts and deletes of myObject before the count to until after the save
新的db4o-extras 项目包含 AutoIncrementID 支持插件。该项目刚刚开始,我还没有发布编译后的二进制文件。但它通过使用单个属性添加了对“身份”列或自动递增 ID 字段/属性的支持。
The new db4o-extras project contains an AutoIncrementID support add-in. The project was just started, and I havn't yet posted a compiled binary. But it adds support for "Identity" columns or an auto-incremented ID field/property through the use of a single attribute.