├── .gitignore
├── .pmd
├── .springBeans
├── .travis.yml
├── LICENSE
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── de
│ │ └── viadee
│ │ └── spring
│ │ └── batch
│ │ ├── infrastructure
│ │ ├── ActivityNotifier.java
│ │ ├── Configurator.java
│ │ ├── DataSourceHolder.java
│ │ ├── DatabaseScheduledWriter.java
│ │ ├── JdbcTemplateHolder.java
│ │ ├── JobEndQueueCleaner.java
│ │ ├── LoggingWrapper.java
│ │ ├── SBPMConfiguration.java
│ │ └── SchedulingHolder.java
│ │ ├── operational
│ │ ├── chronometer
│ │ │ ├── ChronoHelper.java
│ │ │ ├── Chronometer.java
│ │ │ ├── ChronometerType.java
│ │ │ └── TimeLogger.java
│ │ ├── monitoring
│ │ │ ├── BatchChunkListener.java
│ │ │ ├── BatchJobListener.java
│ │ │ ├── BatchStepListener.java
│ │ │ ├── ItemProcessAspectListener.java
│ │ │ ├── ItemReadAspectListener.java
│ │ │ ├── ItemWriteAspectListener.java
│ │ │ ├── PostProcessorGenericListener.java
│ │ │ ├── TimeAwareSPBMChunkExecution.java
│ │ │ └── writer
│ │ │ │ ├── LoggingIterator.java
│ │ │ │ └── LoggingList.java
│ │ └── setupverification
│ │ │ ├── AspectTestClass.java
│ │ │ ├── ContainerTest.java
│ │ │ └── TestAspect.java
│ │ └── persistence
│ │ ├── SBPMActionDAO.java
│ │ ├── SBPMActionDAOImpl.java
│ │ ├── SBPMChunkExecutionDAO.java
│ │ ├── SBPMChunkExecutionDAOImpl.java
│ │ ├── SBPMChunkExecutionQueue.java
│ │ ├── SBPMItemDAO.java
│ │ ├── SBPMItemDAOImpl.java
│ │ ├── SBPMItemQueue.java
│ │ ├── SBPMJobDAO.java
│ │ ├── SBPMJobDAOImpl.java
│ │ ├── SBPMStepActionDAO.java
│ │ ├── SBPMStepActionDAOImpl.java
│ │ ├── SBPMStepDAO.java
│ │ ├── SBPMStepDAOImpl.java
│ │ └── types
│ │ ├── SBPMAction.java
│ │ ├── SBPMChunkExecution.java
│ │ ├── SBPMItem.java
│ │ ├── SBPMJob.java
│ │ ├── SBPMStep.java
│ │ └── SBPMStepAction.java
└── resources
│ ├── BSD3-license.txt
│ ├── SQL
│ ├── create-tables.sql
│ └── schema-h2.sql
│ ├── h2starter.sh
│ ├── sbpmApplicationContext.xml
│ └── springBatchMonitoringDefault.properties
└── test
├── java
└── de
│ └── viadee
│ └── spring
│ └── batch
│ ├── integrationtest
│ ├── JobLauncherController.java
│ ├── MainApplication.java
│ ├── TestMonitoring.java
│ ├── common
│ │ ├── Customer.java
│ │ ├── CustomerEnhanced.java
│ │ ├── CustomerRowMapper.java
│ │ ├── Transaction.java
│ │ └── TransactionRowMapper.java
│ ├── configuration
│ │ ├── ApplicationConfiguration.java
│ │ ├── InfrastructureConfiguration.java
│ │ ├── JobLaunchController.java
│ │ └── StandaloneInfrastructureConfiguration.java
│ └── jobs
│ │ ├── JobCreator.java
│ │ ├── calculategradepoints
│ │ ├── CalculateTransactionTotalJobConfig.java
│ │ ├── CalculateTransactionTotalPartitionJob.java
│ │ ├── CalculateTransactionTotalPartitionReader.java
│ │ ├── CalculateTransactionTotalPartitioningListener.java
│ │ ├── CalculateTransactionTotalPartitioningStepConfig.java
│ │ ├── CalculateTransactionTotalProcessor.java
│ │ ├── CalculateTransactionTotalReadListener.java
│ │ ├── CalculateTransactionTotalStepConfig.java
│ │ ├── CustomerItemPreparedStatementSetter.java
│ │ ├── CustomerSqlParameterSourceProvider.java
│ │ └── RangePartitioner.java
│ │ ├── formatnames
│ │ ├── CustomerItemProcessorLowerCase.java
│ │ ├── CustomerItemProcessorUpperCase.java
│ │ ├── FormatNamesJobConfig.java
│ │ └── FormatNamesStep.java
│ │ └── preparedatabase
│ │ ├── DataBaseFiller.java
│ │ ├── DelayTasklet.java
│ │ ├── PrepareDatabaseJobConfig.java
│ │ ├── PrepareDatabaseTasklet.java
│ │ └── TaskletOnlyStepConfig.java
│ └── operational
│ └── monitoring
│ └── writer
│ └── TestLoggingList.java
└── resources
├── SQL
└── prepare-tables.sql
└── SpringBatchMonitoring.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 |
14 |
15 | *target*
16 | *.jar
17 | *.war
18 | *.ear
19 | *.class
20 |
21 | # eclipse specific git ignore
22 | *.pydevproject
23 | .project
24 | .metadata
25 | bin/**
26 | tmp/**
27 | tmp/**/*
28 | *.tmp
29 | *.bak
30 | *.swp
31 | *~.nib
32 | local.properties
33 | .classpath
34 | .settings/
35 | .loadpath
36 |
37 | # External tool builders
38 | .externalToolBuilders/
39 |
40 | # Locally stored "Eclipse launch configurations"
41 | *.launch
42 |
43 | # Intellij
44 | .idea/
45 | *.iml
46 | *.iws
47 |
48 | # Maven
49 | log/
50 | target/
51 |
52 | # Mac
53 | .DS_Store
--------------------------------------------------------------------------------
/.springBeans:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 |
5 |
6 |
7 |
8 |
9 |
10 | src/main/resources/sbpmApplicationContext.xml
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2018, viadee IT-Unternehmensberatung AG
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Spring Batch Performance Monitoring (SBPM)
2 | This Tool provides the means to monitor the performance of Spring Batch applications without the need to manipulate the respective code basis.
3 |
4 | Through Listeners and AOP it evaluates the throughput of a monitored Job and writes the result to a simple database-schema (a file-based H2 by default).
5 |
6 | It measures the performance of Job, Step, Chunk, Reader/Processor/Writer/Tasklet down to indivdual Items.
7 |
8 | ## Installation/Usage
9 |
10 | 1. Add the dependency to your POM:
11 | ```xml
12 |
13 | de.viadee
14 | springBatchPerformanceMonitoring
15 | ...
16 |
17 | ```
18 | 2. Add the de.viadee.spring.batch.infrastructure.Configurator.class to your Spring-Application-Context (via @Import on your Configuration)
19 | 3. Run the Job
20 | 4. By default the monitoring result is written to project-folder/target/database/monitoringDB.mv.db
21 |
22 | You can access the database with the credentials sa/sasa. It contains all perfomance data measured in snowflake style as well as number of prepared views for typical questions on all the detail levels mentioned above. You can see the [SQL schema in H2 syntax in the code](https://github.com/viadee/springBatchPerformanceMonitoring/blob/master/src/main/resources/SQL/schema-h2.sql).
23 |
24 | ## Commitments
25 | This library will remain under an open source licence indefinately.
26 |
27 | We follow the [semantic versioning](http://semver.org) scheme (2.0.0).
28 |
29 | In the sense of semantic versioning, the resulting database schema is the _only public API_ provided here. We will keep the database schema as stable as possible, in order to enable users to analyse performance logs with the toolsets of their choice.
30 |
31 | For the same reason, we do not use any database specific features and we minimize the assumptions made regarding Spring versions and the whole runtime environment.
32 |
33 | ## Cooperation
34 | Feel free to add issues, questions, ideas or patches. We are looking forward to it.
35 |
36 | [](https://travis-ci.org/viadee/springBatchPerformanceMonitoring)
37 |
38 | ## License (BSD 3-Clause License)
39 |
40 | Copyright (c) 2018, viadee IT-Unternehmensberatung AG
41 | All rights reserved.
42 |
43 | Redistribution and use in source and binary forms, with or without
44 | modification, are permitted provided that the following conditions are met:
45 |
46 | * Redistributions of source code must retain the above copyright notice, this
47 | list of conditions and the following disclaimer.
48 |
49 | * Redistributions in binary form must reproduce the above copyright notice,
50 | this list of conditions and the following disclaimer in the documentation
51 | and/or other materials provided with the distribution.
52 |
53 | * Neither the name of the copyright holder nor the names of its
54 | contributors may be used to endorse or promote products derived from
55 | this software without specific prior written permission.
56 |
57 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
58 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
61 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
63 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
64 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
65 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
66 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/infrastructure/ActivityNotifier.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.infrastructure;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.stereotype.Component;
33 |
34 | /**
35 | *
36 | * This class is used to extend the BatchJobListener class. It offers methods to give a (Log4J based) visual Feedback
37 | * indicating whether a Batch Job is about to be monitored or if a Job has been monitored.
38 | *
39 | */
40 | @Component
41 | public class ActivityNotifier {
42 |
43 | private static final Logger LOGGER = LoggingWrapper.getLogger(ActivityNotifier.class);
44 |
45 | private boolean currentlyActive;
46 |
47 | public boolean getcurrentlyActive() {
48 | return currentlyActive;
49 | }
50 |
51 | public void beforeJob() {
52 | LOGGER.info("###\n Spring Batch Monitoring Tool is now starting Performance measuring for the started job");
53 | }
54 |
55 | public void afterJob() {
56 | LOGGER.info("###\n Spring Batch Monitoring Tool ended measuring performance of the Job.");
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/infrastructure/Configurator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.infrastructure;
30 |
31 | import java.sql.SQLException;
32 |
33 | import javax.annotation.PostConstruct;
34 | import javax.annotation.PreDestroy;
35 |
36 | import org.apache.log4j.Logger;
37 | import org.springframework.beans.factory.annotation.Autowired;
38 | import org.springframework.context.annotation.Bean;
39 | import org.springframework.context.annotation.ComponentScan;
40 | import org.springframework.context.annotation.ComponentScan.Filter;
41 | import org.springframework.context.annotation.Configuration;
42 | import org.springframework.context.annotation.EnableAspectJAutoProxy;
43 | import org.springframework.context.annotation.FilterType;
44 | import org.springframework.transaction.annotation.EnableTransactionManagement;
45 |
46 | import de.viadee.spring.batch.operational.chronometer.ChronoHelper;
47 | import de.viadee.spring.batch.operational.setupverification.AspectTestClass;
48 | import de.viadee.spring.batch.operational.setupverification.ContainerTest;
49 | import de.viadee.spring.batch.operational.setupverification.TestAspect;
50 | import de.viadee.spring.batch.persistence.SBPMChunkExecutionQueue;
51 | import de.viadee.spring.batch.persistence.SBPMItemQueue;
52 |
53 | /**
54 | *
55 | * Main Configuration class of the Monitoring Tool. This class sets up the
56 | * Environment which the Monitoring Tool needs to be operational. This includes:
57 | * Package based Component scanning (excluding the SetupVerification package),
58 | * enabling AspectJAutoProxy, creating necessary Beans for DB Access...
59 | *
60 | */
61 | @Configuration
62 | @ComponentScan(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, value = { ContainerTest.class,
63 | AspectTestClass.class, TestAspect.class }), basePackages = { "de.viadee.spring.batch" })
64 | @EnableTransactionManagement
65 | @EnableAspectJAutoProxy(proxyTargetClass = true)
66 | public class Configurator {
67 |
68 | @Autowired
69 | private SBPMItemQueue spbmItemQueue;
70 |
71 | @Autowired
72 | private SBPMChunkExecutionQueue spbmChunkExecutionQueue;
73 |
74 | @Autowired
75 | private SBPMConfiguration sbpmConfig;
76 |
77 | @Autowired
78 | private ChronoHelper chronoHelper;
79 |
80 | @Bean
81 | public JdbcTemplateHolder getJdbcTemplateHolder() throws SQLException {
82 | final JdbcTemplateHolder jdbcTemplateHolder = new JdbcTemplateHolder();
83 | jdbcTemplateHolder.setDataSourceHolder(getDataSourceHolder());
84 | jdbcTemplateHolder.setNamedParameterJdbcTemplate();
85 | jdbcTemplateHolder.setChronoHelper(chronoHelper);
86 | return jdbcTemplateHolder;
87 | }
88 |
89 | @Bean
90 | public SchedulingHolder schedulingHolder() throws SQLException, IllegalStateException, InterruptedException {
91 | final SchedulingHolder schedulingHolder = new SchedulingHolder(spbmItemQueue, spbmChunkExecutionQueue,
92 | getJdbcTemplateHolder(), chronoHelper);
93 | return schedulingHolder;
94 | }
95 |
96 | @Bean
97 | public JobEndQueueCleaner jobEndQueueCleaner() throws SQLException {
98 | final JobEndQueueCleaner jobEndQueueCleaner = new JobEndQueueCleaner(spbmItemQueue, spbmChunkExecutionQueue,
99 | getJdbcTemplateHolder());
100 | return jobEndQueueCleaner;
101 | }
102 |
103 | private static final Logger LOGGER = LoggingWrapper.getLogger(Configurator.class);
104 |
105 | /**
106 | * Note: You MUST see this message. Otherwise the In-Memory-Monitoring-DB may be
107 | * killed before completely syncing with the File-Based one (which leads to Loss
108 | * of monitoring data).
109 | */
110 | @PreDestroy
111 | public void stopNotifier() {
112 | LOGGER.info("Spring Batch Monitoring Tool has sucsessfully been unloaded.");
113 | }
114 |
115 | @PostConstruct
116 | public void notifyInitializaion() {
117 | LOGGER.info("Spring batch Monitoring Tool has been successfully loaded.");
118 | }
119 |
120 | @Bean
121 | public DataSourceHolder getDataSourceHolder() {
122 | return new DataSourceHolder(sbpmConfig);
123 | }
124 |
125 | }
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/infrastructure/DataSourceHolder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.infrastructure;
30 |
31 | import java.sql.Driver;
32 |
33 | import javax.sql.DataSource;
34 |
35 | import org.apache.log4j.Logger;
36 | import org.springframework.core.io.ClassPathResource;
37 | import org.springframework.jdbc.datasource.SimpleDriverDataSource;
38 | import org.springframework.jdbc.datasource.init.DataSourceInitializer;
39 | import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
40 |
41 | /**
42 | * The monitoring tool stores its data in its own database. Since this requires DataSource and a JdbcTemplate, it will
43 | * lead to problems when the monitored batch Project is using Autowire on "DataSource" or "JdbcTemplate". To prevent
44 | * possible errors on context creation (Autowiring identifies two possible candidates for Autowiring), both the
45 | * DataSource and the JdbcTemplate are encapsulated into these "Holder" classes.
46 | *
47 | * This class knowingly violates the dependency injection principle by instantiating dependencies - preventing
48 | * interference with the client project is more important.
49 | */
50 |
51 | public final class DataSourceHolder {
52 |
53 | private static final Logger LOG = LoggingWrapper.getLogger(DataSourceHolder.class);
54 |
55 | private final DataSource datasource;
56 |
57 | SBPMConfiguration config;
58 |
59 | DataSourceHolder(SBPMConfiguration config) {
60 | LOG.debug("DataSourceHolder buildt");
61 | this.config = config;
62 | this.datasource = createDataSource();
63 | }
64 |
65 | public DataSource getDataSource() {
66 | return datasource;
67 | }
68 |
69 | protected DataSource createDataSource() {
70 |
71 | LOG.trace("CreateDataSource was called");
72 | final SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
73 | simpleDriverDataSource.setUrl(config.getUrl());
74 | simpleDriverDataSource.setUsername(config.getUsername());
75 | simpleDriverDataSource.setPassword(config.getPassword());
76 | try {
77 | simpleDriverDataSource.setDriverClass((Class extends Driver>) Class.forName(config.getDriver()));
78 | } catch (final ClassNotFoundException e) {
79 | LOG.warn(e);
80 | }
81 | // Initialize DB
82 | final DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
83 | dataSourceInitializer.setDataSource(simpleDriverDataSource);
84 | final ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
85 | resourceDatabasePopulator.addScript(new ClassPathResource("SQL/create-tables.sql"));
86 | dataSourceInitializer.setDatabasePopulator(resourceDatabasePopulator);
87 | dataSourceInitializer.afterPropertiesSet();
88 |
89 | return simpleDriverDataSource;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/infrastructure/JdbcTemplateHolder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.infrastructure;
30 |
31 | import javax.annotation.PreDestroy;
32 |
33 | import org.apache.log4j.Logger;
34 | import org.springframework.jdbc.core.JdbcTemplate;
35 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
36 |
37 | import de.viadee.spring.batch.operational.chronometer.ChronoHelper;
38 |
39 | /**
40 | * The Monitoring-Tool stores its Data in an own Database. Since this needs a DataSource and a JdbcTemplate, it might
41 | * lead to problems when the monitored Batch Project is using Autowire on "DataSource" or "JdbcTemplate". To prevent
42 | * possible errors on context creation (Autowiring identifies two possible candidates for Autowiring), both the
43 | * DataSource and the JdbcTemplate used by the Monitoring-Tool are encapsulated into these "Holder" classes.
44 | *
45 | * Accessing the Monitoring-Database only works by these classes.
46 | *
47 | */
48 | public final class JdbcTemplateHolder {
49 |
50 | private ChronoHelper chronoHelper;
51 |
52 | private final Logger LOG = LoggingWrapper.getLogger(JdbcTemplateHolder.class);
53 |
54 | private DataSourceHolder dataSourceHolder;
55 |
56 | private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
57 |
58 | public JdbcTemplateHolder() {
59 | LOG.debug("JdbcTemplateHolder buildt");
60 | }
61 |
62 | public void setChronoHelper(final ChronoHelper chronoHelper) {
63 | this.chronoHelper = chronoHelper;
64 | }
65 |
66 | public void setDataSourceHolder(final DataSourceHolder dataSourceHolder) {
67 | this.dataSourceHolder = dataSourceHolder;
68 | }
69 |
70 | public NamedParameterJdbcTemplate getJdbcTemplate() {
71 | return this.namedParameterJdbcTemplate;
72 | }
73 |
74 | public void setNamedParameterJdbcTemplate() {
75 | namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSourceHolder.getDataSource());
76 | final JdbcTemplate tempTemplate = new JdbcTemplate();
77 | tempTemplate.setDataSource(dataSourceHolder.getDataSource());
78 | }
79 |
80 | @PreDestroy
81 | public void destroy() throws InterruptedException {
82 | LOG.debug("Want to destroy JdbcTemplateHolder - checking, if Daemon is still active");
83 | if (chronoHelper.getDaemonRunning()) {
84 | LOG.debug("Should stop for flushing the itemqueue");
85 |
86 | while (chronoHelper.getDaemonRunning()) {
87 | LOG.debug("Stopped");
88 | Thread.sleep(5);
89 | }
90 | LOG.debug("Done stopping");
91 |
92 | } else {
93 | LOG.debug("No need to wait");
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/infrastructure/JobEndQueueCleaner.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.infrastructure;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.scheduling.annotation.Async;
33 | import org.springframework.scheduling.annotation.EnableAsync;
34 |
35 | import de.viadee.spring.batch.persistence.SBPMChunkExecutionDAOImpl;
36 | import de.viadee.spring.batch.persistence.SBPMChunkExecutionQueue;
37 | import de.viadee.spring.batch.persistence.SBPMItemDAOImpl;
38 | import de.viadee.spring.batch.persistence.SBPMItemQueue;
39 |
40 | /**
41 | * TODO: Check if we even need this Doesn't seem like it at this time
42 | *
43 | */
44 | @EnableAsync
45 | public class JobEndQueueCleaner {
46 |
47 | private final DatabaseScheduledWriter dbScheduledWriter;
48 |
49 | private static final Logger LOG = LoggingWrapper.getLogger(JobEndQueueCleaner.class);
50 |
51 | public JobEndQueueCleaner(final SBPMItemQueue sPBMItemQueue, final SBPMChunkExecutionQueue sPBMChunkExecutionQueue,
52 | final JdbcTemplateHolder templateHolder) {
53 | this.dbScheduledWriter = new DatabaseScheduledWriter();
54 | dbScheduledWriter.setSPBMItemDAO(new SBPMItemDAOImpl());
55 | dbScheduledWriter.setSPBMChunkExecutionDAO(new SBPMChunkExecutionDAOImpl());
56 | dbScheduledWriter.setJdbcTemplateHolder(templateHolder);
57 | dbScheduledWriter.setSPBMItemQueue(sPBMItemQueue);
58 | dbScheduledWriter.setSPBMChunkExecutionQueue(sPBMChunkExecutionQueue);
59 | }
60 |
61 | @Async
62 | public void asyncTest(final String jobName) throws InterruptedException {
63 | LOG.debug("Cleaning up for Job " + jobName);
64 | dbScheduledWriter.run();
65 | LOG.debug("Cleaned up for job " + jobName);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/infrastructure/LoggingWrapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.infrastructure;
30 |
31 | import org.apache.log4j.Logger;
32 |
33 | /**
34 | * This is some kind of a Log4J Proxy. Its purpose is to give the developer the ability to redirect the tool-based Log4J
35 | * Output in order to separate it from the Batch-Processes Log. See "log4j.additivity" in the Log4J documentation for
36 | * further details.
37 | *
38 | */
39 |
40 | public final class LoggingWrapper {
41 |
42 | public static Logger getLogger(final Class> clazz) {
43 | return Logger.getLogger("SpringBatchMonitoring." + clazz.getName());
44 | }
45 |
46 | private LoggingWrapper() {
47 |
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/infrastructure/SBPMConfiguration.java:
--------------------------------------------------------------------------------
1 | package de.viadee.spring.batch.infrastructure;
2 |
3 | import javax.annotation.PostConstruct;
4 |
5 | import org.apache.log4j.Logger;
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.context.annotation.PropertySource;
10 | import org.springframework.context.annotation.PropertySources;
11 | import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
12 |
13 | @Configuration
14 | @PropertySources({ @PropertySource("classpath:springBatchMonitoringDefault.properties"),
15 | @PropertySource(value = "classpath:springBatchMonitoring.properties", ignoreResourceNotFound = true) })
16 | public class SBPMConfiguration {
17 |
18 | private static final Logger LOG = LoggingWrapper.getLogger(SBPMConfiguration.class);
19 |
20 | @Bean
21 | public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
22 | return new PropertySourcesPlaceholderConfigurer();
23 | }
24 |
25 | @Value("${db.username}")
26 | private String username;
27 |
28 | @Value("${db.password}")
29 | private String password;
30 |
31 | @Value("${db.url}")
32 | private String url;
33 |
34 | @Value("${db.driver}")
35 | private String driver;
36 |
37 | @Value("${db.anomalydetection}")
38 | private String trackanomaly;
39 |
40 | public String getUsername() {
41 | return username;
42 | }
43 |
44 | public String getPassword() {
45 | return password;
46 | }
47 |
48 | public String getUrl() {
49 | return url;
50 | }
51 |
52 | public String getDriver() {
53 | return driver;
54 | }
55 |
56 | public boolean trackAnomaly() {
57 | return Boolean.parseBoolean(trackanomaly);
58 | }
59 |
60 | @PostConstruct
61 | protected void getProperties() {
62 | LOG.debug("Property trackanomaly was set to: " + trackanomaly);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/infrastructure/SchedulingHolder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.infrastructure;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
33 |
34 | import de.viadee.spring.batch.operational.chronometer.ChronoHelper;
35 | import de.viadee.spring.batch.persistence.SBPMChunkExecutionDAOImpl;
36 | import de.viadee.spring.batch.persistence.SBPMChunkExecutionQueue;
37 | import de.viadee.spring.batch.persistence.SBPMItemDAOImpl;
38 | import de.viadee.spring.batch.persistence.SBPMItemQueue;
39 |
40 | /**
41 | * The SchedulingHolder class is used to create an isolated TaskScheduler environment, which doesn't affect / isn't
42 | * affected by any possible existing code which might be located in the Batch Project that is to be monitored.
43 | *
44 | * This class takes care of triggering the DatabaseScheduledWriter on an interval basis. It also registers the spawned
45 | * Thread as a Daemon-Thread.
46 | *
47 | * However, the Daemon-Thread is semi-blocking. See DatabaseScheduledWriter class for further Details.
48 | *
49 | */
50 | public class SchedulingHolder {
51 |
52 | private static final Logger LOG = LoggingWrapper.getLogger(SchedulingHolder.class);
53 |
54 | private final ThreadPoolTaskScheduler heldTaskScheduler;
55 |
56 | public SchedulingHolder(final SBPMItemQueue sPBMItemQueue, final SBPMChunkExecutionQueue sPBMChunkExecutionQueue,
57 | final JdbcTemplateHolder jdbcTemplateHolder, final ChronoHelper chronoHelper)
58 | throws IllegalStateException, InterruptedException {
59 |
60 | LOG.debug("SchedulingHolder instantiated");
61 | heldTaskScheduler = new ThreadPoolTaskScheduler();
62 | heldTaskScheduler.setPoolSize(1);
63 | heldTaskScheduler.setDaemon(true);
64 |
65 | heldTaskScheduler.afterPropertiesSet();
66 | final DatabaseScheduledWriter dbScheduledWriter = new DatabaseScheduledWriter();
67 | dbScheduledWriter.setSPBMChunkExecutionDAO(new SBPMChunkExecutionDAOImpl());
68 | dbScheduledWriter.setSPBMItemDAO(new SBPMItemDAOImpl());
69 | dbScheduledWriter.setSPBMItemQueue(sPBMItemQueue);
70 | dbScheduledWriter.setSPBMChunkExecutionQueue(sPBMChunkExecutionQueue);
71 | dbScheduledWriter.setJdbcTemplateHolder(jdbcTemplateHolder);
72 | dbScheduledWriter.setChronoHelper(chronoHelper);
73 | heldTaskScheduler.scheduleAtFixedRate(dbScheduledWriter, 100);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/operational/chronometer/Chronometer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.operational.chronometer;
30 |
31 | import java.util.ArrayList;
32 | import java.util.List;
33 |
34 | /**
35 | * This class is used to measure the elapsed time between two points in time.
36 | *
37 | * It also has the ability, to interconnect several TimeLogger and Chronometer objects, which is necessary for
38 | * outputting an hierarchical overview of the measured times onto the console.
39 | *
40 | */
41 | public class Chronometer {
42 |
43 | private boolean isRunning = false;
44 |
45 | private final List childTimeLogger = new ArrayList();
46 |
47 | /**
48 | * This variable is supposed to hold the name for the Object, the Chronometer is bound to.
49 | */
50 | private String objectName;
51 |
52 | private String objectReflection;
53 |
54 | private String objectClass;
55 |
56 | private long startTimeMillis, endTimeMillis;
57 |
58 | public List getChildTimeLogger() {
59 | return childTimeLogger;
60 | }
61 |
62 | public void addChildTimeLogger(final TimeLogger timeLogger) {
63 | childTimeLogger.add(timeLogger);
64 | }
65 |
66 | public boolean getIsRunning() {
67 | return this.isRunning;
68 | }
69 |
70 | public void startChronometer() {
71 | if (!isRunning) {
72 | this.startTimeMillis = System.currentTimeMillis();
73 | }
74 |
75 | this.isRunning = true;
76 | }
77 |
78 | public void stop() {
79 | if (isRunning) {
80 | this.endTimeMillis = System.currentTimeMillis();
81 | }
82 | this.isRunning = false;
83 | }
84 |
85 | public long getDuration() {
86 | return this.endTimeMillis - this.startTimeMillis;
87 | }
88 |
89 | public String getObjectName() {
90 | return objectName;
91 | }
92 |
93 | public void setObjectReflection(final String objectReflection) {
94 | this.objectReflection = objectReflection;
95 | }
96 |
97 | public String getObjectReflection() {
98 | return objectReflection;
99 | }
100 |
101 | public void setObjectName(final String objectName) {
102 | this.objectName = objectName;
103 | }
104 |
105 | public String getObjectClass() {
106 | return objectClass;
107 | }
108 |
109 | public void setObjectClass(final String objectClass) {
110 | this.objectClass = objectClass;
111 | }
112 |
113 | public long getStartTimeMillis() {
114 | return startTimeMillis;
115 | }
116 |
117 | public long getEndTimeMillis() {
118 | return endTimeMillis;
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/operational/chronometer/ChronometerType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.operational.chronometer;
30 |
31 | /**
32 | * This is an enumeration used to determine the Type of a Chronometer.
33 | */
34 | public enum ChronometerType {
35 | UNDEF, JOB, STEP, TASKLET, READER, PROCESSOR, WRITER, COMPOSITEPROCESSOR, COMPOSITEWRITER
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/operational/monitoring/ItemProcessAspectListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.operational.monitoring;
30 |
31 | import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
32 | import org.apache.commons.lang3.builder.ToStringStyle;
33 | import org.apache.log4j.Logger;
34 | import org.aspectj.lang.ProceedingJoinPoint;
35 | import org.aspectj.lang.annotation.Around;
36 | import org.aspectj.lang.annotation.Aspect;
37 | import org.springframework.batch.item.ItemProcessor;
38 | import org.springframework.batch.item.support.CompositeItemProcessor;
39 | import org.springframework.beans.factory.annotation.Autowired;
40 | import org.springframework.stereotype.Component;
41 | import org.springframework.transaction.annotation.Isolation;
42 | import org.springframework.transaction.annotation.Transactional;
43 |
44 | import de.viadee.spring.batch.infrastructure.LoggingWrapper;
45 | import de.viadee.spring.batch.infrastructure.SBPMConfiguration;
46 | import de.viadee.spring.batch.operational.chronometer.ChronoHelper;
47 | import de.viadee.spring.batch.operational.chronometer.Chronometer;
48 | import de.viadee.spring.batch.persistence.SBPMItemQueue;
49 | import de.viadee.spring.batch.persistence.types.SBPMItem;
50 |
51 | /**
52 | * This class uses SpringAOP to measure any ItemProcessor on Item-Level.
53 | *
54 | */
55 | @Aspect
56 | @Component
57 | public class ItemProcessAspectListener {
58 |
59 | @Autowired
60 | ChronoHelper chronoHelper;
61 |
62 | @Autowired
63 | SBPMItemQueue sPBMItemQueue;
64 |
65 | @Autowired
66 | private SBPMConfiguration sbpmConfig;
67 |
68 | private static final Logger LOGGER = LoggingWrapper.getLogger(ItemProcessAspectListener.class);
69 |
70 | @Transactional(isolation = Isolation.READ_UNCOMMITTED)
71 | @Around("execution(* org.springframework.batch.item.ItemProcessor.*(..)) && args(item)")
72 | public Object aroundProcess(final ProceedingJoinPoint jp, final I item) throws Throwable {
73 | LOGGER.trace("ItemProcessor Around advice has been called");
74 | final ItemProcessor itemProcessor = (ItemProcessor) jp.getTarget();
75 | chronoHelper.setActiveAction(itemProcessor, 2, Thread.currentThread());
76 |
77 | // Start Chrono
78 | final Chronometer chronometer = new Chronometer();
79 |
80 | chronometer.startChronometer();
81 | // Proceed
82 | LOGGER.trace("ItemProcessor Around advice has sucessfully set up its environment");
83 | LOGGER.trace("ItemProcesser Around advice is now proceeding its joinpoint");
84 | final Object o = jp.proceed();
85 | // Stop Chrono
86 | chronometer.stop();
87 | if (!(itemProcessor instanceof CompositeItemProcessor)) {
88 | String itemReflection = "";
89 | String itemClassName = "";
90 |
91 | if(sbpmConfig.trackAnomaly()) {
92 | LOGGER.trace("Write ItemReflection to DB");
93 | itemClassName = item.getClass().getSimpleName();
94 | final ReflectionToStringBuilder reflectionToStringBuilder = new ReflectionToStringBuilder(item,
95 | ToStringStyle.JSON_STYLE);
96 | itemReflection = reflectionToStringBuilder.toString();
97 | }
98 | final SBPMItem sPBMItem = new SBPMItem(
99 | chronoHelper.getActiveActionID(Thread.currentThread()), chronoHelper.getBatchChunkListener()
100 | .getSPBMChunkExecution(Thread.currentThread()).getChunkExecutionID(),
101 | (int) chronometer.getDuration(), 0, item.toString(), itemReflection, itemClassName);
102 | sPBMItemQueue.addItem(sPBMItem);
103 | }
104 | LOGGER.trace("ItemProcessor Around advice proceeded and has stopped its Chronometer");
105 | return o;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/operational/monitoring/ItemReadAspectListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.operational.monitoring;
30 |
31 | import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
32 | import org.apache.commons.lang3.builder.ToStringStyle;
33 | import org.apache.log4j.Logger;
34 | import org.aspectj.lang.ProceedingJoinPoint;
35 | import org.aspectj.lang.annotation.Around;
36 | import org.aspectj.lang.annotation.Aspect;
37 | import org.springframework.batch.item.ItemReader;
38 | import org.springframework.beans.factory.annotation.Autowired;
39 | import org.springframework.stereotype.Component;
40 | import org.springframework.transaction.annotation.Isolation;
41 | import org.springframework.transaction.annotation.Transactional;
42 |
43 | import de.viadee.spring.batch.infrastructure.LoggingWrapper;
44 | import de.viadee.spring.batch.infrastructure.SBPMConfiguration;
45 | import de.viadee.spring.batch.operational.chronometer.ChronoHelper;
46 | import de.viadee.spring.batch.operational.chronometer.Chronometer;
47 | import de.viadee.spring.batch.persistence.SBPMItemQueue;
48 | import de.viadee.spring.batch.persistence.types.SBPMItem;
49 |
50 | /**
51 | * This class uses SpringAOP to measure any ItemReader on Item-Level.
52 | *
53 | */
54 | @Aspect
55 | @Component
56 | public class ItemReadAspectListener {
57 |
58 | @Autowired
59 | ChronoHelper chronoHelper;
60 |
61 | @Autowired
62 | SBPMItemQueue sPBMItemQueue;
63 |
64 | @Autowired
65 | private SBPMConfiguration sbpmConfig;
66 |
67 | private static final Logger LOGGER = LoggingWrapper.getLogger(ItemReadAspectListener.class);
68 |
69 | @Transactional(isolation = Isolation.READ_UNCOMMITTED)
70 | @Around("execution(* org.springframework.batch.item.ItemReader.*(..))")
71 | public Object aroundRead(final ProceedingJoinPoint jp) throws Throwable {
72 | LOGGER.trace("ItemRead Around advice has been called");
73 | // Start Chrono
74 | // Get Reference in this method scope so a change of the static variable
75 | // during the jp.proceed wont lead to
76 | // problems
77 | final ItemReader itemReader = (ItemReader) jp.getTarget();
78 | chronoHelper.setActiveAction(itemReader, 1, Thread.currentThread());
79 | // Proceed
80 | final Chronometer itemChronometer = new Chronometer();
81 | itemChronometer.startChronometer();
82 | LOGGER.trace("ItemRead Around advice has sucessfully set up its environment");
83 | LOGGER.trace("ItemRead Around advice is now proceeding its joinpoint");
84 | final Object readItem = jp.proceed();
85 |
86 | // Stop chrono
87 | itemChronometer.stop();
88 | // Name the Chrono
89 | if (!(readItem == null)) {
90 | String itemReflection = "";
91 | String itemClassName = "";
92 | if (sbpmConfig.trackAnomaly()) {
93 | itemClassName = readItem.getClass().getSimpleName();
94 | final ReflectionToStringBuilder reflectionToStringBuilder = new ReflectionToStringBuilder(readItem,
95 | ToStringStyle.JSON_STYLE);
96 | itemReflection = reflectionToStringBuilder.toString();
97 | }
98 | final SBPMItem sPBMItem = new SBPMItem(chronoHelper.getActiveActionID(Thread.currentThread()),
99 | chronoHelper.getBatchChunkListener().getSPBMChunkExecution(Thread.currentThread())
100 | .getChunkExecutionID(),
101 | (int) itemChronometer.getDuration(), 0, readItem.toString(), itemReflection, itemClassName);
102 | sPBMItemQueue.addItem(sPBMItem);
103 |
104 | }
105 | LOGGER.trace("ItemRead Around advice proceeded and has stopped its Chronometer");
106 | return readItem;
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/operational/monitoring/TimeAwareSPBMChunkExecution.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.operational.monitoring;
30 |
31 | import de.viadee.spring.batch.operational.chronometer.TimeLogger;
32 | import de.viadee.spring.batch.persistence.types.SBPMChunkExecution;
33 |
34 | /**
35 | * A chunk execution that logs its time of instantiation .
36 | *
37 | */
38 | public class TimeAwareSPBMChunkExecution {
39 |
40 | private final SBPMChunkExecution sPBMChunkExecution;
41 |
42 | private final TimeLogger timeLogger;
43 |
44 | public SBPMChunkExecution getsPBMChunkExecution() {
45 | return sPBMChunkExecution;
46 | }
47 |
48 | public TimeLogger getTimeLogger() {
49 | return timeLogger;
50 | }
51 |
52 | public TimeAwareSPBMChunkExecution(final SBPMChunkExecution sPBMChunkExecution, final TimeLogger timeLogger) {
53 | super();
54 | this.sPBMChunkExecution = sPBMChunkExecution;
55 | this.timeLogger = timeLogger;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/operational/setupverification/AspectTestClass.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.operational.setupverification;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.stereotype.Component;
33 |
34 | /**
35 | * This class is used by the ContainerTest class to ensure that Aspects are working. It provides a method that simply
36 | * returns a given value. When calling the "returnVal(int val)" method, the call shall be intercepted by SpringAOP and
37 | * redirected to the TestAspect classes method. See TestAspect class for further Detail.
38 | *
39 | */
40 | @Component
41 | public class AspectTestClass {
42 |
43 | private static final Logger LOGGER = Logger.getLogger(AspectTestClass.class);
44 |
45 | public int returnVal(final int val) {
46 | LOGGER.debug("Return Method has been called!");
47 | return val;
48 | }
49 | }
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/operational/setupverification/TestAspect.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.operational.setupverification;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.aspectj.lang.ProceedingJoinPoint;
33 | import org.aspectj.lang.annotation.Around;
34 | import org.aspectj.lang.annotation.Aspect;
35 | import org.springframework.stereotype.Component;
36 |
37 | /**
38 | * This class uses SpringAOP to intercept a method-call in order to test functionality of SpringAOP. See ContainerTest
39 | * and AspectTestClass for further details.
40 | *
41 | */
42 | @Aspect
43 | @Component
44 | public class TestAspect {
45 |
46 | private static final Logger LOGGER = Logger.getLogger(TestAspect.class);
47 |
48 | @Around("execution(* AspectTestClass.returnVal(..)) && args (val)")
49 | public int testAspectMethod(final ProceedingJoinPoint jp, final int val) throws Throwable {
50 | LOGGER.debug("Around advice invoked!");
51 | return val + 2;
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMActionDAO.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import de.viadee.spring.batch.persistence.types.SBPMAction;
32 |
33 | /**
34 | * DAO Interface for the Action Object. See SpbmAction Class for further Details.
35 | *
36 | */
37 | public interface SBPMActionDAO {
38 |
39 | public void insert(SBPMAction sPBMAction);
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMActionDAOImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.HashMap;
32 | import java.util.Map;
33 |
34 | import org.springframework.beans.factory.annotation.Autowired;
35 | import org.springframework.stereotype.Repository;
36 |
37 | import de.viadee.spring.batch.infrastructure.JdbcTemplateHolder;
38 | import de.viadee.spring.batch.persistence.types.SBPMAction;
39 |
40 | /**
41 | * DAO for the action object. See SpbmAction class for further details.
42 | *
43 | */
44 | @Repository
45 | public class SBPMActionDAOImpl implements SBPMActionDAO {
46 |
47 | @Autowired
48 | private JdbcTemplateHolder jdbcTemplateHolder;
49 |
50 | private final String INSERTSQL = "INSERT INTO \"Action\" (\"ActionID\",\"ActionName\",\"ActionType\",\"ActionFather\",\"ActionTime\") VALUES (:actionID,:actionName,:actionType,:actionFather,:actionTime);";
51 |
52 | @Override
53 | public void insert(final SBPMAction sPBMAction) {
54 | final Map params = new HashMap();
55 | params.put("actionID", "" + sPBMAction.getActionID());
56 | params.put("actionName", sPBMAction.getActionName());
57 | params.put("actionType", "" + sPBMAction.getActionType());
58 | params.put("actionFather", "" + sPBMAction.getActionFather());
59 | params.put("actionTime", "" + sPBMAction.getActionTime());
60 | jdbcTemplateHolder.getJdbcTemplate().update(INSERTSQL, params);
61 | }
62 | }
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMChunkExecutionDAO.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.List;
32 |
33 | import de.viadee.spring.batch.infrastructure.JdbcTemplateHolder;
34 | import de.viadee.spring.batch.persistence.types.SBPMChunkExecution;
35 |
36 | /**
37 | * DAO Interface for the ChunkExecution Object. See SpbmChunkExecution Class for further Details.
38 | *
39 | */
40 | public interface SBPMChunkExecutionDAO {
41 |
42 | public void insert(SBPMChunkExecution sPBMChunkExecution);
43 |
44 | public void insertBatch(List chunkExecutionList);
45 |
46 | public void setJdbcTemplateHolder(JdbcTemplateHolder jdbcTemplateHolder);
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMChunkExecutionDAOImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung GmbH
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.HashMap;
32 | import java.util.List;
33 | import java.util.Map;
34 |
35 | import de.viadee.spring.batch.infrastructure.JdbcTemplateHolder;
36 | import de.viadee.spring.batch.persistence.types.SBPMChunkExecution;
37 |
38 | /**
39 | * DAO Object for the Action ChunkExecution. See SpbmChunkExecution Class for
40 | * further Details.
41 | *
42 | */
43 | public class SBPMChunkExecutionDAOImpl implements SBPMChunkExecutionDAO {
44 |
45 | private JdbcTemplateHolder jdbcTemplateHolder;
46 |
47 | private final String CHUNKEXECUTIONINSERTSQL = "INSERT INTO \"ChunkExecution\" (\"ChunkExecutionID\", \"StepID\", \"StepName\", \"Iteration\",\"ChunkTime\") VALUES (:chunkExecutionID,:stepID,:stepName,:iteration,:chunkTime);";
48 |
49 | @Override
50 | public void insert(final SBPMChunkExecution sPBMChunkExecution) {
51 | final Map params = getParams(sPBMChunkExecution);
52 | jdbcTemplateHolder.getJdbcTemplate().update(CHUNKEXECUTIONINSERTSQL, params);
53 | }
54 |
55 | @Override
56 | public void insertBatch(final List chunkExecutionList) {
57 | final Map[] parameters = new Map[chunkExecutionList.size()];
58 | Map params;
59 | int counter = 0;
60 | for (final SBPMChunkExecution sPBMChunkExecution : chunkExecutionList) {
61 | params = getParams(sPBMChunkExecution);
62 | parameters[counter++] = params;
63 | }
64 | this.jdbcTemplateHolder.getJdbcTemplate().batchUpdate(CHUNKEXECUTIONINSERTSQL, parameters);
65 | }
66 |
67 | private Map getParams(final SBPMChunkExecution sPBMChunkExecution) {
68 | Map params = new HashMap();
69 | params.put("chunkExecutionID", "" + sPBMChunkExecution.getChunkExecutionID());
70 | params.put("stepID", "" + sPBMChunkExecution.getStepID());
71 | params.put("stepName", sPBMChunkExecution.getStepName());
72 | params.put("iteration", "" + sPBMChunkExecution.getIteration());
73 | params.put("chunkTime", "" + sPBMChunkExecution.getChunkTime());
74 | return params;
75 | }
76 |
77 | @Override
78 | public void setJdbcTemplateHolder(JdbcTemplateHolder jdbcTemplateHolder) {
79 | this.jdbcTemplateHolder = jdbcTemplateHolder;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMChunkExecutionQueue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.Queue;
32 | import java.util.concurrent.ConcurrentLinkedQueue;
33 |
34 | import org.apache.log4j.Logger;
35 | import org.springframework.stereotype.Component;
36 |
37 | import de.viadee.spring.batch.infrastructure.LoggingWrapper;
38 | import de.viadee.spring.batch.persistence.types.SBPMChunkExecution;
39 |
40 | /**
41 | * This class holds a ThreadSafe Queue containing ChunkExecution Objects that shall be stored in the Database.
42 | *
43 | * Whenever a SpbmChunkExecution Object shall be persisted into the Database, it is pushed into this List.
44 | *
45 | * The DatabaseScheduledWriter takes care of emptying this list and persisting the Entrys into the Database.
46 | *
47 | * See DatabaseScheduledWriter class for further Details.
48 | *
49 | */
50 | @Component
51 | public class SBPMChunkExecutionQueue {
52 |
53 | private final Queue chunkExecutionQueue = new ConcurrentLinkedQueue();
54 |
55 | private static final Logger LOG = LoggingWrapper.getLogger(SBPMChunkExecutionQueue.class);
56 |
57 | public synchronized void addChunkExecution(final SBPMChunkExecution sPBMChunkExecution) {
58 | this.chunkExecutionQueue.add(sPBMChunkExecution);
59 | }
60 |
61 | public SBPMChunkExecution getChunk() {
62 | final SBPMChunkExecution chunkExecution = chunkExecutionQueue.poll();
63 | if (chunkExecution == null) {
64 | LOG.trace("EMPTY POLL - Chunk Queue is empty");
65 | }
66 | return chunkExecution;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMItemDAO.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.List;
32 |
33 | import de.viadee.spring.batch.infrastructure.JdbcTemplateHolder;
34 | import de.viadee.spring.batch.persistence.types.SBPMItem;
35 |
36 | /**
37 | * DAO Interface for the Item Object. See SpbmItem Class for further Details.
38 | *
39 | */
40 | public interface SBPMItemDAO {
41 |
42 | public void insert(SBPMItem sPBMItem);
43 |
44 | public void insertBatch(List itemList);
45 |
46 | public void setJdbcTemplateHolder(JdbcTemplateHolder jdbcTemplateHolder);
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMItemDAOImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.HashMap;
32 | import java.util.List;
33 | import java.util.Map;
34 |
35 | import de.viadee.spring.batch.infrastructure.JdbcTemplateHolder;
36 | import de.viadee.spring.batch.persistence.types.SBPMItem;
37 |
38 | /**
39 | * DAO for the item object. See SpbmItem class for further details.
40 | *
41 | */
42 | //@Repository
43 | public class SBPMItemDAOImpl implements SBPMItemDAO {
44 |
45 |
46 | private JdbcTemplateHolder jdbcTemplateHolder;
47 |
48 | private final String ITEMINSERTSQL = "INSERT INTO \"Item\" (\"ActionID\",\"ChunkExecutionID\",\"ItemName\", \"ItemClassName\", \"ItemReflection\", \"TimeInMS\",\"Timestamp\", \"Error\") VALUES (:actionID,:chunkExecutionID,:itemName,:className,:itemJson,:timeInMS,:timestamp,:error);";
49 |
50 | @Override
51 | public void insert(final SBPMItem sPBMItem) {
52 | final Map params = getParams(sPBMItem);
53 | jdbcTemplateHolder.getJdbcTemplate().update(ITEMINSERTSQL, params);
54 | }
55 |
56 | @Override
57 | public void insertBatch(final List itemList) {
58 | final Map[] parameters = new Map[itemList.size()];
59 | Map params;
60 | int counter = 0;
61 | for (final SBPMItem sPBMItem : itemList) {
62 | params = getParams(sPBMItem);
63 | parameters[counter++] = params;
64 | }
65 | this.jdbcTemplateHolder.getJdbcTemplate().batchUpdate(ITEMINSERTSQL, parameters);
66 | }
67 |
68 | private Map getParams(final SBPMItem sPBMItem) {
69 | final Map params = new HashMap();
70 | params.put("actionID", "" + sPBMItem.getActionID());
71 | params.put("chunkExecutionID", "" + sPBMItem.getChunkExecutionID());
72 | params.put("itemName", "" + sPBMItem.getItemName());
73 | params.put("className", sPBMItem.getItemClass());
74 | params.put("itemJson", "" + sPBMItem.getItemReflection());
75 | params.put("timeInMS", "" + sPBMItem.getTimeInMS());
76 | params.put("timestamp", "" + sPBMItem.getTimestamp());
77 | params.put("error", "" + sPBMItem.isError());
78 | return params;
79 | }
80 |
81 | @Override
82 | public void setJdbcTemplateHolder(JdbcTemplateHolder jdbcTemplateHolder) {
83 | this.jdbcTemplateHolder = jdbcTemplateHolder;
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMItemQueue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.Queue;
32 | import java.util.concurrent.ConcurrentLinkedQueue;
33 |
34 | import org.apache.log4j.Logger;
35 | import org.springframework.stereotype.Component;
36 |
37 | import de.viadee.spring.batch.infrastructure.LoggingWrapper;
38 | import de.viadee.spring.batch.persistence.types.SBPMItem;
39 |
40 | /**
41 | * This class holds a ThreadSafe Queue containing item objects that shall be stored in the Database.
42 | *
43 | * Whenever an SpbmItem object needs to be persisted, it is pushed into this list.
44 | *
45 | * The DatabaseScheduledWriter takes care of emptying this list and persisting the entrys in the database.
46 | *
47 | * See DatabaseScheduledWriter class for further Details.
48 | *
49 | */
50 | @Component
51 | public class SBPMItemQueue {
52 |
53 | private final Queue itemQueue = new ConcurrentLinkedQueue();
54 |
55 | private static final Logger LOG = LoggingWrapper.getLogger(SBPMItemQueue.class);
56 |
57 | public void addItem(final SBPMItem sPBMItem) {
58 | this.itemQueue.add(sPBMItem);
59 | }
60 |
61 | public SBPMItem getItem() {
62 | final SBPMItem item = itemQueue.poll();
63 | if (item == null) {
64 | LOG.trace("EMPTY POLL - Item Queue is empty");
65 | }
66 | return item;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMJobDAO.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import de.viadee.spring.batch.persistence.types.SBPMJob;
32 |
33 | /**
34 | * DAO Interface for the Job Object. See SpbmJobClass for further Details.
35 | *
36 | *
37 | */
38 | public interface SBPMJobDAO {
39 |
40 | public void insert(SBPMJob job);
41 |
42 | public void insertMeta(SBPMJob job);
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMJobDAOImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.HashMap;
32 | import java.util.Map;
33 |
34 | import org.springframework.beans.factory.annotation.Autowired;
35 | import org.springframework.stereotype.Repository;
36 |
37 | import de.viadee.spring.batch.infrastructure.JdbcTemplateHolder;
38 | import de.viadee.spring.batch.infrastructure.SBPMConfiguration;
39 | import de.viadee.spring.batch.persistence.types.SBPMJob;
40 |
41 | /**
42 | * DAO Object for the Job Object. See SpbmJob Class for further Details.
43 | *
44 | *
45 | */
46 | @Repository
47 | public class SBPMJobDAOImpl implements SBPMJobDAO {
48 |
49 | @Autowired
50 | private JdbcTemplateHolder jdbcTemplateHolder;
51 |
52 | @Autowired
53 | private SBPMConfiguration sbpmConfig;
54 |
55 | private final String INSERTSQL = "INSERT INTO \"Job\" (\"JobID\",\"JobName\",\"JobStart\",\"JobEnd\",\"Duration\") VALUES (:jobID,:jobName,:jobStart,:jobEnd,:duration);";
56 |
57 | private final String INSERTMETASQL = "INSERT INTO \"BatchRuns\"(\"JobID\", \"StepID\", \"ActionType\", \"JobName\", \"StepName\", \"StepStart\", \"StepEnd\", \"ActionName\", \"TotalTime\", \"ProcessedItems\", \"MeanTimePerItem\") SELECT \"OV\".*, (\"OV\".\"Total\"/ \"OV\".\"ProcessedItems\") AS \"MeanTimePerItem\" FROM \"Overview\" AS \"OV\" WHERE \"OV\".\"JobID\" = :jobID;";
58 |
59 | @Override
60 | public void insert(final SBPMJob job) {
61 | final Map params = new HashMap();
62 | params.put("jobID", "" + job.getJobID());
63 | params.put("jobName", job.getJobName());
64 | params.put("jobStart", String.valueOf(job.getJobStart()));
65 | params.put("jobEnd", String.valueOf(job.getJobEnd()));
66 | params.put("duration", "" + job.getDuration());
67 | jdbcTemplateHolder.getJdbcTemplate().update(INSERTSQL, params);
68 | if (sbpmConfig.trackAnomaly()) {
69 | insertMeta(job);
70 | }
71 | }
72 |
73 | @Override
74 | public void insertMeta(final SBPMJob job) {
75 | final Map params = new HashMap();
76 | params.put("jobID", "" + job.getJobID());
77 | jdbcTemplateHolder.getJdbcTemplate().update(INSERTMETASQL, params);
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMStepActionDAO.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import de.viadee.spring.batch.persistence.types.SBPMStepAction;
32 |
33 | /**
34 | * DAO Interface for the StepAction Object. See SpbmStepAction Class for further Details.
35 | *
36 | *
37 | */
38 | public interface SBPMStepActionDAO {
39 |
40 | public void insert(SBPMStepAction sPBMStepAction);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMStepActionDAOImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.HashMap;
32 | import java.util.Map;
33 |
34 | import org.springframework.beans.factory.annotation.Autowired;
35 | import org.springframework.stereotype.Repository;
36 |
37 | import de.viadee.spring.batch.infrastructure.JdbcTemplateHolder;
38 | import de.viadee.spring.batch.persistence.types.SBPMStepAction;
39 |
40 | /**
41 | * DAO Object for the StepAction Object. See SpbmStepAction Class for further Details.
42 | *
43 | *
44 | */
45 | @Repository
46 | public class SBPMStepActionDAOImpl implements SBPMStepActionDAO {
47 |
48 | @Autowired
49 | private JdbcTemplateHolder jdbcTemplateHolder;
50 |
51 | private final String INSERTSQL = "INSERT INTO \"StepAction\" (\"StepID\", \"ActionID\") VALUES (:stepID,:actionID);";
52 |
53 | @Override
54 | public void insert(final SBPMStepAction sPBMStepAction) {
55 | final Map params = new HashMap();
56 | params.put("stepID", "" + sPBMStepAction.getStepID());
57 | params.put("actionID", "" + sPBMStepAction.getActionID());
58 | jdbcTemplateHolder.getJdbcTemplate().update(INSERTSQL, params);
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMStepDAO.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import de.viadee.spring.batch.persistence.types.SBPMStep;
32 |
33 | /**
34 | * DAO Interface for the Step Object. See SpbmStep Class for further Details.
35 | *
36 | *
37 | */
38 | public interface SBPMStepDAO {
39 |
40 | public void insert(SBPMStep sPBMStep);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/SBPMStepDAOImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence;
30 |
31 | import java.util.HashMap;
32 | import java.util.Map;
33 |
34 | import org.springframework.beans.factory.annotation.Autowired;
35 | import org.springframework.stereotype.Repository;
36 |
37 | import de.viadee.spring.batch.infrastructure.JdbcTemplateHolder;
38 | import de.viadee.spring.batch.persistence.types.SBPMStep;
39 |
40 | /**
41 | * DAO Object for the Step Object. See SpbmStep Class for further Details.
42 | *
43 | *
44 | */
45 | @Repository
46 | public class SBPMStepDAOImpl implements SBPMStepDAO {
47 |
48 | @Autowired
49 | private JdbcTemplateHolder jdbcTemplateHolder;
50 |
51 | private final String INSERTSQL = "INSERT INTO \"Step\" (\"StepID\",\"JobID\",\"StepName\",\"StepStart\",\"StepEnd\",\"StepTime\") VALUES (:stepID, :jobID, :stepName, :stepStart, :stepEnd, :stepTime);";
52 |
53 | @Override
54 | public void insert(final SBPMStep sPBMStep) {
55 | final Map params = new HashMap();
56 | params.put("stepID", "" + sPBMStep.getStepID());
57 | params.put("jobID", "" + sPBMStep.getJobID());
58 | params.put("stepName", sPBMStep.getStepName());
59 | params.put("stepStart", String.valueOf(sPBMStep.getStepStart()));
60 | params.put("stepEnd", String.valueOf(sPBMStep.getStepEnd()));
61 | params.put("stepTime", "" + sPBMStep.getStepTime());
62 | jdbcTemplateHolder.getJdbcTemplate().update(INSERTSQL, params);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/types/SBPMAction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence.types;
30 |
31 | /**
32 | * This is the Database representation of an action. An action is defined as either a reader, (Composite-)ItemProcessor
33 | * or an (Composite-) ItemWriter. The different types are distinguished by the "actionType" attribute, whereas a one
34 | * stands for an ItemReader, a two for an (Composite-) ItemProcessor and a three for an (Composite-) ItemWriter.
35 | *
36 | * This is an immutable class.
37 | */
38 | public class SBPMAction {
39 |
40 | private final int actionID;
41 |
42 | private final String actionName;
43 |
44 | private final int actionType;
45 |
46 | private final int actionFather;
47 |
48 | private final int actionTime;
49 |
50 | public SBPMAction(final int actionID, final String actionName, final int actionType, final int actionFather,
51 | final int actionTime) {
52 | super();
53 | this.actionID = actionID;
54 | this.actionName = actionName;
55 | this.actionType = actionType;
56 | this.actionFather = actionFather;
57 | this.actionTime = actionTime;
58 | }
59 |
60 | public int getActionID() {
61 | return actionID;
62 | }
63 |
64 | public String getActionName() {
65 | return actionName;
66 | }
67 |
68 | public int getActionType() {
69 | return actionType;
70 | }
71 |
72 | public int getActionFather() {
73 | return actionFather;
74 | }
75 |
76 | public int getActionTime() {
77 | return actionTime;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/types/SBPMChunkExecution.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence.types;
30 |
31 | /**
32 | * This is the Database representation of a ChunkExecution. Each ChunkExecution creates an own dataset inside the
33 | * Database.
34 | *
35 | * Example Scenario: A Step processing 40 Items having a Chunksize of 30 Items.
36 | *
37 | * In this Scenario, the Monitoring-Tool will create two separate ChunkExecution Elements for the particular Step.
38 | *
39 | *
40 | *
41 | */
42 | public class SBPMChunkExecution {
43 |
44 | private final int chunkExecutionID;
45 |
46 | private final int stepID;
47 |
48 | private final String stepName;
49 |
50 | private final int iteration;
51 |
52 | private int chunkTime;
53 |
54 | public SBPMChunkExecution(final int chunkExecutionID, final int stepID, final String stepName, final int iteration,
55 | final int chunkTime) {
56 | super();
57 | this.chunkExecutionID = chunkExecutionID;
58 | this.stepID = stepID;
59 | this.stepName = stepName;
60 | this.iteration = iteration;
61 | this.chunkTime = chunkTime;
62 | }
63 |
64 | public int getChunkExecutionID() {
65 | return chunkExecutionID;
66 | }
67 |
68 | public int getStepID() {
69 | return stepID;
70 | }
71 |
72 | public String getStepName() {
73 | return this.stepName;
74 | }
75 |
76 | public int getIteration() {
77 | return iteration;
78 | }
79 |
80 | public int getChunkTime() {
81 | return chunkTime;
82 | }
83 |
84 | public void setChunkTime(final int chunkTime) {
85 | this.chunkTime = chunkTime;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/types/SBPMItem.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence.types;
30 |
31 | import org.joda.time.Instant;
32 |
33 | /**
34 | * This is the Database representation of an Item-Based Performance-Measurement. It stores the information, how long an
35 | * item has been active in a particular action (Read / Process / Write).
36 | *
37 | * IMPORTANT: This class makes use of the "toString()" Method of the processed Item in order to empower the Developer to
38 | * identify the particular Item that has been processed by the dataset inside the Monitoring-Database. Please do use a
39 | * StringBuffer rather than String concatination in the "toString()" Method of your Items in order to keep the
40 | * monitoring overhead minimal.
41 | *
42 | * This is an immutable class.
43 | *
44 | */
45 | public class SBPMItem {
46 |
47 | private final int actionID;
48 |
49 | private final int chunkExecutionID;
50 |
51 | private final int timeInMS;
52 |
53 | private final String itemName;
54 |
55 | private final String itemReflection;
56 |
57 | private final String itemClass;
58 |
59 | private final long timestamp;
60 |
61 | private final int error;
62 |
63 | public SBPMItem(final int actionID, final int chunkExecutionID, final int timeInMS, final int error,
64 | String itemName, String itemReflection, String itemClass) {
65 | super();
66 | this.actionID = actionID;
67 | this.chunkExecutionID = chunkExecutionID;
68 | this.timeInMS = timeInMS;
69 | this.timestamp = Instant.now().getMillis();
70 | this.error = error;
71 | if (itemName.length() >= 1000) {
72 | itemName = itemName.substring(0, 1000);
73 | }
74 | this.itemName = itemName;
75 | this.itemReflection = itemReflection;
76 | this.itemClass = itemClass;
77 | }
78 |
79 | public String getItemName() {
80 | return itemName;
81 | }
82 |
83 | public String getItemClass() {
84 | return itemClass;
85 | }
86 |
87 | public String getItemReflection() {
88 | return itemReflection;
89 | }
90 |
91 |
92 | public int getActionID() {
93 | return actionID;
94 | }
95 |
96 | public int getChunkExecutionID() {
97 | return chunkExecutionID;
98 | }
99 |
100 | public int getTimeInMS() {
101 | return timeInMS;
102 | }
103 |
104 | public long getTimestamp() {
105 | return timestamp;
106 | }
107 |
108 | public int isError() {
109 | return error;
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/types/SBPMJob.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence.types;
30 |
31 | /**
32 | * This is the database representation of a Job.
33 | *
34 | */
35 | public class SBPMJob {
36 |
37 | private final int jobID;
38 |
39 | private final String jobName;
40 |
41 | private int duration;
42 |
43 | private long jobStart;
44 |
45 | private long jobEnd;
46 |
47 | public SBPMJob(final int jobID, final String jobName, final int Duration) {
48 | this.jobID = jobID;
49 | this.jobName = jobName;
50 | }
51 |
52 | public int getJobID() {
53 | return this.jobID;
54 | }
55 |
56 | public String getJobName() {
57 | return this.jobName;
58 | }
59 |
60 | public void setDuration(final int duration) {
61 | this.duration = duration;
62 | }
63 |
64 | public int getDuration() {
65 | return this.duration;
66 | }
67 |
68 | public long getJobStart() {
69 | return jobStart;
70 | }
71 |
72 | public void setJobStart(long jobStart) {
73 | this.jobStart = jobStart;
74 | }
75 |
76 | public long getJobEnd() {
77 | return jobEnd;
78 | }
79 |
80 | public void setJobEnd(long jobEnd) {
81 | this.jobEnd = jobEnd;
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/types/SBPMStep.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence.types;
30 |
31 | /**
32 | * This is the Database representation of a Step.
33 | *
34 | *
35 | */
36 | public class SBPMStep {
37 |
38 | private final int stepID;
39 |
40 | private final int jobID;
41 |
42 | private final String stepName;
43 |
44 | private int stepTime;
45 |
46 | private long stepStart;
47 |
48 | private long stepEnd;
49 |
50 | public SBPMStep(final int stepID, final int jobID, final String stepName, final int stepTime) {
51 | super();
52 | this.stepID = stepID;
53 | this.jobID = jobID;
54 | this.stepName = stepName;
55 | this.stepTime = stepTime;
56 | }
57 |
58 | public int getStepID() {
59 | return stepID;
60 | }
61 |
62 | public int getJobID() {
63 | return jobID;
64 | }
65 |
66 | public String getStepName() {
67 | return stepName;
68 | }
69 |
70 | public int getStepTime() {
71 | return stepTime;
72 | }
73 |
74 | public void setStepTime(final int stepTime) {
75 | this.stepTime = stepTime;
76 | }
77 |
78 | public long getStepStart() {
79 | return stepStart;
80 | }
81 |
82 | public void setStepStart(long stepStart) {
83 | this.stepStart = stepStart;
84 | }
85 |
86 | public long getStepEnd() {
87 | return stepEnd;
88 | }
89 |
90 | public void setStepEnd(long stepEnd) {
91 | this.stepEnd = stepEnd;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/de/viadee/spring/batch/persistence/types/SBPMStepAction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.persistence.types;
30 |
31 | /**
32 | * This is the Database representation the interconnection between a Step and an Action. This is needed to speed up
33 | * analytical querys (also for the provided views), since gathering this connection from the database would need to join
34 | * almost all tables which is impractical when a lot of items have been measured.
35 | *
36 | */
37 | public class SBPMStepAction {
38 |
39 | private final int stepID;
40 |
41 | private final int actionID;
42 |
43 | public SBPMStepAction(final int stepID, final int actionID) {
44 | this.stepID = stepID;
45 | this.actionID = actionID;
46 | }
47 |
48 | public int getStepID() {
49 | return stepID;
50 | }
51 |
52 | public int getActionID() {
53 | return actionID;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/resources/BSD3-license.txt:
--------------------------------------------------------------------------------
1 | Copyright � ${project.inceptionYear}, ${owner}
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are met:
5 |
6 | * Redistributions of source code must retain the above copyright notice, this
7 | list of conditions and the following disclaimer.
8 |
9 | * Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 |
13 | * Neither the name of the copyright holder nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 |
--------------------------------------------------------------------------------
/src/main/resources/SQL/schema-h2.sql:
--------------------------------------------------------------------------------
1 | -- Autogenerated: do not edit this file
2 |
3 | -- Clean the whole DB
4 | DROP ALL OBJECTS;
5 |
6 |
7 | CREATE TABLE BATCH_JOB_INSTANCE (
8 | JOB_INSTANCE_ID BIGINT IDENTITY NOT NULL PRIMARY KEY ,
9 | VERSION BIGINT ,
10 | JOB_NAME VARCHAR(100) NOT NULL,
11 | JOB_KEY VARCHAR(32) NOT NULL,
12 | constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY)
13 | ) ;
14 |
15 | CREATE TABLE BATCH_JOB_EXECUTION (
16 | JOB_EXECUTION_ID BIGINT IDENTITY NOT NULL PRIMARY KEY ,
17 | VERSION BIGINT ,
18 | JOB_INSTANCE_ID BIGINT NOT NULL,
19 | CREATE_TIME TIMESTAMP NOT NULL,
20 | START_TIME TIMESTAMP DEFAULT NULL ,
21 | END_TIME TIMESTAMP DEFAULT NULL ,
22 | STATUS VARCHAR(10) ,
23 | EXIT_CODE VARCHAR(2500) ,
24 | EXIT_MESSAGE VARCHAR(2500) ,
25 | LAST_UPDATED TIMESTAMP,
26 | JOB_CONFIGURATION_LOCATION VARCHAR(2500) NULL,
27 | constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID)
28 | references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)
29 | ) ;
30 |
31 | CREATE TABLE BATCH_JOB_EXECUTION_PARAMS (
32 | JOB_EXECUTION_ID BIGINT NOT NULL ,
33 | TYPE_CD VARCHAR(6) NOT NULL ,
34 | KEY_NAME VARCHAR(100) NOT NULL ,
35 | STRING_VAL VARCHAR(250) ,
36 | DATE_VAL TIMESTAMP DEFAULT NULL ,
37 | LONG_VAL BIGINT ,
38 | DOUBLE_VAL DOUBLE PRECISION ,
39 | IDENTIFYING CHAR(1) NOT NULL ,
40 | constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID)
41 | references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
42 | ) ;
43 |
44 | CREATE TABLE BATCH_STEP_EXECUTION (
45 | STEP_EXECUTION_ID BIGINT IDENTITY NOT NULL PRIMARY KEY ,
46 | VERSION BIGINT NOT NULL,
47 | STEP_NAME VARCHAR(100) NOT NULL,
48 | JOB_EXECUTION_ID BIGINT NOT NULL,
49 | START_TIME TIMESTAMP NOT NULL ,
50 | END_TIME TIMESTAMP DEFAULT NULL ,
51 | STATUS VARCHAR(10) ,
52 | COMMIT_COUNT BIGINT ,
53 | READ_COUNT BIGINT ,
54 | FILTER_COUNT BIGINT ,
55 | WRITE_COUNT BIGINT ,
56 | READ_SKIP_COUNT BIGINT ,
57 | WRITE_SKIP_COUNT BIGINT ,
58 | PROCESS_SKIP_COUNT BIGINT ,
59 | ROLLBACK_COUNT BIGINT ,
60 | EXIT_CODE VARCHAR(2500) ,
61 | EXIT_MESSAGE VARCHAR(2500) ,
62 | LAST_UPDATED TIMESTAMP,
63 | constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID)
64 | references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
65 | ) ;
66 |
67 | CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT (
68 | STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
69 | SHORT_CONTEXT VARCHAR(2500) NOT NULL,
70 | SERIALIZED_CONTEXT LONGVARCHAR ,
71 | constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID)
72 | references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID)
73 | ) ;
74 |
75 | CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT (
76 | JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
77 | SHORT_CONTEXT VARCHAR(2500) NOT NULL,
78 | SERIALIZED_CONTEXT LONGVARCHAR ,
79 | constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID)
80 | references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
81 | ) ;
82 |
83 | CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ;
84 | CREATE SEQUENCE BATCH_JOB_EXECUTION_SEQ;
85 | CREATE SEQUENCE BATCH_JOB_SEQ;
86 |
--------------------------------------------------------------------------------
/src/main/resources/h2starter.sh:
--------------------------------------------------------------------------------
1 | ####
2 | # Analysetool
3 | ####
4 | # Voraussetzungen zum Start:
5 | # - Java im Systempfad vorhanden und aufrufbar
6 | # - das H2-Jar befindet sich im aktuellen Verzeichnis
7 | # - Das H2Starter.jar befindet sich im aktuellen Verzeichnis
8 | ####
9 | java -jar H2Starter.jar
--------------------------------------------------------------------------------
/src/main/resources/sbpmApplicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/resources/springBatchMonitoringDefault.properties:
--------------------------------------------------------------------------------
1 | # Properties file for internal purposes (Unit-Testing etc.)
2 |
3 | #Database Configuration
4 | db.driver=org.h2.Driver
5 | db.username=sa
6 | db.password=sasa
7 | db.url=jdbc:h2:./target/database/monitoringDB;MULTI_THREADED=1
8 | db.anomalydetection=false
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/JobLauncherController.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest;
30 |
31 | import javax.servlet.http.HttpServletRequest;
32 |
33 | import org.springframework.batch.core.JobParametersBuilder;
34 | import org.springframework.batch.core.configuration.JobRegistry;
35 | import org.springframework.batch.core.launch.JobLauncher;
36 | import org.springframework.http.HttpStatus;
37 | import org.springframework.web.bind.annotation.RequestMapping;
38 | import org.springframework.web.bind.annotation.RequestMethod;
39 | import org.springframework.web.bind.annotation.RequestParam;
40 | import org.springframework.web.bind.annotation.ResponseStatus;
41 |
42 | public class JobLauncherController {
43 |
44 | private static final String JOB_PARAM = "job";
45 |
46 | private JobLauncher jobLauncher;
47 |
48 | private JobRegistry jobRegistry;
49 |
50 | public JobLauncherController(final JobLauncher jobLauncher, final JobRegistry jobRegistry) {
51 | super();
52 | this.jobLauncher = jobLauncher;
53 | this.jobRegistry = jobRegistry;
54 | }
55 |
56 | @RequestMapping(value = "joblauncher", method = RequestMethod.GET)
57 | @ResponseStatus(HttpStatus.ACCEPTED)
58 | public void launch(@RequestParam final String job, final HttpServletRequest request) throws Exception {
59 | final JobParametersBuilder builder = extractParameters(request);
60 | jobLauncher.run(jobRegistry.getJob(request.getParameter(JOB_PARAM)), builder.toJobParameters());
61 | }
62 |
63 | public void init() {
64 | System.out.println("#################################");
65 | System.out.println("#################################");
66 | System.out.println("########I AM YOUR SERVLET########");
67 | System.out.println("#################################");
68 | System.out.println("#################################");
69 |
70 | }
71 |
72 | public JobLauncherController() {
73 | System.out.println("#################################");
74 | System.out.println("#################################");
75 | System.out.println("########I AM YOUR SERVLET2########");
76 | System.out.println("#################################");
77 | System.out.println("#################################");
78 | System.out.println("");
79 | System.out.println("");
80 | System.out.println("");
81 | System.out.println("Now starting the SpringBatchExamples");
82 | }
83 |
84 | private JobParametersBuilder extractParameters(final HttpServletRequest request) {
85 | return new JobParametersBuilder();
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/MainApplication.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.core.JobParametersInvalidException;
33 | import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
34 | import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
35 | import org.springframework.batch.core.repository.JobRestartException;
36 | import org.springframework.beans.BeansException;
37 | import org.springframework.context.ApplicationContext;
38 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
39 | import org.springframework.context.support.AbstractApplicationContext;
40 |
41 | public class MainApplication {
42 |
43 | private static final Logger LOG = Logger.getLogger(MainApplication.class);
44 |
45 | // Amount of Student objects generated for the batch processing during the first step.
46 |
47 | public static void main(final String[] args)
48 | throws BeansException, JobExecutionAlreadyRunningException, JobRestartException,
49 | JobInstanceAlreadyCompleteException, JobParametersInvalidException, InterruptedException {
50 | // LOG.info("Sleeping 5 Seconds.");
51 | // Thread.sleep(5000);
52 | LOG.info("Done sleeping - Now creating ApplicationContext");
53 | final ApplicationContext ctx = new AnnotationConfigApplicationContext(
54 | de.viadee.spring.batch.integrationtest.configuration.ApplicationConfiguration.class);
55 | // ((AbstractApplicationContext) ctx).addApplicationListener(new ContextCloseEventHandler());
56 | final de.viadee.spring.batch.integrationtest.configuration.JobLaunchController appConfig = ctx
57 | .getBean(de.viadee.spring.batch.integrationtest.configuration.JobLaunchController.class);
58 | appConfig.launchJobs();
59 | // LOG.info("Sleeping 5 Seconds.");
60 | // Thread.sleep(5000);
61 | ((AbstractApplicationContext) ctx).close();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/common/Customer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.common;
30 |
31 | public class Customer {
32 |
33 | private int customerID;
34 |
35 | private String firstName, lastName;
36 |
37 | private float transactionTotal;
38 |
39 | public Customer(final int customerID, final String firstName, final String lastName) {
40 | this.customerID = customerID;
41 | this.firstName = firstName;
42 | this.lastName = lastName;
43 | this.transactionTotal = 0;
44 | }
45 |
46 | public Customer(final int customerID, final String firstName, final String lastName, final float transactionTotal) {
47 | this.customerID = customerID;
48 | this.firstName = firstName;
49 | this.lastName = lastName;
50 | this.transactionTotal = transactionTotal;
51 | }
52 |
53 | public Customer() {
54 | super();
55 | }
56 |
57 | public int getCustomerID() {
58 | return customerID;
59 | }
60 |
61 | public void setCustomerID(final int customerID) {
62 | this.customerID = customerID;
63 | }
64 |
65 | public String getFirstName() {
66 | return firstName;
67 | }
68 |
69 | public void setFirstName(final String firstName) {
70 | this.firstName = firstName;
71 | }
72 |
73 | public String getLastName() {
74 | return lastName;
75 | }
76 |
77 | public void setLastName(final String lastName) {
78 | this.lastName = lastName;
79 | }
80 |
81 | public float getTransactionTotal() {
82 | return transactionTotal;
83 | }
84 |
85 | public void setTransactionTotal(final float transactionTotal) {
86 | this.transactionTotal = transactionTotal;
87 | }
88 |
89 | @Override
90 | public String toString() {
91 | final StringBuilder str = new StringBuilder();
92 | str.append("<");
93 | str.append(this.customerID);
94 | str.append(">, <");
95 | str.append(this.firstName);
96 | str.append(">, <");
97 | str.append(this.lastName);
98 | str.append(">, <");
99 | str.append(this.getTransactionTotal());
100 | str.append(">");
101 | return str.toString();
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/common/CustomerEnhanced.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.common;
30 |
31 | public class CustomerEnhanced extends Customer {
32 |
33 | private String firstNameUpperCase, lastNameUpperCase, firstNameLowerCase, lastNameLowerCase;
34 |
35 | public CustomerEnhanced() {
36 | super();
37 | }
38 |
39 | public CustomerEnhanced(final int customerID, final String firstName, final String lastName,
40 | final float transactionTotal) {
41 | super(customerID, firstName, lastName, transactionTotal);
42 | }
43 |
44 | public String getFirstNameUpperCase() {
45 | return firstNameUpperCase;
46 | }
47 |
48 | public void setFirstNameUpperCase(final String firstNameUpperCase) {
49 | this.firstNameUpperCase = firstNameUpperCase;
50 | }
51 |
52 | public String getLastNameUpperCase() {
53 | return lastNameUpperCase;
54 | }
55 |
56 | public void setLastNameUpperCase(final String lastNameUpperCase) {
57 | this.lastNameUpperCase = lastNameUpperCase;
58 | }
59 |
60 | public String getFirstNameLowerCase() {
61 | return firstNameLowerCase;
62 | }
63 |
64 | public void setFirstNameLowerCase(final String firstnameLowerCase) {
65 | this.firstNameLowerCase = firstnameLowerCase;
66 | }
67 |
68 | public String getLastNameLowerCase() {
69 | return lastNameLowerCase;
70 | }
71 |
72 | public void setLastNameLowerCase(final String lastNameLowerCase) {
73 | this.lastNameLowerCase = lastNameLowerCase;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/common/CustomerRowMapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.common;
30 |
31 | import java.sql.ResultSet;
32 | import java.sql.SQLException;
33 |
34 | import org.springframework.jdbc.core.RowMapper;
35 | import org.springframework.stereotype.Component;
36 |
37 | @Component
38 | public class CustomerRowMapper implements RowMapper {
39 |
40 | @Override
41 | public Customer mapRow(final ResultSet rs, final int rowNum) throws SQLException {
42 |
43 | final Customer customer = new Customer();
44 | customer.setCustomerID(rs.getInt("CustomerID"));
45 | customer.setFirstName(rs.getString("FirstName"));
46 | customer.setLastName(rs.getString("LastName"));
47 | customer.setTransactionTotal(rs.getFloat("TransactionTotal"));
48 | return customer;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/common/Transaction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.common;
30 |
31 | public class Transaction {
32 |
33 | private int customerID;
34 |
35 | private int amount;
36 |
37 | public Transaction(final int customerID, final int amount) {
38 | super();
39 |
40 | this.customerID = customerID;
41 | this.amount = amount;
42 | }
43 |
44 | public Transaction() {
45 | super();
46 | }
47 |
48 | public int getCustomerID() {
49 | return customerID;
50 | }
51 |
52 | public void setCustomerID(final int customerID) {
53 | this.customerID = customerID;
54 | }
55 |
56 | public int getAmount() {
57 | return amount;
58 | }
59 |
60 | public void setAmount(final int amount) {
61 | this.amount = amount;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/common/TransactionRowMapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.common;
30 |
31 | import java.sql.ResultSet;
32 | import java.sql.SQLException;
33 |
34 | import org.apache.log4j.Logger;
35 | import org.springframework.jdbc.core.RowMapper;
36 |
37 | public class TransactionRowMapper implements RowMapper {
38 |
39 | private static Logger LOG = Logger.getLogger(TransactionRowMapper.class);
40 |
41 | public Transaction mapRow(ResultSet rs, int rowNum) throws SQLException {
42 | Transaction transaction = new Transaction();
43 | transaction.setCustomerID(rs.getInt("CustomerID"));
44 | transaction.setAmount(rs.getInt("Amount"));
45 | return transaction;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/configuration/ApplicationConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.configuration;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.beans.factory.annotation.Autowired;
33 | import org.springframework.context.annotation.Configuration;
34 | import org.springframework.context.annotation.Import;
35 |
36 | @Configuration
37 | @Import({ StandaloneInfrastructureConfiguration.class, de.viadee.spring.batch.infrastructure.Configurator.class,
38 | de.viadee.spring.batch.integrationtest.jobs.JobCreator.class, JobLaunchController.class })
39 | public class ApplicationConfiguration {
40 |
41 | private static Logger LOG = Logger.getLogger(ApplicationConfiguration.class);
42 |
43 | @Autowired
44 | JobLaunchController jobLaunchController;
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/configuration/InfrastructureConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.configuration;
30 |
31 | import javax.sql.DataSource;
32 |
33 | import org.springframework.context.annotation.Bean;
34 | import org.springframework.core.task.TaskExecutor;
35 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
36 | import org.springframework.transaction.PlatformTransactionManager;
37 |
38 | public interface InfrastructureConfiguration {
39 |
40 | @Bean
41 | public abstract DataSource dataSource();
42 |
43 | @Bean
44 | public abstract PlatformTransactionManager platformTransactionManager();
45 |
46 | @Bean
47 | public abstract NamedParameterJdbcTemplate template();
48 |
49 | @Bean
50 | public abstract TaskExecutor taskExecutor();
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/configuration/JobLaunchController.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.configuration;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.core.Job;
33 | import org.springframework.batch.core.JobParameters;
34 | import org.springframework.batch.core.JobParametersInvalidException;
35 | import org.springframework.batch.core.launch.JobLauncher;
36 | import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
37 | import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
38 | import org.springframework.batch.core.repository.JobRestartException;
39 | import org.springframework.beans.factory.annotation.Autowired;
40 | import org.springframework.context.annotation.Configuration;
41 | import org.springframework.context.annotation.Import;
42 |
43 | import de.viadee.spring.batch.integrationtest.jobs.calculategradepoints.CalculateTransactionTotalJobConfig;
44 | import de.viadee.spring.batch.integrationtest.jobs.calculategradepoints.CalculateTransactionTotalPartitionJob;
45 | import de.viadee.spring.batch.integrationtest.jobs.formatnames.FormatNamesJobConfig;
46 | import de.viadee.spring.batch.integrationtest.jobs.preparedatabase.PrepareDatabaseJobConfig;
47 |
48 | @Import({ de.viadee.spring.batch.integrationtest.jobs.preparedatabase.PrepareDatabaseJobConfig.class,
49 | CalculateTransactionTotalJobConfig.class, CalculateTransactionTotalPartitionJob.class, FormatNamesJobConfig.class })
50 |
51 | @Configuration
52 | public class JobLaunchController {
53 |
54 | private static Logger LOG = Logger.getLogger(JobLaunchController.class);
55 |
56 | @Autowired
57 | JobLauncher jobLauncher;
58 |
59 | @Autowired
60 | PrepareDatabaseJobConfig prepareDatabaseJob;
61 |
62 | @Autowired
63 | FormatNamesJobConfig formatNamesJob;
64 |
65 | @Autowired
66 | CalculateTransactionTotalJobConfig calculateTransactionTotalJob;
67 |
68 | @Autowired
69 | CalculateTransactionTotalPartitionJob calculateTransactionTotalPartitionJob;
70 |
71 | private Job getPrepareDatabaseJob() {
72 | return prepareDatabaseJob.prepareDatabaseJob();
73 | }
74 |
75 | private Job getCalculateTransactionTotalJob() {
76 | return calculateTransactionTotalJob.calculateTransactionTotalJob();
77 | }
78 |
79 | private Job getCalculateTransactionTotalPartitionJob() {
80 | return calculateTransactionTotalPartitionJob.calculateTransactionTotaPartitionlJob();
81 | }
82 |
83 | private Job getFormatNamesJob() {
84 | return formatNamesJob.formatNamesJob();
85 | }
86 |
87 | public void launchJobs() throws JobExecutionAlreadyRunningException, JobRestartException,
88 | JobInstanceAlreadyCompleteException, JobParametersInvalidException, InterruptedException {
89 | long before, after;
90 | LOG.debug("Launching Job1");
91 | before = System.currentTimeMillis();
92 | jobLauncher.run(getPrepareDatabaseJob(), new JobParameters());
93 | after = System.currentTimeMillis();
94 | LOG.info("Runtime for Job1: " + (after - before) + "ms");
95 | LOG.debug("Launching Job2");
96 | before = System.currentTimeMillis();
97 | jobLauncher.run(getCalculateTransactionTotalJob(), new JobParameters());
98 | after = System.currentTimeMillis();
99 | LOG.info("Runtime for Job2: " + (after - before) + "ms");
100 |
101 | LOG.debug("Launching Job3");
102 | before = System.currentTimeMillis();
103 | jobLauncher.run(getCalculateTransactionTotalPartitionJob(), new JobParameters());
104 | after = System.currentTimeMillis();
105 | LOG.info("Runtime for Job3: " + (after - before) + "ms");
106 |
107 | LOG.debug("Launching Job4");
108 | before = System.currentTimeMillis();
109 | jobLauncher.run(getFormatNamesJob(), new JobParameters());
110 | after = System.currentTimeMillis();
111 | LOG.info("Runtime for Job4: " + (after - before) + "ms");
112 | LOG.debug("JobLauncher done");
113 |
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/JobCreator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs;
30 |
31 | import org.springframework.context.annotation.Import;
32 | import org.springframework.stereotype.Component;
33 |
34 | import de.viadee.spring.batch.integrationtest.jobs.calculategradepoints.CalculateTransactionTotalJobConfig;
35 | import de.viadee.spring.batch.integrationtest.jobs.formatnames.FormatNamesJobConfig;
36 | import de.viadee.spring.batch.integrationtest.jobs.preparedatabase.PrepareDatabaseJobConfig;
37 |
38 | @Import({ PrepareDatabaseJobConfig.class, CalculateTransactionTotalJobConfig.class, FormatNamesJobConfig.class })
39 | @Component
40 | public class JobCreator {
41 |
42 | // private static Logger LOG = Logger.getLogger(JobCreator.class);
43 | //
44 | // @Autowired
45 | // private PrepareDatabaseJob prepareDatabaseJob;
46 | //
47 | // @Autowired
48 | // private CalculateGradePointsAverageJob calculateGradePointsAverageJob;
49 | //
50 | // @Autowired
51 | // private FormatNamesJob formatNamesJob;
52 |
53 | // public Job getPrepareDatabaseJob() {
54 | // System.out.println("#############getPrepareDB");
55 | // return prepareDatabaseJob.getPrepareDatabaseJob();
56 | // }
57 | //
58 | // public Job getCalculateGradePointsAverageJob() {
59 | // return calculateGradePointsAverageJob.getCalculateGradePointsAverageJob();
60 | // }
61 | //
62 | // public Job getFormatNamesJob() {
63 | // return formatNamesJob.getFormatNamesJob();
64 | // }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/CalculateTransactionTotalJobConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.core.Job;
33 | import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
34 | import org.springframework.beans.factory.annotation.Autowired;
35 | import org.springframework.context.annotation.Bean;
36 | import org.springframework.context.annotation.Configuration;
37 | import org.springframework.context.annotation.Import;
38 |
39 | @Import(CalculateTransactionTotalStepConfig.class)
40 | @Configuration
41 | public class CalculateTransactionTotalJobConfig {
42 |
43 | private static Logger LOG = Logger.getLogger(CalculateTransactionTotalJobConfig.class);
44 |
45 | @Autowired
46 | private JobBuilderFactory jobBuilders;
47 |
48 | @Autowired
49 | private CalculateTransactionTotalStepConfig calculateTransactionTotalStep;
50 |
51 | @Bean
52 | public Job calculateTransactionTotalJob() {
53 | return jobBuilders.get("calculateTransactionTotalJob")
54 | .start(calculateTransactionTotalStep.calculateTransactionTotalStep()).build();
55 |
56 | }
57 |
58 | public Job getCalculateTransactionTotalJob() {
59 | return calculateTransactionTotalJob();
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/CalculateTransactionTotalPartitionJob.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.core.Job;
33 | import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
34 | import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
35 | import org.springframework.beans.factory.annotation.Autowired;
36 | import org.springframework.context.annotation.Bean;
37 | import org.springframework.context.annotation.Configuration;
38 | import org.springframework.context.annotation.Import;
39 |
40 | @Import(CalculateTransactionTotalPartitioningStepConfig.class)
41 | @Configuration
42 | @EnableBatchProcessing
43 | public class CalculateTransactionTotalPartitionJob {
44 |
45 | private static Logger LOG = Logger.getLogger(CalculateTransactionTotalJobConfig.class);
46 |
47 | @Autowired
48 | private JobBuilderFactory jobBuilders;
49 |
50 | @Autowired
51 | private CalculateTransactionTotalPartitioningStepConfig calculateTransactionTotalPartitioningStep;
52 |
53 | @Bean
54 | public Job calculateTransactionTotaPartitionlJob() {
55 | return jobBuilders.get("calculateTransactionTotalPartitioningJob")
56 | .start(calculateTransactionTotalPartitioningStep.partitionStep()).build();
57 |
58 | }
59 |
60 | public Job getCalculateTransactionTotalJob() {
61 | return calculateTransactionTotaPartitionlJob();
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/CalculateTransactionTotalPartitionReader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import javax.sql.DataSource;
32 |
33 | import org.springframework.batch.item.ExecutionContext;
34 | import org.springframework.batch.item.ItemReader;
35 | import org.springframework.batch.item.NonTransientResourceException;
36 | import org.springframework.batch.item.ParseException;
37 | import org.springframework.batch.item.UnexpectedInputException;
38 | import org.springframework.batch.item.database.JdbcCursorItemReader;
39 | import org.springframework.beans.factory.annotation.Autowired;
40 | import org.springframework.context.annotation.Bean;
41 | import org.springframework.stereotype.Component;
42 |
43 | import de.viadee.spring.batch.integrationtest.common.Customer;
44 | import de.viadee.spring.batch.integrationtest.common.CustomerRowMapper;
45 |
46 | @Component
47 | public class CalculateTransactionTotalPartitionReader implements ItemReader {
48 |
49 | @Autowired
50 | DataSource dataSource;
51 |
52 | @Override
53 | public Customer read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
54 | return customerIdItemReader().read();
55 | }
56 |
57 | @Bean
58 | public ItemReader customerIdItemReader() {
59 | JdbcCursorItemReader reader = new JdbcCursorItemReader();
60 | // int fromId = Integer.parseInt(reader.getExecutionContextKey("fromId"));
61 | // int toId = Integer.parseInt(reader.getExecutionContextKey("toId"));
62 | // System.out.println("From - " + fromId + " To " + toId);
63 | // reader.
64 | // System.out.println("ToId is:" + reader.getExecutionContextKey("toId"));
65 |
66 | // System.out.println("To: " + this.stepExecution.getExecutionContext().getInt("toId"));
67 | // System.out.println("From: " + fromId);
68 | // System.out.println("To: " + toId);
69 | reader.setSql(
70 | "SELECT CustomerID, FirstName, LastName, TransactionTotal FROM Customer WHERE CustomerId >= 100000 and CustomerId < 100010");
71 | reader.setDataSource(dataSource);
72 | reader.setRowMapper(new CustomerRowMapper());
73 | try {
74 | reader.afterPropertiesSet();
75 | } catch (Exception e) {
76 | // TODO Auto-generated catch block
77 | e.printStackTrace();
78 | }
79 | return reader;
80 | }
81 |
82 | public void open(ExecutionContext ctx) {
83 | System.out.println("#####################" + ctx.getInt("fromInt"));
84 |
85 | }
86 |
87 | }
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/CalculateTransactionTotalPartitioningListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import org.springframework.batch.core.ExitStatus;
32 | import org.springframework.batch.core.StepExecution;
33 | import org.springframework.batch.core.StepExecutionListener;
34 |
35 | public class CalculateTransactionTotalPartitioningListener implements StepExecutionListener {
36 |
37 | private CalculateTransactionTotalPartitioningStepConfig step;
38 |
39 | public void setStep(CalculateTransactionTotalPartitioningStepConfig step) {
40 | this.step = step;
41 | }
42 |
43 | @Override
44 | public void beforeStep(StepExecution stepExecution) {
45 | System.out.println("########## Name: " + stepExecution.getExecutionContext().getString("name") + " From: "
46 | + stepExecution.getExecutionContext().getInt("fromId") + " to: "
47 | + stepExecution.getExecutionContext().getInt("toId"));
48 | step.sayHello();
49 | }
50 |
51 | @Override
52 | public ExitStatus afterStep(StepExecution stepExecution) {
53 | // TODO Auto-generated method stub
54 | return null;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/CalculateTransactionTotalProcessor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import java.util.HashMap;
32 | import java.util.List;
33 | import java.util.Map;
34 |
35 | import org.apache.log4j.Logger;
36 | import org.springframework.batch.item.ItemProcessor;
37 | import org.springframework.context.annotation.Import;
38 | import org.springframework.context.annotation.Scope;
39 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
40 | import org.springframework.stereotype.Component;
41 |
42 | import de.viadee.spring.batch.integrationtest.common.Customer;
43 | import de.viadee.spring.batch.integrationtest.common.Transaction;
44 | import de.viadee.spring.batch.integrationtest.common.TransactionRowMapper;
45 | import de.viadee.spring.batch.integrationtest.configuration.StandaloneInfrastructureConfiguration;
46 |
47 | @Import(StandaloneInfrastructureConfiguration.class)
48 | @Component
49 | @Scope("step")
50 | public class CalculateTransactionTotalProcessor implements ItemProcessor {
51 |
52 | // Section for multithreading support (partitioning)
53 | // @Value("#{stepExecutionContext[name]}")
54 | private String name;
55 |
56 | private static Logger LOG = Logger.getLogger(CalculateTransactionTotalProcessor.class);
57 |
58 | private NamedParameterJdbcTemplate template;
59 |
60 | private static int x = 0;
61 |
62 | public void setTemplate(NamedParameterJdbcTemplate template) {
63 | this.template = template;
64 | }
65 |
66 | private final String SELECTSQL = "SELECT CustomerID, Amount FROM Transaction WHERE CustomerID = :custID";
67 |
68 | @Override
69 | public Customer process(Customer item) throws Exception {
70 | Thread.sleep(50);
71 | LOG.debug("Processing: " + item.getFirstName() + " - " + item.getCustomerID());
72 | Map map = new HashMap();
73 | map.put("custID", "" + item.getCustomerID());
74 | List transaction = template.query(SELECTSQL, map, new TransactionRowMapper());
75 | // TODO: An dieser Stelle muss der Iterator vom Projekt verwendet werden
76 | LOG.debug("Item: " + item.getFirstName() + " " + item.getLastName() + " HAS got " + transaction.size()
77 | + " Grade entrys");
78 | if (transaction.size() > 10) {
79 | // Thread.sleep(1000);
80 | }
81 | int accumulated = 0;
82 | for (Transaction myTransaction : transaction) {
83 | accumulated += myTransaction.getAmount();
84 | }
85 | map.put("TTO", "" + accumulated);
86 |
87 | String name = item.toString();
88 | if (name.length() >= 300) {
89 | name = name.substring(0, 300);
90 | }
91 | LOG.debug("Total Transaction amount for " + name + " is " + (accumulated / (float) transaction.size())
92 | + " having " + transaction.size() + " transactions. - " + ++x);
93 | item.setTransactionTotal(accumulated);
94 | // BAD!
95 | System.out.println(name + " processing Item-ID : " + item.getCustomerID());
96 | return item;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/CalculateTransactionTotalReadListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import org.springframework.batch.core.ExitStatus;
32 | import org.springframework.batch.core.StepExecution;
33 | import org.springframework.batch.core.StepExecutionListener;
34 |
35 | public class CalculateTransactionTotalReadListener implements StepExecutionListener {
36 |
37 | @Override
38 | public void beforeStep(StepExecution stepExecution) {
39 | // int fromId = stepExecution.getExecutionContext().getInt("fromId");
40 | // int toId = stepExecution.getExecutionContext().getInt("toId");
41 | // System.out.println("########## From: " + stepExecution.getExecutionContext().getInt("fromId") + " to: "
42 | // + stepExecution.getExecutionContext().getInt("toId"));
43 | }
44 |
45 | @Override
46 | public ExitStatus afterStep(StepExecution stepExecution) {
47 | // TODO Auto-generated method stub
48 | return null;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/CalculateTransactionTotalStepConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import javax.sql.DataSource;
32 |
33 | import org.apache.log4j.Logger;
34 | import org.springframework.batch.core.Step;
35 | import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
36 | import org.springframework.batch.item.ItemProcessor;
37 | import org.springframework.batch.item.ItemReader;
38 | import org.springframework.batch.item.database.JdbcBatchItemWriter;
39 | import org.springframework.batch.item.database.JdbcCursorItemReader;
40 | import org.springframework.beans.factory.annotation.Autowired;
41 | import org.springframework.context.annotation.Bean;
42 | import org.springframework.context.annotation.Configuration;
43 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
44 | import org.springframework.transaction.PlatformTransactionManager;
45 |
46 | import de.viadee.spring.batch.integrationtest.common.Customer;
47 | import de.viadee.spring.batch.integrationtest.common.CustomerRowMapper;
48 |
49 | @Configuration
50 | public class CalculateTransactionTotalStepConfig {
51 |
52 | private static Logger LOG = Logger.getLogger(CalculateTransactionTotalStepConfig.class);
53 |
54 | @Autowired
55 | private StepBuilderFactory stepBuilders;
56 |
57 | @Autowired
58 | private DataSource dataSource;
59 |
60 | @Autowired
61 | private PlatformTransactionManager platformTransactionManager;
62 |
63 | @Autowired
64 | private NamedParameterJdbcTemplate template;
65 |
66 | @Bean
67 | public ItemReader customerIDItemReaderFull() {
68 | JdbcCursorItemReader reader = new JdbcCursorItemReader();
69 | reader.setSql("SELECT CustomerID, FirstName, LastName, TransactionTotal FROM Customer");
70 | reader.setDataSource(dataSource);
71 | reader.setRowMapper(new CustomerRowMapper());
72 | return reader;
73 | }
74 |
75 | @Bean
76 | public ItemProcessor customerItemProcessor() {
77 | CalculateTransactionTotalProcessor processor = new CalculateTransactionTotalProcessor();
78 | processor.setTemplate(template);
79 | return processor;
80 | }
81 |
82 | @Bean
83 | public Step calculateTransactionTotalStep() {
84 | return stepBuilders.get("calculateTransactionTotalStep"). chunk(20)
85 | .reader(customerIDItemReaderFull()).chunk(20).processor(customerItemProcessor()).chunk(20)
86 | .writer(customerItemWriter()).transactionManager(platformTransactionManager).build();
87 | }
88 |
89 | @Bean
90 | public JdbcBatchItemWriter customerItemWriter() {
91 | JdbcBatchItemWriter writer = new JdbcBatchItemWriter();
92 | writer.setSql("UPDATE Customer SET TransactionTotal = :TTO WHERE CustomerID = :custID");
93 | writer.setItemSqlParameterSourceProvider(new CustomerSqlParameterSourceProvider());
94 | writer.setDataSource(dataSource);
95 | writer.afterPropertiesSet();
96 | return writer;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/CustomerItemPreparedStatementSetter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import java.sql.PreparedStatement;
32 | import java.sql.SQLException;
33 |
34 | import org.apache.log4j.Logger;
35 | import org.springframework.batch.item.database.ItemPreparedStatementSetter;
36 | import org.springframework.stereotype.Component;
37 |
38 | import de.viadee.spring.batch.integrationtest.common.Customer;
39 |
40 | @Component
41 | public class CustomerItemPreparedStatementSetter implements ItemPreparedStatementSetter {
42 |
43 | private static Logger LOG = Logger.getLogger(CustomerItemPreparedStatementSetter.class);
44 |
45 | public void setValues(Customer item, PreparedStatement ps) throws SQLException {
46 | ps.setFloat(1, item.getTransactionTotal());
47 | ps.setInt(2, item.getCustomerID());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/CustomerSqlParameterSourceProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.item.database.ItemSqlParameterSourceProvider;
33 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
34 | import org.springframework.jdbc.core.namedparam.SqlParameterSource;
35 | import org.springframework.stereotype.Component;
36 |
37 | import de.viadee.spring.batch.integrationtest.common.Customer;
38 |
39 | @Component
40 | public class CustomerSqlParameterSourceProvider implements ItemSqlParameterSourceProvider {
41 |
42 | private static Logger LOG = Logger.getLogger(CustomerSqlParameterSourceProvider.class);
43 |
44 | public SqlParameterSource createSqlParameterSource(Customer item) {
45 |
46 | MapSqlParameterSource paramSrc = new MapSqlParameterSource();
47 | paramSrc.addValue("custID", item.getCustomerID());
48 | paramSrc.addValue("TTO", item.getTransactionTotal());
49 | return paramSrc;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/calculategradepoints/RangePartitioner.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.calculategradepoints;
30 |
31 | import java.util.HashMap;
32 | import java.util.Map;
33 |
34 | import org.springframework.batch.core.partition.support.Partitioner;
35 | import org.springframework.batch.item.ExecutionContext;
36 |
37 | public class RangePartitioner implements Partitioner {
38 |
39 | @Override
40 | public Map partition(int gridSize) {
41 |
42 | Map result = new HashMap();
43 |
44 | int range = 10;
45 | int fromId = 100000;
46 | int toId = fromId + range;
47 |
48 | for (int i = 1; i <= gridSize; i++) {
49 | ExecutionContext value = new ExecutionContext();
50 |
51 | System.out.println("\nStarting : Thread" + i);
52 | System.out.println("fromId : " + fromId);
53 | System.out.println("toId : " + toId);
54 |
55 | value.putInt("fromId", fromId);
56 | value.putInt("toId", toId);
57 |
58 | // give each thread a name, thread 1,2,3
59 | value.putString("name", "Thread" + i);
60 | result.put("partition" + i, value);
61 |
62 | fromId = toId + 1;
63 | toId += range;
64 |
65 | }
66 |
67 | return result;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/formatnames/CustomerItemProcessorLowerCase.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.formatnames;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.item.ItemProcessor;
33 | import org.springframework.stereotype.Component;
34 |
35 | import de.viadee.spring.batch.integrationtest.common.CustomerEnhanced;
36 |
37 | @Component
38 | public class CustomerItemProcessorLowerCase implements ItemProcessor {
39 |
40 | private static Logger LOG = Logger.getLogger(CustomerItemProcessorLowerCase.class);
41 |
42 | public CustomerEnhanced process(CustomerEnhanced item) throws Exception {
43 |
44 | item.setFirstNameLowerCase(item.getFirstName().toLowerCase());
45 | item.setLastNameLowerCase(item.getLastName().toLowerCase());
46 | return item;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/formatnames/CustomerItemProcessorUpperCase.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.formatnames;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.item.ItemProcessor;
33 | import org.springframework.stereotype.Component;
34 |
35 | import de.viadee.spring.batch.integrationtest.common.Customer;
36 | import de.viadee.spring.batch.integrationtest.common.CustomerEnhanced;
37 |
38 | @Component
39 | public class CustomerItemProcessorUpperCase implements ItemProcessor {
40 |
41 | private static Logger LOG = Logger.getLogger(CustomerItemProcessorUpperCase.class);
42 |
43 | public CustomerEnhanced process(Customer item) throws Exception {
44 |
45 | CustomerEnhanced studentEnhanced = new CustomerEnhanced(item.getCustomerID(), item.getFirstName(),
46 | item.getLastName(), item.getTransactionTotal());
47 | studentEnhanced.setFirstNameUpperCase(item.getFirstName().toUpperCase());
48 | studentEnhanced.setLastNameUpperCase(item.getLastName().toUpperCase());
49 | return studentEnhanced;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/formatnames/FormatNamesJobConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.formatnames;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.core.Job;
33 | import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
34 | import org.springframework.beans.factory.annotation.Autowired;
35 | import org.springframework.context.annotation.Bean;
36 | import org.springframework.context.annotation.Configuration;
37 | import org.springframework.context.annotation.Import;
38 |
39 | @Import(de.viadee.spring.batch.integrationtest.jobs.formatnames.FormatNamesStep.class)
40 | @Configuration
41 | public class FormatNamesJobConfig {
42 |
43 | private static Logger LOG = Logger.getLogger(FormatNamesJobConfig.class);
44 |
45 | @Autowired
46 | private JobBuilderFactory jobBuilders;
47 |
48 | @Autowired
49 | private FormatNamesStep formatNamesStep;
50 |
51 | @Bean
52 | public Job formatNamesJob() {
53 | return jobBuilders.get("formatNamesJob").start(formatNamesStep.getFormatNamesStep()).build();
54 | }
55 |
56 | public Job getFormatNamesJob() {
57 | return formatNamesJob();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/preparedatabase/DelayTasklet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.preparedatabase;
30 |
31 | import org.springframework.batch.core.StepContribution;
32 | import org.springframework.batch.core.scope.context.ChunkContext;
33 | import org.springframework.batch.core.step.tasklet.Tasklet;
34 | import org.springframework.batch.repeat.RepeatStatus;
35 |
36 | public class DelayTasklet implements Tasklet {
37 |
38 | @Override
39 | public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
40 | // TODO Auto-generated method stub
41 | Thread.sleep(2000);
42 | return RepeatStatus.FINISHED;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/preparedatabase/PrepareDatabaseJobConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.preparedatabase;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.core.Job;
33 | import org.springframework.batch.core.Step;
34 | import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
35 | import org.springframework.beans.factory.annotation.Autowired;
36 | import org.springframework.context.annotation.Bean;
37 | import org.springframework.context.annotation.Configuration;
38 | import org.springframework.context.annotation.Import;
39 |
40 | @Import({ TaskletOnlyStepConfig.class, DataBaseFiller.class })
41 | @Configuration
42 | public class PrepareDatabaseJobConfig {
43 |
44 | private static Logger LOG = Logger.getLogger(PrepareDatabaseJobConfig.class);
45 |
46 | @Autowired
47 | private JobBuilderFactory jobBuilders;
48 |
49 | @Autowired
50 | private Step taskletOnlyStep;
51 |
52 | @Autowired
53 | private Step delayTaskletStep;
54 |
55 | @Bean
56 | public Job prepareDatabaseJob() {
57 | return jobBuilders.get("prepareDatabaseJob").start(taskletOnlyStep).next(delayTaskletStep).build();
58 | }
59 |
60 | public Job getPrepareDatabaseJob() {
61 | return prepareDatabaseJob();
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/preparedatabase/PrepareDatabaseTasklet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.preparedatabase;
30 |
31 | import java.util.HashMap;
32 | import java.util.List;
33 | import java.util.Map;
34 |
35 | import org.apache.log4j.Logger;
36 | import org.springframework.batch.core.StepContribution;
37 | import org.springframework.batch.core.scope.context.ChunkContext;
38 | import org.springframework.batch.core.step.tasklet.Tasklet;
39 | import org.springframework.batch.repeat.RepeatStatus;
40 | import org.springframework.beans.factory.annotation.Autowired;
41 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
42 | import org.springframework.stereotype.Component;
43 |
44 | import de.viadee.spring.batch.integrationtest.common.Customer;
45 | import de.viadee.spring.batch.integrationtest.common.Transaction;
46 |
47 | @Component
48 | public class PrepareDatabaseTasklet implements Tasklet {
49 |
50 | private static Logger LOG = Logger.getLogger(PrepareDatabaseTasklet.class);
51 |
52 | private NamedParameterJdbcTemplate template;
53 |
54 | private int testDataSize;
55 |
56 | private int maxGrades;
57 |
58 | private static final String SQL = "INSERT INTO Customer VALUES (:customerID, :firstname, :lastname, 0)";
59 |
60 | private static final String SQL2 = "INSERT INTO Transaction VALUES (:transactionID, :customerID, :amount)";
61 |
62 | public void setTemplate(NamedParameterJdbcTemplate template) {
63 | this.template = template;
64 | }
65 |
66 | @Autowired
67 | DataBaseFiller dataBaseFiller;
68 |
69 | public void setTestDataSize(int amount) {
70 | this.testDataSize = amount;
71 | }
72 |
73 | public void setMaxGrades(int maxGrades) {
74 | this.maxGrades = maxGrades;
75 | }
76 |
77 | public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
78 | List customers = dataBaseFiller.getCustomerList(testDataSize);
79 | for (Customer student : customers) {
80 | Map map = new HashMap();
81 | map.put("customerID", "" + student.getCustomerID());
82 | map.put("firstname", student.getFirstName());
83 | map.put("lastname", student.getLastName());
84 | template.update(SQL, map);
85 | }
86 | List transactions = dataBaseFiller.generateGrades(customers, maxGrades);
87 | int i = 0;
88 | for (Transaction grade : transactions) {
89 | Map map = new HashMap();
90 | map.put("customerID", "" + grade.getCustomerID());
91 | map.put("amount", "" + grade.getAmount());
92 | map.put("transactionID", "" + i++);
93 | template.update(SQL2, map);
94 | }
95 | customers = null;
96 | transactions = null;
97 | dataBaseFiller.cleanCustomerID();
98 | return RepeatStatus.FINISHED;
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/src/test/java/de/viadee/spring/batch/integrationtest/jobs/preparedatabase/TaskletOnlyStepConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright � 2016, viadee Unternehmensberatung AG
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * * Redistributions of source code must retain the above copyright notice, this
8 | * list of conditions and the following disclaimer.
9 | *
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * * Neither the name of the copyright holder nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package de.viadee.spring.batch.integrationtest.jobs.preparedatabase;
30 |
31 | import org.apache.log4j.Logger;
32 | import org.springframework.batch.core.Step;
33 | import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
34 | import org.springframework.batch.core.step.tasklet.Tasklet;
35 | import org.springframework.beans.factory.annotation.Autowired;
36 | import org.springframework.context.annotation.Bean;
37 | import org.springframework.context.annotation.Configuration;
38 | import org.springframework.context.annotation.Import;
39 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
40 | import org.springframework.transaction.PlatformTransactionManager;
41 |
42 | import de.viadee.spring.batch.integrationtest.configuration.StandaloneInfrastructureConfiguration;
43 |
44 | @Import(StandaloneInfrastructureConfiguration.class)
45 | @Configuration
46 | public class TaskletOnlyStepConfig {
47 |
48 | private static Logger LOG = Logger.getLogger(TaskletOnlyStepConfig.class);
49 |
50 | @Autowired
51 | private StepBuilderFactory stepBuilders;
52 |
53 | @Autowired
54 | private PlatformTransactionManager platformTransactionManager;
55 |
56 | @Autowired
57 | private NamedParameterJdbcTemplate template;
58 |
59 | @Bean
60 | public Tasklet prepareDatabaseTasklet() {
61 | final PrepareDatabaseTasklet tasklet = new PrepareDatabaseTasklet();
62 | tasklet.setTemplate(template);
63 | tasklet.setTestDataSize(80);
64 | tasklet.setMaxGrades(5);
65 | return tasklet;
66 | }
67 |
68 | @Bean
69 | public Tasklet delayTasklet() {
70 | return new DelayTasklet();
71 | }
72 |
73 | @Bean
74 | public Step delayTaskletStep() {
75 | return stepBuilders.get("DelayTaskletStep").tasklet(delayTasklet())
76 | .transactionManager(platformTransactionManager).build();
77 | }
78 |
79 | public Step getDelayTaskletStep() {
80 | return delayTaskletStep();
81 | }
82 |
83 | @Bean
84 | public Step taskletOnlyStep() {
85 | return stepBuilders.get("TaskletOnlyStep").tasklet(prepareDatabaseTasklet())
86 | .transactionManager(platformTransactionManager).build();
87 | }
88 |
89 | public Step getStep() {
90 | return taskletOnlyStep();
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/test/resources/SQL/prepare-tables.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE `Customer` (
2 | `CustomerID` INT NOT NULL,
3 | `FirstName` VARCHAR(100) NOT NULL,
4 | `LastName` VARCHAR(100) NOT NULL,
5 | `TransactionTotal` FLOAT NULL DEFAULT 0,
6 | PRIMARY KEY (`CustomerID`));
7 |
8 |
9 | CREATE TABLE `Transaction` (
10 | `ID` INT NOT NULL AUTO_INCREMENT,
11 | `CustomerID` INT NOT NULL,
12 | `Amount` INT NULL,
13 | PRIMARY KEY (`ID`));
14 |
15 |
16 | TRUNCATE TABLE Customer;
17 | TRUNCATE TABLE Transaction;
18 |
19 |
20 | CREATE TABLE `CustomerUpperCase` (
21 | `CustomerID` INT NOT NULL,
22 | `FirstName` VARCHAR(100) NOT NULL,
23 | `LastName` VARCHAR(100) NOT NULL,
24 | `TransactionTotal` FLOAT NULL DEFAULT 0,
25 | PRIMARY KEY (`CustomerID`));
26 |
27 |
28 | CREATE TABLE `CustomerLowerCase` (
29 | `CustomerID` INT NOT NULL,
30 | `FirstName` VARCHAR(100) NOT NULL,
31 | `LastName` VARCHAR(100) NOT NULL,
32 | `TransactionTOtal` FLOAT NULL DEFAULT 0,
33 | PRIMARY KEY (`CustomerID`));
--------------------------------------------------------------------------------
/src/test/resources/SpringBatchMonitoring.properties:
--------------------------------------------------------------------------------
1 |
2 | #Database Configuration
3 | db.driver=org.h2.Driver
4 | db.username=sa
5 | db.password=sasa
6 | db.url=jdbc:h2:./target/database/monitoringDB;MULTI_THREADED=1
7 |
8 | db.anomalydetection=true
--------------------------------------------------------------------------------