diff --git a/src/main/kotlin/me/msoucy/gbat/models/KnowledgeModel.kt b/src/main/kotlin/me/msoucy/gbat/models/KnowledgeModel.kt index 00f329f..19893b8 100644 --- a/src/main/kotlin/me/msoucy/gbat/models/KnowledgeModel.kt +++ b/src/main/kotlin/me/msoucy/gbat/models/KnowledgeModel.kt @@ -5,6 +5,7 @@ import me.msoucy.gbat.mutableCopyOf import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.transaction +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq class KnowledgeModel(val db: Database, val constant: Double, val riskModel: RiskModel) { @@ -71,7 +72,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk } fun knowledgeSummary(lineNum: Int) = transaction(db) { - LineKnowledge.select { + LineKnowledge.selectAll().where { LineKnowledge.linenum eq lineNum }.map { val acct = getKnowledgeAcct(it[LineKnowledge.knowledgeacctid]) @@ -90,7 +91,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk } private fun getKnowledgeAcct(knowledgeAcctId: Int): KnowledgeAcct = transaction(db) { - KnowledgeAcctsTable.select { + KnowledgeAcctsTable.selectAll().where { KnowledgeAcctsTable.id eq knowledgeAcctId }.map { KnowledgeAcct( @@ -103,8 +104,8 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk private fun destroyLineKnowledge(knowledgeId: Int, lineNum: Int) = transaction(db) { LineKnowledge.deleteWhere { - (LineKnowledge.knowledgeacctid eq knowledgeId) and - (LineKnowledge.linenum eq lineNum) + (knowledgeacctid eq knowledgeId) and + (linenum eq lineNum) } } @@ -137,7 +138,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk } private fun knowledgeInAcct(knowledgeAcctId: Int, lineNum: Int) = transaction(db) { - LineKnowledge.select { + LineKnowledge.selectAll().where { (LineKnowledge.knowledgeacctid eq knowledgeAcctId) and (LineKnowledge.linenum eq lineNum) }.map { @@ -146,7 +147,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk } private fun nonSafeAcctsWithKnowledgeOf(lineNum: Int) = transaction(db) { - LineKnowledge.select { + LineKnowledge.selectAll().where { (LineKnowledge.linenum eq lineNum) and (LineKnowledge.knowledgeacctid neq SAFE_KNOWLEDGE_ACCT_ID) }.map { @@ -155,7 +156,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk } private fun allAcctsWithKnowledgeOf(lineNum: Int) = transaction(db) { - LineKnowledge.select { + LineKnowledge.selectAll().where { LineKnowledge.linenum eq lineNum }.map { it[LineKnowledge.knowledgeacctid] @@ -163,7 +164,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk } private fun adjustKnowledge(knowledgeAcctId: Int, lineNum: Int, adjustment: Double) = transaction(db) { - val lineExists = LineKnowledge.select { + val lineExists = LineKnowledge.selectAll().where { (LineKnowledge.knowledgeacctid eq knowledgeAcctId) and (LineKnowledge.linenum eq lineNum) }.count() > 0 @@ -186,7 +187,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk private fun lookupOrCreateKnowledgeAcct(authors: List) = transaction(db) { val authorStr = authors.sorted().joinToString("\n") - KnowledgeAcctsTable.select { + KnowledgeAcctsTable.selectAll().where { KnowledgeAcctsTable.authors eq authorStr }.map { it[KnowledgeAcctsTable.id].value @@ -194,7 +195,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk KnowledgeAcctsTable.insert { it[KnowledgeAcctsTable.authors] = authorStr } - val theNewId = KnowledgeAcctsTable.select { + val theNewId = KnowledgeAcctsTable.selectAll().where { KnowledgeAcctsTable.authors eq authorStr }.map { it[KnowledgeAcctsTable.id].value @@ -214,7 +215,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk AuthorsTable.insertIgnore { it[author] = authorName } - AuthorsTable.select { + AuthorsTable.selectAll().where { AuthorsTable.author eq authorName }.first().let { it[AuthorsTable.id] @@ -222,7 +223,7 @@ class KnowledgeModel(val db: Database, val constant: Double, val riskModel: Risk } private fun totalLineKnowledge(linenum: Int) = transaction(db) { - LineKnowledge.select { + LineKnowledge.selectAll().where { LineKnowledge.linenum eq linenum }.map { it[LineKnowledge.knowledge] diff --git a/src/main/kotlin/me/msoucy/gbat/models/SummaryModel.kt b/src/main/kotlin/me/msoucy/gbat/models/SummaryModel.kt index 0e0b738..c20f909 100644 --- a/src/main/kotlin/me/msoucy/gbat/models/SummaryModel.kt +++ b/src/main/kotlin/me/msoucy/gbat/models/SummaryModel.kt @@ -166,7 +166,7 @@ class SummaryModel(val db: Database) { } fun fpath(fileId: Int): Path = transaction(db) { - FilesTable.select { + FilesTable.selectAll().where { FilesTable.id eq fileId }.first().let { row -> val dirs = reconsDirs(row[FilesTable.dirid]) @@ -176,7 +176,7 @@ class SummaryModel(val db: Database) { fun projectFiles(project: String): List = transaction(db) { val projectId = findOrCreateProject(project) - (FilesTable innerJoin DirsTable).select { + (FilesTable innerJoin DirsTable).selectAll().where { (FilesTable.dirid eq DirsTable.id) and (DirsTable.projectid eq projectId) }.map { row -> @@ -192,7 +192,7 @@ class SummaryModel(val db: Database) { val parentDirIds = mutableListOf(0) while (parentDirIds.isNotEmpty()) { val parentId = parentDirIds.removeAt(0) - DirsTable.select { DirsTable.parentdirid eq parentId } + DirsTable.selectAll().where { DirsTable.parentdirid eq parentId } .forEach { row -> val dirId = row[DirsTable.id].value theTree.getOrPut(parentId) { ProjectTree() }.dirs.add(dirId) @@ -203,13 +203,13 @@ class SummaryModel(val db: Database) { // Then add the files theTree.entries.forEach { entry -> - FilesTable.select { FilesTable.dirid eq entry.key }.forEach { row -> + FilesTable.selectAll().where { FilesTable.dirid eq entry.key }.forEach { row -> entry.value.files[row[FilesTable.id].value] = FileEntry(row[FilesTable.fname]) } entry.value.files.entries.forEach { (fileId, fileEntry) -> lineAllocations - .slice(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum()) - .select { LinesTable.fileid eq fileId } + .select(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum()) + .where { LinesTable.fileid eq fileId } .groupBy(LinesTable.fileid) .forEach { row -> fileEntry.stats.totKnowledge = row[AllocationsTable.knowledge.sum()] ?: 0.0 @@ -219,12 +219,12 @@ class SummaryModel(val db: Database) { } entry.value.files.entries.forEach { (fileId, fileEntry) -> lineAllocationGroups - .slice( + .select( AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum(), AuthorsGroupsTable.authors - ).select { LinesTable.fileid eq fileId } + ).where { LinesTable.fileid eq fileId } .groupBy(AllocationsTable.authorgroupid) .orderBy(AuthorsGroupsTable.authors) .forEach { row -> @@ -239,24 +239,24 @@ class SummaryModel(val db: Database) { val projectTree = ProjectTreeResult(project, root) allJoined - .slice( + .select( AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum(), AuthorsGroupsTable.authors ) - .select { DirsTable.projectid eq projectId } + .where { DirsTable.projectid eq projectId } .groupBy(AuthorsGroupsTable.id) .forEach { row -> projectTree.authorRisks[row[AuthorsGroupsTable.authors]] = Statistics(row) } manyJoined - .slice( + .select( AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum() - ).select { + ).where { DirsTable.projectid eq projectId }.first().let { row -> projectTree.stats = Statistics(row) @@ -268,8 +268,8 @@ class SummaryModel(val db: Database) { fun fileSummary(fileId: Int) = transaction(db) { var fileTree = FileTree() lineAllocationGroups - .slice(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum(), AuthorsGroupsTable.authors) - .select { + .select(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum(), AuthorsGroupsTable.authors) + .where { LinesTable.fileid eq fileId }.groupBy(AuthorsGroupsTable.id).forEach { row -> val authors = row[AuthorsGroupsTable.authors] @@ -279,29 +279,29 @@ class SummaryModel(val db: Database) { JoinType.LEFT, LinesTable.fileid, FilesTable.id ) - .slice(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum()) - .select { LinesTable.fileid eq fileId } + .select(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum()) + .where { LinesTable.fileid eq fileId } .first().let { row -> fileTree.stats = Statistics(row) } - fileTree.name = FilesTable.select { FilesTable.id eq fileId }.map { it[FilesTable.fname] }.first() + fileTree.name = FilesTable.selectAll().where { FilesTable.id eq fileId }.map { it[FilesTable.fname] }.first() - LinesTable.select { LinesTable.fileid eq fileId } + LinesTable.selectAll().where { LinesTable.fileid eq fileId } .map { it[LinesTable.id].value } .forEach { lineId -> val lineDict = LineDict() lineAllocationGroups - .slice(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum(), AuthorsGroupsTable.authors) - .select { + .select(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum(), AuthorsGroupsTable.authors) + .where { LinesTable.id eq lineId }.groupBy(AuthorsGroupsTable.id).forEach { lineRow -> lineDict.authorRisks[lineRow[AuthorsGroupsTable.authors]] = Statistics(lineRow) } lineAllocations - .slice(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum()) - .select { + .select(AllocationsTable.knowledge.sum(), AllocationsTable.risk.sum(), AllocationsTable.orphaned.sum()) + .where { LinesTable.id eq lineId }.first().let { lineDict.stats = Statistics(it) @@ -312,7 +312,7 @@ class SummaryModel(val db: Database) { } fun fileLines(fileId: Int): List = transaction(db) { - LinesTable.select { + LinesTable.selectAll().where { LinesTable.fileid eq fileId }.orderBy(LinesTable.linenum).map { it[LinesTable.line] @@ -338,7 +338,7 @@ class SummaryModel(val db: Database) { val segs = mutableListOf() var newDirId = dirId while (newDirId != 0) { - DirsTable.select { + DirsTable.selectAll().where { DirsTable.id eq newDirId }.forEach { segs.add(it[DirsTable.dir]) @@ -362,7 +362,7 @@ class SummaryModel(val db: Database) { private fun findOrCreateAuthorGroup(authors: List): Int = transaction(db) { val authorsstr = authors.joinToString("\n") - var authorGroupId = AuthorsGroupsTable.select { + var authorGroupId = AuthorsGroupsTable.selectAll().where { AuthorsGroupsTable.authors eq authorsstr }.map { it[AuthorsGroupsTable.id].value @@ -387,7 +387,7 @@ class SummaryModel(val db: Database) { AuthorsTable.insertIgnore { it[AuthorsTable.author] = author } - AuthorsTable.select { + AuthorsTable.selectAll().where { AuthorsTable.author eq author }.map { it[AuthorsTable.id].value @@ -413,7 +413,7 @@ class SummaryModel(val db: Database) { ProjectTable.insertIgnore { it[ProjectTable.project] = project } - ProjectTable.select { + ProjectTable.selectAll().where { ProjectTable.project eq project }.map { it[ProjectTable.id].value @@ -426,7 +426,7 @@ class SummaryModel(val db: Database) { it[parentdirid] = parentDirId it[projectid] = projectId } - DirsTable.select { + DirsTable.selectAll().where { DirsTable.dir eq dirname DirsTable.parentdirid eq parentDirId DirsTable.projectid eq projectId @@ -454,7 +454,7 @@ class SummaryModel(val db: Database) { val dirs = mutableListOf() var parentDirId = dirId while (parentDirId != 0) { - DirsTable.select { + DirsTable.selectAll().where { DirsTable.id eq parentDirId } .first()