This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 633d013
Showing
9 changed files
with
748 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>net.tirasa.blog</groupId> | ||
<artifactId>SpringQuartzJPA</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>SpringQuartzJPA</name> | ||
<url>http://blog.tirasa.net</url> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<properties> | ||
<spring.version>3.0.6.RELEASE</spring.version> | ||
<quartz.version>1.8.5</quartz.version> | ||
|
||
<hibernate.version>3.6.8.Final</hibernate.version> | ||
|
||
<h2.version>1.3.161</h2.version> | ||
|
||
<logback.version>1.0.0</logback.version> | ||
<slf4j.version>1.6.4</slf4j.version> | ||
|
||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-beans</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context-support</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jdbc</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-orm</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-tx</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-entitymanager</artifactId> | ||
<version>${hibernate.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.quartz-scheduler</groupId> | ||
<artifactId>quartz</artifactId> | ||
<version>${quartz.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<version>${logback.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>${logback.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
<version>1.1.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.9</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>${h2.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<defaultGoal>clean test</defaultGoal> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.10</version> | ||
<configuration> | ||
<redirectTestOutputToFile>true</redirectTestOutputToFile> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
|
||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<repositories> | ||
|
||
<repository> | ||
<id>main</id> | ||
<url>http://repo1.maven.org/maven2/</url> | ||
</repository> | ||
|
||
<repository> | ||
<id>jboss</id> | ||
<url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url> | ||
</repository> | ||
|
||
</repositories> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package net.tirasa.blog.springquartz; | ||
|
||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
import org.quartz.StatefulJob; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
public class MyJob implements StatefulJob { | ||
|
||
/** | ||
* Logger. | ||
*/ | ||
private static final Logger LOG = LoggerFactory.getLogger( | ||
MyJob.class); | ||
|
||
@Override | ||
@Transactional | ||
public void execute(final JobExecutionContext context) | ||
throws JobExecutionException { | ||
|
||
LOG.info("SONO IO!"); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/net/tirasa/blog/springquartz/SpringBeanJobFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package net.tirasa.blog.springquartz; | ||
|
||
import org.quartz.SchedulerContext; | ||
import org.quartz.spi.TriggerFiredBundle; | ||
import org.springframework.beans.BeanWrapper; | ||
import org.springframework.beans.MutablePropertyValues; | ||
import org.springframework.beans.PropertyAccessorFactory; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
public class SpringBeanJobFactory | ||
extends org.springframework.scheduling.quartz.SpringBeanJobFactory { | ||
|
||
private String[] ignoredUnknownProperties; | ||
|
||
private SchedulerContext schedulerContext; | ||
|
||
@Override | ||
public void setIgnoredUnknownProperties( | ||
final String[] ignoredUnknownProperties) { | ||
|
||
super.setIgnoredUnknownProperties(ignoredUnknownProperties); | ||
this.ignoredUnknownProperties = ignoredUnknownProperties; | ||
} | ||
|
||
@Override | ||
public void setSchedulerContext(final SchedulerContext schedulerContext) { | ||
super.setSchedulerContext(schedulerContext); | ||
this.schedulerContext = schedulerContext; | ||
} | ||
|
||
/** | ||
* An implementation of SpringBeanJobFactory that retrieves the bean from | ||
* the Spring context so that autowiring and transactions work | ||
* | ||
* This method is overriden. | ||
* @see org.springframework.scheduling.quartz.SpringBeanJobFactory#createJobInstance(org.quartz.spi.TriggerFiredBundle) | ||
*/ | ||
@Override | ||
protected Object createJobInstance(final TriggerFiredBundle bundle) | ||
throws Exception { | ||
|
||
final ConfigurableApplicationContext ctx = | ||
((ConfigurableApplicationContext) schedulerContext.get( | ||
"applicationContext")); | ||
final Object job = ctx.getBean(bundle.getJobDetail().getName()); | ||
final BeanWrapper wrapper = | ||
PropertyAccessorFactory.forBeanPropertyAccess(job); | ||
if (isEligibleForPropertyPopulation(wrapper.getWrappedInstance())) { | ||
final MutablePropertyValues pvs = new MutablePropertyValues(); | ||
if (this.schedulerContext != null) { | ||
pvs.addPropertyValues(this.schedulerContext); | ||
} | ||
pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap()); | ||
pvs.addPropertyValues(bundle.getTrigger().getJobDataMap()); | ||
if (this.ignoredUnknownProperties == null) { | ||
wrapper.setPropertyValues(pvs, true); | ||
} else { | ||
for (String propName : this.ignoredUnknownProperties) { | ||
if (pvs.contains(propName) | ||
&& !wrapper.isWritableProperty(propName)) { | ||
|
||
pvs.removePropertyValue(propName); | ||
} | ||
} | ||
wrapper.setPropertyValues(pvs); | ||
} | ||
} | ||
return job; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<persistence xmlns="http://java.sun.com/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence | ||
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" | ||
version="2.0"> | ||
<persistence-unit name="syncopePersistenceUnit"> | ||
</persistence-unit> | ||
</persistence> |
Oops, something went wrong.