@Test public void shouldDropIndexInPostgreSQL() throws Exception { DropIndexGenerator dropIndexGenerator = new DropIndexGenerator(); DropIndexStatement statement = new DropIndexStatement("indexName", "defaultSchema", "aTable", null); Database database = new PostgresDatabase(); SortedSet<SqlGenerator> sqlGenerators = new TreeSet<SqlGenerator>(); SqlGeneratorChain sqlGenerationChain = new SqlGeneratorChain(sqlGenerators); Sql[] sqls = dropIndexGenerator.generateSql(statement, database, sqlGenerationChain); assertEquals("DROP INDEX \"defaultSchema\".\"indexName\"", sqls[0].toSql()); statement = new DropIndexStatement("index_name", "default_schema", "a_table", null); sqls = dropIndexGenerator.generateSql(statement, database, sqlGenerationChain); assertEquals("DROP INDEX default_schema.index_name", sqls[0].toSql()); statement = new DropIndexStatement("index_name", null, "a_table", null); sqls = dropIndexGenerator.generateSql(statement, database, sqlGenerationChain); assertEquals("DROP INDEX index_name", sqls[0].toSql()); }
public Sql[] generateSql(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { List<String> associatedWith = StringUtils.splitAndTrim(statement.getAssociatedWith(), ","); if (associatedWith != null) { if (associatedWith.contains(Index.MARK_PRIMARY_KEY)|| associatedWith.contains(Index.MARK_UNIQUE_CONSTRAINT)) { return new Sql[0]; } else if (associatedWith.contains(Index.MARK_FOREIGN_KEY) ) { if (!(database instanceof OracleDatabase || database instanceof MSSQLDatabase)) { return new Sql[0]; } } } String schemaName = statement.getTableSchemaName(); if (database instanceof MySQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(null, statement.getIndexName()) + " ON " + database.escapeTableName(schemaName, statement.getTableName())) }; } else if (database instanceof MSSQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeTableName(schemaName, statement.getTableName()) + "." + database.escapeIndexName(null, statement.getIndexName())) }; } else if (database instanceof PostgresDatabase) { return new Sql[]{new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName()))}; } return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName())) }; }
DropIndexGenerator extends AbstractSqlGenerator<DropIndexStatement> { public Sql[] generateSql(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { List<String> associatedWith = StringUtils.splitAndTrim(statement.getAssociatedWith(), ","); if (associatedWith != null) { if (associatedWith.contains(Index.MARK_PRIMARY_KEY)|| associatedWith.contains(Index.MARK_UNIQUE_CONSTRAINT)) { return new Sql[0]; } else if (associatedWith.contains(Index.MARK_FOREIGN_KEY) ) { if (!(database instanceof OracleDatabase || database instanceof MSSQLDatabase)) { return new Sql[0]; } } } String schemaName = statement.getTableSchemaName(); if (database instanceof MySQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(null, statement.getIndexName()) + " ON " + database.escapeTableName(schemaName, statement.getTableName())) }; } else if (database instanceof MSSQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeTableName(schemaName, statement.getTableName()) + "." + database.escapeIndexName(null, statement.getIndexName())) }; } else if (database instanceof PostgresDatabase) { return new Sql[]{new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName()))}; } return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName())) }; } }
DropIndexGenerator extends AbstractSqlGenerator<DropIndexStatement> { public Sql[] generateSql(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { List<String> associatedWith = StringUtils.splitAndTrim(statement.getAssociatedWith(), ","); if (associatedWith != null) { if (associatedWith.contains(Index.MARK_PRIMARY_KEY)|| associatedWith.contains(Index.MARK_UNIQUE_CONSTRAINT)) { return new Sql[0]; } else if (associatedWith.contains(Index.MARK_FOREIGN_KEY) ) { if (!(database instanceof OracleDatabase || database instanceof MSSQLDatabase)) { return new Sql[0]; } } } String schemaName = statement.getTableSchemaName(); if (database instanceof MySQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(null, statement.getIndexName()) + " ON " + database.escapeTableName(schemaName, statement.getTableName())) }; } else if (database instanceof MSSQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeTableName(schemaName, statement.getTableName()) + "." + database.escapeIndexName(null, statement.getIndexName())) }; } else if (database instanceof PostgresDatabase) { return new Sql[]{new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName()))}; } return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName())) }; }  }
DropIndexGenerator extends AbstractSqlGenerator<DropIndexStatement> { public Sql[] generateSql(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { List<String> associatedWith = StringUtils.splitAndTrim(statement.getAssociatedWith(), ","); if (associatedWith != null) { if (associatedWith.contains(Index.MARK_PRIMARY_KEY)|| associatedWith.contains(Index.MARK_UNIQUE_CONSTRAINT)) { return new Sql[0]; } else if (associatedWith.contains(Index.MARK_FOREIGN_KEY) ) { if (!(database instanceof OracleDatabase || database instanceof MSSQLDatabase)) { return new Sql[0]; } } } String schemaName = statement.getTableSchemaName(); if (database instanceof MySQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(null, statement.getIndexName()) + " ON " + database.escapeTableName(schemaName, statement.getTableName())) }; } else if (database instanceof MSSQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeTableName(schemaName, statement.getTableName()) + "." + database.escapeIndexName(null, statement.getIndexName())) }; } else if (database instanceof PostgresDatabase) { return new Sql[]{new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName()))}; } return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName())) }; }  ValidationErrors validate(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain); Sql[] generateSql(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain); }
DropIndexGenerator extends AbstractSqlGenerator<DropIndexStatement> { public Sql[] generateSql(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { List<String> associatedWith = StringUtils.splitAndTrim(statement.getAssociatedWith(), ","); if (associatedWith != null) { if (associatedWith.contains(Index.MARK_PRIMARY_KEY)|| associatedWith.contains(Index.MARK_UNIQUE_CONSTRAINT)) { return new Sql[0]; } else if (associatedWith.contains(Index.MARK_FOREIGN_KEY) ) { if (!(database instanceof OracleDatabase || database instanceof MSSQLDatabase)) { return new Sql[0]; } } } String schemaName = statement.getTableSchemaName(); if (database instanceof MySQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(null, statement.getIndexName()) + " ON " + database.escapeTableName(schemaName, statement.getTableName())) }; } else if (database instanceof MSSQLDatabase) { return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeTableName(schemaName, statement.getTableName()) + "." + database.escapeIndexName(null, statement.getIndexName())) }; } else if (database instanceof PostgresDatabase) { return new Sql[]{new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName()))}; } return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName())) }; }  ValidationErrors validate(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain); Sql[] generateSql(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain);  }