1
1
package fly4s .data
2
2
3
+ import cats .MonadThrow
3
4
import cats .data .NonEmptyList
4
5
import org .flywaydb .core .api .configuration .{Configuration , FluentConfiguration }
5
6
@@ -8,6 +9,7 @@ import scala.jdk.CollectionConverters.{MapHasAsJava, MapHasAsScala}
8
9
import scala .util .Try
9
10
10
11
private [fly4s] trait Fly4sConfigContract {
12
+ val baseJavaConfig : Option [Configuration ]
11
13
val connectRetries : Int
12
14
val initSql : Option [String ]
13
15
val defaultSchemaName : Option [String ]
@@ -115,6 +117,7 @@ private[fly4s] trait Fly4sConfigBuilder {
115
117
116
118
def fromJava (c : Configuration ): Fly4sConfig =
117
119
new Fly4sConfig (
120
+ baseJavaConfig = Some (c),
118
121
// ---------- connection ----------
119
122
connectRetries = c.getConnectRetries,
120
123
initSql = Option (c.getInitSql),
@@ -161,12 +164,25 @@ private[fly4s] trait Fly4sConfigBuilder {
161
164
skipDefaultResolvers = c.isSkipDefaultResolvers
162
165
)
163
166
167
+ @ deprecated(" Use toJavaF[Try] instead, this will be removed in the future versions." , " 1.0.1" )
164
168
def toJava (
165
169
c : Fly4sConfig ,
166
170
classLoader : ClassLoader = Thread .currentThread.getContextClassLoader
167
- ): Try [Configuration ] = Try {
171
+ ): Try [Configuration ] = toJavaF[Try ](c, classLoader)
172
+
173
+ // TODO Remove this method in the future to `toJava`
174
+ def toJavaF [F [_]: MonadThrow ](
175
+ c : Fly4sConfig ,
176
+ classLoader : ClassLoader = Thread .currentThread.getContextClassLoader
177
+ ): F [Configuration ] = MonadThrow [F ].catchNonFatal {
178
+
179
+ val fluentConfiguration : FluentConfiguration = c.baseJavaConfig match {
180
+ case Some (jconf) => new FluentConfiguration (classLoader).configuration(jconf)
181
+ case None => new FluentConfiguration (classLoader)
182
+ }
183
+
168
184
// ---------- connection ----------
169
- new FluentConfiguration (classLoader)
185
+ fluentConfiguration
170
186
.connectRetries(c.connectRetries)
171
187
.initSql(c.initSql.orNull)
172
188
.defaultSchema(c.defaultSchemaName.orNull)
0 commit comments