在Java小程序中运行OrientDB

3

编辑: 找到了解决方案。这是一个在maven构建过程中压缩代码的问题。在Java小程序中运行OrientDB是可行的。

我在一个Java小程序中启动内存中的OrientDB时遇到了问题。我使用带有OrientDB版本1.0.1的签名小程序。是否有人已经在小程序中实现了OrientDB,并可以验证其可行性或者能够帮助我解决这个异常?

我得到的异常信息:

2012-06-20 11:22:24:734 INFO OrientDB Server v1.0.1 is starting up... [OServer]Exception in thread "thread applet-de.test.all.Applet-1" sun.misc.ServiceConfigurationError: com.orientechnologies.orient.core.sql.OCommandExecutorSQLFactory: Provider com.orientechnologies.orient.core.sql.ODefaultCommandExecutorSQLFactory not found
at sun.misc.Service.fail(Service.java:129)
at sun.misc.Service.access$000(Service.java:111)
at sun.misc.Service$LazyIterator.next(Service.java:273)
at com.orientechnologies.orient.core.sql.OSQLEngine.getCommandFactories(OSQLEngine.java:186)
at com.orientechnologies.orient.core.sql.OSQLEngine.getCommandNames(OSQLEngine.java:216)
at com.orientechnologies.orient.core.sql.OSQLEngine.getCommand(OSQLEngine.java:239)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:41)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:31)
at com.orientechnologies.orient.core.storage.OStorageEmbedded.command(OStorageEmbedded.java:62)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:60)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.createClass(OSchemaShared.java:218)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.createClass(OSchemaShared.java:164)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.createClass(OSchemaShared.java:145)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.createClass(OSchemaShared.java:116)
at com.orientechnologies.orient.core.metadata.schema.OSchemaProxy.createClass(OSchemaProxy.java:65)
at com.orientechnologies.orient.core.metadata.security.OSecurityShared.createMetadata(OSecurityShared.java:259)
at com.orientechnologies.orient.core.metadata.security.OSecurityShared.create(OSecurityShared.java:202)
at com.orientechnologies.orient.core.metadata.security.OSecurityProxy.create(OSecurityProxy.java:37)
at com.orientechnologies.orient.core.metadata.OMetadata.create(OMetadata.java:68)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.create(ODatabaseRecordAbstract.java:171)
at com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.create(ODatabaseWrapperAbstract.java:53)
at com.orientechnologies.orient.core.db.ODatabaseRecordWrapperAbstract.create(ODatabaseRecordWrapperAbstract.java:54)
at com.orientechnologies.orient.server.OServer.loadStorages(OServer.java:451)
at com.orientechnologies.orient.server.OServer.loadConfiguration(OServer.java:394)
at com.orientechnologies.orient.server.OServer.startup(OServer.java:152)
at com.orientechnologies.orient.server.OServer.startup(OServer.java:143)
at com.orientechnologies.orient.server.OServer.startup(OServer.java:132)
at de.test.all.Applet$1.run(Applet.java:132)
at de.test.all.Applet$1.run(Applet.java:125)
at java.security.AccessController.doPrivileged(Native Method)
at de.test.all.Applet.init(Applet.java:124)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1639)
at java.lang.Thread.run(Thread.java:680)

我的小程序代码启动数据库:

    public class Applet extends java.applet.Applet {

    OrientDbConfigurationLoader configLoader = null;
    OServer server = null;
    ODatabaseDocumentTx db = null;

    @Override
    public void init() {
        AccessController.doPrivileged(new
                PrivilegedAction<OServer>() {

            public OServer run() {
                configLoader = new OrientDbConfigurationLoader("db/", "test");

                try {
                    server = OServerMain.create();
                    server.startup(configLoader.loadDefaultConfig());
                    server.activate();
                } catch (InstanceAlreadyExistsException e) {
                    server = OServerMain.server();
                } catch (Exception e) {
                    System.out.println("Something went wrong while the server should start");
                    e.printStackTrace();
                }

                try {
                    db = new ODatabaseDocumentTx("memory:temp");
                    db = db.open(OrientDbConfigurationLoader.USERNAME, OrientDbConfigurationLoader.PASSWORD);
                } catch (Exception e) {
                    System.out.println("Can't init the in-memory db.");
                    e.printStackTrace();
                }
                return null;
            }
        });
    }
}
1个回答

1

问题似乎出在Java服务注册表的使用上。请查看:

OClassLoaderHelper.lookupProviderWithOrientClassLoader()

它被称为:

ServiceRegistry.lookupProviders(clazz);

我刚刚在 SVN 主干(r5909)中添加了此检查:
 try {
          factories.add(ite.next());
        } catch (Exception e) {
          OLogManager.instance().warn(null, "Cannot load OCommandExecutorSQLFactory instance from service registry", e);
        }

这样可以输出一个警告,但如果需要,您仍然可以继续配置自己的工厂。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接