use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfColumnValueConverter method processTimestamp.
protected String processTimestamp(String tableName, String columnName, Map<String, DfColumnMeta> columnMetaMap, String filteredValue, String before, String after) {
if (!"$$Timestamp$$".equalsIgnoreCase(before)) {
// no converted
return null;
}
final DfColumnMeta columnMeta = columnMetaMap.get(columnName);
final Class<?> boundType = _bindTypeProvider.provide(tableName, columnMeta);
if (!Timestamp.class.isAssignableFrom(boundType)) {
// no converted
return null;
}
// process target here
if (after.equalsIgnoreCase("$$ZeroPrefixMillis$$")) {
// DBFlute default
if (filteredValue != null && filteredValue.contains(".")) {
final String front = Srl.substringLastFront(filteredValue, ".");
final String millis = Srl.substringLastRear(filteredValue, ".");
if (millis.length() == 1) {
filteredValue = front + ".00" + millis;
} else if (millis.length() == 2) {
filteredValue = front + ".0" + millis;
}
// processed
return filteredValue;
}
} else if (after.equalsIgnoreCase("$$ZeroSuffixMillis$$")) {
if (filteredValue != null && filteredValue.contains(".")) {
final String millis = Srl.substringLastRear(filteredValue, ".");
if (millis.length() == 1) {
filteredValue = filteredValue + "00";
} else if (millis.length() == 2) {
filteredValue = filteredValue + "0";
}
// processed
return filteredValue;
}
}
// no converted
return null;
}
use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfColumnValueConverter method findTypedColumnConvertMap.
protected Map<String, String> findTypedColumnConvertMap(String columnName, Map<String, DfColumnMeta> columnMetaMap) {
final DfColumnMeta meta = columnMetaMap.get(columnName);
if (meta == null) {
// no way, just in case
throw new IllegalStateException("Not found the column meta: " + columnName);
}
final String jdbcType = TypeMap.findJdbcTypeByJdbcDefValue(meta.getJdbcDefValue());
if (jdbcType == null) {
// as not found
return Collections.emptyMap();
}
if (_typedColumnConvertMap != null) {
final Map<String, String> existingMap = _typedColumnConvertMap.get(jdbcType);
if (existingMap != null) {
return existingMap;
}
} else {
_typedColumnConvertMap = StringKeyMap.createAsCaseInsensitive();
}
// e.g. $$type(VARCHAR)$$
final String typedKey = "$$type(" + jdbcType + ")$$";
final Map<String, String> valueMap = _convertValueMap.getOrDefault(typedKey, Collections.emptyMap());
_typedColumnConvertMap.put(jdbcType, valueMap);
return _typedColumnConvertMap.get(jdbcType);
}
use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfAbsractDataWriter method getColumnMetaMap.
// ===================================================================================
// Column Meta
// ===========
protected Map<String, DfColumnMeta> getColumnMetaMap(String tableDbName) {
if (_columnInfoCacheMap.containsKey(tableDbName)) {
return _columnInfoCacheMap.get(tableDbName);
}
// because the name might be user favorite case name
prepareTableCaseTranslationIfNeeds();
final Map<String, DfColumnMeta> columnMetaMap = StringKeyMap.createAsFlexible();
Connection conn = null;
try {
conn = _dataSource.getConnection();
final DatabaseMetaData metaData = conn.getMetaData();
final List<DfColumnMeta> columnList = _columnHandler.getColumnList(metaData, _unifiedSchema, tableDbName);
for (DfColumnMeta columnInfo : columnList) {
columnMetaMap.put(columnInfo.getColumnName(), columnInfo);
}
_columnInfoCacheMap.put(tableDbName, columnMetaMap);
return columnMetaMap;
} catch (SQLException e) {
String msg = "Failed to get column meta informations: table=" + tableDbName;
throw new IllegalStateException(msg, e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ignored) {
}
}
}
}
use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfAbsractDataWriter method processXml.
// -----------------------------------------------------
// XML
// ---
protected boolean processXml(String tableName, String columnName, String value, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
if (value == null || value.trim().length() == 0) {
// cannot be XML
return false;
}
final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
if (columnInfo != null) {
if (getBasicProperties().isDatabasePostgreSQL()) {
final String dbTypeName = columnInfo.getDbTypeName();
if (!dbTypeName.startsWith("xml")) {
return false;
}
value = filterXmlValue(value);
ps.setObject(bindCount, value, Types.OTHER);
return true;
}
}
// unsupported when meta data is not found
return false;
}
use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfAbsractDataWriter method processNotNullNotString.
// -----------------------------------------------------
// NotNull NotString
// -----------------
protected boolean processNotNullNotString(String dataDirectory, String tableName, String columnName, Object obj, Connection conn, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
if (!isNotNullNotString(obj)) {
return false;
}
final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
if (columnInfo != null) {
final Class<?> columnType = getBindType(tableName, columnInfo);
if (columnType != null) {
bindNotNullValueByColumnType(tableName, columnName, conn, ps, bindCount, obj, columnType, rowNumber);
return true;
}
}
bindNotNullValueByInstance(tableName, columnName, conn, ps, bindCount, obj, rowNumber);
return true;
}
Aggregations