Home Programming The right way to customise a jOOQ Configuration that’s injected utilizing Spring Boot – Java, SQL and jOOQ.

The right way to customise a jOOQ Configuration that’s injected utilizing Spring Boot – Java, SQL and jOOQ.

0
The right way to customise a jOOQ Configuration that’s injected utilizing Spring Boot – Java, SQL and jOOQ.

[ad_1]

Ranging from Spring Boot 2.5, there’s a helpful new callback that you could implement, known as DefaultConfigurationCustomizer, the place the phrase DefaultConfiguration corresponds to jOOQ’s DefaultConfiguration. You may merely create a category like this in your venture:

import org.jooq.conf.RenderQuotedNames;
import org.jooq.impl.DefaultConfiguration;
import org.springframework.boot.autoconfigure.jooq.*;
import org.springframework.context.annotation.*;

@Configuration
public class Config {
	@Bean
	public DefaultConfigurationCustomizer configurationCustomiser() {
		return (DefaultConfiguration c) -> c.settings()
			.withRenderQuotedNames(
				RenderQuotedNames.EXPLICIT_DEFAULT_UNQUOTED
			);
	}
}

The above callback receives the DefaultConfiguration at its initialisation stage, throughout which you’ll be able to nonetheless safely mutate it to alter any of the defaults, or add further settings, and so on. That’s it!

You may set a breakpoint within the lambda to validate when this initialisation is invoked:

Attributable to: java.lang.RuntimeException
	at org.jooq.instance.spring.Config.lambda$0(Config.java:30)
	at org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration$DslContextConfiguration.lambda$jooqConfiguration$1(JooqAutoConfiguration.java:104)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.settle for(ForEachOps.java:183)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.stream.SortedOps$RefSortingSink.finish(SortedOps.java:395)
	at java.base/java.util.stream.Sink$ChainedReference.finish(Sink.java:258)
	at java.base/java.util.stream.Sink$ChainedReference.finish(Sink.java:258)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.consider(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration$DslContextConfiguration.jooqConfiguration(JooqAutoConfiguration.java:104)
	at java.base/jdk.inside.replicate.NativeMethodAccessorImpl.invoke0(Native Technique)
	at java.base/jdk.inside.replicate.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.inside.replicate.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.replicate.Technique.invoke(Technique.java:568)
	at org.springframework.beans.manufacturing facility.help.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 119 extra

To mess around with this instance, try our jOOQ-spring-boot-example on github.

[ad_2]

Supply hyperlink

LEAVE A REPLY

Please enter your comment!
Please enter your name here