Skip to content

Commit

Permalink
#112 Exposed executing things more than once when adding a DROP
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapac committed Sep 3, 2018
1 parent 9de65cc commit dbe104b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -192,7 +195,7 @@ object SchemaUtils {
tablesForDeletion
.flatMap { it.dropStatement() }
.forEach {
TransactionManager.current().exec(it)
transaction.exec(it)
}
currentDialect.resetCaches()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -656,6 +655,22 @@ class DDLTests : DatabaseTestsBase() {
}
}
}

// https://github.com/JetBrains/Exposed/issues/112
@Test fun testDropTableFlushesCache() {
withDb {
class Keyword(id: EntityID<Int>) : IntEntity(id) {
var bool by KeyWordTable.bool
}
val KeywordEntityClass = object : IntEntityClass<Keyword>(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 ->
Expand Down

0 comments on commit dbe104b

Please sign in to comment.