如何在 Quartz 中使用 SQLite? [英] How can I use SQLite in Quartz?

查看:162
本文介绍了如何在 Quartz 中使用 SQLite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在应用程序中使用 Quartz 和 SQLite.当我阅读文档 here 时,我注意到他们没有在可用的数据库中提到 SQLite.他们说:

I'm trying to use quartz with SQLite in an application . When I read the documentation here I notice that they didn't mention SQLite among the databases available. They say:

JDBCJobStore 几乎适用于任何数据库,它已被广泛使用使用 Oracle、PostgreSQL、MySQL、MS SQLServer、HSQLDB 和 DB2.使用JDBCJobStore,首先要创建一组数据库表石英使用.您可以在以下目录中找到创建表的 SQL 脚本Quartz 发行版的docs/dbTables"目录.

JDBCJobStore works with nearly any database, it has been used widely with Oracle, PostgreSQL, MySQL, MS SQLServer, HSQLDB, and DB2. To use JDBCJobStore, you must first create a set of database tables for Quartz to use. You can find table-creation SQL scripts in the "docs/dbTables" directory of the Quartz distribution.

所以,从这个问题:哪个用于设置石英 sqlite 表的设置脚本? 我使用 derby 脚本作为我的 sqlite 脚本.

So, from this question: Which setup script to use for setting up quartz sqlite table? I use derby script to be applied as my sqlite script.

问题是当我尝试在之前插入的作业中安排触发器时.这是我的代码的一部分:

The problem is when I trying to schedule a trigger in a previous inserted job. This is part of my code:

// and start it off
scheduler.start();

Map<String, String> map = new HashMap<>();
map.put("key", "value");

JobDataMap jdm = new JobDataMap(map);

JobKey key = new JobKey("job1", "key1");

 if(!scheduler.checkExists(key)){
     JobDetail job = newJob(HelloJob.class).withIdentity(key).storeDurably().usingJobData(jdm).build();
     addJob(scheduler, job);

     // Trigger the job to run now, and then repeat every 40 seconds
    Trigger trigger = newTrigger()
         .withIdentity("trigger1", "group1")
         .startNow()
            .forJob(job)
               .withSchedule(simpleSchedule()
                 .withIntervalInSeconds(40)
                 .repeatForever())            
         .build();

    // Tell quartz to schedule the job using our trigger
    scheduler.scheduleJob(trigger); // here is where I get an error
 }

Thread.sleep(60000);

scheduler.shutdown();

我的quartz.properties 是这样的:

My quartz.properties is this:

org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 5
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.dataSource.SQLiteDB.driver = org.sqlite.JDBC
org.quartz.dataSource.SQLiteDB.URL = jdbc:sqlite:bota.db
org.quartz.dataSource.SQLiteDB.maxConnections = 30
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = SQLiteDB

我正在使用 sqlite v-3.8.11.2 和石英 v-2.2.2.这是我在日志中得到的:

I'm using sqlite v-3.8.11.2 and quartz v-2.2.2. This is what I get in the log:

org.quartz.JobPersistenceException: Couldn't store trigger 'group1.trigger1' for 'key1.job1' job:Couldn't retrieve job: not implemented by SQLite JDBC driver [See nested exception: org.quartz.JobPersistenceException: Couldn't retrieve job: not implemented by SQLite JDBC driver [See nested exception: java.sql.SQLException: not implemented by SQLite JDBC driver]]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1223)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport$4.executeVoid(JobStoreSupport.java:1159)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport$VoidTransactionCallback.execute(JobStoreSupport.java:3715)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport$VoidTransactionCallback.execute(JobStoreSupport.java:3713)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3799)
    at org.quartz.impl.jdbcjobstore.JobStoreTX.executeInLock(JobStoreTX.java:93)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1155)
    at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:932)
    at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:258)
    at javaapplication2.JavaApplication2.main(JavaApplication2.java:174)
Caused by: org.quartz.JobPersistenceException: Couldn't retrieve job: not implemented by SQLite JDBC driver [See nested exception: java.sql.SQLException: not implemented by SQLite JDBC driver]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveJob(JobStoreSupport.java:1396)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1205)
    ... 9 more
Caused by: java.sql.SQLException: not implemented by SQLite JDBC driver
    at org.sqlite.jdbc4.JDBC4ResultSet.unused(JDBC4ResultSet.java:320)
    at org.sqlite.jdbc4.JDBC4ResultSet.getBlob(JDBC4ResultSet.java:345)
    at com.mchange.v2.c3p0.impl.NewProxyResultSet.getBlob(NewProxyResultSet.java:285)
    at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.getObjectFromBlob(StdJDBCDelegate.java:3190)
    at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.selectJobDetail(StdJDBCDelegate.java:860)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveJob(JobStoreSupport.java:1385)
    ... 10 more
BUILD STOPPED (total time: 11 seconds)

推荐答案

问题好像是sqlite jdbc driver 不支持方法ResultSet.getBlob().

The problem seems to be that the sqlite jdbc driver does not support the method ResultSet.getBlob().

但是quartz 使用这种方法来检索JobDataMap分配给作业.

But quartz uses this method to retrieve the JobDataMap that is assigned to a Job.

如果您仍然想在 sqlite 中使用石英,您可以扩展 StdJDBCDelegate 并检索/设置 blob,如在此答案中建议的 .

If you still want to use quartz with sqlite you could extend the StdJDBCDelegate and retrieve/set blobs like suggested in this answer.

乍一看似乎你只需要覆盖方法

At first glance it seems that you only must override the methods

  1. StdJDBCDelegate.getObjectFromBlob() 和
  2. StdJDBCDelegate.getJobDataFromBlob()

因为我不确定以后是否会出现更多问题(例如,您可以看到 sqlite jdbcdriver 有更多 不支持的 ResultSet 方法 ) 我宁愿建议使用一个有效的数据库开箱即用.

Since I'm not sure wether later come more problems ( for example you could see that the sqlite jdbcdriver has a lot more unsupported ResultSet methods ) I would rather recommend to use a database which works out-of the-box.

这篇关于如何在 Quartz 中使用 SQLite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆