Sunday, September 8, 2024
HomeProgrammingcustomise a jOOQ Configuration that's injected utilizing Spring Boot – Java, SQL...

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


Ranging from Spring Boot 2.5, there’s a helpful new callback which you could implement, referred to as DefaultConfigurationCustomizer, the place the phrase DefaultConfiguration corresponds to jOOQ’s DefaultConfiguration. You possibly can merely create a category like this in your mission:

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 extra settings, and so on. That’s it!

You possibly can set a breakpoint inside 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.mirror.NativeMethodAccessorImpl.invoke0(Native Technique)
	at java.base/jdk.inside.mirror.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.inside.mirror.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.mirror.Technique.invoke(Technique.java:568)
	at org.springframework.beans.manufacturing facility.assist.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 119 extra

To mess around with this instance, take a look at our jOOQ-spring-boot-example on github.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments