From dbe104b11c1ca74a3898261ad11a367a11c4b8e3 Mon Sep 17 00:00:00 2001 From: "andrey.tarashevskiy" Date: Wed, 18 Jul 2018 15:29:36 +0300 Subject: [PATCH] #112 Exposed executing things more than once when adding a DROP --- .../org/jetbrains/exposed/sql/SchemaUtils.kt | 5 ++++- .../exposed/sql/tests/shared/DDLTests.kt | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt b/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt index 36ca7d59ab..e190ca58af 100644 --- a/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt +++ b/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt @@ -182,6 +182,9 @@ object SchemaUtils { } fun drop(vararg tables: Table) { + if (tables.isEmpty()) return + val transaction = TransactionManager.current() + transaction.flushCache() var tablesForDeletion = EntityCache .sortTablesByReferences(tables.toList()) .reversed() @@ -192,7 +195,7 @@ object SchemaUtils { tablesForDeletion .flatMap { it.dropStatement() } .forEach { - TransactionManager.current().exec(it) + transaction.exec(it) } currentDialect.resetCaches() } diff --git a/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/DDLTests.kt b/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/DDLTests.kt index b6143e145b..cfa00cdf24 100644 --- a/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/DDLTests.kt +++ b/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/DDLTests.kt @@ -10,7 +10,6 @@ import org.joda.time.DateTime import org.junit.Assert.assertTrue import org.junit.Test import org.postgresql.util.PGobject -import java.lang.Exception import java.sql.SQLException import java.util.* import javax.sql.rowset.serial.SerialBlob @@ -656,6 +655,22 @@ class DDLTests : DatabaseTestsBase() { } } } + + // https://github.com/JetBrains/Exposed/issues/112 + @Test fun testDropTableFlushesCache() { + withDb { + class Keyword(id: EntityID) : IntEntity(id) { + var bool by KeyWordTable.bool + } + val KeywordEntityClass = object : IntEntityClass(KeyWordTable, Keyword::class.java) {} + + SchemaUtils.create(KeyWordTable) + + val newKeyword = KeywordEntityClass.new { bool = true } + + SchemaUtils.drop(KeyWordTable) + } + } } private fun String.inProperCase(): String = TransactionManager.currentOrNull()?.let { tm ->