Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
9377b9a9
Commit
9377b9a9
authored
Sep 18, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support -- and # by default as Quartz datasource init comment prefixes
Closes gh-17435
parent
bf56b24c
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
10 deletions
+56
-10
QuartzDataSourceInitializer.java
...oot/autoconfigure/quartz/QuartzDataSourceInitializer.java
+1
-1
QuartzProperties.java
...framework/boot/autoconfigure/quartz/QuartzProperties.java
+7
-4
additional-spring-configuration-metadata.json
...es/META-INF/additional-spring-configuration-metadata.json
+7
-0
QuartzDataSourceInitializerTests.java
...utoconfigure/quartz/QuartzDataSourceInitializerTests.java
+21
-5
tables_#_comments.sql
...framework/boot/autoconfigure/quartz/tables_#_comments.sql
+10
-0
tables_--_comments.sql
...ramework/boot/autoconfigure/quartz/tables_--_comments.sql
+10
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java
View file @
9377b9a9
...
@@ -43,7 +43,7 @@ public class QuartzDataSourceInitializer extends AbstractDataSourceInitializer {
...
@@ -43,7 +43,7 @@ public class QuartzDataSourceInitializer extends AbstractDataSourceInitializer {
@Override
@Override
protected
void
customize
(
ResourceDatabasePopulator
populator
)
{
protected
void
customize
(
ResourceDatabasePopulator
populator
)
{
populator
.
setCommentPrefix
(
this
.
properties
.
getJdbc
().
getCommentPrefix
(
));
populator
.
setCommentPrefix
es
(
this
.
properties
.
getJdbc
().
getCommentPrefix
().
toArray
(
new
String
[
0
]
));
}
}
@Override
@Override
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzProperties.java
View file @
9377b9a9
...
@@ -17,7 +17,10 @@
...
@@ -17,7 +17,10 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
quartz
;
package
org
.
springframework
.
boot
.
autoconfigure
.
quartz
;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
...
@@ -144,9 +147,9 @@ public class QuartzProperties {
...
@@ -144,9 +147,9 @@ public class QuartzProperties {
private
DataSourceInitializationMode
initializeSchema
=
DataSourceInitializationMode
.
EMBEDDED
;
private
DataSourceInitializationMode
initializeSchema
=
DataSourceInitializationMode
.
EMBEDDED
;
/**
/**
* Prefix for single-line comments in SQL initialization scripts.
* Prefix
es
for single-line comments in SQL initialization scripts.
*/
*/
private
String
commentPrefix
=
"--"
;
private
List
<
String
>
commentPrefix
=
new
ArrayList
<>(
Arrays
.
asList
(
"#"
,
"--"
))
;
public
String
getSchema
()
{
public
String
getSchema
()
{
return
this
.
schema
;
return
this
.
schema
;
...
@@ -164,11 +167,11 @@ public class QuartzProperties {
...
@@ -164,11 +167,11 @@ public class QuartzProperties {
this
.
initializeSchema
=
initializeSchema
;
this
.
initializeSchema
=
initializeSchema
;
}
}
public
String
getCommentPrefix
()
{
public
List
<
String
>
getCommentPrefix
()
{
return
this
.
commentPrefix
;
return
this
.
commentPrefix
;
}
}
public
void
setCommentPrefix
(
String
commentPrefix
)
{
public
void
setCommentPrefix
(
List
<
String
>
commentPrefix
)
{
this
.
commentPrefix
=
commentPrefix
;
this
.
commentPrefix
=
commentPrefix
;
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
View file @
9377b9a9
...
@@ -743,6 +743,13 @@
...
@@ -743,6 +743,13 @@
"level"
:
"error"
"level"
:
"error"
}
}
},
},
{
"name"
:
"spring.quartz.jdbc.comment-prefix"
,
"defaultValue"
:
[
"#"
,
"--"
]
},
{
{
"name"
:
"spring.quartz.jdbc.initialize-schema"
,
"name"
:
"spring.quartz.jdbc.initialize-schema"
,
"defaultValue"
:
"embedded"
"defaultValue"
:
"embedded"
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializerTests.java
View file @
9377b9a9
...
@@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
...
@@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -47,16 +48,31 @@ class QuartzDataSourceInitializerTests {
...
@@ -47,16 +48,31 @@ class QuartzDataSourceInitializerTests {
.
withPropertyValues
(
"spring.datasource.url="
+
String
.
format
(
.
withPropertyValues
(
"spring.datasource.url="
+
String
.
format
(
"jdbc:h2:mem:test-%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
,
UUID
.
randomUUID
().
toString
()));
"jdbc:h2:mem:test-%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
,
UUID
.
randomUUID
().
toString
()));
@Test
void
hashIsUsedAsACommentPrefixByDefault
()
{
this
.
contextRunner
.
withUserConfiguration
(
TestConfiguration
.
class
).
withPropertyValues
(
"spring.quartz.jdbc.schema=classpath:org/springframework/boot/autoconfigure/quartz/tables_#_comments.sql"
)
.
run
(
this
::
assertThatDataSourceHasBeenInitialized
);
}
@Test
void
doubleDashIsUsedAsACommentPrefixByDefault
()
{
this
.
contextRunner
.
withUserConfiguration
(
TestConfiguration
.
class
).
withPropertyValues
(
"spring.quartz.jdbc.schema=classpath:org/springframework/boot/autoconfigure/quartz/tables_--_comments.sql"
)
.
run
(
this
::
assertThatDataSourceHasBeenInitialized
);
}
@Test
@Test
void
commentPrefixCanBeCustomized
()
{
void
commentPrefixCanBeCustomized
()
{
this
.
contextRunner
.
withUserConfiguration
(
TestConfiguration
.
class
).
withPropertyValues
(
this
.
contextRunner
.
withUserConfiguration
(
TestConfiguration
.
class
).
withPropertyValues
(
"spring.quartz.jdbc.comment-prefix=##"
,
"spring.quartz.jdbc.comment-prefix=##"
,
"spring.quartz.jdbc.schema=classpath:org/springframework/boot/autoconfigure/quartz/tables_@@platform@@.sql"
)
"spring.quartz.jdbc.schema=classpath:org/springframework/boot/autoconfigure/quartz/tables_@@platform@@.sql"
)
.
run
((
context
)
->
{
.
run
(
this
::
assertThatDataSourceHasBeenInitialized
);
}
private
void
assertThatDataSourceHasBeenInitialized
(
AssertableApplicationContext
context
)
{
JdbcTemplate
jdbcTemplate
=
context
.
getBean
(
JdbcTemplate
.
class
);
JdbcTemplate
jdbcTemplate
=
context
.
getBean
(
JdbcTemplate
.
class
);
assertThat
(
jdbcTemplate
.
queryForObject
(
"SELECT COUNT(*) FROM QRTZ_TEST_TABLE"
,
Integer
.
class
))
assertThat
(
jdbcTemplate
.
queryForObject
(
"SELECT COUNT(*) FROM QRTZ_TEST_TABLE"
,
Integer
.
class
)).
isEqualTo
(
0
);
.
isEqualTo
(
0
);
});
}
}
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/quartz/tables_#_comments.sql
0 → 100644
View file @
9377b9a9
#
This
is
a
test
script
to
check
#
is
treated
as
a
comment
prefix
by
default
CREATE
TABLE
QRTZ_TEST_TABLE
(
SCHED_NAME
VARCHAR
(
120
)
NOT
NULL
,
CALENDAR_NAME
VARCHAR
(
200
)
NOT
NULL
);
#
Another
comment
COMMIT
;
spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/quartz/tables_--_comments.sql
0 → 100644
View file @
9377b9a9
-- This is a test script to check -- is treated as a comment prefix by default
CREATE
TABLE
QRTZ_TEST_TABLE
(
SCHED_NAME
VARCHAR
(
120
)
NOT
NULL
,
CALENDAR_NAME
VARCHAR
(
200
)
NOT
NULL
);
-- Another comment
COMMIT
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment