-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6481454
commit 5b80a0b
Showing
7 changed files
with
73 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...in/kotlin/app/aaps/database/transactions/InsertOrUpdateCachedTotalDailyDoseTransaction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package app.aaps.database.transactions | ||
|
||
import app.aaps.database.entities.TotalDailyDose | ||
import app.aaps.database.entities.embedments.InterfaceIDs | ||
|
||
/** | ||
* Creates or updates the TotalDailyDose from data caching | ||
*/ | ||
class InsertOrUpdateCachedTotalDailyDoseTransaction( | ||
private val tdd: TotalDailyDose | ||
) : Transaction<InsertOrUpdateCachedTotalDailyDoseTransaction.TransactionResult>() { | ||
|
||
override fun run(): TransactionResult { | ||
val result = TransactionResult() | ||
var current: TotalDailyDose? = null | ||
// search by timestamp | ||
current = database.totalDailyDoseDao.findByPumpTimestamp(tdd.timestamp, InterfaceIDs.PumpType.CACHE) | ||
if (current == null) { | ||
database.totalDailyDoseDao.insertNewEntry(tdd) | ||
result.inserted.add(tdd) | ||
} else { | ||
current.basalAmount = tdd.basalAmount | ||
current.bolusAmount = tdd.bolusAmount | ||
current.totalAmount = tdd.totalAmount | ||
current.carbs = tdd.carbs | ||
database.totalDailyDoseDao.updateExistingEntry(current) | ||
result.updated.add(current) | ||
} | ||
|
||
return result | ||
} | ||
|
||
class TransactionResult { | ||
|
||
val inserted = mutableListOf<TotalDailyDose>() | ||
val updated = mutableListOf<TotalDailyDose>() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters