use of org.dbflute.exception.DfJDBCException in project dbflute-core by dbflute.
the class DfDBFluteTaskUtil method shutdownIfDerbyEmbedded.
// ===================================================================================
// Connection
// ==========
public static void shutdownIfDerbyEmbedded(String driver) throws SQLException {
if (!driver.startsWith("org.apache.derby.") || !driver.endsWith(".EmbeddedDriver")) {
return;
}
final String shutdownUrl = "jdbc:derby:;shutdown=true";
Connection conn = null;
try {
_log.info("...Shutting down the connection to Derby");
conn = DriverManager.getConnection(shutdownUrl);
} catch (SQLException e) {
if ("XJ015".equals(e.getSQLState())) {
_log.info(" -> success: " + e.getMessage());
} else {
String msg = "Failed to shut down the connection to Derby:";
msg = msg + " shutdownUrl=" + shutdownUrl;
throw new DfJDBCException(msg, e);
}
} finally {
if (conn != null) {
conn.close();
}
}
}
use of org.dbflute.exception.DfJDBCException in project dbflute-core by dbflute.
the class DfDBFluteTaskUtil method buildSQLExceptionMessage.
protected static void buildSQLExceptionMessage(ExceptionMessageBuilder br, SQLException e) {
final String sqlState = DfJDBCException.extractSQLState(e);
br.addItem("SQLState");
br.addElement(sqlState);
final Integer errorCode = DfJDBCException.extractErrorCode(e);
br.addItem("ErrorCode");
br.addElement(errorCode);
br.addItem("SQLException");
br.addElement(e.getClass().getName());
if (e instanceof DfJDBCException) {
br.addElement("*Look at the message on the stack trace");
} else {
br.addElement(DfJDBCException.extractMessage(e));
}
final SQLException nextEx = e.getNextException();
if (nextEx != null) {
br.addItem("NextException");
br.addElement(nextEx.getClass().getName());
br.addElement(DfJDBCException.extractMessage(nextEx));
final SQLException nextNextEx = nextEx.getNextException();
if (nextNextEx != null) {
br.addItem("NextNextException");
br.addElement(nextNextEx.getClass().getName());
br.addElement(DfJDBCException.extractMessage(nextNextEx));
}
}
}
use of org.dbflute.exception.DfJDBCException in project dbflute-core by dbflute.
the class DfAutoIncrementExtractor method throwAutoIncrementDeterminationFailureException.
protected void throwAutoIncrementDeterminationFailureException(DfTableMeta tableInfo, String primaryKeyColumnName, String sql, SQLException e) throws DfJDBCException {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Failed to execute the SQL for getting auto-increment");
br.addItem("Advice");
br.addElement("DBFlute executes the SQL to get auto-increment meta data.");
br.addElement("The table might not exist on your schema. Or the schema");
br.addElement("to be set at 'dfprop' might be mistake in the first place.");
br.addElement("");
br.addElement("And other points can be causes");
br.addElement(" e.g. reservation word, authentication, ...");
br.addElement("If your primary key of the table is reservation word in the DBMS,");
br.addElement("set quatation settings 'quoteColumnNameList' of littleAdjustmentMap.dfprop.");
br.addElement("");
br.addElement("So check your settings and environments.");
br.addItem("Table");
br.addElement(tableInfo.getTableFullQualifiedName());
br.addItem("PrimaryKey");
br.addElement(primaryKeyColumnName);
br.addItem("SQL for getting");
br.addElement(sql);
final String msg = br.buildExceptionMessage();
throw new DfJDBCException(msg, e);
}
use of org.dbflute.exception.DfJDBCException in project dbflute-core by dbflute.
the class DfAbsractDataWriter method processNull.
// ===================================================================================
// Process Binding
// ===============
// -----------------------------------------------------
// Null Value
// ----------
protected boolean processNull(String dataDirectory, String tableName, String columnName, Object value, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
if (!isNullValue(value)) {
return false;
}
Map<String, Integer> cacheMap = _nullTypeCacheMap.get(tableName);
if (cacheMap == null) {
cacheMap = StringKeyMap.createAsFlexibleOrdered();
_nullTypeCacheMap.put(tableName, cacheMap);
}
final Integer cachedType = cacheMap.get(columnName);
if (cachedType != null) {
// cache hit
// basically no exception
ps.setNull(bindCount, cachedType);
return true;
}
final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
if (columnInfo != null) {
// use mapped type at first
final String mappedJdbcType = _columnHandler.getColumnJdbcType(columnInfo);
final Integer mappedJdbcDefValue = TypeMap.getJdbcDefValueByJdbcType(mappedJdbcType);
try {
ps.setNull(bindCount, mappedJdbcDefValue);
cacheMap.put(columnName, mappedJdbcDefValue);
} catch (SQLException e) {
// retry by plain type
final int plainJdbcDefValue = columnInfo.getJdbcDefValue();
try {
ps.setNull(bindCount, plainJdbcDefValue);
cacheMap.put(columnName, plainJdbcDefValue);
} catch (SQLException ignored) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Failed to execute setNull(bindCount, jdbcDefValue).");
br.addItem("Column");
br.addElement(tableName + "." + columnName);
br.addElement(columnInfo.toString());
br.addItem("Mapped JDBC Type");
br.addElement(mappedJdbcType);
br.addItem("First JDBC Def-Value");
br.addElement(mappedJdbcDefValue);
br.addItem("Retry JDBC Def-Value");
br.addElement(plainJdbcDefValue);
br.addItem("Retry Message");
br.addElement(ignored.getMessage());
String msg = br.buildExceptionMessage();
throw new DfJDBCException(msg, e);
}
}
} else {
// basically no way
// as default
Integer tryType = Types.VARCHAR;
try {
ps.setNull(bindCount, tryType);
cacheMap.put(columnName, tryType);
} catch (SQLException e) {
tryType = Types.NUMERIC;
try {
ps.setNull(bindCount, tryType);
cacheMap.put(columnName, tryType);
} catch (SQLException ignored) {
tryType = Types.TIMESTAMP;
try {
ps.setNull(bindCount, tryType);
cacheMap.put(columnName, tryType);
} catch (SQLException iignored) {
tryType = Types.OTHER;
try {
// last try
ps.setNull(bindCount, tryType);
cacheMap.put(columnName, tryType);
} catch (SQLException iiignored) {
throw e;
}
}
}
}
}
return true;
}
use of org.dbflute.exception.DfJDBCException in project dbflute-core by dbflute.
the class DfAbsractDataWriter method throwColumnValueProcessingFailureException.
protected void throwColumnValueProcessingFailureException(StringProcessor processor, String tableName, String columnName, String value) throws SQLException {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("The column value could not be treated by the processor.");
br.addItem("Advice");
br.addElement("The column has string expressions judging the type of the column");
br.addElement("by analyzing the value of first record.");
br.addElement("But the value of second or more record did not match the type.");
br.addElement("So confirm your expressions.");
br.addItem("Table Name");
br.addElement(tableName);
br.addItem("Column Name");
br.addElement(columnName);
br.addItem("String Expression");
br.addElement(value);
br.addItem("Processor");
br.addElement(processor);
final String msg = br.buildExceptionMessage();
throw new DfJDBCException(msg);
}
Aggregations