Unitils 和 DBMaintainer - 如何使它们与多个用户/模式一起工作?

发布于 2024-11-05 21:32:03 字数 1569 浏览 3 评论 0原文

我正在开发一个新的 Oracle ADF 项目,该项目使用 Oragle 10g 数据库,并且我在我们的项目中使用 Unitils 和 DBMaintainer 来执行以下操作:

  • 更新数据库结构
  • 单元测试
  • 读取种子数据
  • 读取测试数据
  • 列表项

在我们的项目中,我们有2 个架构,以及 2 个有权连接到这些架构的数据库用户。我将它们放在具有增量名称的文件夹结构中,并且我使用 @convention 进行脚本命名。

001_@schemaA_name.sql 
002_@schemaB_name.sql 
003_@schemaA_name.sql 

这适用于 ant 和 DBMaintainer 更新任务,并且我通过为 ant 任务配置额外元素来提供多个用户名。

<target name="create" depends="users-drop, users-create" description="This tasks ... ">
    <updateDatabase scriptLocations="${dbscript.maintainer.dir}" autoCreateDbMaintainScriptsTable="true">
       <database name="${db.user.dans}" driverClassName="${driver}" userName="${db.user.dans}" password="${db.user.dans.pwd}" url="${db.url.full}" schemaNames="${db.user.dans}" />
        <database name="idp" driverClassName="${driver}" userName="${db.user.idp}"
            password="${db.user.idp.pwd}" url="${db.url.full}" schemaNames="${db.user.idp}" />
    </updateDatabase>
</target>

但是,我不知道如何使 DBMaintainer 更新任务从我的数据库模式创建 xsd 模式?

因此,我决定使用 Unitils,因为它的更新创建了 xsd 模式。 我还没有找到有关 Unitils ant 任务的任何描述或文档 - 谁能给出一些提示? 目前,我已经想出通过创建带有 @Dataset 注释的 Junit 测试来运行 Unitils。我可以让它与一种模式和一个数据库用户一起使用。但我不知道如何让它与多个用户一起工作?

这是我的unitils-local.properties 设置:

database.url=jdbc\:oracle\:thin\:@localhost\:1521\:vipu
database.schemaNames=a,b
database.userName=a
database.password=a1

你们中的任何人都可以给我一个提示,如何使Unitils 与第二个用户/模式一起工作? 我将非常感谢您的帮助!

I am working on a new Oracle ADF project, that is using Oragle 10g Database, and I am using Unitils and DBMaintainer in our project for:

  • updating the db structure
  • unittesting
  • read in seed data
  • read in test data
  • List item

In our project, we have 2 schemas, and 2 db users that have privilegies to connect to these schemas. I have them in a folder structure with incremental names and I am using the @convention for script naming.

001_@schemaA_name.sql 
002_@schemaB_name.sql 
003_@schemaA_name.sql 

This works fine with ant and DBMaintainer update task, and I supply the multiple user names by configuring extra elements for the ant task.

<target name="create" depends="users-drop, users-create" description="This tasks ... ">
    <updateDatabase scriptLocations="${dbscript.maintainer.dir}" autoCreateDbMaintainScriptsTable="true">
       <database name="${db.user.dans}" driverClassName="${driver}" userName="${db.user.dans}" password="${db.user.dans.pwd}" url="${db.url.full}" schemaNames="${db.user.dans}" />
        <database name="idp" driverClassName="${driver}" userName="${db.user.idp}"
            password="${db.user.idp.pwd}" url="${db.url.full}" schemaNames="${db.user.idp}" />
    </updateDatabase>
</target>

However, I cant figure out, how to make the DBMaintainer update task create the xsd schemas from my db schemas?

So, I decided to use Unitils, since its update creates xsd schemas.
I haven't found any description or documentation for the Unitils ant tasks - can anyone give some hints?
For the time being I have figured out to run Unitils by creating a Junit test, with @Dataset annotation. I can make it work with one schema, and one db user. But I am out of ideas how to make it work with multiple users?

Here is the unitils-local.properties setup I have:

database.url=jdbc\:oracle\:thin\:@localhost\:1521\:vipu
database.schemaNames=a,b
database.userName=a
database.password=a1

Can any of you guys give me a tip, how to make Unitils work with the second user/schema ??
I will be extremely gratefull for your help!

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

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

发布评论

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

评论(4

天冷不及心凉 2024-11-12 21:32:03

最终我找到了一种方法来注入您选择的任何unitil.properties——通过自己实例化Unitils!

您需要一个调用 @BeforeClass 的方法,在其中执行如下操作:

@BeforeClass
public void initializeUnitils {
    Properties properties;
    ...
    // load properties file/values depending on various conditions
    ...
    Unitils unitils = new Unitils();
    unitils.init(properties);
    Unitils.setInstance( unitils );     
}

我根据加载的 hibernate 配置(通过 @HibernateSessionFactory)选择属性文件,但还应该有其他选项

eventually I found a way to inject any unitil.properties of your choice --- by instantiating Unitils yourself!

You need a method that is evoked @BeforeClass, in which you perform something like the following:

@BeforeClass
public void initializeUnitils {
    Properties properties;
    ...
    // load properties file/values depending on various conditions
    ...
    Unitils unitils = new Unitils();
    unitils.init(properties);
    Unitils.setInstance( unitils );     
}

I choose the properties file depending on which hibernate configuration is loaded (via @HibernateSessionFactory), but there should be other options as well

假扮的天使 2024-11-12 21:32:03

我已经弄清楚如何使 dbmaintain 和 unitils 在多数据库用户支持上协同工作,但解决方案是纯粹的 ant hack。

  1. 我已经使用多数据库用户支持设置了 dbmaintain 的配置。
  2. 我制作了一个带有令牌密钥的unitils-local.properties 文件以供替换。
  3. 我的ant脚本的init目标正在生成一个新的unitils-local.properties文件,通过将用户名/密码/模式的标记替换为适合目标环境的值,然后将其复制到用户主目录。
  4. 我已将测试分类到文件夹中,这些文件夹以模式名称为前缀。
  5. 当调用unitils 时,它会选取刚刚由ant 脚本创建的unitils-local.properties 文件,并发挥其魔力。

它远非漂亮,但它确实有效。

I have figure out how to make dbmaintain and unitils work together on multi-database-user support, but the solution is a pure ant hack.

  1. I have set up the configuration for dbmaintain, using multi-database-user support.
  2. I have made a unitils-local.properties file with token keys for replacement.
  3. The init target of my ant script is generating a new unitils-local.properties file, by replacing tokens for username/password/schema with values that are correct for the target envirnonment, and then copies it to the users home directory.
  4. I have sorted the tests into folders, that are prefixed with the schema name
  5. When unitils is invoked, it picks up the unitils-local.properties file just created by the ant script, and does its magic.

Its far from pretty, but it works.

以为你会在 2024-11-12 21:32:03

查看此链接:http://www.dbmaintain.org/tutorial.html#From_Java_code

具体来说,您可能需要执行以下操作:

databases.names=admin,user,read
database.driverClassName=oracle.jdbc.driver.OracleDriver
database.url=jdbc:oracle:thin://mydb:1521:MYDB
database.admin.username=admin
database.admin.password=adminpwd
database.admin.schemaNames=admin
database.user.userName=user
database.user.password=userpwd
database.user.schemaNames=user
database.read.userName=read
database.read.password=readpwd
database.read.schemaNames=read

此外,此链接可能会有所帮助:http:// www.dbmaintain.org/tutorial.html#Multi-database__user_support

Check out this link: http://www.dbmaintain.org/tutorial.html#From_Java_code

Specifically you may need to do something like:

databases.names=admin,user,read
database.driverClassName=oracle.jdbc.driver.OracleDriver
database.url=jdbc:oracle:thin://mydb:1521:MYDB
database.admin.username=admin
database.admin.password=adminpwd
database.admin.schemaNames=admin
database.user.userName=user
database.user.password=userpwd
database.user.schemaNames=user
database.read.userName=read
database.read.password=readpwd
database.read.schemaNames=read

Also this link may be helpful: http://www.dbmaintain.org/tutorial.html#Multi-database__user_support

伪装你 2024-11-12 21:32:03

我听从了瑞安的建议。当我调试 UnitilsDB 时,我注意到一些变化。

以下是我正在运行的 unitils-local.properties:

database.names=db1,db2
database.driverClassName.db1=oracle.jdbc.driver.OracleDriver
database.url.db1=jdbc:oracle:thin:@db1d.company.com:123:db1d
database.userName.db1=user
database.password.db1=password
database.dialect.db1=oracle
database.schemaNames.db1=user_admin

database.driverClassName.db2=oracle.jdbc.driver.OracleDriver
database.url.db2=jdbc:oracle:thin:@db2s.company.com:456:db2s
database.userName.db2=user
database.password.db2=password
database.dialect.db2=oracle

确保使用 @ConfigurationProperties(prefix = "database.db1") 连接到测试用例中的特定数据库:

@RunWith(UnitilsJUnit4TestClassRunner.class)
@ConfigurationProperties(prefix = "database.db1")
@Transactional
@DataSet
public class MyDAOTest {

..

}

I followed Ryan suggestion. I noticed couple changes when I debugged UnitilsDB.

Following is my running unitils-local.properties:

database.names=db1,db2
database.driverClassName.db1=oracle.jdbc.driver.OracleDriver
database.url.db1=jdbc:oracle:thin:@db1d.company.com:123:db1d
database.userName.db1=user
database.password.db1=password
database.dialect.db1=oracle
database.schemaNames.db1=user_admin

database.driverClassName.db2=oracle.jdbc.driver.OracleDriver
database.url.db2=jdbc:oracle:thin:@db2s.company.com:456:db2s
database.userName.db2=user
database.password.db2=password
database.dialect.db2=oracle

Make sure to use @ConfigurationProperties(prefix = "database.db1") to connecto to particular database in your test case:

@RunWith(UnitilsJUnit4TestClassRunner.class)
@ConfigurationProperties(prefix = "database.db1")
@Transactional
@DataSet
public class MyDAOTest {

..

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