01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestCreateSequence.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.database.queries;
09:
10: import com.uwyn.rife.database.Datasource;
11: import com.uwyn.rife.database.DbConnection;
12: import com.uwyn.rife.database.exceptions.DatabaseException;
13:
14: public abstract class TestCreateSequence extends TestQuery {
15: public TestCreateSequence(String name) {
16: super (name);
17: }
18:
19: public void execute(Datasource datasource, CreateSequence query) {
20: DbConnection connection = null;
21: DropSequence drop_sequence = new DropSequence(datasource);
22:
23: try {
24: connection = datasource.getConnection();
25: } catch (DatabaseException e) {
26: throw new RuntimeException(e);
27: }
28:
29: try {
30: connection.beginTransaction();
31:
32: // try to execute the table creation
33: connection.createStatement().executeUpdate(query);
34:
35: // it wass succesful, remove the table again
36: drop_sequence.name(query.getName());
37: connection.createStatement().executeUpdate(drop_sequence);
38: } catch (DatabaseException e) {
39: throw new RuntimeException(e);
40: } finally {
41: // clean up foreign key table
42: try {
43: connection.rollback();
44: } catch (DatabaseException e) {
45: throw new RuntimeException(e);
46: }
47: }
48: }
49: }
|