use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class JdbcDatabasePlatformFactory method determineDatabaseNameVersionSubprotocol.
protected static String[] determineDatabaseNameVersionSubprotocol(DataSource dataSource) {
Connection connection = null;
String[] nameVersion = new String[3];
try {
connection = dataSource.getConnection();
DatabaseMetaData metaData = connection.getMetaData();
nameVersion[0] = metaData.getDatabaseProductName();
nameVersion[1] = Integer.toString(metaData.getDatabaseMajorVersion());
final String PREFIX = "jdbc:";
String url = metaData.getURL();
if (StringUtils.isNotBlank(url) && url.length() > PREFIX.length()) {
url = url.substring(PREFIX.length());
if (url.indexOf(":") > 0) {
url = url.substring(0, url.indexOf(":"));
}
}
nameVersion[2] = url;
/* query the metadata to determine which one it is */
if (nameVersion[0].equalsIgnoreCase("PostgreSql")) {
if (isGreenplumDatabase(connection)) {
nameVersion[0] = DatabaseNamesConstants.GREENPLUM;
nameVersion[1] = Integer.toString(getGreenplumVersion(connection));
} else if (isRedshiftDatabase(connection)) {
nameVersion[0] = DatabaseNamesConstants.REDSHIFT;
}
}
/*
* if the productName is MySQL, it could be either MysSQL or MariaDB
* query the metadata to determine which one it is
*/
if (nameVersion[0].equalsIgnoreCase(DatabaseNamesConstants.MYSQL)) {
if (isMariaDBDatabase(connection)) {
nameVersion[0] = DatabaseNamesConstants.MARIADB;
}
}
if (nameVersion[0].toLowerCase().indexOf(DatabaseNamesConstants.DB2) != -1) {
if (nameVersion[0].toUpperCase().indexOf("Z") != -1) {
nameVersion[0] = DatabaseNamesConstants.DB2ZOS;
} else if (nameVersion[0].indexOf("400") != -1) {
nameVersion[0] = DatabaseNamesConstants.DB2AS400;
} else {
nameVersion[0] = DatabaseNamesConstants.DB2;
}
}
if (nameVersion[0].equalsIgnoreCase("AS") && nameVersion[2].equalsIgnoreCase("db2")) {
nameVersion[0] = DatabaseNamesConstants.DB2AS400;
}
if (nameVersion[0].toLowerCase().startsWith(DatabaseNamesConstants.FIREBIRD)) {
if (isFirebirdDialect1(connection)) {
nameVersion[0] = DatabaseNamesConstants.FIREBIRD_DIALECT1;
}
}
log.info("Detected database '" + nameVersion[0] + "', version '" + nameVersion[1] + "', protocol '" + nameVersion[2] + "'");
return nameVersion;
} catch (SQLException ex) {
throw new SqlException("Error while reading the database metadata: " + ex.getMessage(), ex);
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException ex) {
// we ignore this one
}
}
}
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class JdbcDatabasePlatformFactory method getDatabaseMinorVersion.
public static int getDatabaseMinorVersion(DataSource dataSource) {
Connection connection = null;
try {
connection = dataSource.getConnection();
DatabaseMetaData metaData = connection.getMetaData();
return metaData.getDatabaseMinorVersion();
} catch (SQLException ex) {
throw new SqlException("Error while reading the database metadata: " + ex.getMessage(), ex);
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException ex) {
// we ignore this one
}
}
}
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class JdbcDatabasePlatformFactory method getDatabaseMajorVersion.
public static int getDatabaseMajorVersion(DataSource dataSource) {
Connection connection = null;
try {
connection = dataSource.getConnection();
DatabaseMetaData metaData = connection.getMetaData();
return metaData.getDatabaseMajorVersion();
} catch (SQLException ex) {
throw new SqlException("Error while reading the database metadata: " + ex.getMessage(), ex);
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException ex) {
// we ignore this one
}
}
}
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class SqlAnywhereSymmetricDialect method switchCatalogForTriggerInstall.
@Override
protected String switchCatalogForTriggerInstall(String catalog, ISqlTransaction transaction) {
if (catalog != null) {
Connection c = ((JdbcSqlTransaction) transaction).getConnection();
String previousCatalog;
try {
previousCatalog = c.getCatalog();
c.setCatalog(catalog);
return previousCatalog;
} catch (SQLException e) {
throw new SqlException(e);
}
} else {
return null;
}
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class AseSymmetricDialect method switchCatalogForTriggerInstall.
@Override
protected String switchCatalogForTriggerInstall(String catalog, ISqlTransaction transaction) {
if (catalog != null) {
Connection c = ((JdbcSqlTransaction) transaction).getConnection();
String previousCatalog;
try {
previousCatalog = c.getCatalog();
c.setCatalog(catalog);
return previousCatalog;
} catch (SQLException e) {
throw new SqlException(e);
}
} else {
return null;
}
}
Aggregations