Skip to content

Commit

Permalink
feat(core): Relationships auto-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion committed Feb 26, 2024
1 parent b501990 commit 989f24c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.github.joselion.springr2dbcrelationships;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;

import lombok.extern.slf4j.Slf4j;

/**
* Relationships autoconfiguration.
*/
@Slf4j
@Configuration
public class RelationshipAutoConfiguration {

/**
* Default configuration constructor.
*/
protected RelationshipAutoConfiguration() {
log.info("R2DBC Relationships auto-configuration loaded.");
}

/**
* Creates the {@link RelationshipCallbacks} bean.
*
* @param <T> the type of the entity in the callback
* @param template the r2dbc entity template
* @param context the Spring application context
* @return the relationship callbacks bean
*/
@Bean
public <T> RelationshipCallbacks<T> relationshipCallbacks(
final @Lazy R2dbcEntityTemplate template,
final @Lazy ApplicationContext context
) {
return new RelationshipCallbacks<>(template, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

import org.reactivestreams.Publisher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.r2dbc.mapping.OutboundRow;
import org.springframework.data.r2dbc.mapping.event.AfterConvertCallback;
import org.springframework.data.r2dbc.mapping.event.AfterSaveCallback;
import org.springframework.data.r2dbc.mapping.event.BeforeConvertCallback;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.stereotype.Component;

import io.github.joselion.springr2dbcrelationships.annotations.ManyToMany;
import io.github.joselion.springr2dbcrelationships.annotations.ManyToOne;
Expand All @@ -43,10 +41,9 @@
* @param template the r2dbc entity template
* @param context the Spring application context
*/
@Component
public record RelationshipCallbacks<T>(
@Lazy R2dbcEntityTemplate template,
@Lazy ApplicationContext context
R2dbcEntityTemplate template,
ApplicationContext context
) implements AfterConvertCallback<T>, AfterSaveCallback<T>, BeforeConvertCallback<T> {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.github.joselion.springr2dbcrelationships.RelationshipAutoConfiguration

0 comments on commit 989f24c

Please sign in to comment.