use of liquibase.exception.DatabaseException in project liquibase by liquibase.
the class BigIntType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof InformixDatabase) {
if (isAutoIncrement()) {
return new DatabaseDataType("SERIAL8");
} else {
return new DatabaseDataType("INT8");
}
}
if (database instanceof OracleDatabase) {
return new DatabaseDataType("NUMBER", 38, 0);
}
if (database instanceof SybaseDatabase) {
return new DatabaseDataType("BIGINT");
}
if (database instanceof MSSQLDatabase) {
return new DatabaseDataType(database.escapeDataTypeName("bigint"));
}
if (database instanceof MySQLDatabase) {
DatabaseDataType type = new DatabaseDataType("BIGINT");
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
if ((database instanceof AbstractDb2Database) || (database instanceof DerbyDatabase) || (database instanceof HsqlDatabase) || (database instanceof FirebirdDatabase)) {
return new DatabaseDataType("BIGINT");
}
if (database instanceof PostgresDatabase) {
if (isAutoIncrement()) {
int majorVersion = 9;
try {
majorVersion = database.getDatabaseMajorVersion();
} catch (DatabaseException e) {
// ignore
}
if (majorVersion < 10) {
return new DatabaseDataType("BIGSERIAL");
} else {
if (GlobalConfiguration.CONVERT_DATA_TYPES.getCurrentValue() || this.getRawDefinition() == null) {
return new DatabaseDataType("BIGINT");
} else {
return new DatabaseDataType(this.getRawDefinition());
}
}
}
}
if (database instanceof SybaseASADatabase) {
return new DatabaseDataType("BIGINT");
}
return super.toDatabaseDataType(database);
}
use of liquibase.exception.DatabaseException in project liquibase by liquibase.
the class JdbcConnection method open.
@Override
public void open(String url, Driver driverObject, Properties driverProperties) throws DatabaseException {
String driverClassName = driverObject.getClass().getName();
String errorMessage = "Connection could not be created to " + url + " with driver " + driverClassName;
try {
this.con = driverObject.connect(url, driverProperties);
if (this.con == null) {
throw new DatabaseException(errorMessage + ". Possibly the wrong driver for the given database URL");
}
} catch (SQLException sqle) {
if (driverClassName.equals("org.h2.Driver")) {
errorMessage += ". Make sure your H2 database is active and accessible by opening a new terminal window, run \"liquibase init start-h2\", and then return to this terminal window to run commands";
}
throw new DatabaseException(errorMessage + ". " + sqle.getMessage());
}
}
use of liquibase.exception.DatabaseException in project liquibase by liquibase.
the class DatabaseFactory method openConnection.
public DatabaseConnection openConnection(String url, String username, String driver, String databaseClass, Properties driverProperties, ResourceAccessor resourceAccessor) throws DatabaseException {
if (url.startsWith("offline:")) {
OfflineConnection offlineConnection = new OfflineConnection(url, resourceAccessor);
offlineConnection.setConnectionUserName(username);
return offlineConnection;
}
DatabaseConnection databaseConnection;
try {
DatabaseFactory databaseFactory = DatabaseFactory.getInstance();
if (databaseClass != null) {
databaseFactory.clearRegistry();
databaseFactory.register((Database) Class.forName(databaseClass, true, Scope.getCurrentScope().getClassLoader()).getConstructor().newInstance());
}
String selectedDriverClass = findDriverClass(url, driver, databaseFactory);
Driver driverObject = loadDriver(selectedDriverClass);
if (driverObject instanceof LiquibaseExtDriver) {
((LiquibaseExtDriver) driverObject).setResourceAccessor(resourceAccessor);
}
if (selectedDriverClass.contains("oracle")) {
driverProperties.put("remarksReporting", "true");
} else if (selectedDriverClass.contains("mysql")) {
driverProperties.put("useInformationSchema", "true");
}
LOG.fine("Connecting to the URL:'" + JdbcConnection.sanitizeUrl(url) + "' using driver:'" + driverObject.getClass().getName() + "'");
databaseConnection = ConnectionServiceFactory.getInstance().create(url, driverObject, driverProperties);
LOG.fine("Connection has been created");
} catch (Exception e) {
throw new DatabaseException(e);
}
return databaseConnection;
}
use of liquibase.exception.DatabaseException in project liquibase by liquibase.
the class PostgresDatabase method setConnection.
@Override
public void setConnection(DatabaseConnection conn) {
super.setConnection(conn);
if (conn instanceof JdbcConnection) {
Statement statement = null;
ResultSet resultSet = null;
try {
statement = ((JdbcConnection) conn).createStatement();
resultSet = statement.executeQuery("select setting from pg_settings where name = 'edb_redwood_date'");
if (resultSet.next()) {
String setting = resultSet.getString(1);
if ((setting != null) && "on".equals(setting)) {
LOG.warning("EnterpriseDB " + conn.getURL() + " does not store DATE columns. Instead, it auto-converts " + "them " + "to TIMESTAMPs. (edb_redwood_date=true)");
}
}
} catch (SQLException | DatabaseException e) {
LOG.info("Cannot check pg_settings", e);
} finally {
JdbcUtil.close(resultSet, statement);
}
}
}
use of liquibase.exception.DatabaseException in project liquibase by liquibase.
the class DiffToChangeLog method sortObjects.
private List<DatabaseObject> sortObjects(final String type, Collection<DatabaseObject> objects, Database database) {
if (!objects.isEmpty() && supportsSortingObjects(database) && (database.getConnection() != null) && !(database.getConnection() instanceof OfflineConnection)) {
List<String> schemas = new ArrayList<>();
CompareControl.SchemaComparison[] schemaComparisons = this.diffOutputControl.getSchemaComparisons();
if (schemaComparisons != null) {
for (CompareControl.SchemaComparison comparison : schemaComparisons) {
String schemaName = comparison.getReferenceSchema().getSchemaName();
if (schemaName == null) {
schemaName = database.getDefaultSchemaName();
}
schemas.add(schemaName);
}
}
if (schemas.isEmpty()) {
schemas.add(database.getDefaultSchemaName());
}
try {
final List<String> dependencyOrder = new ArrayList<>();
DependencyUtil.NodeValueListener<String> nameListener = new DependencyUtil.NodeValueListener<String>() {
@Override
public void evaluating(String nodeValue) {
dependencyOrder.add(nodeValue);
}
};
DependencyUtil.DependencyGraph<String> graph = new DependencyUtil.DependencyGraph<String>(nameListener);
addDependencies(graph, schemas, database);
graph.computeDependencies();
if (!dependencyOrder.isEmpty()) {
final List<DatabaseObject> toSort = new ArrayList<>();
final List<DatabaseObject> toNotSort = new ArrayList<>();
for (DatabaseObject obj : objects) {
if (!(obj instanceof Column)) {
String schemaName = null;
if (obj.getSchema() != null) {
schemaName = obj.getSchema().getName();
}
String name = schemaName + "." + obj.getName();
if (dependencyOrder.contains(name)) {
toSort.add(obj);
} else {
toNotSort.add(obj);
}
} else {
toNotSort.add(obj);
}
}
Collections.sort(toSort, new Comparator<DatabaseObject>() {
@Override
public int compare(DatabaseObject o1, DatabaseObject o2) {
String o1Schema = null;
if (o1.getSchema() != null) {
o1Schema = o1.getSchema().getName();
}
String o2Schema = null;
if (o2.getSchema() != null) {
o2Schema = o2.getSchema().getName();
}
Integer o1Order = dependencyOrder.indexOf(o1Schema + "." + o1.getName());
int o2Order = dependencyOrder.indexOf(o2Schema + "." + o2.getName());
int order = o1Order.compareTo(o2Order);
if ("unexpected".equals(type)) {
order = order * -1;
}
return order;
}
});
toSort.addAll(toNotSort);
return toSort;
}
} catch (DatabaseException e) {
Scope.getCurrentScope().getLog(getClass()).fine("Cannot get object dependencies: " + e.getMessage());
}
}
return new ArrayList<>(objects);
}
Aggregations