io.lsdconsulting.lsd.distributed.postgres.config.LibraryConfig.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lsd-distributed-postgres-connector Show documentation
Show all versions of lsd-distributed-postgres-connector Show documentation
This is a PostgreSQL version of the data connector for the distributed data storage.
package io.lsdconsulting.lsd.distributed.postgres.config
import com.fasterxml.jackson.databind.ObjectMapper
import io.lsdconsulting.lsd.distributed.postgres.repository.InterceptedDocumentPostgresAdminRepository
import io.lsdconsulting.lsd.distributed.postgres.repository.InterceptedDocumentPostgresRepository
import lsd.logging.log
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import javax.sql.DataSource
@Configuration
open class LibraryConfig {
@Bean
@ConditionalOnExpression("#{'\${lsd.dist.connectionString:}'.startsWith('jdbc:postgresql://')}")
open fun interceptedDocumentRepositoryFromConnectionString(
@Value("\${lsd.dist.connectionString}") dbConnectionString: String,
objectMapper: ObjectMapper,
@Value("\${lsd.dist.db.failOnConnectionError:#{true}}") failOnConnectionError: Boolean,
) = InterceptedDocumentPostgresRepository(dbConnectionString, objectMapper, failOnConnectionError)
@Bean
@ConditionalOnExpression("#{'\${lsd.dist.connectionString:}'.startsWith('dataSource')}")
@ConditionalOnMissingBean(value = [InterceptedDocumentPostgresRepository::class])
open fun interceptedDocumentRepositoryFromDataSource(
dataSource: DataSource,
objectMapper: ObjectMapper,
@Value("\${lsd.dist.db.failOnConnectionError:#{true}}") failOnConnectionError: Boolean,
): InterceptedDocumentPostgresRepository {
return InterceptedDocumentPostgresRepository(dataSource, objectMapper)
}
@Bean
@ConditionalOnExpression("#{'\${lsd.dist.connectionString:}'.startsWith('jdbc:postgresql://')}")
open fun interceptedDocumentAdminRepositoryFromConnectionString(
@Value("\${lsd.dist.connectionString}") dbConnectionString: String,
objectMapper: ObjectMapper,
) = InterceptedDocumentPostgresAdminRepository(dbConnectionString, objectMapper)
@Bean
@ConditionalOnExpression("#{'\${lsd.dist.connectionString:}'.startsWith('dataSource')}")
@ConditionalOnMissingBean(value = [InterceptedDocumentPostgresAdminRepository::class])
open fun interceptedDocumentAdminRepositoryFromDataSource(
dataSource: DataSource,
objectMapper: ObjectMapper,
): InterceptedDocumentPostgresAdminRepository {
log().info("Instantiating InterceptedDocumentPostgresAdminRepository")
return InterceptedDocumentPostgresAdminRepository(dataSource, objectMapper)
}
}