Add support for org.jooq.RecordUnmapperProvider

Closes gh-12560
pull/12627/merge
Stephane Nicoll 7 years ago
parent bf4c57209b
commit ccbfcbedf0

@ -23,6 +23,7 @@ import org.jooq.DSLContext;
import org.jooq.ExecuteListenerProvider; import org.jooq.ExecuteListenerProvider;
import org.jooq.RecordListenerProvider; import org.jooq.RecordListenerProvider;
import org.jooq.RecordMapperProvider; import org.jooq.RecordMapperProvider;
import org.jooq.RecordUnmapperProvider;
import org.jooq.TransactionProvider; import org.jooq.TransactionProvider;
import org.jooq.VisitListenerProvider; import org.jooq.VisitListenerProvider;
import org.jooq.conf.Settings; import org.jooq.conf.Settings;
@ -94,6 +95,8 @@ public class JooqAutoConfiguration {
private final RecordMapperProvider recordMapperProvider; private final RecordMapperProvider recordMapperProvider;
private final RecordUnmapperProvider recordUnmapperProvider;
private final Settings settings; private final Settings settings;
private final RecordListenerProvider[] recordListenerProviders; private final RecordListenerProvider[] recordListenerProviders;
@ -106,6 +109,7 @@ public class JooqAutoConfiguration {
ConnectionProvider connectionProvider, DataSource dataSource, ConnectionProvider connectionProvider, DataSource dataSource,
ObjectProvider<TransactionProvider> transactionProvider, ObjectProvider<TransactionProvider> transactionProvider,
ObjectProvider<RecordMapperProvider> recordMapperProvider, ObjectProvider<RecordMapperProvider> recordMapperProvider,
ObjectProvider<RecordUnmapperProvider> recordUnmapperProvider,
ObjectProvider<Settings> settings, ObjectProvider<Settings> settings,
ObjectProvider<RecordListenerProvider[]> recordListenerProviders, ObjectProvider<RecordListenerProvider[]> recordListenerProviders,
ExecuteListenerProvider[] executeListenerProviders, ExecuteListenerProvider[] executeListenerProviders,
@ -115,6 +119,7 @@ public class JooqAutoConfiguration {
this.dataSource = dataSource; this.dataSource = dataSource;
this.transactionProvider = transactionProvider.getIfAvailable(); this.transactionProvider = transactionProvider.getIfAvailable();
this.recordMapperProvider = recordMapperProvider.getIfAvailable(); this.recordMapperProvider = recordMapperProvider.getIfAvailable();
this.recordUnmapperProvider = recordUnmapperProvider.getIfAvailable();
this.settings = settings.getIfAvailable(); this.settings = settings.getIfAvailable();
this.recordListenerProviders = recordListenerProviders.getIfAvailable(); this.recordListenerProviders = recordListenerProviders.getIfAvailable();
this.executeListenerProviders = executeListenerProviders; this.executeListenerProviders = executeListenerProviders;
@ -138,6 +143,9 @@ public class JooqAutoConfiguration {
if (this.recordMapperProvider != null) { if (this.recordMapperProvider != null) {
configuration.set(this.recordMapperProvider); configuration.set(this.recordMapperProvider);
} }
if (this.recordUnmapperProvider != null) {
configuration.set(this.recordUnmapperProvider);
}
if (this.settings != null) { if (this.settings != null) {
configuration.set(this.settings); configuration.set(this.settings);
} }

@ -27,6 +27,8 @@ import org.jooq.RecordListenerProvider;
import org.jooq.RecordMapper; import org.jooq.RecordMapper;
import org.jooq.RecordMapperProvider; import org.jooq.RecordMapperProvider;
import org.jooq.RecordType; import org.jooq.RecordType;
import org.jooq.RecordUnmapper;
import org.jooq.RecordUnmapperProvider;
import org.jooq.SQLDialect; import org.jooq.SQLDialect;
import org.jooq.TransactionalRunnable; import org.jooq.TransactionalRunnable;
import org.jooq.VisitListener; import org.jooq.VisitListener;
@ -134,18 +136,21 @@ public class JooqAutoConfigurationTests {
public void customProvidersArePickedUp() { public void customProvidersArePickedUp() {
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class,
TxManagerConfiguration.class, TestRecordMapperProvider.class, TxManagerConfiguration.class, TestRecordMapperProvider.class,
TestRecordListenerProvider.class, TestExecuteListenerProvider.class, TestRecordUnmapperProvider.class, TestRecordListenerProvider.class,
TestVisitListenerProvider.class).run((context) -> { TestExecuteListenerProvider.class, TestVisitListenerProvider.class
DSLContext dsl = context.getBean(DSLContext.class); ).run((context) -> {
assertThat(dsl.configuration().recordMapperProvider().getClass()) DSLContext dsl = context.getBean(DSLContext.class);
.isEqualTo(TestRecordMapperProvider.class); assertThat(dsl.configuration().recordMapperProvider().getClass())
assertThat(dsl.configuration().recordListenerProviders().length) .isEqualTo(TestRecordMapperProvider.class);
.isEqualTo(1); assertThat(dsl.configuration().recordUnmapperProvider().getClass())
assertThat(dsl.configuration().executeListenerProviders().length) .isEqualTo(TestRecordUnmapperProvider.class);
.isEqualTo(2); assertThat(dsl.configuration().recordListenerProviders().length)
assertThat(dsl.configuration().visitListenerProviders().length) .isEqualTo(1);
.isEqualTo(1); assertThat(dsl.configuration().executeListenerProviders().length)
}); .isEqualTo(2);
assertThat(dsl.configuration().visitListenerProviders().length)
.isEqualTo(1);
});
} }
@Test @Test
@ -230,6 +235,16 @@ public class JooqAutoConfigurationTests {
} }
protected static class TestRecordUnmapperProvider implements RecordUnmapperProvider {
@Override
public <E, R extends Record> RecordUnmapper<E, R> provide(
Class<? extends E> aClass, RecordType<R> recordType) {
return null;
}
}
protected static class TestRecordListenerProvider implements RecordListenerProvider { protected static class TestRecordListenerProvider implements RecordListenerProvider {
@Override @Override

@ -3733,6 +3733,7 @@ following jOOQ Types:
* `ConnectionProvider` * `ConnectionProvider`
* `TransactionProvider` * `TransactionProvider`
* `RecordMapperProvider` * `RecordMapperProvider`
* `RecordUnmapperProvider`
* `RecordListenerProvider` * `RecordListenerProvider`
* `ExecuteListenerProvider` * `ExecuteListenerProvider`
* `VisitListenerProvider` * `VisitListenerProvider`

Loading…
Cancel
Save