Seam + Quartz + Postgresql
jonne.deprez Jun 29, 2009 1:01 PMI got Quartz 1.6.0 to work Seam 2.1.1 with a Postgresql 8.3 database to store the jobs. This is how I got it to work:
Add quartz.jar to your project. In my project the folder is called EarContent.
Using JobStoreCMT is necessary when working with Seam, because you don't use Seam to handle database access for quartz. Quartz database access is handled by the container (the JBoss server).
You need to create 2 separate databases: one for use in Seam and one for quartz. Make sure the database for quartz is in the public shema.
Add <async:quartz-dispatcher/> to components.xml.
Define quartz.jar as a module in application.xml. Just add
<module>
<ejb>quartz.jar</ejb>
</module>
to the list of modules.
The two datasources are defined in myapplication-ds.xml.
Mine looks like:
<datasources> <local-tx-datasource> <jndi-name>myappDatasource</jndi-name> <connection-url>jdbc:postgresql://localhost:5432/myapp</connection-url> <driver-class>org.postgresql.Driver</driver-class> <user-name>seamuser</user-name> <password>password</password> </local-tx-datasource> <xa-datasource> <jndi-name>quartzDatasource</jndi-name> <track-connection-by-tx/> <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class> <xa-datasource-property name="ServerName">localhost</xa-datasource-property> <xa-datasource-property name="PortNumber">5432</xa-datasource-property> <xa-datasource-property name="DatabaseName">quartz</xa-datasource-property> <xa-datasource-property name="User">postgres</xa-datasource-property> <xa-datasource-property name="Password">password</xa-datasource-property> <metadata> <type-mapping>PostgreSQL 8.0</type-mapping> </metadata> </xa-datasource> </datasources>
In the ejbModule folder I created a seam.quartz.properties file with the following contents:
#============================================================================ # Configure Main Scheduler Properties #============================================================================ org.quartz.scheduler.instanceName MyAppQuartzScheduler org.quartz.scheduler.instanceId AUTO org.quartz.scheduler.rmi.export false org.quartz.scheduler.rmi.proxy false #============================================================================ # Configure ThreadPool #============================================================================ org.quartz.threadPool.class org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.threadCount 5 org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread true #============================================================================ # Configure JobStore #============================================================================ org.quartz.jobStore.misfireThreshold 60000 org.quartz.jobStore.class org.quartz.impl.jdbcjobstore.JobStoreCMT org.quartz.jobStore.driverDelegateClass org.quartz.impl.jdbcjobstore.PostgreSQLDelegate org.quartz.jobStore.useProperties false org.quartz.jobStore.dataSource quartzDatasource org.quartz.jobStore.tablePrefix qrtz_ org.quartz.jobStore.nonManagedTXDataSource quartzDatasource #============================================================================ # Configure Datasources #============================================================================ org.quartz.dataSource.quartzDatasource.jndiURL java:/quartzDatasource
Last small detail: to persist handles to jobs in postgresql, annotate the getter of the entity bean with @Lob and use the oid type type in postgresql.
That's it!