-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple primary keys on replicate entities
- Loading branch information
1 parent
938b5f3
commit 098f7a0
Showing
11 changed files
with
179 additions
and
16 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package db3 | ||
|
||
import androidx.room.Entity | ||
import com.ustadmobile.door.annotation.* | ||
import kotlinx.serialization.Serializable | ||
|
||
@Entity( | ||
primaryKeys = arrayOf("uidHi", "uidLo") | ||
) | ||
@ReplicateEntity( | ||
tableId = StatementEntity.TABLE_ID, | ||
remoteInsertStrategy = ReplicateEntity.RemoteInsertStrategy.INSERT_INTO_RECEIVE_VIEW | ||
) | ||
|
||
@Triggers( | ||
arrayOf( | ||
Trigger( | ||
name = "statement_remote_insert", | ||
order = Trigger.Order.INSTEAD_OF, | ||
events = arrayOf(Trigger.Event.INSERT), | ||
conditionSql = "SELECT %NEW_LAST_MODIFIED_GREATER_THAN_EXISTING%", | ||
on = Trigger.On.RECEIVEVIEW, | ||
sqlStatements = arrayOf("%UPSERT%"), | ||
) | ||
) | ||
) | ||
@Serializable | ||
data class StatementEntity( | ||
var uidHi: Long = 0, | ||
var uidLo: Long = 0, | ||
@ReplicateLastModified | ||
@ReplicateEtag | ||
var lct: Long = 0, | ||
var name: String? = null, | ||
) { | ||
companion object { | ||
const val TABLE_ID = 12121 | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
door-testdb/src/commonMain/kotlin/db3/StatementEntityDao.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,41 @@ | ||
package db3 | ||
|
||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import com.ustadmobile.door.annotation.DoorDao | ||
import com.ustadmobile.door.annotation.HttpAccessible | ||
import com.ustadmobile.door.annotation.Repository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@DoorDao | ||
@Repository | ||
|
||
expect abstract class StatementEntityDao { | ||
|
||
@Insert | ||
abstract suspend fun insertAsync(entity: StatementEntity) | ||
|
||
@Query(""" | ||
SELECT StatementEntity.* | ||
FROM StatementEntity | ||
""") | ||
abstract suspend fun findAllAsync(): List<StatementEntity> | ||
|
||
@Query(""" | ||
SELECT StatementEntity.* | ||
FROM StatementEntity | ||
WHERE StatementEntity.uidHi = :uidHi | ||
AND StatementEntity.uidLo = :uidLo | ||
""") | ||
abstract fun findByUidAsFlow(uidHi: Long, uidLo: Long): Flow<StatementEntity?> | ||
|
||
@HttpAccessible(clientStrategy = HttpAccessible.ClientStrategy.PULL_REPLICATE_ENTITIES) | ||
@Query(""" | ||
SELECT StatementEntity.* | ||
FROM StatementEntity | ||
WHERE StatementEntity.uidHi = :uidHi | ||
AND StatementEntity.uidLo = :uidLo | ||
""") | ||
abstract suspend fun findByUidAsync(uidHi: Long, uidLo: Long): StatementEntity? | ||
|
||
} |
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