Skip to content

Commit

Permalink
Update Kotlin to 1.3.40
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredrummler committed Jun 22, 2019
1 parent 36c3611 commit cc89efd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlinVersion = '1.3.20'
ext.kotlinVersion = '1.3.40'

repositories {
google()
Expand Down
6 changes: 3 additions & 3 deletions generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'java-library'
apply plugin: 'kotlin'

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
compile 'com.google.code.gson:gson:2.8.2'
compile 'org.xerial:sqlite-jdbc:3.20.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.xerial:sqlite-jdbc:3.20.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,19 @@ import java.sql.SQLException
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

private const val SQL_INSERT = "INSERT INTO devices (name, codename, model) VALUES (?, ?, ?)"
private const val SQL_DROP = "DROP TABLE IF EXISTS devices;"
private const val SQL_CREATE = "CREATE TABLE devices (\n" +
"_id INTEGER PRIMARY KEY,\n" +
"name TEXT,\n" +
"codename TEXT,\n" +
"model TEXT\n" +
");"

class DatabaseGenerator(private val devices: List<Device>,
class DatabaseGenerator(
private val devices: List<Device>,
private val databasename: String = "database/android-devices.db",
private val zipname: String = "database/android-devices.zip") {
private val zipname: String = "database/android-devices.zip"
) {

fun generate() {
val url = "jdbc:sqlite:$databasename"

try {
File(databasename).parentFile?.mkdirs()

DriverManager.getConnection(url).use { conn ->
DriverManager.getConnection(url)?.let { conn ->
conn.createStatement().execute(SQL_DROP)
conn.createStatement().execute(SQL_CREATE)
val statement = conn.prepareStatement(SQL_INSERT)
Expand All @@ -56,6 +49,7 @@ class DatabaseGenerator(private val devices: List<Device>,
statement.addBatch()
}
statement.executeBatch()
conn.close()
}

ZipOutputStream(BufferedOutputStream(FileOutputStream(zipname))).use { out ->
Expand All @@ -67,10 +61,20 @@ class DatabaseGenerator(private val devices: List<Device>,
}
}
}

} catch (e: SQLException) {
e.printStackTrace()
}
}

companion object {
private const val SQL_INSERT = "INSERT INTO devices (name, codename, model) VALUES (?, ?, ?)"
private const val SQL_DROP = "DROP TABLE IF EXISTS devices;"
private const val SQL_CREATE = "CREATE TABLE devices (\n" +
"_id INTEGER PRIMARY KEY,\n" +
"name TEXT,\n" +
"codename TEXT,\n" +
"model TEXT\n" +
");"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.jaredrummler.androiddevicenames

fun main(args: Array<String>) {
fun main() {
// Get the devices supported by Google Play
val devices = getDevices()
// Create the database
Expand Down

0 comments on commit cc89efd

Please sign in to comment.