我正在使用OrientDB 2.2.5作为多线程Java Web应用程序的后端,我尝试了许多不同的连接方法。每种方法似乎都有问题。
我基本上需要能够同时调用以使用OrientDB数据库的东西,无论是静态方法还是对象实例。
我尝试了各种方法,并遇到了记录锁定或其他各种异常的问题。该文档显示了折旧的连接池方法(ODatabaseDocumentPool
),互联网上的各种其他来源显示了多种方式(ODatabaseDocumentTx
,OPartitionedDatabasePool
)。
请有人提供可重用的方法来连接到实例(目前只是一个本地)并发出基本查询。还请包括任何连接清理逻辑(我认为这导致我锁定记录的问题,甚至在上次更新后几秒钟)。
任何帮助/指针将不胜感激。
答案 0 :(得分:2)
使用最少1个,最多10个实例的可循环实例池:
Array
(
[user] => Array
(
[0] => stdClass Object
(
[id] => 5
[name] =>
[email] => test@test.com
[password] => test
[role] =>
[status] => 1
)
)
[books] => Array
(
[0] => stdClass Object
(
[id] => 1
[user_id] => 5
[book_id] => 1
[date_issue] => 2016-07-24 00:00:00
[date_return] => 2016-07-25 00:00:00
)
[1] => stdClass Object
(
[id] => 2
[user_id] => 5
[book_id] => 2
[date_issue] => 2016-07-24 00:00:00
[date_return] => 2016-07-25 00:00:00
)
[2] => stdClass Object
(
[id] => 3
[user_id] => 5
[book_id] => 1
[date_issue] => 2016-07-25 00:00:00
[date_return] => 2016-07-25 00:00:00
)
)
[bookdata] => Array
(
[0] => Array
(
[0] => stdClass Object
(
[id] => 1
[title] => PHP Made Easy
[author] => Dietel & Dietel
[serial_no] => 232323
[qty] => 9
[row_no] => 1
[col_no] => 2
[status] => 1
[category_id] => 1
[description] => This is a book about php
)
)
[1] => Array
(
[0] => stdClass Object
(
[id] => 2
[title] => C++
[author] => Dietel & Dietel
[serial_no] => 232323
[qty] => 9
[row_no] => 1
[col_no] => 2
[status] => 1
[category_id] => 1
[description] => This is a book about c++
)
)
[2] => Array
(
[0] => stdClass Object
(
[id] => 1
[title] => PHP Made Easy
[author] => Dietel & Dietel
[serial_no] => 232323
[qty] => 9
[row_no] => 1
[col_no] => 2
[status] => 1
[category_id] => 1
[description] => This is a book about php
)
)
)
)
配置工厂后,您可以获得Graph实例以开始工作。 OrientGraphFactory有两种方法来检索Transactional和Non-Transactional实例:
foreach ($data as $key=> $value) {
echo $key[$value]->id;
}
希望它有所帮助。
答案 1 :(得分:0)
如果您使用文档API,则OPartitionedDatabasePool
是您选择的池。请注意,这是OrientGraphFactory
内部使用的池实现。