liquibase.database.core.PostgresDatabase Java Examples
The following examples show how to use
liquibase.database.core.PostgresDatabase.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeometryColumnsUtils.java From liquibase-spatial with Apache License 2.0 | 6 votes |
/** * Indicates if the <code>GEOMETRY_COLUMNS</code> table or view exists. * * @param database * the database to check. * @return <code>true</code> if the table or view exists. */ public static boolean geometryColumnsExists(final Database database) { String geometryColumnsName = database.correctObjectName( "geometry_columns", Table.class); DatabaseObject example = null; if (database instanceof DerbyDatabase || database instanceof H2Database) { final Table tableExample = new Table(); tableExample.setName(geometryColumnsName); tableExample.setSchema(database.getDefaultCatalogName(), database.getDefaultSchemaName()); example = tableExample; } else if (database instanceof PostgresDatabase) { final View viewExample = new View(); viewExample.setName(geometryColumnsName); viewExample.setSchema(database.getDefaultCatalogName(), "public"); example = viewExample; } try { return example != null && SnapshotGeneratorFactory.getInstance().has(example, database); } catch (final LiquibaseException e) { throw new UnexpectedLiquibaseException( "Failed to determine if the geometry_columns table or view exists", e); } }
Example #2
Source File: DropSpatialIndexChange.java From liquibase-spatial with Apache License 2.0 | 6 votes |
/** * Generates a {@link DropSpatialIndexStatement} followed by a {@link DropIndexStatement}, if * applicable. The first statement allows extra clean-up when dropping an index. The second * statement leverages the normal <code>DROP INDEX</code> logic. */ @Override public SqlStatement[] generateStatements(final Database database) { final Collection<SqlStatement> statements = new ArrayList<SqlStatement>(); // MySQL and PostgreSQL only need the normal DROP INDEX statement. if (!(database instanceof MySQLDatabase) && !(database instanceof PostgresDatabase)) { final DropSpatialIndexStatement dropSpatialIndex = new DropSpatialIndexStatement( this.indexName, this.catalogName, this.schemaName, this.tableName); statements.add(dropSpatialIndex); } // GeoDB doesn't use a tradition index structure so don't issue the normal DROP INDEX // statement. if (!(database instanceof DerbyDatabase) && !(database instanceof H2Database)) { final DropIndexStatement dropIndex = new DropIndexStatement(this.indexName, this.catalogName, this.schemaName, this.tableName, null); statements.add(dropIndex); } return statements.toArray(new SqlStatement[statements.size()]); }
Example #3
Source File: CreateSpatialIndexGeneratorPostgreSQLTest.java From liquibase-spatial with Apache License 2.0 | 6 votes |
/** * Tests * {@link CreateSpatialIndexGeneratorPostgreSQL#generateSql(CreateSpatialIndexStatement, Database, SqlGeneratorChain)} * with a variety of inputs. * * @param statement */ @Test(dataProvider = "generateSqlTestData") public void testGenerateSql(final CreateSpatialIndexStatement statement) { final CreateSpatialIndexGeneratorPostgreSQL generator = new CreateSpatialIndexGeneratorPostgreSQL(); final Database database = new PostgresDatabase(); final SqlGeneratorChain sqlGeneratorChain = mock(SqlGeneratorChain.class); final Sql[] result = generator.generateSql(statement, database, sqlGeneratorChain); assertNotNull(result); assertEquals(result.length, 1); final String sql = result[0].toSql(); String pattern = "(?i)CREATE INDEX "; pattern += statement.getIndexName() + " ON "; if (statement.getTableSchemaName() != null) { pattern += statement.getTableSchemaName() + '.'; } pattern += statement.getTableName() + " USING GIST \\(" + statement.getColumns()[0]; if (statement.getColumns().length > 1) { pattern += ", " + statement.getColumns()[1]; } pattern += "\\)"; assertTrue(sql.matches(pattern), "'" + sql + "' does not match the pattern '" + pattern + "'"); assertNotNull(result[0].getAffectedDatabaseObjects()); assertTrue(result[0].getAffectedDatabaseObjects().size() > 1, result[0] .getAffectedDatabaseObjects().toString()); }
Example #4
Source File: SpatialSupportedPrecondition.java From liquibase-spatial with Apache License 2.0 | 5 votes |
@Override public Warnings warn(final Database database) { final Warnings warnings = new Warnings(); if (!(database instanceof DerbyDatabase || database instanceof H2Database || database instanceof MySQLDatabase || database instanceof OracleDatabase || database instanceof PostgresDatabase)) { warnings.addWarning(database.getDatabaseProductName() + " is not supported by this extension"); } return warnings; }
Example #5
Source File: SpatialSupportedPrecondition.java From liquibase-spatial with Apache License 2.0 | 5 votes |
@Override public ValidationErrors validate(final Database database) { final ValidationErrors errors = new ValidationErrors(); if (!(database instanceof DerbyDatabase || database instanceof H2Database || database instanceof MySQLDatabase || database instanceof OracleDatabase || database instanceof PostgresDatabase)) { errors.addError(database.getDatabaseProductName() + " is not supported by this extension"); } return errors; }
Example #6
Source File: CreateSpatialIndexGeneratorPostgreSQLTest.java From liquibase-spatial with Apache License 2.0 | 5 votes |
/** * Tests * {@link CreateSpatialIndexGeneratorPostgreSQL#supports(CreateSpatialIndexStatement, Database)} */ @Test public void testSupports() { final CreateSpatialIndexGeneratorPostgreSQL generator = new CreateSpatialIndexGeneratorPostgreSQL(); final CreateSpatialIndexStatement statement = mock(CreateSpatialIndexStatement.class); assertTrue(generator.supports(statement, new PostgresDatabase())); assertFalse(generator.supports(statement, new H2Database())); }
Example #7
Source File: CustomLockDatabaseChangeLogGenerator.java From keycloak with Apache License 2.0 | 5 votes |
private Sql generateSelectForUpdate(Database database, int id) { String catalog = database.getLiquibaseCatalogName(); String schema = database.getLiquibaseSchemaName(); String rawLockTableName = database.getDatabaseChangeLogLockTableName(); String lockTableName = database.escapeTableName(catalog, schema, rawLockTableName); String idColumnName = database.escapeColumnName(catalog, schema, rawLockTableName, "ID"); String sqlBase = "SELECT " + idColumnName + " FROM " + lockTableName; String sqlWhere = " WHERE " + idColumnName + "=" + id; String sql; if (database instanceof MySQLDatabase || database instanceof PostgresDatabase || database instanceof H2Database || database instanceof OracleDatabase) { sql = sqlBase + sqlWhere + " FOR UPDATE"; } else if (database instanceof MSSQLDatabase) { sql = sqlBase + " WITH (UPDLOCK, ROWLOCK)" + sqlWhere; } else if (database instanceof DB2Database) { sql = sqlBase + sqlWhere + " FOR READ ONLY WITH RS USE AND KEEP UPDATE LOCKS"; } else { sql = sqlBase + sqlWhere; logger.warnf("No direct support for database %s . Database lock may not work correctly", database.getClass().getName()); } logger.debugf("SQL command for pessimistic lock: %s", sql); return new UnparsedSql(sql); }
Example #8
Source File: AbstractJdbcDatabase.java From jweb-cms with GNU Affero General Public License v3.0 | 4 votes |
@Override public boolean supportsDropTableCascadeConstraints() { return ((this instanceof SQLiteDatabase) || (this instanceof SybaseDatabase) || (this instanceof SybaseASADatabase) || (this instanceof PostgresDatabase) || (this instanceof OracleDatabase)); }
Example #9
Source File: CreateSpatialIndexGeneratorPostgreSQL.java From liquibase-spatial with Apache License 2.0 | 4 votes |
@Override public boolean supports(final CreateSpatialIndexStatement statement, final Database database) { return database instanceof PostgresDatabase; }