Integrations
Integrations
Java
Dalesbred provides built-in type-conversions for the following classes:
| Model type | Direction | Database type |
|---|---|---|
java.net.URI |
<-> | String |
java.net.URL |
<-> | String |
java.util.TimeZone |
<-> | String |
Short/Integer/Long/Float/Double |
<- | Number |
BigInteger/BigDecimal |
<- | Number |
BigInteger |
-> | BigDecimal |
String/java.io.Reader |
<- | Clob |
byte[]/java.io.InputStream |
<- | Blob |
org.w3c.dom.Document |
<- | SQLXML |
java.time.Instant |
<-> | Timestamp |
java.time.LocalDateTime |
<-> | Timestamp |
java.time.LocalTime |
<-> | Time |
java.time.ZoneId |
<-> | String |
java.time.LocalDate |
<-> | java.util.Date/java.sql.Date |
Kotlin
Dalesbred has no required dependencies on Kotlin, but comes with a set of extension methods
to make Kotlin use nicer. Just import everything from org.dalesbred.integration.kotlin and you're good to go:
import org.dalesbred.integration.kotlin.*
...
fun findEmployees() = db.findAll<Employee>("""
select id, name, salary
from employee
order by name, id
""")
Joda-Time
If Joda-Time is detected on the classpath, Dalesbred will automatically register type-conversions between Joda-Time's DateTime, LocalDate and LocalTime to java.sql.Timestamp, java.sql.Date and java.sql.Time.
Spring
Dalesbred has support for integration with Spring Framework and its transaction management. To integrate Dalesbred, create a configuration class inheriting from DalesbredConfigurationSupport and specify beans for DataSource and PlatformTransactionManager. A minimal configuration would therefore be something like the following:
@Configuration
@EnableTransactionManagement
public class MyDatabaseConfiguration extends DalesbredConfigurationSupport {
@Bean
public DataSource dataSource() {
return new JndiDataSourceLookup().getDataSource("jdbc/my-database");
}
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
}
After this you can inject Database normally in your beans.