use of org.dbflute.util.DfTypeUtil.ParseTimestampException in project dbflute-core by dbflute.
the class DfParameterAutoDetectAssist method doDerivePropertyTypeFromTestValue.
protected String doDerivePropertyTypeFromTestValue(String testValue) {
// test point
if (testValue == null) {
String msg = "The argument 'testValue' should be not null.";
throw new IllegalArgumentException(msg);
}
final DfLanguageGrammar grammar = getLanguageGrammar();
final String plainTypeName;
if (Srl.startsWithIgnoreCase(testValue, "date '", "date'")) {
plainTypeName = "Date";
} else if (Srl.startsWithIgnoreCase(testValue, "timestamp '", "timestamp'")) {
plainTypeName = "Timestamp";
} else if (Srl.startsWithIgnoreCase(testValue, "time '", "time'")) {
plainTypeName = "Time";
} else {
if (Srl.isQuotedSingle(testValue)) {
final String unquoted = Srl.unquoteSingle(testValue);
Timestamp timestamp = null;
Time time = null;
try {
timestamp = DfTypeUtil.toTimestamp(unquoted);
} catch (ParseTimestampException ignored) {
try {
time = DfTypeUtil.toTime(unquoted);
} catch (ParseTimeException andIgnored) {
}
}
if (timestamp != null) {
final String timeParts = DfTypeUtil.toString(timestamp, "HH:mm:ss.SSS");
if (timeParts.equals("00:00:00.000")) {
plainTypeName = "Date";
} else {
plainTypeName = "Timestamp";
}
} else if (time != null) {
plainTypeName = "Time";
} else {
plainTypeName = "String";
}
} else if (Srl.isQuotedAnything(testValue, "(", ")")) {
final String unquoted = Srl.unquoteAnything(testValue, "(", ")");
final List<String> elementList = Srl.splitListTrimmed(unquoted, ",");
if (elementList.size() > 0) {
final String firstElement = elementList.get(0);
// InScope for Date is unsupported at this analyzing
if (Srl.isQuotedSingle(firstElement)) {
plainTypeName = "List" + grammar.buildGenericOneClassHint("String");
} else {
final String elementType = doDeriveNonQuotedLiteralTypeFromTestValue(firstElement);
plainTypeName = "List" + grammar.buildGenericOneClassHint(elementType);
}
} else {
plainTypeName = "List" + grammar.buildGenericOneClassHint("String");
}
} else {
plainTypeName = doDeriveNonQuotedLiteralTypeFromTestValue(testValue);
}
}
return plainTypeName;
}
use of org.dbflute.util.DfTypeUtil.ParseTimestampException in project dbflute-core by dbflute.
the class DfAbsractDataWriter method processDate.
// -----------------------------------------------------
// Date
// ----
protected boolean processDate(String dataDirectory, String tableName, String columnName, String value, Connection conn, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
if (value == null || value.trim().length() == 0) {
// cannot be date
return false;
}
final DfColumnMeta columnMeta = columnInfoMap.get(columnName);
if (columnMeta != null) {
final Class<?> columnType = getBindType(tableName, columnMeta);
if (columnType != null) {
if (!java.util.Date.class.isAssignableFrom(columnType)) {
return false;
}
// only when column type specified
final String resolved = resolveRelativeSysdate(dataDirectory, tableName, columnName, value);
bindNotNullValueByColumnType(tableName, columnName, conn, ps, bindCount, resolved, columnType, rowNumber);
return true;
}
}
// if meta data is not found (basically no way)
try {
final Timestamp timestamp = DfTypeUtil.toTimestamp(value);
ps.setTimestamp(bindCount, timestamp);
return true;
} catch (ParseTimestampException ignored) {
// retry as time
try {
Time time = DfTypeUtil.toTime(value);
ps.setTime(bindCount, time);
return true;
} catch (ParseTimeException ignored2) {
}
// couldn't parse as timestamp and time
return false;
}
}
use of org.dbflute.util.DfTypeUtil.ParseTimestampException in project dbflute-core by dbflute.
the class DfAbsractDataWriter method processDate.
// -----------------------------------------------------
// Date
// ----
protected boolean processDate(String dataDirectory, String tableName, String columnName, String value, Connection conn, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
if (value == null || value.trim().length() == 0) {
// cannot be date
return false;
}
final DfColumnMeta columnMeta = columnInfoMap.get(columnName);
if (columnMeta != null) {
final Class<?> columnType = getBindType(tableName, columnMeta);
if (columnType != null) {
if (!java.util.Date.class.isAssignableFrom(columnType)) {
return false;
}
// only when column type specified
final String resolved = resolveRelativeSysdate(dataDirectory, tableName, columnName, value);
bindNotNullValueByColumnType(tableName, columnName, conn, ps, bindCount, resolved, columnType, rowNumber);
return true;
}
}
// if meta data is not found (basically no way)
try {
final Timestamp timestamp = DfTypeUtil.toTimestamp(value);
ps.setTimestamp(bindCount, timestamp);
return true;
} catch (ParseTimestampException ignored) {
// retry as time
try {
Time time = DfTypeUtil.toTime(value);
ps.setTime(bindCount, time);
return true;
} catch (ParseTimeException ignored2) {
}
// couldn't parse as timestamp and time
return false;
}
}
Aggregations