Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H2 Database #660

Merged
merged 7 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ gradle-app.setting
### Gradle Cache ###
.cache

### ObjectBox ###
objectbox*.dll
libobjectbox*.so
libobjectbox*.dylib

### Kotlin ###
.kotlin

Expand Down
13 changes: 3 additions & 10 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
kotlin("jvm")
kotlin("kapt")
id("io.objectbox")
id("com.gradleup.shadow")
}

Expand Down Expand Up @@ -40,7 +38,9 @@ dependencies {
implementation(libs.javalin)
implementation(libs.koin)
implementation(libs.airline)

implementation(libs.h2)
implementation(libs.bundles.exposed)
implementation(libs.flyway)
testImplementation(project(":nebulosa-astrobin-api"))
testImplementation(project(":nebulosa-skycatalog-stellarium"))
testImplementation(project(":nebulosa-test"))
Expand All @@ -56,10 +56,3 @@ tasks.withType<ShadowJar> {
attributes["Main-Class"] = "nebulosa.api.MainKt"
}
}

kapt {
arguments {
arg("objectbox.modelPath", "$projectDir/schemas/objectbox.json")
arg("objectbox.myObjectBoxPackage", "nebulosa.api.database")
}
}
1 change: 0 additions & 1 deletion api/schemas/.gitignore

This file was deleted.

220 changes: 0 additions & 220 deletions api/schemas/objectbox.json

This file was deleted.

9 changes: 9 additions & 0 deletions api/src/main/kotlin/nebulosa/api/Nebulosa.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import io.javalin.http.HttpStatus.BAD_REQUEST
import io.javalin.json.JavalinJackson
import nebulosa.api.converters.DeviceModule
import nebulosa.api.core.ErrorResponse
import nebulosa.api.database.MainDatabaseMigrator
import nebulosa.api.database.SkyDatabaseMigrator
import nebulosa.api.inject.*
import nebulosa.json.PathModule
import nebulosa.log.i
import nebulosa.log.loggerFor
import org.koin.core.context.startKoin
import org.slf4j.LoggerFactory
import java.net.ConnectException
import java.util.concurrent.ExecutorService

@Command(name = "nebulosa")
class Nebulosa : Runnable, AutoCloseable {
Expand Down Expand Up @@ -65,6 +68,12 @@ class Nebulosa : Runnable, AutoCloseable {
startKoin(koinApp)

LOG.i("server is started at port: {}", app.port())

with(koinApp.koin) {
val executor = get<ExecutorService>()
executor.submit(get<MainDatabaseMigrator>())
executor.submit(get<SkyDatabaseMigrator>())
}
}

private fun handleException(ex: Exception, ctx: Context) {
Expand Down
9 changes: 7 additions & 2 deletions api/src/main/kotlin/nebulosa/api/atlas/IERSUpdateTask.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nebulosa.api.atlas

import io.javalin.http.Header
import nebulosa.api.database.MainDatabaseMigrator
import nebulosa.api.preference.PreferenceService
import nebulosa.io.transferAndClose
import nebulosa.log.d
Expand All @@ -13,6 +14,8 @@ import nebulosa.time.IERSAB
import nebulosa.time.IERSB
import okhttp3.OkHttpClient
import okhttp3.Request
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import java.nio.file.Path
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
Expand All @@ -24,13 +27,15 @@ class IERSUpdateTask(
private val httpClient: OkHttpClient,
private val preferenceService: PreferenceService,
scheduledExecutorService: ScheduledExecutorService,
) : Runnable {
) : Runnable, KoinComponent {

init {
scheduledExecutorService.schedule(this, 0L, TimeUnit.SECONDS)
scheduledExecutorService.schedule(this, 5L, TimeUnit.SECONDS)
}

override fun run() {
get<MainDatabaseMigrator>().await()

val iersa = IERSA()
val iersb = IERSB()

Expand Down
7 changes: 6 additions & 1 deletion api/src/main/kotlin/nebulosa/api/atlas/LibWCSDownloadTask.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nebulosa.api.atlas

import com.sun.jna.Platform
import nebulosa.api.database.MainDatabaseMigrator
import nebulosa.api.preference.PreferenceService
import nebulosa.io.transferAndCloseOutput
import nebulosa.log.e
Expand All @@ -10,6 +11,8 @@ import nebulosa.wcs.LibWCS
import okhttp3.OkHttpClient
import okhttp3.Request
import org.apache.commons.codec.digest.DigestUtils
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import java.nio.file.Path
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
Expand All @@ -22,13 +25,15 @@ class LibWCSDownloadTask(
private val httpClient: OkHttpClient,
private val preferenceService: PreferenceService,
scheduledExecutorService: ScheduledExecutorService,
) : Runnable {
) : Runnable, KoinComponent {

init {
scheduledExecutorService.schedule(this, 5L, TimeUnit.SECONDS)
}

override fun run() {
get<MainDatabaseMigrator>().await()

var request = Request.Builder().get().url(VERSION_URL).build()

val libraryUrl = LIBRARY_URLS[Platform.RESOURCE_PREFIX]
Expand Down
Loading