use of liquibase.database.jvm.JdbcConnection in project liquibase by liquibase.
the class MSSQLDatabase method isCaseSensitive.
@Override
public boolean isCaseSensitive() {
if (caseSensitive == null) {
try {
if (getConnection() instanceof JdbcConnection) {
String catalog = getConnection().getCatalog();
String sql = "SELECT CONVERT([sysname], DATABASEPROPERTYEX(N'" + escapeStringForDatabase(catalog) + "', 'Collation'))";
String collation = ExecutorService.getInstance().getExecutor(this).queryForObject(new RawSqlStatement(sql), String.class);
caseSensitive = collation != null && !collation.contains("_CI_");
} else if (getConnection() instanceof OfflineConnection) {
caseSensitive = ((OfflineConnection) getConnection()).isCaseSensitive();
}
} catch (Exception e) {
LogFactory.getLogger().warning("Cannot determine case sensitivity from MSSQL", e);
}
}
return caseSensitive != null && caseSensitive;
}
use of liquibase.database.jvm.JdbcConnection in project liquibase by liquibase.
the class MSSQLDatabase method sendsStringParametersAsUnicode.
public boolean sendsStringParametersAsUnicode() {
if (sendsStringParametersAsUnicode == null) {
try {
if (getConnection() instanceof JdbcConnection) {
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = "SELECT CONVERT([sysname], SQL_VARIANT_PROPERTY(?, 'BaseType'))";
ps = ((JdbcConnection) getConnection()).prepareStatement(sql);
ps.setString(1, "Liquibase");
rs = ps.executeQuery();
String baseType = null;
if (rs.next()) {
baseType = rs.getString(1);
}
// i.e. nvarchar (or nchar)
sendsStringParametersAsUnicode = baseType == null || baseType.startsWith("n");
} finally {
JdbcUtils.close(rs, ps);
}
} else if (getConnection() instanceof OfflineConnection) {
sendsStringParametersAsUnicode = ((OfflineConnection) getConnection()).getSendsStringParametersAsUnicode();
}
} catch (Exception e) {
LogFactory.getLogger().warning("Cannot determine whether String parameters are sent as Unicode for MSSQL", e);
}
}
return sendsStringParametersAsUnicode == null ? true : sendsStringParametersAsUnicode;
}
use of liquibase.database.jvm.JdbcConnection in project liquibase by liquibase.
the class JdbcExecutor method execute.
public Object execute(CallableStatementCallback action, List<SqlVisitor> sqlVisitors) throws DatabaseException {
DatabaseConnection con = database.getConnection();
if (con instanceof OfflineConnection) {
throw new DatabaseException("Cannot execute commands against an offline database");
}
CallableStatement stmt = null;
try {
String sql = applyVisitors(action.getStatement(), sqlVisitors)[0];
stmt = ((JdbcConnection) con).getUnderlyingConnection().prepareCall(sql);
return action.doInCallableStatement(stmt);
} catch (SQLException ex) {
// Release Connection early, to avoid potential connection pool deadlock
// in the case when the exception translator hasn't been initialized yet.
JdbcUtils.closeStatement(stmt);
stmt = null;
throw new DatabaseException("Error executing SQL " + StringUtils.join(applyVisitors(action.getStatement(), sqlVisitors), "; on " + con.getURL()) + ": " + ex.getMessage(), ex);
} finally {
JdbcUtils.closeStatement(stmt);
}
}
use of liquibase.database.jvm.JdbcConnection in project liquibase by liquibase.
the class AbstractIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
openConnection(url);
if (database != null) {
if (!database.getConnection().getAutoCommit()) {
database.rollback();
}
SnapshotGeneratorFactory.resetAll();
ExecutorService.getInstance().reset();
LockServiceFactory.getInstance().resetAll();
LockServiceFactory.getInstance().getLockService(database).init();
ChangeLogHistoryServiceFactory.getInstance().resetAll();
if (database.getConnection() != null) {
((JdbcConnection) database.getConnection()).getUnderlyingConnection().createStatement().executeUpdate("drop table " + database.getDatabaseChangeLogLockTableName());
database.commit();
}
SnapshotGeneratorFactory.resetAll();
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
database.dropDatabaseObjects(CatalogAndSchema.DEFAULT);
if (database.supportsSchemas()) {
database.dropDatabaseObjects(new CatalogAndSchema((String) null, DatabaseTestContext.ALT_SCHEMA));
}
if (supportsAltCatalogTests()) {
if (database.supportsSchemas() && database.supportsCatalogs()) {
database.dropDatabaseObjects(new CatalogAndSchema(DatabaseTestContext.ALT_CATALOG, DatabaseTestContext.ALT_SCHEMA));
} else if (database.supportsCatalogs()) {
database.dropDatabaseObjects(new CatalogAndSchema(DatabaseTestContext.ALT_SCHEMA, null));
}
}
database.commit();
SnapshotGeneratorFactory.resetAll();
}
}
use of liquibase.database.jvm.JdbcConnection in project liquibase by liquibase.
the class AbstractIntegrationTest method runUpdateOnOldChangelogTableFormat.
@Test
public void runUpdateOnOldChangelogTableFormat() throws Exception {
if (database == null) {
return;
}
Liquibase liquibase = createLiquibase(completeChangeLog);
clearDatabase(liquibase);
((JdbcConnection) database.getConnection()).getUnderlyingConnection().createStatement().execute("CREATE TABLE DATABASECHANGELOG (id varchar(150) NOT NULL, " + "author varchar(150) NOT NULL, " + "filename varchar(255) NOT NULL, " + "dateExecuted " + DataTypeFactory.getInstance().fromDescription("datetime", database).toDatabaseDataType(database) + " NOT NULL, " + "md5sum varchar(32), " + "description varchar(255), " + "comments varchar(255), " + "tag varchar(255), " + "liquibase varchar(10), " + "PRIMARY KEY(id, author, filename))");
liquibase = createLiquibase(completeChangeLog);
liquibase.update(this.contexts);
}
Aggregations