Skip to content

Commit

Permalink
Variant of drop operation supplying database handle and table name - c…
Browse files Browse the repository at this point in the history
…loses #16
  • Loading branch information
edrdo committed May 16, 2017
1 parent 9e85f33 commit 762bc20
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/jdbdt/DBSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,12 @@ static int deleteAll(CallInfo callInfo, Table table, String where, Object... arg
/**
* Drop a table.
* @param callInfo Call info.
* @param table Table.
* @param db Database
* @param tableName Table name.
*/
public static void drop(CallInfo callInfo, Table table) {
String sql = String.format("DROP TABLE %s", table.getName());
DB db = table.getDB();
public static void drop(CallInfo callInfo, DB db, String tableName) {
String sql = String.format("DROP TABLE %s", tableName);
db.access(() -> {
table.setDirtyStatus(true);
db.logSetup(callInfo, sql);
try (WrappedStatement ws = db.compile(sql)) {
PreparedStatement dropStmt = ws.getStatement();
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/org/jdbdt/JDBDT.java
Original file line number Diff line number Diff line change
Expand Up @@ -551,17 +551,36 @@ public static int deleteAll(Table table) {
}

/**
* Drop a table.
* Drop a table (table handle variant).
*
* <p>
* A call to this method is shorthand for <code>drop(table.getDB(), table.getName()))</code>.
* </p>
*
* @param table Table to drop.
*
* @see #drop(DB, String)
* @see #assertTableExists(DB, String)
* @see #assertTableDoesNotExist(DB, String)
*/
public static void drop(Table table) {
DBSetup.drop(CallInfo.create(), table);
DBSetup.drop(CallInfo.create(), table.getDB(), table.getName());
}


/**
* Drop a table.
* @param db Database.
* @param tableName Table name.
*
* @see #drop(Table)
* @see #assertTableExists(DB, String)
* @see #assertTableDoesNotExist(DB, String)
*/
public static void drop(DB db, String tableName) {
DBSetup.drop(CallInfo.create(), db, tableName);
}

/**
* Delete all data from a table, subject to a <code>WHERE</code>
* clause.
Expand Down
13 changes: 12 additions & 1 deletion src/test/java/org/jdbdt/DBSetupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void testDeleteAll4() throws SQLException {
}

@Test
public void testDrop() throws SQLException {
public void testDrop1() throws SQLException {
drop(table);
try {
assertFalse(getDAO().tableExists());
Expand All @@ -184,4 +184,15 @@ public void testDrop() throws SQLException {
}
}

@Test
public void testDrop2() throws SQLException {
drop(getDB(), table.getName());
try {
assertFalse(getDAO().tableExists());
}
finally {
getDAO().createTable();
}
}

}

0 comments on commit 762bc20

Please sign in to comment.