[英]Using an embedded OrientDB instance is a multithreaded environment
I have an embedded document store setup with OrientDB; 我在OrientDB中有一个嵌入式文档存储设置; using the Object API.
使用对象API。 My application is multithreaded (eg part of my application is a REST) and needs to access the database.
我的应用程序是多线程的(例如,我的应用程序的一部分是REST),并且需要访问数据库。
According to the documentation ( http://www.orientechnologies.com/docs/last/orientdb.wiki/Object-Database.html ), I should be using a ConnectionPool in an application similar to mine. 根据文档( http://www.orientechnologies.com/docs/last/orientdb.wiki/Object-Database.html ),我应该在类似于我的应用程序中使用ConnectionPool。 They provide the following code example:
他们提供以下代码示例:
// OPEN THE DATABASE
OObjectDatabaseTx db= OObjectDatabasePool.global().acquire("remote:localhost/petshop", "admin", "admin");
// REGISTER THE CLASS ONLY ONCE AFTER THE DB IS OPEN/CREATED
db.getEntityManager().registerEntityClass("org.petshop.domain");
try {
...
} finally {
db.close();
}
However, it "appears" that this is doing a fair bit of work. 但是,它“似乎”正在做大量工作。 As far as I can see it, for each REST request I need to make a connection to the database (admittedly the code might be caching the connections).
据我所知,对于每个REST请求,我都需要建立与数据库的连接(当然,代码可能会缓存连接)。 For this I need the username and password everytime which seems strange to me - maybe because I am used to having all this managed for me.
为此,我每次都需要用户名和密码,这对我来说似乎很奇怪-也许是因为我已经习惯了为我管理所有这些。
My question is essentially - have I got this right? 我的问题本质上是-我说对了吗? Do I have to acquire a connection for each REST request using the username and password and then close it afterwards to release the connection back to the pool?
我是否必须使用用户名和密码为每个REST请求获取连接,然后再将其关闭以将连接释放回池中?
From the code i see that OObjectDatabasePool.global() return a Singleton instance with no username and password setted in the constructor of course. 从代码中,我看到OObjectDatabasePool.global()返回了一个Singleton实例,当然在构造函数中没有设置用户名和密码。 I think to avoid using username and password every request do not use OObjectDatabasePool.global() But create your own pool singleton using the OObjectDatabasePool
我认为避免使用用户名和密码每个请求都不要使用OObjectDatabasePool.global(),而是使用OObjectDatabasePool创建自己的池单例
like 喜欢
OObjectDatabasePool singleton = new OObjectDatabasePool("remote:localhost/petshop", "admin", "admin").setup(1,10);;
Then get the db from this instance 然后从该实例获取数据库
just use 只是使用
OObjectDatabaseTx db = singleton.acquire();
// REGISTER THE CLASS ONLY ONCE AFTER THE DB IS OPEN/CREATED
db.getEntityManager().registerEntityClass("org.petshop.domain");
try {
...
} finally {
db.close();
}
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.