在 SymmetricDS Embedded 中创建 SYM 表
Create SYM Tables in SymmetricDS Embedded
我正在尝试将 Symmetricds 3.7 嵌入到使用 H2 数据库的 java 应用程序中。该应用程序是一个客户端节点,并使用来自 SymmetricDS API.
的 class ClientSymmetricEngine
主节点运行独立的 symmetricds 服务器,当我在应用程序中使用先前测试中已配置的数据库时,我能够同步数据。
当运行在一个新的数据库上应用时,抛出这个异常:
java.lang.IllegalStateException: This node has not been configured.Could not find a row in the identity table
at
org.jumpmind.symmetric.service.impl.RegistrationService.openRegistration(RegistrationService.java:562)
at
org.jumpmind.symmetric.service.impl.RegistrationService.openRegistration(RegistrationService.java:530)
at
org.jumpmind.symmetric.service.impl.RegistrationService.openRegistration(RegistrationService.java:519)
at
org.jumpmind.symmetric.AbstractSymmetricEngine.openRegistration(AbstractSymmetricEngine.java:890)
at syncdemo.ClientNode.<init>(ClientNode.java:32)
at syncdemo.SyncDemo.main(SyncDemo.java:37)
如何通过 API 在客户端节点中创建 SYM 表?
我从 获得了同步代码。在 ClientNode class 中使用如下:
public class ClientNode {
private ClientSymmetricEngine cEngine;
private File propFile;
public ClientNode(File file) throws FileNotFoundException, IOException {
propFile = file;
Properties propertiesFile = new Properties();
propertiesFile.load(new FileReader(propFile));
cEngine = new ClientSymmetricEngine(propertiesFile, true);
getcEngine().openRegistration("store", "001");
getcEngine().setup();
getcEngine().start();
}
public ClientSymmetricEngine getcEngine() {
return cEngine;
}
public void setcEngine(ClientSymmetricEngine cEngine) {
this.cEngine = cEngine;
}
}
从这里调用 clientNode class:
public class SyncDemo {
public static void main(String[] args) {
try
{
new ClientNode(new File("/client.properties"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
client.properties 文件的内容:
external.id=001
engine.name=store-001
sync.url=http://192.168.1.107:31415/sync/corp-000
group.id=store
db.url=jdbc:h2:./syncdata/store001;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000
db.driver=org.h2.Driver
db.user=symmetric
registration.url=http://192.168.1.107:31415/sync/corp-000
db.password=
auto.config.database=true
我刚刚注意到,即使客户端节点的数据库中存在 SYM 表,也会抛出相同的异常,除非在 SYM_NODE 和 SYM_NODE_IDENTITY 表中插入适当的数据。
问题已通过修改代码解决:
public ClientNode(File file) throws FileNotFoundException, IOException {
propFile = file;
Properties propertiesFile = new Properties();
propertiesFile.load(new FileReader(propFile));
cEngine = new ClientSymmetricEngine(propertiesFile, true);
getcEngine().setup();
getcEngine().openRegistration("store", "001");
getcEngine().start();
}
我认为 setup() 函数会在数据库中创建配置表,需要在注册前调用。
接受的答案对我不起作用,我仍然遇到同样的错误。我结合接受的答案中的更改以及理解来使用它:
- 每个客户端节点上的sync.url在注册时来自服务器。
- registration.url 告诉客户端节点在哪里可以找到配置(主)节点。
- 如果您过去曾经搞砸过其中任何一个,那么您的 sym_ 表中的某些东西就乱七八糟了。您最好擦除数据库并重新开始。
- sym_ 表不会在嵌入式应用程序中为您自动填充。您必须手动填充它们。
.../samples/insert_sample.sql
文件是你的朋友。
我正在尝试将 Symmetricds 3.7 嵌入到使用 H2 数据库的 java 应用程序中。该应用程序是一个客户端节点,并使用来自 SymmetricDS API.
的 classClientSymmetricEngine
主节点运行独立的 symmetricds 服务器,当我在应用程序中使用先前测试中已配置的数据库时,我能够同步数据。
当运行在一个新的数据库上应用时,抛出这个异常:
java.lang.IllegalStateException: This node has not been configured.Could not find a row in the identity table
at
org.jumpmind.symmetric.service.impl.RegistrationService.openRegistration(RegistrationService.java:562)
at
org.jumpmind.symmetric.service.impl.RegistrationService.openRegistration(RegistrationService.java:530)
at
org.jumpmind.symmetric.service.impl.RegistrationService.openRegistration(RegistrationService.java:519)
at
org.jumpmind.symmetric.AbstractSymmetricEngine.openRegistration(AbstractSymmetricEngine.java:890)
at syncdemo.ClientNode.<init>(ClientNode.java:32)
at syncdemo.SyncDemo.main(SyncDemo.java:37)
如何通过 API 在客户端节点中创建 SYM 表?
我从
public class ClientNode {
private ClientSymmetricEngine cEngine;
private File propFile;
public ClientNode(File file) throws FileNotFoundException, IOException {
propFile = file;
Properties propertiesFile = new Properties();
propertiesFile.load(new FileReader(propFile));
cEngine = new ClientSymmetricEngine(propertiesFile, true);
getcEngine().openRegistration("store", "001");
getcEngine().setup();
getcEngine().start();
}
public ClientSymmetricEngine getcEngine() {
return cEngine;
}
public void setcEngine(ClientSymmetricEngine cEngine) {
this.cEngine = cEngine;
}
}
从这里调用 clientNode class:
public class SyncDemo {
public static void main(String[] args) {
try
{
new ClientNode(new File("/client.properties"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
client.properties 文件的内容:
external.id=001
engine.name=store-001
sync.url=http://192.168.1.107:31415/sync/corp-000
group.id=store
db.url=jdbc:h2:./syncdata/store001;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000
db.driver=org.h2.Driver
db.user=symmetric
registration.url=http://192.168.1.107:31415/sync/corp-000
db.password=
auto.config.database=true
我刚刚注意到,即使客户端节点的数据库中存在 SYM 表,也会抛出相同的异常,除非在 SYM_NODE 和 SYM_NODE_IDENTITY 表中插入适当的数据。
问题已通过修改代码解决:
public ClientNode(File file) throws FileNotFoundException, IOException {
propFile = file;
Properties propertiesFile = new Properties();
propertiesFile.load(new FileReader(propFile));
cEngine = new ClientSymmetricEngine(propertiesFile, true);
getcEngine().setup();
getcEngine().openRegistration("store", "001");
getcEngine().start();
}
我认为 setup() 函数会在数据库中创建配置表,需要在注册前调用。
接受的答案对我不起作用,我仍然遇到同样的错误。我结合接受的答案中的更改以及理解来使用它:
- 每个客户端节点上的sync.url在注册时来自服务器。
- registration.url 告诉客户端节点在哪里可以找到配置(主)节点。
- 如果您过去曾经搞砸过其中任何一个,那么您的 sym_ 表中的某些东西就乱七八糟了。您最好擦除数据库并重新开始。
- sym_ 表不会在嵌入式应用程序中为您自动填充。您必须手动填充它们。
.../samples/insert_sample.sql
文件是你的朋友。