Add artifact_sources table

Signed-off-by: Graham <gpe@openrs2.org>
Graham 1 year ago
parent 3da5bb0786
commit 3932debd92
  1. 27
      archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt
  2. 7
      archive/src/main/kotlin/org/openrs2/archive/client/ImportCommand.kt
  3. 11
      archive/src/main/resources/org/openrs2/archive/migrations/V23__client_sources.sql

@ -60,7 +60,7 @@ public class ClientImporter @Inject constructor(
private val packClassLibraryReader: PackClassLibraryReader,
private val importer: CacheImporter
) {
public suspend fun import(paths: Iterable<Path>) {
public suspend fun import(paths: Iterable<Path>, name: String?, description: String?, url: String?) {
alloc.buffer().use { buf ->
for (path in paths) {
buf.clear()
@ -72,19 +72,34 @@ public class ClientImporter @Inject constructor(
}
logger.info { "Importing $path" }
import(parse(buf))
import(parse(buf), name, description, url)
}
}
}
public suspend fun import(artifact: Artifact) {
public suspend fun import(artifact: Artifact, name: String?, description: String?, url: String?) {
database.execute { connection ->
importer.prepare(connection)
import(connection, artifact)
val id = import(connection, artifact)
connection.prepareStatement(
"""
INSERT INTO artifact_sources (blob_id, name, description, url)
VALUES (?, ?, ?, ?)
""".trimIndent()
).use { stmt ->
stmt.setLong(1, id)
stmt.setString(2, name)
stmt.setString(3, description)
stmt.setString(4, url)
stmt.execute()
}
}
}
private fun import(connection: Connection, artifact: Artifact) {
private fun import(connection: Connection, artifact: Artifact): Long {
val id = importer.addBlob(connection, artifact)
val gameId = connection.prepareStatement(
@ -187,6 +202,8 @@ public class ClientImporter @Inject constructor(
stmt.executeBatch()
}
return id
}
public suspend fun refresh() {

@ -3,6 +3,7 @@ package org.openrs2.archive.client
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.path
import com.google.inject.Guice
import kotlinx.coroutines.runBlocking
@ -10,6 +11,10 @@ import org.openrs2.archive.ArchiveModule
import org.openrs2.inject.CloseableInjector
public class ImportCommand : CliktCommand(name = "import") {
private val name by option()
private val description by option()
private val url by option()
private val input by argument().path(
mustExist = true,
canBeDir = false,
@ -19,7 +24,7 @@ public class ImportCommand : CliktCommand(name = "import") {
override fun run(): Unit = runBlocking {
CloseableInjector(Guice.createInjector(ArchiveModule)).use { injector ->
val importer = injector.getInstance(ClientImporter::class.java)
importer.import(input)
importer.import(input, name, description, url)
}
}
}

@ -0,0 +1,11 @@
-- @formatter:off
CREATE TABLE artifact_sources (
id SERIAL PRIMARY KEY NOT NULL,
blob_id BIGINT NOT NULL REFERENCES artifacts (blob_id),
name TEXT NULL,
description TEXT NULL,
url TEXT NULL
);
CREATE INDEX ON artifact_sources (blob_id);
Loading…
Cancel
Save