-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new configuration that will format the SQL (#89)
* Add an option to format the SQL before logging * revert unwanted code formatting changes for a cleaner diff * apply PR comments
- Loading branch information
1 parent
33292e8
commit 5a3f370
Showing
9 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...com/github/gavlyukovskiy/boot/jdbc/decorator/dsproxy/HibernateFormatterConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.gavlyukovskiy.boot.jdbc.decorator.dsproxy; | ||
|
||
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; | ||
import org.hibernate.engine.jdbc.internal.BasicFormatterImpl; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnClass(BasicFormatterImpl.class) | ||
@ConditionalOnProperty(name = "decorator.datasource.datasource-proxy.format-sql", havingValue = "true") | ||
class HibernateFormatterConfiguration { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(HibernateFormatterConfiguration.class); | ||
|
||
@Bean | ||
@ConditionalOnMissingBean // let users define their own | ||
public ProxyDataSourceBuilder.FormatQueryCallback hibernateFormatQueryCallback() { | ||
log.debug("{} will be used as formatter", BasicFormatterImpl.class.getName()); | ||
BasicFormatterImpl hibernateFormatter = new BasicFormatterImpl(); | ||
return hibernateFormatter::format; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../java/com/github/gavlyukovskiy/boot/jdbc/decorator/dsproxy/SqlFormatterConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.gavlyukovskiy.boot.jdbc.decorator.dsproxy; | ||
|
||
import com.github.vertical_blank.sqlformatter.SqlFormatter; | ||
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnClass(SqlFormatter.class) | ||
@ConditionalOnProperty(name = "decorator.datasource.datasource-proxy.format-sql", havingValue = "true") | ||
class SqlFormatterConfiguration { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(SqlFormatterConfiguration.class); | ||
|
||
@Bean | ||
@ConditionalOnMissingBean // let users define their own | ||
public ProxyDataSourceBuilder.FormatQueryCallback sqlFormatterFormatQueryCallback() { | ||
log.debug("{} will be used as formatter", SqlFormatter.class.getName()); | ||
return SqlFormatter::format; | ||
} | ||
} |