1 package liquibase.ext.spatial.sqlgenerator;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.List;
6
7 import liquibase.database.Database;
8 import liquibase.database.core.OracleDatabase;
9 import liquibase.exception.ValidationErrors;
10 import liquibase.sql.Sql;
11 import liquibase.sql.UnparsedSql;
12 import liquibase.sqlgenerator.SqlGeneratorChain;
13 import liquibase.sqlgenerator.core.AbstractSqlGenerator;
14 import liquibase.statement.core.DropTableStatement;
15 import liquibase.structure.core.Table;
16 import liquibase.structure.core.View;
17
18
19
20
21
22 public class DropSpatialTableGeneratorOracle extends AbstractSqlGenerator<DropTableStatement> {
23 @Override
24 public boolean supports(final DropTableStatement statement, final Database database) {
25 return database instanceof OracleDatabase;
26 }
27
28 @Override
29 public int getPriority() {
30 return super.getPriority() + 1;
31 }
32
33 @Override
34 public ValidationErrors validate(final DropTableStatement statement, final Database database,
35 final SqlGeneratorChain sqlGeneratorChain) {
36 return sqlGeneratorChain.validate(statement, database);
37 }
38
39 @Override
40 public Sql[] generateSql(final DropTableStatement statement, final Database database,
41 final SqlGeneratorChain sqlGeneratorChain) {
42 final StringBuilder sql = new StringBuilder();
43 sql.append("DELETE FROM user_sdo_geom_metadata ");
44 sql.append("WHERE table_name = '").append(
45 database.correctObjectName(statement.getTableName(), Table.class));
46 sql.append("'");
47 final UnparsedSql deleteMetadata = new UnparsedSql(sql.toString(),
48 new View().setName("user_sdo_geom_metadata"));
49
50
51 final List<Sql> list = new ArrayList<Sql>();
52 list.add(deleteMetadata);
53 list.addAll(Arrays.asList(sqlGeneratorChain.generateSql(statement, database)));
54 return list.toArray(new Sql[list.size()]);
55 }
56 }