gpt4 book ai didi

java - db4o : ActivationDepth seems to have no effect (?)

转载 作者:行者123 更新时间:2023-12-01 05:39:24 39 4
gpt4 key购买 nike

有人可以向我解释一下为什么要设置吗激活深度似乎没有效果在下面的代码示例中?

此示例创建“ block ”对象,这些对象都具有一个数字和一个子 block 。

由于 ActivationDepth 设置为“2”,我希望仅从 block 01 和 02 中检索数据库,但可以遍历子 block 一直到 block 05(?)。

我猜这意味着整个对象图已加载,而不是仅加载级别 01 和 02,即这正是我通过设置激活深度试图避免的。

这是完整的代码示例:

import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.config.CommonConfiguration;
import com.db4o.config.EmbeddedConfiguration;
import com.db4o.query.Predicate;

public class Test02
{
private final String DATABASE_NAME = "MyDatabase";

public static void main(String[] args)
{
new Test02().test();
}

public void test()
{
storeContent();
exploreContent();
}

private void storeContent()
{
Block block01 = new Block(1);
Block block02 = new Block(2);
Block block03 = new Block(3);
Block block04 = new Block(4);
Block block05 = new Block(5);
Block block06 = new Block(6);

block01.setChild(block02);
block02.setChild(block03);
block03.setChild(block04);
block04.setChild(block05);
block05.setChild(block06);

ObjectContainer container = Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(), DATABASE_NAME);
try
{
container.store(block01);
container.store(block02);
container.store(block03);
container.store(block04);
container.store(block05);
container.store(block06);
}
finally
{
container.close();
}
}

private void exploreContent()
{
EmbeddedConfiguration configEmbedded = Db4oEmbedded.newConfiguration();
CommonConfiguration configCommon = configEmbedded.common();
configCommon.activationDepth(2); // Global activation depth.

ObjectContainer container = Db4oEmbedded.openFile(configEmbedded, DATABASE_NAME);

try
{
int targetNumber = 1;
ObjectSet blocks = getBlocksFromDatabase(container, targetNumber);

System.out.println(String.format("activationDepth : %s ", configEmbedded.common().activationDepth()));
System.out.println(String.format("Blocks found : %s ", blocks.size()));

Block block = blocks.get(0);
System.out.println(block); // Block 01
System.out.println(block.child); // Block 02
System.out.println(block.child.child); // Block 03 // Why are these
System.out.println(block.child.child.child); // Block 04 // blocks available
System.out.println(block.child.child.child.child); // Block 05 // as well ??
// System.out.println(block.child.child.child.child.child); // Block 06
}
finally
{
container.close();
}
}

private ObjectSet getBlocksFromDatabase(ObjectContainer db, final int number)
{
ObjectSet results = db.query
(
new Predicate()
{
@Override
public boolean match(Block block)
{
return block.number == number;
}
}
);

return results;
}
}

class Block
{
public Block child;
public int number;

public Block(int i)
{
number = i;
}

public void setChild(Block ch)
{
child = ch;
}

@Override
public String toString()
{
return String.format("Block number %s / child = %s ", number, child.number);
}

}

最佳答案

我最好的选择是您缺少 db4o-xxx-nqopt.jar,其中包含 NQ 优化所需的类。

当 NQ 查询失败时,运行优化 db4o 的条件仍会运行您的查询,但这次作为评估,需要激活所有候选。

在这种情况下遵循 DiagnoticToConsole() 的输出:

Test02$1@235dd910 :: Native Query Predicate could not be run optimized.

This Native Query was run by instantiating all objects of the candidate class.

Consider simplifying the expression in the Native Query method. If you feel that the Native Query processor should understand your code better, you are invited to post yout query code to db4o forums at http://developer.db4o.com/forums

要解决此问题,请确保至少有 db4o-xxx-core-java5.jardb4o-xxx-nqopt-java5.jardb4o-xxx-instrumentation-java5.jarbloat-1.0.jar 位于您的类路径中。或者,您可以将所有这些 jar 替换为 db4o-xxx-all-java5.jar

关于java - db4o : ActivationDepth seems to have no effect (?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7533350/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com