두 개의 db4o 데이터베이스간에 복제 기능이 완전히 작동하지 않습니다. 나는 많은 튜토리얼을 따라 왔고 코드는 그들과 동등한 것으로 보인다 (물론 분명하지는 않다). 결과는 ReplicationSession이 변경 사항을 감지하지만 다른 데이터베이스의 변경 사항을 복제하지 않는다는 것을 나타냅니다. 여기 db4o에서 db4o 로의 복제가 제대로 복제되지 않습니다.
private ReflectiveDatabase()
{
openDb();
providerA = new Db4oEmbeddedReplicationProvider(hostContainer);
providerB = new Db4oEmbeddedReplicationProvider(clientContainer);
//Start a new ReplicationSession with event for replacing newest object on conflict.
replication = Replication.begin(providerA, providerB,
new ReplicationEventListener() {
@Override
public void onReplicate(ReplicationEvent replicationEvent) {
if (replicationEvent.isConflict()) {
ObjectState stateDesktop = replicationEvent.stateInProviderA();
ObjectState stateMobile = replicationEvent.stateInProviderB();
if (stateDesktop.modificationDate() >= stateMobile.modificationDate()) {
replicationEvent.overrideWith(stateDesktop);
} else {
replicationEvent.overrideWith(stateMobile);
}
}
}
});
}
public EmbeddedConfiguration configure()
{
EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
configuration.file().generateUUIDs(ConfigScope.GLOBALLY);
configuration.file().generateCommitTimestamps(true);
return configuration;
}
public void openDb()
{
// try to connect to the host
if(hostContainer != null) hostContainer.close();
try
{
hostContainer = Db4oEmbedded.openFile(configure(), "local1.db4o");
}
catch (com.db4o.ext.Db4oIOException e)
{
...
}
// try to connect to the client
if(clientContainer != null)
{
clientContainer.close();
}
try
{
clientContainer = Db4oEmbedded.openFile(configure(), "local2.db4o");
}
catch (com.db4o.ext.Db4oIOException e)
{
...
}
}
그리고
내가 모든 8S 생성하고 데이터베이스에 기록 된 새 개체에 대한 잘public void syncDatabases()
{
// First get the changes of the two replication-partners
ObjectSet<Object> changesOnHost = replication.providerA().objectsChangedSinceLastReplication();
ObjectSet<Object> changesOnClient = replication.providerB().objectsChangedSinceLastReplication();
System.out.println("Changes on Server: " + changesOnHost.size());
System.out.println("Changes on Client: " + changesOnClient.size());
// then iterate over both change-sets and replicate it
for (Object changedObjectOnClient : changesOnClient)
{
replication.replicate(changedObjectOnClient);
}
for (Object changedObjectOnHost : changesOnHost)
{
replication.replicate(changedObjectOnHost);
}
replication.commit();
}
public void writeToClient(Object object)
{
clientContainer.store(object);
clientContainer.commit();
}
작품 타이머에서 실행 된 실제 동기화입니다.
필드 변경과 같이 이러한 데이터베이스 중 하나에서 변경된 개체를 쓰면 동기화 메서드가 실행될 때 변경된 개체가 있음을 인식하고 실제로 올바른 필드이고 해당 필드가 변경되었습니다. . 그러나, 다른 데이터베이스에서 복제되는 개체를 볼 수 없습니다. 필드가 변경된 객체의 필드와 같지 않습니다.
db4o의 복제 기능에 대해 오해가 있습니까? 이것은 2 년차로 내 리그에서 조금 벗어나지 만, 내가 잘못 가고있는 곳을 누군가 볼 수 있다면 크게 감사 할 것입니다.
위의 코드는 bd4o 및 drs의 8.0.249.16098을 사용했습니다 ... – Spleen
버전 7.12로 변경되었으며 예상대로 전체 복제가 있습니다. 이 방법론은 두 버전간에 많은 변화가 있었지만 설명서의 튜토리얼을 다시 읽었을 때와 다릅니다. 왜 버전 8에서 위의 코드가 제대로 작동하지 않는지 모르겠다. – Spleen