Code style improvements (thanks to codebeat.co)

This commit is contained in:
Christian Basler 2017-11-27 22:26:30 +01:00
parent 760e423b9b
commit f6ebd62c8d
3 changed files with 24 additions and 43 deletions

View File

@ -24,6 +24,7 @@ import ch.dissem.apps.abit.util.Labels
import ch.dissem.bitmessage.entity.valueobject.Label
import ch.dissem.bitmessage.ports.AbstractLabelRepository
import ch.dissem.bitmessage.ports.MessageRepository
import org.jetbrains.anko.db.transaction
import java.util.*
/**
@ -60,9 +61,7 @@ class AndroidLabelRepository(private val sql: SqlHelper, private val context: Co
values.put(COLUMN_ORDER, label.ord)
db.update(TABLE_NAME, values, "id=?", arrayOf(label.id.toString()))
} else {
try {
db.beginTransaction()
db.transaction {
val exists = DatabaseUtils.queryNumEntries(db, TABLE_NAME, "label=?", arrayOf(label.toString())) > 0
if (exists) {
@ -79,9 +78,6 @@ class AndroidLabelRepository(private val sql: SqlHelper, private val context: Co
values.put(COLUMN_ORDER, label.ord)
db.insertOrThrow(TABLE_NAME, null, values)
}
db.setTransactionSuccessful()
} finally {
db.endTransaction()
}
}
}

View File

@ -33,6 +33,7 @@ import ch.dissem.bitmessage.ports.AlreadyStoredException
import ch.dissem.bitmessage.ports.MessageRepository
import ch.dissem.bitmessage.utils.Encode
import ch.dissem.bitmessage.utils.Strings.hex
import org.jetbrains.anko.db.transaction
import java.io.ByteArrayInputStream
import java.util.*
@ -182,9 +183,7 @@ class AndroidMessageRepository(private val sql: SqlHelper) : AbstractMessageRepo
saveContactIfNecessary(message.from)
saveContactIfNecessary(message.to)
val db = sql.writableDatabase
try {
db.beginTransaction()
db.transaction {
// save message
if (message.id == null) {
insert(db, message)
@ -204,11 +203,6 @@ class AndroidMessageRepository(private val sql: SqlHelper) : AbstractMessageRepo
values.put(JT_COLUMN_MESSAGE, message.id as Long?)
db.insertOrThrow(JOIN_TABLE_NAME, null, values)
}
db.setTransactionSuccessful()
} catch (e: SQLiteConstraintException) {
throw AlreadyStoredException(cause = e)
} finally {
db.endTransaction()
}
}

View File

@ -16,6 +16,7 @@ import ch.dissem.bitmessage.utils.UnixTime.DAY
import ch.dissem.bitmessage.utils.UnixTime.MINUTE
import ch.dissem.bitmessage.utils.UnixTime.now
import ch.dissem.bitmessage.utils.max
import org.jetbrains.anko.db.transaction
import org.slf4j.LoggerFactory
import java.util.*
import kotlin.concurrent.getOrSet
@ -64,12 +65,11 @@ class AndroidNodeRegistry(private val sql: SqlHelper) : NodeRegistry {
}
override fun getKnownAddresses(limit: Int, vararg streams: Long): List<NetworkAddress> {
val projection = arrayOf(COLUMN_STREAM, COLUMN_ADDRESS, COLUMN_PORT, COLUMN_SERVICES, COLUMN_TIME)
val result = LinkedList<NetworkAddress>()
try {
sql.readableDatabase.query(
TABLE_NAME, projection,
TABLE_NAME,
arrayOf(COLUMN_STREAM, COLUMN_ADDRESS, COLUMN_PORT, COLUMN_SERVICES, COLUMN_TIME),
"stream IN (?)",
arrayOf(SqlStrings.join(*streams)), null, null,
"time DESC",
@ -85,10 +85,6 @@ class AndroidNodeRegistry(private val sql: SqlHelper) : NodeRegistry {
))
}
}
} catch (e: Exception) {
LOG.error(e.message, e)
throw ApplicationException(e)
}
if (result.isEmpty()) {
streams
@ -101,9 +97,7 @@ class AndroidNodeRegistry(private val sql: SqlHelper) : NodeRegistry {
}
override fun offerAddresses(nodes: List<NetworkAddress>) {
val db = sql.writableDatabase
db.beginTransaction()
try {
sql.writableDatabase.transaction {
cleanUp()
nodes
.filter {
@ -120,9 +114,6 @@ class AndroidNodeRegistry(private val sql: SqlHelper) : NodeRegistry {
}
}
}
db.setTransactionSuccessful()
} finally {
db.endTransaction()
}
}