Skip to content

Commit e516fe9

Browse files
committed
[ARQ-1248] Documented DerbyDropTable stored procedure.
1 parent 76b6ae7 commit e516fe9

File tree

2 files changed

+46
-8
lines changed
  • int-tests-testng/src/test/java/org/jboss/arquillian/integration/persistence/datasource/derby
  • int-tests/src/test/java/org/jboss/arquillian/integration/persistence/datasource/derby

2 files changed

+46
-8
lines changed

int-tests-testng/src/test/java/org/jboss/arquillian/integration/persistence/datasource/derby/DerbyDropTable.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,45 @@
2222
import java.sql.PreparedStatement;
2323
import java.sql.SQLException;
2424

25+
/**
26+
*
27+
* Registered as stored procedure for Apache Derby database.
28+
* It's a workaround for missing "DROP IF EXISTS" feature.
29+
*
30+
* The main rationale is to have repeatable tests where you can create drop/create tables safely.
31+
*
32+
*/
2533
public class DerbyDropTable
2634
{
2735

2836
public static void dropTable(String schema, String table)
2937
{
3038
Connection conn = null;
39+
PreparedStatement preparedStatement = null;
3140
try
3241
{
3342
conn = DriverManager.getConnection("jdbc:derby:target/db/derby");
34-
PreparedStatement ps = conn.prepareStatement("drop table " + schema + "." + table);
35-
ps.executeUpdate();
43+
preparedStatement = conn.prepareStatement("drop table " + schema + "." + table);
44+
preparedStatement.executeUpdate();
3645
conn.commit();
37-
ps.close();
3846
}
3947
catch (SQLException e)
4048
{
4149
// IGNORE - it fails when you try to drop non-existing table, but we want to continue
4250
}
4351
finally
4452
{
53+
if (preparedStatement !=null)
54+
{
55+
try
56+
{
57+
preparedStatement.close();
58+
}
59+
catch (SQLException e)
60+
{
61+
throw new RuntimeException("Failed closing prepared statement", e);
62+
}
63+
}
4564
if (conn != null)
4665
{
4766
try
@@ -50,7 +69,7 @@ public static void dropTable(String schema, String table)
5069
}
5170
catch (SQLException e)
5271
{
53-
// IGNORE
72+
throw new RuntimeException("Failed closing connection", e);
5473
}
5574
}
5675
}

int-tests/src/test/java/org/jboss/arquillian/integration/persistence/datasource/derby/DerbyDropTable.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,45 @@
2222
import java.sql.PreparedStatement;
2323
import java.sql.SQLException;
2424

25+
/**
26+
*
27+
* Registered as stored procedure for Apache Derby database.
28+
* It's a workaround for missing "DROP IF EXISTS" feature.
29+
*
30+
* The main rationale is to have repeatable tests where you can create drop/create tables safely.
31+
*
32+
*/
2533
public class DerbyDropTable
2634
{
2735

2836
public static void dropTable(String schema, String table)
2937
{
3038
Connection conn = null;
39+
PreparedStatement preparedStatement = null;
3140
try
3241
{
3342
conn = DriverManager.getConnection("jdbc:derby:target/db/derby");
34-
PreparedStatement ps = conn.prepareStatement("drop table " + schema + "." + table);
35-
ps.executeUpdate();
43+
preparedStatement = conn.prepareStatement("drop table " + schema + "." + table);
44+
preparedStatement.executeUpdate();
3645
conn.commit();
37-
ps.close();
3846
}
3947
catch (SQLException e)
4048
{
4149
// IGNORE - it fails when you try to drop non-existing table, but we want to continue
4250
}
4351
finally
4452
{
53+
if (preparedStatement !=null)
54+
{
55+
try
56+
{
57+
preparedStatement.close();
58+
}
59+
catch (SQLException e)
60+
{
61+
throw new RuntimeException("Failed closing prepared statement", e);
62+
}
63+
}
4564
if (conn != null)
4665
{
4766
try
@@ -50,7 +69,7 @@ public static void dropTable(String schema, String table)
5069
}
5170
catch (SQLException e)
5271
{
53-
// IGNORE
72+
throw new RuntimeException("Failed closing connection", e);
5473
}
5574
}
5675
}

0 commit comments

Comments
 (0)