Add base models.
This commit is contained in:
parent
223837ee69
commit
542b673a1f
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,10 +1,36 @@
|
||||
package ru.ulstu.`is`.pmu.student.model
|
||||
|
||||
import java.io.Serializable
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(
|
||||
tableName = "levels"
|
||||
)
|
||||
data class Level(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val uid: Long?,
|
||||
@ColumnInfo(name = "level")
|
||||
val level: Int,
|
||||
) : Serializable
|
||||
){
|
||||
@Ignore
|
||||
constructor(
|
||||
level: Int
|
||||
) : this(null, level)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as Level
|
||||
if (uid != other.uid) return false
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return (uid ?: -1) as Int
|
||||
}
|
||||
}
|
||||
|
||||
fun getLevels(): List<Level> {
|
||||
return listOf(
|
||||
|
@ -0,0 +1,16 @@
|
||||
package ru.ulstu.`is`.pmu.student.model
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
//one to many for level and tanks
|
||||
data class LevelWithTanks (
|
||||
@Embedded
|
||||
val level: Level,
|
||||
|
||||
@Relation(
|
||||
parentColumn = "uid",
|
||||
entityColumn = "levelId"
|
||||
)
|
||||
val tanks: List<Tank>
|
||||
)
|
@ -0,0 +1,16 @@
|
||||
package ru.ulstu.`is`.pmu.student.model
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
//one to many for nation and tanks
|
||||
data class NaationWithTanks (
|
||||
@Embedded
|
||||
val nation: Nation,
|
||||
|
||||
@Relation(
|
||||
parentColumn = "uid",
|
||||
entityColumn = "nationId"
|
||||
)
|
||||
val tanks: List<Tank>
|
||||
)
|
@ -1,10 +1,37 @@
|
||||
package ru.ulstu.`is`.pmu.student.model
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import androidx.room.PrimaryKey
|
||||
import java.io.Serializable
|
||||
|
||||
@Entity(
|
||||
tableName = "nations"
|
||||
)
|
||||
data class Nation(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val uid: Long?,
|
||||
@ColumnInfo(name = "name")
|
||||
val name: String,
|
||||
) : Serializable
|
||||
) {
|
||||
@Ignore
|
||||
constructor(
|
||||
name: String
|
||||
) : this(null, name)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as Nation
|
||||
if (uid != other.uid) return false
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return (uid ?: -1) as Int
|
||||
}
|
||||
}
|
||||
|
||||
fun getNations(): List<Nation> {
|
||||
return listOf(
|
||||
|
@ -1,19 +1,52 @@
|
||||
package ru.ulstu.`is`.pmu.student.model
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import androidx.room.PrimaryKey
|
||||
import java.io.Serializable
|
||||
|
||||
@Entity(
|
||||
tableName = "tanks"
|
||||
)
|
||||
data class Tank(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val uid: Long?,
|
||||
@ColumnInfo(name = "name")
|
||||
val name: String,
|
||||
@ColumnInfo(name = "price")
|
||||
val price: Int,
|
||||
val level: Int,
|
||||
val nation: String
|
||||
) : Serializable
|
||||
@ColumnInfo(name = "levelId")
|
||||
val levelId: Long?,
|
||||
@ColumnInfo(name = "nationId")
|
||||
val nationId: Long?
|
||||
) {
|
||||
@Ignore
|
||||
constructor(
|
||||
name: String,
|
||||
price: Int,
|
||||
level: Level,
|
||||
nation: Nation
|
||||
) : this(null, name, price, level.uid, nation.uid)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as Tank
|
||||
if (uid != other.uid) return false
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return (uid ?: -1) as Int
|
||||
}
|
||||
}
|
||||
|
||||
fun getTanks(): List<Tank> {
|
||||
return listOf(
|
||||
Tank("T-38-85", 970000, 6, "СССР"),
|
||||
Tank("M3 Lee", 140000, 4, "США"),
|
||||
Tank("Foch B", 6100000, 10, "Франция")
|
||||
//Tank("T-38-85", 970000, 6, "СССР"),
|
||||
//Tank("M3 Lee", 140000, 4, "США"),
|
||||
//Tank("Foch B", 6100000, 10, "Франция")
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user