ORMLite reset all tables

dierre picture dierre · May 13, 2012 · Viewed 14.7k times · Source

I have an application that uses ORMLite. I need to create a function to reset the entire db (basically I need to delete all rows from every db, reset the autoincrement and reset indexes).

I probably can do this by launching a truncate on every table but does ORMLite has some specific method to do this?

Answer

Gray picture Gray · May 13, 2012

ORMLite does not have a special method to reset the entire db. It does support the TableUtils.clearTable(connectionSource, dataClass)) method which removes all of the rows from the table, which would clear the index, but this will not reset the auto-increment. Also, I'm not sure what "reset indexes" implies more than clearing them. The process of resetting the auto-increment is going to be extremely database dependent so ORMLite will most likely never have native support that anyway.

I think your best bet is to drop the table using TableUtils.dropTable() and then re-create it with TableUtils.createTable() .