对事务中需要的 DDL 语句进行单元测试

发布于 2024-07-21 00:36:41 字数 662 浏览 9 评论 0原文

我正在开发一个使用 Oracle 内置身份验证机制来管理用户帐户和密码的应用程序。 该应用程序还使用行级安全性。 基本上,通过应用程序注册的每个用户都会获得 Oracle 用户名和密码,而不是“USERS”表中的典型条目。 用户还会收到某些桌子上的标签。 此类功能要求在许多实例中组合执行 DML 和 DDL 语句,但这会带来问题,因为 DDL 语句执行隐式提交。 如果执行 DDL 语句后发生错误,事务管理不会回滚所有内容。 例如,当新用户在系统中注册时,可能会发生以下情况:

  1. 启动事务
  2. 将人员详细信息插入表中。 (即名字、姓氏等) -DML
  3. 创建oracle帐户(创建由密码标识的用户testuser;) -DDL 隐式提交。 交易结束。
  4. 新的交易开始。
  5. 执行更多 DML 语句(插入、更新等)。
  6. 发生错误,事务仅回滚到步骤 4。

我知道上述逻辑按设计工作,但我发现很难对此类功能进行单元测试并在数据访问层中对其进行管理。 我在单元测试期间发生了数据库故障或错误,导致测试模式被本应回滚的测试数据污染。 发生这种情况时,擦除测试模式很容易,但我担心生产环境中的数据库故障。 我正在寻找管理这个问题的策略。

这是一个 Java/Spring 应用程序。 Spring提供事务管理。

I am working on an application that uses Oracle's built in authentication mechanisms to manage user accounts and passwords. The application also uses row level security. Basically every user that registers through the application gets an Oracle username and password instead of the typical entry in a "USERS" table. The users also receive labels on certain tables. This type of functionality requires that the execution of DML and DDL statements be combined in many instances, but this poses a problem because the DDL statements perform implicit commits. If an error occurs after a DDL statement has executed, the transaction management will not roll everything back. For example, when a new user registers with the system the following might take place:

  1. Start transaction
  2. Insert person details into a table. (i.e. first name, last name, etc.) -DML
  3. Create an oracle account (create user testuser identified by password;) -DDL implicit commit. Transaction ends.
  4. New transaction begins.
  5. Perform more DML statments (inserts,updates,etc).
  6. Error occurs, transaction only rolls back to step 4.

I understand that the above logic is working as designed, but I'm finding it difficult to unit test this type of functionality and manage it in data access layer. I have had the database go down or errors occur during the unit tests that caused the test schema to be contaminated with test data that should have been rolled back. It's easy enough to wipe the test schema when this happens, but I'm worried about database failures in a production environment. I'm looking for strategies to manage this.

This is a Java/Spring application. Spring is providing the transaction management.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浴红衣 2024-07-28 00:36:41

您应该将 Oracle 代理身份验证与行级安全性结合使用。

阅读此内容:http://www.oracle.com/technology /pub/articles/dikmans-toplink-security.html

You should use Oracle proxy authentication in combination with row level security.

Read this: http://www.oracle.com/technology/pub/articles/dikmans-toplink-security.html

寄意 2024-07-28 00:36:41

首先我必须说:这样做是个坏主意。 有两个原因:

  1. 连接基于用户。 这意味着您在很大程度上失去了连接池的好处。 它的扩展性也不是很好。 如果您同时有 10,000 个用户,您将不断打开和关闭硬连接(而不是软连接池); 正如
  2. 您所发现的,创建和删除用户是 DDL 而不是 DML,因此您会失去“事务性”。

不确定您为什么选择这样做,但我强烈建议您在应用程序而不是数据库层实现用户。

至于如何解决你的问题,基本上是无法解决的。 与在序列中间创建表或索引相同。

First off I have to say: bad idea doing it this way. For two reasons:

  1. Connections are based on user. That means you largely lose the benefits of connection pooling. It also doesn't scale terribly well. If you have 10,000 users on at once, you're going to be continually opening and closing hard connections (rather than soft connection pools); and
  2. As you've discovered, creating and removing users is DDL not DML and thus you lose "transactionality".

Not sure why you've chosen to do it this but I would strongly recommend you implement users at the application and not the database layer.

As for how to solve your problem, basically you can't. Same as if you were creating a table or an index in the middle of your sequence.

止于盛夏 2024-07-28 00:36:41

我不同意之前的一些评论,并指出使用内置 Oracle 帐户安全性有很多优点。 如果您必须使用某种带有附加信息的用户影子表来扩充它,那么如何将 Oracle 帐户创建包装在声明为 PRAGMA AUTONOMOUS_TRANSACTION 的单独包中,并向执行插入操作的包返回成功/失败状态影子表? 我相信这会将 Oracle 帐户创建与交易隔离开来。

I'll disagree with some of the previous comments and say that there are a lot of advantages to using the built-in Oracle account security. If you have to augment this with some sort of shadow table of users with additional information, how about wrapping the Oracle account creation in a separate package that is declared PRAGMA AUTONOMOUS_TRANSACTION and returns a sucess/failure status to the package that is doing the insert into the shadow table? I believe this would isolate the Oracle account creation from the transaction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文