FINERACT-2099: Initial Liquibase got executed every execution
This commit is contained in:
committed by
Adam Saghy
parent
f17a0965db
commit
112787cf07
+1
-4
@@ -18,8 +18,6 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.core.service.database;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.util.List;
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -45,8 +43,7 @@ public class MySQLQueryService implements DatabaseQueryService {
|
||||
@Override
|
||||
public boolean isTablePresent(DataSource dataSource, String tableName) {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
SqlRowSet rs = jdbcTemplate.queryForRowSet(format("SHOW TABLES LIKE '%s'", tableName));
|
||||
return rs.next();
|
||||
return jdbcTemplate.queryForRowSet("SHOW TABLES LIKE ?", tableName).next();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-9
@@ -18,8 +18,6 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.core.service.database;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.sql.DataSource;
|
||||
@@ -46,8 +44,9 @@ public class PostgreSQLQueryService implements DatabaseQueryService {
|
||||
@Override
|
||||
public boolean isTablePresent(DataSource dataSource, String tableName) {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
Integer result = jdbcTemplate.queryForObject(format("SELECT COUNT(table_name) " + "FROM information_schema.tables "
|
||||
+ "WHERE table_schema = 'public' " + "AND table_name = '%s';", tableName), Integer.class);
|
||||
Integer result = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(table_name) FROM information_schema.tables " + "WHERE table_schema = 'public' AND table_name = ?",
|
||||
Integer.class, tableName);
|
||||
return Objects.equals(result, 1);
|
||||
}
|
||||
|
||||
@@ -56,9 +55,8 @@ public class PostgreSQLQueryService implements DatabaseQueryService {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
String sql = "SELECT column_name, is_nullable, data_type,"
|
||||
+ " coalesce(character_maximum_length, numeric_precision, datetime_precision) AS max_length, ordinal_position = 1 AS column_key"
|
||||
+ " FROM information_schema.columns WHERE table_catalog = current_catalog AND table_schema = current_schema AND table_name = '"
|
||||
+ tableName + "' ORDER BY ordinal_position";
|
||||
final SqlRowSet columnDefinitions = jdbcTemplate.queryForRowSet(sql); // NOSONAR
|
||||
+ " FROM information_schema.columns WHERE table_catalog = current_catalog AND table_schema = current_schema AND table_name = ? ORDER BY ordinal_position";
|
||||
final SqlRowSet columnDefinitions = jdbcTemplate.queryForRowSet(sql, tableName); // NOSONAR
|
||||
if (columnDefinitions.next()) {
|
||||
return columnDefinitions;
|
||||
} else {
|
||||
@@ -69,8 +67,8 @@ public class PostgreSQLQueryService implements DatabaseQueryService {
|
||||
@Override
|
||||
public List<IndexDetail> getTableIndexes(DataSource dataSource, String tableName) {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
String sql = "SELECT indexname FROM pg_indexes WHERE schemaname = 'public' AND tablename = '" + tableName + "'";
|
||||
final SqlRowSet indexDefinitions = jdbcTemplate.queryForRowSet(sql); // NOSONAR
|
||||
String sql = "SELECT indexname FROM pg_indexes WHERE schemaname = 'public' AND tablename = ?";
|
||||
final SqlRowSet indexDefinitions = jdbcTemplate.queryForRowSet(sql, tableName); // NOSONAR
|
||||
if (indexDefinitions.next()) {
|
||||
return DatabaseIndexMapper.getIndexDetails(indexDefinitions);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user