use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfSchemaInitializerJdbc method callbackDropTableByJdbc.
protected void callbackDropTableByJdbc(Connection conn, List<DfTableMeta> tableMetaList, DfDropTableByJdbcCallback callback) {
String currentSql = null;
Statement st = null;
try {
st = conn.createStatement();
for (DfTableMeta tableMeta : tableMetaList) {
final String dropTableSql = callback.buildDropTableSql(tableMeta);
currentSql = dropTableSql;
logReplaceSql(dropTableSql);
try {
st.execute(dropTableSql);
} catch (SQLException e) {
handleDroppingRetry(callback, st, tableMeta, e);
}
}
} catch (SQLException e) {
String msg = "Failed to drop the table: " + currentSql;
throw new SQLFailureException(msg, e);
} finally {
closeStatement(st);
}
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfSchemaInitializerJdbc method initializeSchema.
// ===================================================================================
// Initialize Schema
// =================
public void initializeSchema() {
Connection conn = null;
try {
try {
conn = _dataSource.getConnection();
} catch (SQLException e) {
if (_suppressConnectionFailure) {
handleSuppressedConnectionFailure(e);
return;
} else {
throw e;
}
}
final List<DfTableMeta> tableMetaList;
try {
final DatabaseMetaData metaData = conn.getMetaData();
final DfTableExtractor tableExtractor = createDropTableExtractor();
tableMetaList = tableExtractor.getTableList(metaData, _unifiedSchema);
} catch (SQLException e) {
throw new RuntimeException(e);
}
executeObject(conn, tableMetaList);
} catch (SQLException e) {
String msg = "Failed to the initialize schema: " + _unifiedSchema;
throw new SQLFailureException(msg, e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ignored) {
_log.info("connection.close() threw the exception!", ignored);
}
}
}
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfSchemaInitializerJdbc method dropProcedure.
// ===================================================================================
// Drop Procedure
// ==============
protected void dropProcedure(Connection conn, List<DfTableMeta> tableMetaList) {
final DfProcedureExtractor handler = new DfProcedureExtractor();
handler.suppressAdditionalSchema();
handler.suppressLogging();
final List<DfProcedureMeta> procedureList;
try {
procedureList = handler.getPlainProcedureList(_dataSource, _unifiedSchema);
} catch (SQLException e) {
String msg = "Failed to get procedure meta data: " + _unifiedSchema;
throw new SQLFailureException(msg, e);
}
callbackDropProcedureByJdbc(conn, procedureList, createDropProcedureByJdbcCallback());
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfSchemaInitializerOracle method dropDicObject.
// ===================================================================================
// Assist Helper
// =============
protected boolean dropDicObject(Connection conn, String titleName, String sqlName, String tableName, String ownerColumnName, String targetColumnName, String orderBy, boolean schemaPrefix, boolean errorContinue, ObjectExceptCallback callback) {
if (!_unifiedSchema.hasSchema()) {
return true;
}
final String schema = _unifiedSchema.getPureSchema();
final List<String> objectNameList = new ArrayList<String>();
final StringBuilder sb = new StringBuilder();
sb.append("select * from ").append(tableName);
sb.append(" where ").append(ownerColumnName).append(" = '").append(schema).append("'");
if (Srl.is_NotNull_and_NotTrimmedEmpty(orderBy)) {
sb.append(" order by ").append(orderBy);
}
final String metaSql = sb.toString();
Statement st = null;
ResultSet rs = null;
try {
st = conn.createStatement();
_log.info("...Executing helper SQL:" + ln() + metaSql);
rs = st.executeQuery(metaSql);
while (rs.next()) {
final String objectName = rs.getString(targetColumnName);
objectNameList.add(objectName);
}
} catch (SQLException continued) {
// if the data dictionary table is not found,
// it continues because it might be a version difference
String msg = "*Failed to the SQL:" + ln();
msg = msg + (continued.getMessage() != null ? continued.getMessage() : null) + ln();
msg = msg + metaSql;
_log.info(metaSql);
return true;
} finally {
closeResource(rs, st);
}
try {
boolean complete = true;
st = conn.createStatement();
for (String objectName : objectNameList) {
if (callback != null && callback.isExcept(objectName)) {
continue;
}
final String prefix = schemaPrefix ? schema + "." : "";
final String dropSql = "drop " + sqlName + " " + prefix + objectName;
logReplaceSql(dropSql);
try {
st.execute(dropSql);
} catch (SQLException e) {
if (errorContinue) {
complete = false;
continue;
}
throw e;
}
}
return complete;
} catch (SQLException e) {
String msg = "Failed to drop " + titleName + ": " + objectNameList;
throw new SQLFailureException(msg, e);
} finally {
closeStatement(st);
}
}
use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.
the class DfReplaceSchemaTask method takeFinally.
// -----------------------------------------------------
// Take Finally
// ------------
protected void takeFinally(String sqlRootDir, boolean previous) {
final DfTakeFinallyProcess process = createTakeFinallyProcess(sqlRootDir, previous);
_takeFinallyFinalInfo = process.execute();
final SQLFailureException breakCause = _takeFinallyFinalInfo.getBreakCause();
if (breakCause != null) {
// high priority exception
throw breakCause;
}
final DfTakeFinallyAssertionFailureException assertionEx = _takeFinallyFinalInfo.getAssertionEx();
if (assertionEx != null) {
// high priority exception
throw assertionEx;
}
}
Aggregations