Skip to content

Commit 968a5b5

Browse files
committed
Refine contribution #595
- Update versions of jdbc driver and docker image - Update Javadocs - Remove JOB_CONFIGURATION_LOCATION from DDL schema - Remove unused resources
1 parent 9388abb commit 968a5b5

File tree

15 files changed

+134
-164
lines changed

15 files changed

+134
-164
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<h2.version>2.1.210</h2.version>
9393
<sqlite.version>3.36.0.3</sqlite.version>
9494
<derby.version>10.14.2.0</derby.version>
95-
<hana.version>2.9.12</hana.version>
95+
<hana.version>2.11.17</hana.version>
9696
<artemis.version>2.20.0</artemis.version>
9797
<jaxb-core.version>3.0.2</jaxb-core.version>
9898
<log4j.version>2.17.2</log4j.version>

spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hana.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ CREATE TABLE BATCH_JOB_EXECUTION (
1919
EXIT_CODE VARCHAR(2500) ,
2020
EXIT_MESSAGE VARCHAR(2500) ,
2121
LAST_UPDATED TIMESTAMP,
22-
JOB_CONFIGURATION_LOCATION VARCHAR(2500) ,
2322
constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID)
2423
references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)
2524
) ;

spring-batch-core/src/main/sql/hana.properties

Lines changed: 0 additions & 14 deletions
This file was deleted.

spring-batch-core/src/main/sql/hana.vpp

Lines changed: 0 additions & 3 deletions
This file was deleted.

spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAContainer.java

Lines changed: 0 additions & 130 deletions
This file was deleted.

spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,11 +15,21 @@
1515
*/
1616
package org.springframework.batch.core.test.repository;
1717

18+
import java.time.Duration;
19+
import java.time.temporal.ChronoUnit;
20+
import java.util.Arrays;
21+
import java.util.HashMap;
22+
import java.util.HashSet;
23+
import java.util.Map;
24+
import java.util.Set;
25+
1826
import javax.sql.DataSource;
1927

28+
import com.github.dockerjava.api.model.Ulimit;
2029
import org.junit.Assert;
2130
import org.junit.Before;
2231
import org.junit.ClassRule;
32+
import org.junit.Ignore;
2333
import org.junit.Test;
2434
import org.junit.runner.RunWith;
2535
import org.springframework.batch.core.ExitStatus;
@@ -38,19 +48,30 @@
3848
import org.springframework.core.io.ClassPathResource;
3949
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
4050
import org.springframework.test.context.ContextConfiguration;
51+
import org.springframework.test.context.junit.jupiter.EnabledIf;
4152
import org.springframework.test.context.junit4.SpringRunner;
53+
54+
import org.testcontainers.containers.JdbcDatabaseContainer;
55+
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
4256
import org.testcontainers.utility.DockerImageName;
4357

4458
import com.sap.db.jdbcext.HanaDataSource;
59+
import org.testcontainers.utility.LicenseAcceptance;
4560

4661
/**
62+
* The official Docker image for SAP HANA is not publicly available. SAP HANA support is tested manually.
63+
* See https://hub.docker.com/_/sap-hana-express-edition/plans/f2dc436a-d851-4c22-a2ba-9de07db7a9ac
64+
* FTR, from the previous link: "This installation does not support Docker for Windows or Docker for Mac."
65+
*
4766
* @author Jonathan Bregler
67+
* @author Mahmoud Ben Hassine
4868
*/
4969
@RunWith(SpringRunner.class)
5070
@ContextConfiguration
71+
@Ignore("Official Docker image for SAP HANA not publicly available and works only on Linux")
5172
public class HANAJobRepositoryIntegrationTests {
5273

53-
private static final DockerImageName HANA_IMAGE = DockerImageName.parse( "store/saplabs/hanaexpress:2.00.054.00.20210603.1" );
74+
private static final DockerImageName HANA_IMAGE = DockerImageName.parse( "store/saplabs/hanaexpress:2.00.057.00.20211207.1" );
5475

5576
@ClassRule
5677
public static HANAContainer<?> hana = new HANAContainer<>( HANA_IMAGE ).acceptLicense();
@@ -103,4 +124,103 @@ public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
103124
}
104125

105126
}
127+
128+
/**
129+
* @author Jonathan Bregler
130+
*/
131+
public static class HANAContainer<SELF extends HANAContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
132+
133+
private static final Integer PORT = 39041;
134+
135+
private static final String SYSTEM_USER = "SYSTEM";
136+
private static final String SYSTEM_USER_PASSWORD = "HXEHana1";
137+
138+
public HANAContainer(DockerImageName image) {
139+
140+
super( image );
141+
142+
addExposedPorts( 39013, 39017, 39041, 39042, 39043, 39044, 39045, 1128, 1129, 59013, 59014 );
143+
144+
// create ulimits
145+
Ulimit[] ulimits = new Ulimit[]{ new Ulimit( "nofile", 1048576L, 1048576L ) };
146+
147+
// create sysctls Map.
148+
Map<String, String> sysctls = new HashMap<String, String>();
149+
150+
sysctls.put( "kernel.shmmax", "1073741824" );
151+
sysctls.put( "net.ipv4.ip_local_port_range", "40000 60999" );
152+
153+
// Apply mounts, ulimits and sysctls.
154+
this.withCreateContainerCmdModifier( it -> it.getHostConfig().withUlimits( ulimits ).withSysctls( sysctls ) );
155+
156+
// Arguments for Image.
157+
this.withCommand( "--master-password " + SYSTEM_USER_PASSWORD + " --agree-to-sap-license" );
158+
159+
// Determine if container is ready.
160+
this.waitStrategy = new LogMessageWaitStrategy().withRegEx( ".*Startup finished!*\\s" ).withTimes( 1 )
161+
.withStartupTimeout( Duration.of( 600, ChronoUnit.SECONDS ) );
162+
}
163+
164+
@Override
165+
protected void configure() {
166+
/*
167+
* Enforce that the license is accepted - do not remove. License available at:
168+
* https://www.sap.com/docs/download/cmp/2016/06/sap-hana-express-dev-agmt-and-exhibit.pdf
169+
*/
170+
171+
// If license was not accepted programmatically, check if it was accepted via
172+
// resource file
173+
if ( !getEnvMap().containsKey( "AGREE_TO_SAP_LICENSE" ) ) {
174+
LicenseAcceptance.assertLicenseAccepted( this.getDockerImageName() );
175+
acceptLicense();
176+
}
177+
}
178+
179+
/**
180+
* Accepts the license for the SAP HANA Express container by setting the AGREE_TO_SAP_LICENSE=Y Calling this method
181+
* will automatically accept the license at:
182+
* https://www.sap.com/docs/download/cmp/2016/06/sap-hana-express-dev-agmt-and-exhibit.pdf
183+
*
184+
* @return The container itself with an environment variable accepting the SAP HANA Express license
185+
*/
186+
public SELF acceptLicense() {
187+
addEnv( "AGREE_TO_SAP_LICENSE", "Y" );
188+
return self();
189+
}
190+
191+
@Override
192+
public Set<Integer> getLivenessCheckPortNumbers() {
193+
return new HashSet<>( Arrays.asList( new Integer[]{ getMappedPort( PORT ) } ) );
194+
}
195+
196+
@Override
197+
protected void waitUntilContainerStarted() {
198+
getWaitStrategy().waitUntilReady( this );
199+
}
200+
201+
@Override
202+
public String getDriverClassName() {
203+
return "com.sap.db.jdbc.Driver";
204+
}
205+
206+
@Override
207+
public String getUsername() {
208+
return SYSTEM_USER;
209+
}
210+
211+
@Override
212+
public String getPassword() {
213+
return SYSTEM_USER_PASSWORD;
214+
}
215+
216+
@Override
217+
public String getTestQueryString() {
218+
return "SELECT 1 FROM SYS.DUMMY";
219+
}
220+
221+
@Override
222+
public String getJdbcUrl() {
223+
return "jdbc:sap://" + getContainerIpAddress() + ":" + getMappedPort( PORT ) + "/";
224+
}
225+
}
106226
}

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HanaPagingQueryProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
* SAP HANA implementation of a {@link PagingQueryProvider} using database specific features.
2424
*
2525
* @author Jonathan Bregler
26-
* @since 4.0
26+
* @since 5.0
2727
*/
2828
public class HanaPagingQueryProvider extends AbstractSqlPagingQueryProvider {
2929

@@ -35,7 +35,7 @@ public String generateFirstPageQuery(int pageSize) {
3535
@Override
3636
public String generateRemainingPagesQuery(int pageSize) {
3737
if(StringUtils.hasText(getGroupClause())) {
38-
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, true, buildLimitClause(pageSize));
38+
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, buildLimitClause(pageSize));
3939
}
4040
else {
4141
return SqlPagingQueryUtils.generateLimitSqlQuery(this, true, buildLimitClause(pageSize));

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-batch-infrastructure/src/main/java/org/springframework/batch/support/DatabaseType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)