Code style improvements (thanks to codebeat.co)
This commit is contained in:
parent
760e423b9b
commit
f6ebd62c8d
@ -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.*
|
||||
|
||||
/**
|
||||
@ -40,7 +41,7 @@ class AndroidLabelRepository(private val sql: SqlHelper, private val context: Co
|
||||
|
||||
sql.readableDatabase.query(
|
||||
TABLE_NAME, projection,
|
||||
where, null, null, null,
|
||||
where, null, null, null,
|
||||
COLUMN_ORDER
|
||||
).use { c ->
|
||||
while (c.moveToNext()) {
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,30 +65,25 @@ 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,
|
||||
"stream IN (?)",
|
||||
arrayOf(SqlStrings.join(*streams)), null, null,
|
||||
"time DESC",
|
||||
limit.toString()
|
||||
).use { c ->
|
||||
while (c.moveToNext()) {
|
||||
result.add(NetworkAddress(
|
||||
time = c.getLong(c.getColumnIndex(COLUMN_TIME)),
|
||||
stream = c.getLong(c.getColumnIndex(COLUMN_STREAM)),
|
||||
services = c.getLong(c.getColumnIndex(COLUMN_SERVICES)),
|
||||
IPv6 = c.getBlob(c.getColumnIndex(COLUMN_ADDRESS)),
|
||||
port = c.getInt(c.getColumnIndex(COLUMN_PORT))
|
||||
))
|
||||
}
|
||||
|
||||
sql.readableDatabase.query(
|
||||
TABLE_NAME,
|
||||
arrayOf(COLUMN_STREAM, COLUMN_ADDRESS, COLUMN_PORT, COLUMN_SERVICES, COLUMN_TIME),
|
||||
"stream IN (?)",
|
||||
arrayOf(SqlStrings.join(*streams)), null, null,
|
||||
"time DESC",
|
||||
limit.toString()
|
||||
).use { c ->
|
||||
while (c.moveToNext()) {
|
||||
result.add(NetworkAddress(
|
||||
time = c.getLong(c.getColumnIndex(COLUMN_TIME)),
|
||||
stream = c.getLong(c.getColumnIndex(COLUMN_STREAM)),
|
||||
services = c.getLong(c.getColumnIndex(COLUMN_SERVICES)),
|
||||
IPv6 = c.getBlob(c.getColumnIndex(COLUMN_ADDRESS)),
|
||||
port = c.getInt(c.getColumnIndex(COLUMN_PORT))
|
||||
))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
LOG.error(e.message, e)
|
||||
throw ApplicationException(e)
|
||||
}
|
||||
|
||||
if (result.isEmpty()) {
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user