jdbc 驱动程序使用 Cockroachdb

Cockroachdb usage with jdbc driver

我想用 Nuxeo 平台试验 CockroachDB,这是一个 java 软件,可以使用 Postgresql jdbc 驱动程序 (postgresql-42.1.1.jar) 连接到数据库。

到目前为止,我可以连接并创建对象,但由于一些问题,其中一些创建无法执行。

1) 使用 cockroachdb 的 SQL 限制是什么?我看过这个页面 https://www.cockroachlabs.com/docs/stable/sql-feature-support.html 但仍然缺少限制。

2) 真的很快,你能给我一些关于我得到的错误的提示吗?例如,我如何使用此数据库创建序列和函数?

非常感谢

这是日志:

2017-07-10 20:00:16,363 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: create table NXP_UIDSEQ (SEQ_ID int4 not null, SEQ_INDEX int4 not null, SEQ_KEY varchar(255) not null unique, primary key (SEQ_ID))
2017-07-10 20:00:16,363 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] ERROR: syntax error at or near "int4"
create table NXP_UIDSEQ (SEQ_ID int4 not null, SEQ_INDEX int4 not null, SEQ_KEY varchar(255) not null unique, primary key (SEQ_ID))
                                ^

2017-07-10 20:00:16,363 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: create sequence hibernate_sequence
2017-07-10 20:00:16,363 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] ERROR: syntax error at or near "sequence"
create sequence hibernate_sequence
       ^

2017-07-10 20:00:16,726 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: create table NXP_LOGS_EXTINFO (DISCRIMINATOR varchar(31) not null, LOG_EXTINFO_ID int8 not null, LOG_EXTINFO_STRING varchar(255), LOG_EXTINFO_BOOLEAN bool, LOG_EXTINFO_DOUBLE float8, LOG_EXTINFO_LONG int8, LOG_EXTINFO_DATE timestamp, LOG_EXTINFO_BLOB oid, primary key (LOG_EXTINFO_ID))
2017-07-10 20:00:16,727 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] ERROR: syntax error at or near "float8"
create table NXP_LOGS_EXTINFO (DISCRIMINATOR varchar(31) not null, LOG_EXTINFO_ID int8 not null, LOG_EXTINFO_STRING varchar(255), LOG_EXTINFO_BOOLEAN bool, LOG_EXTINFO_DOUBLE float8, LOG_EXTINFO_LONG int8, LOG_EXTINFO_DATE timestamp, LOG_EXTINFO_BLOB oid, primary key (LOG_EXTINFO_ID))
                                                                                                                                                                               ^

2017-07-10 20:00:16,734 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: alter table NXP_LOGS_MAPEXTINFOS add constraint FKF96F609C4EA9779 foreign key (INFO_FK) references NXP_LOGS_EXTINFO
2017-07-10 20:00:16,734 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] ERROR: referenced table "nxp_logs_extinfo" not found
2017-07-10 20:00:16,750 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: create sequence hibernate_sequence
2017-07-10 20:00:16,750 ERROR [localhost-startStop-1] [org.hibernate.tool.hbm2ddl.SchemaUpdate] ERROR: syntax error at or near "sequence"
create sequence hibernate_sequence
       ^

2017-07-10 20:00:16,832 WARN  [localhost-startStop-1] [org.nuxeo.elasticsearch.core.ElasticSearchAdminImpl] Elasticsearch embedded configuration is ONLY for testing purpose. You need to create a dedicated Elasticsearch cluster for production.
2017-07-10 20:00:27,034 WARN  [localhost-startStop-1] [org.elasticsearch.env] [nuxeoNode] max file descriptors [10240] for elasticsearch process likely too low, consider increasing to at least [65536]
2017-07-10 20:00:29,863 INFO  [localhost-startStop-1] [org.nuxeo.elasticsearch.audit.ESAuditBackend] Activate Elasticsearch backend for Audit
2017-07-10 20:00:30,200 ERROR [localhost-startStop-1] [org.nuxeo.runtime.model.impl.RegistrationInfoImpl] Component service:org.nuxeo.ecm.core.repository.RepositoryServiceComponent notification of application started failed: java.sql.SQLException: Error executing: CREATE FUNCTION nx_in_tree(id varchar, baseid varchar)
RETURNS boolean
AS $$
DECLARE
  curid varchar(36) := id;
BEGIN
  IF baseid IS NULL OR id IS NULL OR baseid = id THEN
    RETURN false;
  END IF;
  LOOP
    SELECT parentid INTO curid FROM hierarchy WHERE hierarchy.id = curid;
    IF curid IS NULL THEN
      RETURN false;
    ELSEIF curid = baseid THEN
      RETURN true;
    END IF;
  END LOOP;
END $$
LANGUAGE plpgsql
STABLE
COST 400; : ERROR: unknown function: pg_get_function_identity_arguments()
org.nuxeo.ecm.core.api.NuxeoException: java.sql.SQLException: Error executing: CREATE FUNCTION nx_in_tree(id varchar, baseid varchar)
RETURNS boolean
AS $$
DECLARE
  curid varchar(36) := id;
BEGIN
  IF baseid IS NULL OR id IS NULL OR baseid = id THEN
    RETURN false;
  END IF;
  LOOP
    SELECT parentid INTO curid FROM hierarchy WHERE hierarchy.id = curid;
    IF curid IS NULL THEN
      RETURN false;
    ELSEIF curid = baseid THEN
      RETURN true;
    END IF;
  END LOOP;
END $$
LANGUAGE plpgsql
STABLE
COST 400; : ERROR: unknown function: pg_get_function_identity_arguments()
    at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapper.createDatabase(JDBCMapper.java:172)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapperConnector.doInvoke(JDBCMapperConnector.java:52)
    at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapperConnector.lambda$doConnectAndInvoke[=11=](JDBCMapperConnector.java:101)
    at org.nuxeo.runtime.transaction.TransactionHelper.runWithoutTransaction(TransactionHelper.java:498)
    at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapperConnector.doConnectAndInvoke(JDBCMapperConnector.java:97)
    at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapperConnector.invoke(JDBCMapperConnector.java:92)
    at com.sun.proxy.$Proxy63.createDatabase(Unknown Source)
    at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCBackend.newMapper(JDBCBackend.java:169)
    at org.nuxeo.ecm.core.storage.sql.RepositoryImpl.newMapper(RepositoryImpl.java:269)
    at org.nuxeo.ecm.core.storage.sql.RepositoryImpl.getConnection(RepositoryImpl.java:251)
    at org.nuxeo.ecm.core.storage.sql.ra.ManagedConnectionFactoryImpl.initialize(ManagedConnectionFactoryImpl.java:250)
    at org.nuxeo.ecm.core.storage.sql.ra.ManagedConnectionFactoryImpl.createManagedConnection(ManagedConnectionFactoryImpl.java:157)
    at org.apache.geronimo.connector.outbound.MCFConnectionInterceptor.getConnection(MCFConnectionInterceptor.java:49)
    at org.apache.geronimo.connector.outbound.XAResourceInsertionInterceptor.getConnection(XAResourceInsertionInterceptor.java:41)
    at org.apache.geronimo.connector.outbound.SinglePoolMatchAllConnectionInterceptor.internalGetConnection(SinglePoolMatchAllConnectionInterceptor.java:88)
    at org.apache.geronimo.connector.outbound.AbstractSinglePoolConnectionInterceptor.getConnection(AbstractSinglePoolConnectionInterceptor.java:80)
    at org.nuxeo.runtime.jtajca.NuxeoPool.getConnection(NuxeoPool.java:66)
    at org.apache.geronimo.connector.outbound.ThreadLocalCachingConnectionInterceptor.getConnection(ThreadLocalCachingConnectionInterceptor.java:70)
    at org.apache.geronimo.connector.outbound.TransactionEnlistingInterceptor.getConnection(TransactionEnlistingInterceptor.java:49)
    at org.apache.geronimo.connector.outbound.TransactionCachingInterceptor.getConnection(TransactionCachingInterceptor.java:101)
    at org.apache.geronimo.connector.outbound.ConnectionHandleInterceptor.getConnection(ConnectionHandleInterceptor.java:43)
    at org.apache.geronimo.connector.outbound.TCCLInterceptor.getConnection(TCCLInterceptor.java:39)
    at org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor.getConnection(ConnectionTrackingInterceptor.java:66)
    at org.apache.geronimo.connector.outbound.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:77)
    at org.nuxeo.runtime.jtajca.NuxeoContainer$ConnectionManagerWrapper.allocateConnection(NuxeoContainer.java:753)
    at org.nuxeo.ecm.core.storage.sql.ra.ConnectionFactoryImpl.getConnection(ConnectionFactoryImpl.java:103)
    at org.nuxeo.ecm.core.storage.sql.ra.ConnectionFactoryImpl.getSession(ConnectionFactoryImpl.java:166)
    at org.nuxeo.ecm.core.repository.RepositoryService.getSession(RepositoryService.java:212)
    at org.nuxeo.ecm.core.api.local.LocalSession.createSession(LocalSession.java:127)
    at org.nuxeo.ecm.core.api.local.LocalSession.<init>(LocalSession.java:84)
    at org.nuxeo.ecm.core.api.CoreSessionServiceImpl.createCoreSession(CoreSessionServiceImpl.java:43)
    at org.nuxeo.ecm.core.api.CoreInstance.openCoreSession(CoreInstance.java:171)
    at org.nuxeo.ecm.core.api.CoreInstance.openCoreSession(CoreInstance.java:71)
    at org.nuxeo.ecm.core.api.UnrestrictedSessionRunner.runUnrestricted(UnrestrictedSessionRunner.java:129)
    at org.nuxeo.ecm.core.repository.RepositoryService.openRepository(RepositoryService.java:127)
    at org.nuxeo.ecm.core.repository.RepositoryService.initRepositories(RepositoryService.java:98)
    at org.nuxeo.runtime.transaction.TransactionHelper.lambda$runInTransaction(TransactionHelper.java:539)
    at org.nuxeo.runtime.transaction.TransactionHelper.runInTransaction(TransactionHelper.java:559)
    at org.nuxeo.runtime.transaction.TransactionHelper.runInTransaction(TransactionHelper.java:539)
    at org.nuxeo.ecm.core.repository.RepositoryService.applicationStarted(RepositoryService.java:87)
    at org.nuxeo.runtime.model.impl.RegistrationInfoImpl.notifyApplicationStarted(RegistrationInfoImpl.java:332)
    at org.nuxeo.runtime.osgi.OSGiRuntimeService.notifyComponentsOnStarted(OSGiRuntimeService.java:482)
    at org.nuxeo.runtime.osgi.OSGiRuntimeService.fireApplicationStarted(OSGiRuntimeService.java:518)
    at org.nuxeo.runtime.api.ServicePassivator$Waiter.proceed(ServicePassivator.java:415)
    at org.nuxeo.runtime.api.ServicePassivator.proceed(ServicePassivator.java:83)
    at org.nuxeo.runtime.osgi.OSGiRuntimeService.frameworkEvent(OSGiRuntimeService.java:530)
    at org.nuxeo.osgi.OSGiAdapter.fireFrameworkEvent(OSGiAdapter.java:232)
    at org.nuxeo.osgi.application.loader.FrameworkLoader.doStart(FrameworkLoader.java:241)
    at org.nuxeo.osgi.application.loader.FrameworkLoader.start(FrameworkLoader.java:125)
    at org.nuxeo.runtime.deployment.NuxeoStarter.start(NuxeoStarter.java:120)
    at org.nuxeo.runtime.deployment.NuxeoStarter.contextInitialized(NuxeoStarter.java:93)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:679)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1966)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: Error executing: CREATE FUNCTION nx_in_tree(id varchar, baseid varchar)
RETURNS boolean
AS $$
DECLARE
  curid varchar(36) := id;
BEGIN
  IF baseid IS NULL OR id IS NULL OR baseid = id THEN
    RETURN false;
  END IF;
  LOOP
    SELECT parentid INTO curid FROM hierarchy WHERE hierarchy.id = curid;
    IF curid IS NULL THEN
      RETURN false;
    ELSEIF curid = baseid THEN
      RETURN true;
    END IF;
  END LOOP;
END $$
LANGUAGE plpgsql
STABLE
COST 400; : ERROR: unknown function: pg_get_function_identity_arguments()
    at org.nuxeo.ecm.core.storage.sql.jdbc.dialect.SQLStatement.execute(SQLStatement.java:374)
    at org.nuxeo.ecm.core.storage.sql.jdbc.SQLInfo.executeSQLStatements(SQLInfo.java:1290)
    at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapper.createTables(JDBCMapper.java:207)
    at org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapper.createDatabase(JDBCMapper.java:170)
    ... 67 more
Caused by: org.postgresql.util.PSQLException: ERROR: unknown function: pg_get_function_identity_arguments()
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
    at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
    at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:231)
    at org.tranql.connector.jdbc.StatementHandle.executeQuery(StatementHandle.java:47)
    at org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.checkStoredProcedure(DialectPostgreSQL.java:1308)
    at org.nuxeo.ecm.core.storage.sql.jdbc.dialect.SQLStatement.execute(SQLStatement.java:365)
    ... 70 more
2017-07-10 20:01:00,264 INFO  [localhost-startStop-1] [org.nuxeo.ecm.automation.core.AutomationComponent] You can activate automation trace mode to get more informations on automation executions
2017-07-10 20:01:00,459 ERROR [localhost-startStop-1] [org.nuxeo.runtime.model.impl.RegistrationInfoImpl] Component service:org.nuxeo.ecm.directory.DirectoryServiceImpl notification of application started failed: Table 'Table(continent)' creation failed: ERROR: multiple primary keys for table "continent" are not allowed
org.nuxeo.ecm.directory.DirectoryException: Table 'Table(continent)' creation failed: ERROR: multiple primary keys for table "continent" are not allowed
    at org.nuxeo.ecm.directory.sql.SQLHelper.createTable(SQLHelper.java:136)
    at org.nuxeo.ecm.directory.sql.SQLHelper.setupTable(SQLHelper.java:92)
    at org.nuxeo.ecm.directory.sql.SQLDirectory.initConnection(SQLDirectory.java:239)
    at org.nuxeo.ecm.directory.sql.SQLDirectory.initConnectionIfNeeded(SQLDirectory.java:175)
    at org.nuxeo.ecm.directory.sql.SQLDirectory.getSession(SQLDirectory.java:261)
    at org.nuxeo.ecm.directory.DirectoryServiceImpl.applicationStarted(DirectoryServiceImpl.java:85)
    at org.nuxeo.runtime.model.impl.RegistrationInfoImpl.notifyApplicationStarted(RegistrationInfoImpl.java:332)
    at org.nuxeo.runtime.osgi.OSGiRuntimeService.notifyComponentsOnStarted(OSGiRuntimeService.java:482)
    at org.nuxeo.runtime.osgi.OSGiRuntimeService.fireApplicationStarted(OSGiRuntimeService.java:518)
    at org.nuxeo.runtime.api.ServicePassivator$Waiter.proceed(ServicePassivator.java:415)
    at org.nuxeo.runtime.api.ServicePassivator.proceed(ServicePassivator.java:83)
    at org.nuxeo.runtime.osgi.OSGiRuntimeService.frameworkEvent(OSGiRuntimeService.java:530)
    at org.nuxeo.osgi.OSGiAdapter.fireFrameworkEvent(OSGiAdapter.java:232)
    at org.nuxeo.osgi.application.loader.FrameworkLoader.doStart(FrameworkLoader.java:241)
    at org.nuxeo.osgi.application.loader.FrameworkLoader.start(FrameworkLoader.java:125)
    at org.nuxeo.runtime.deployment.NuxeoStarter.start(NuxeoStarter.java:120)
    at org.nuxeo.runtime.deployment.NuxeoStarter.contextInitialized(NuxeoStarter.java:93)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:679)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1966)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.postgresql.util.PSQLException: ERROR: multiple primary keys for table "continent" are not allowed
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
    at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:260)
    at org.tranql.connector.jdbc.StatementHandle.execute(StatementHandle.java:119)
    at org.nuxeo.ecm.directory.sql.SQLHelper.createTable(SQLHelper.java:133)

CockroachDB 1.0 不支持序列或 PL/pgSQL 函数。 1.0 中也缺少对较小整数数据类型(int4int2)的支持,但会在 1.1 中出现。

虽然 PL/pgSQL 不在当前的 CockroachDB 路线图上,但序列在。 CREATE SEQUENCE 的跟踪问题可用 on GitHub

Nuxeo 平台使用高级 PostgreSQL(或其他原生 SQL 数据库,如 MySQL、Oracle 或 SQL Server)功能和存储 procedures/functions .它是否与 CockroachDB 开箱即用兼容是值得怀疑的。

另一种选择是使用像 MongoDB 或 MarkLogic 这样的 NoSQL 数据库作为后端数据库,而不是 SQL 数据库。但是Nuxeo目前不直接支持CockroachDB。