Micronaut support for Requery


License

License

Categories

Categories

Micronaut Container Microservices requery Data Databases
GroupId

GroupId

com.github.ryarnyah
ArtifactId

ArtifactId

micronaut-requery
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

Micronaut support for Requery
Micronaut support for Requery
Project URL

Project URL

https://github.com/ryarnyah/micronaut-requery
Source Code Management

Source Code Management

https://github.com/ryarnyah/micronaut-requery

Download micronaut-requery

Dependencies

compile (2)

Group / Artifact Type Version
io.micronaut : micronaut-inject jar
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.10

runtime (3)

Group / Artifact Type Version
io.micronaut.data : micronaut-data-tx jar
io.requery : requery jar 1.6.1
io.requery : requery-kotlin jar 1.6.1

Project Modules

There are no modules declared in this project.

Micronaut-Requery

Micronaut support for Requery

HowTo To install

dependencies {
    //...
    kapt("io.requery:requery-processor:${requeryVersion}")
    //...
    implementation("com.github.ryarnyah:micronaut-requery:${micronautKotlinRequeryVersion}")
    implementation("io.requery:requery:${requeryVersion}")
    implementation("io.requery:requery-kotlin:${requeryVersion}")
    //...
}

HowToUse

Kotlin version

@Entity
data class TestData (
    @get:Key
    @get:Column(nullable = false, length = 256)
    var uid: String
)

@Factory
class MicronautTestFactory {

    @Bean
    fun entityModel(): EntityModel {
        return Models.DEFAULT
    }
}

@Singleton
open class TestService(
    private val entityDataStore: MicronautKotlinEntityDataStore<TestData>
) {
    @Transactional
    open fun save(entity: TestData) {
        entityDataStore.upsert(entity)
    }
    
    open fun findById(id: String): TestData? {
        return entityDataStore.findByKey(TestData::class, id)
    }
}

Java version

@Entity
public class TestData extends Observable, Parcelable, Persistable {
    @Key
    @Generated
    String getUid();
}

@Factory
public class MicronautTestFactory {

    @Bean
    public EntityModel entityModel() {
        return Models.DEFAULT;
    }
}

@Singleton
public class TestService {
    
    private final MicronautEntityDataStore<TestData> entityDataStore;

    public TestService(MicronautEntityDataStore<TestData> entityDataStore) {
        this.entityDataStore = entityDataStore;
    }

    @Transactional
    public void save(TestData entity) {
        entityDataStore.upsert(entity);
    }
    
    public TestData findById(String id) {
        return entityDataStore.findByKey(TestData.class, id);
    }
}

Configuration

Basic configuration can be applied

requery:
  default:
    use-default-logging: false # boolean
    statement-cache-size: 0 # integer
    batch-update-size: 64 # integer
    quote-table-names: false # boolean
    quote-column-names: false # boolean

For more specific configuration, define a bean with RequeryDataSourceConfiguration.DEFAULT qualifier.

Kotlin version

@Factory
class MicronautTestFactory {

    @Bean
    @Named(RequeryDataSourceConfiguration.DEFAULT)
    fun requeryDataSourceConfiguration(): RequeryDataSourceConfiguration {
        val configuration = RequeryDataSourceConfiguration()
        configuration.useDefaultLogging = true
        return configuration
    }
}

Java version

@Factory
public class MicronautTestFactory {

    @Bean
    @Named(RequeryDataSourceConfiguration.DEFAULT)
    public RequeryDataSourceConfiguration requeryDataSourceConfiguration() {
        RequeryDataSourceConfiguration configuration = new RequeryDataSourceConfiguration();
        configuration.setUseDefaultLogging(true);
        return configuration;
    }
}

You can use multiple dataSource like with JDBC (it will try to find dataSource, transactionManager and entityModel with the same qualifier)

requery:
  second-datasource:

Kotlin version

@Factory
class MicronautTestFactory {
    
    @Bean
    // Define it as primary
    @Primary
    fun entityModel(): EntityModel {
        return Models.DEFAULT
    }

    @Bean
    @Named("second-datasource")
    fun secondEntityModel(): EntityModel {
        return Models.DEFAULT
    }

}

Java version

@Factory
public class MicronautTestFactory {
    
    @Bean
    // Define it as primary
    @Primary
    public EntityModel entityModel() {
        return Models.DEFAULT;
    }

    @Bean
    @Named("second-datasource")
    public EntityModel secondEntityModel() {
        return Models.DEFAULT;
    }

}

Current status

  • Add LinkedDataSource to solve statement.getConnection().close() (in requery)
  • Disable requery transaction to prefer using Micronaut transaction support
  • Disable requery cache using EmptyEntityCache
  • Add Java Support

Versions

Version
0.0.1