use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfAbsractDataWriter method processBoolean.
// -----------------------------------------------------
// Boolean
// -------
protected boolean processBoolean(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 boolean
return false;
}
final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
if (columnInfo != null) {
final Class<?> columnType = getBindType(tableName, columnInfo);
if (columnType != null) {
if (!Boolean.class.isAssignableFrom(columnType)) {
return false;
}
bindNotNullValueByColumnType(tableName, columnName, conn, ps, bindCount, value, columnType, rowNumber);
return true;
}
}
// if meta data is not found (basically no way)
try {
final Boolean booleanValue = DfTypeUtil.toBoolean(value);
ps.setBoolean(bindCount, booleanValue);
return true;
} catch (ParseBooleanException ignored) {
// couldn't parse as boolean
return false;
}
}
use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfSynonymExtractorOracle method extractSynonymMap.
// ===================================================================================
// Extract
// =======
public Map<String, DfSynonymMeta> extractSynonymMap() {
final Map<String, DfSynonymMeta> synonymMap = StringKeyMap.createAsFlexibleOrdered();
Map<String, Map<String, SynonymNativeInfo>> dbLinkSynonymNativeMap = null;
final String sql = buildSynonymSelect();
Connection conn = null;
Statement statement = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
statement = conn.createStatement();
_log.info(sql);
rs = statement.executeQuery(sql);
while (rs.next()) {
final UnifiedSchema synonymOwner = createAsDynamicSchema(null, rs.getString("OWNER"));
final String synonymName = rs.getString("SYNONYM_NAME");
final UnifiedSchema tableOwner = createAsDynamicSchema(null, rs.getString("TABLE_OWNER"));
final String tableName = rs.getString("TABLE_NAME");
final String dbLinkName = rs.getString("DB_LINK");
if (_tableExtractor.isTableExcept(synonymOwner, synonymName)) {
// because it is not necessary to handle excepted tables
continue;
}
final DfSynonymMeta info = new DfSynonymMeta();
// Basic
info.setSynonymOwner(synonymOwner);
info.setSynonymName(synonymName);
info.setTableOwner(tableOwner);
info.setTableName(tableName);
info.setDBLinkName(dbLinkName);
// Select-able?
judgeSynonymSelectable(info);
if (info.isSelectable()) {
// e.g. procedure synonym
// set up column definition for supplement info
final List<DfColumnMeta> columnMetaInfoList = getSynonymColumns(conn, synonymOwner, synonymName);
info.setColumnMetaInfoList(columnMetaInfoList);
}
if (dbLinkName != null && dbLinkName.trim().length() > 0) {
if (dbLinkSynonymNativeMap == null) {
// lazy load
dbLinkSynonymNativeMap = extractDBLinkSynonymNativeMap();
}
// = = = = = = = = = = = =
try {
final String synonymKey = buildSynonymMapKey(synonymOwner, synonymName);
synonymMap.put(synonymKey, setupDBLinkSynonym(conn, info, dbLinkSynonymNativeMap));
} catch (Exception continued) {
_log.info("Failed to get meta data of " + synonymName + ": " + continued.getMessage());
}
continue;
}
if (!tableOwner.hasSchema()) {
// basically no way because it may be for DB Link Synonym
continue;
}
// PK, ID, UQ, FK, Index
try {
setupBasicConstraintInfo(info, tableOwner, tableName, conn);
} catch (Exception continued) {
_log.info("Failed to get meta data of " + synonymName + ": " + continued.getMessage());
continue;
}
final String synonymKey = buildSynonymMapKey(synonymOwner, synonymName);
synonymMap.put(synonymKey, info);
}
} catch (SQLException e) {
throw new IllegalStateException(e);
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException ignored) {
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException ignored) {
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException ignored) {
}
}
}
// It translates foreign key meta informations.
translateFKTable(synonymMap);
setupTableColumnComment(synonymMap);
return synonymMap;
}
use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfSchemaXmlSerializer method doProcessTable.
protected boolean doProcessTable(Connection conn, DatabaseMetaData metaData, DfTableMeta tableMeta) throws SQLException {
final String tableFullQualifiedName = tableMeta.getTableFullQualifiedName();
if (tableMeta.isOutOfGenerateTarget()) {
// for example, sequence synonym and so on...
_log.info("$ " + tableFullQualifiedName + " is out of generation target!");
return false;
}
_log.info("$ " + tableMeta.toString());
final Element tableElement = _doc.createElement("table");
tableElement.setAttribute("name", tableMeta.getTableName());
tableElement.setAttribute("type", tableMeta.getTableType());
final UnifiedSchema unifiedSchema = tableMeta.getUnifiedSchema();
if (unifiedSchema.hasSchema()) {
tableElement.setAttribute("schema", unifiedSchema.getIdentifiedSchema());
}
final String tableComment = tableMeta.getTableComment();
if (Srl.is_NotNull_and_NotTrimmedEmpty(tableComment)) {
tableElement.setAttribute("comment", tableComment);
}
final DfPrimaryKeyMeta pkInfo = getPrimaryColumnMetaInfo(metaData, tableMeta);
final List<DfColumnMeta> columns = getColumns(metaData, tableMeta);
for (int j = 0; j < columns.size(); j++) {
final DfColumnMeta columnMeta = columns.get(j);
final Element columnElement = _doc.createElement("column");
processColumnName(columnMeta, columnElement);
processColumnType(columnMeta, columnElement);
processColumnDbType(columnMeta, columnElement);
processColumnJavaType(columnMeta, columnElement);
processColumnSize(columnMeta, columnElement);
processDatetimePrecision(columnMeta, columnElement);
processRequired(columnMeta, columnElement);
processPrimaryKey(columnMeta, pkInfo, columnElement);
processColumnComment(columnMeta, columnElement);
processDefaultValue(columnMeta, columnElement);
processAutoIncrement(tableMeta, columnMeta, pkInfo, conn, columnElement);
tableElement.appendChild(columnElement);
}
processForeignKey(conn, metaData, tableMeta, tableElement);
final Map<String, Map<Integer, String>> uniqueKeyMap = processUniqueKey(metaData, tableMeta, pkInfo, tableElement);
processIndex(metaData, tableMeta, tableElement, uniqueKeyMap);
_tableElementStagingMap.put(tableFullQualifiedName, tableElement);
return true;
}
use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfSchemaXmlSerializer method helpColumnComments.
protected void helpColumnComments(DfTableMeta tableMeta, List<DfColumnMeta> columnList) {
if (_columnCommentAllMap != null) {
final String tableName = tableMeta.getTableName();
final Map<String, Map<String, UserColComments>> tableMap = _columnCommentAllMap.get(tableMeta.getUnifiedSchema());
if (tableMap != null) {
// just in case
final Map<String, UserColComments> columnCommentMap = tableMap.get(tableName);
if (columnCommentMap != null) {
// just in case
for (DfColumnMeta column : columnList) {
column.acceptColumnComment(columnCommentMap);
}
}
}
}
helpSynonymColumnComments(tableMeta, columnList);
}
use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.
the class DfSchemaXmlSerializer method helpColumnAdjustment.
protected List<DfColumnMeta> helpColumnAdjustment(DatabaseMetaData dbMeta, DfTableMeta tableMeta, List<DfColumnMeta> columnList) {
if (!canHandleSynonym(tableMeta)) {
return columnList;
}
final DfSynonymMeta synonym = getSynonymMetaInfo(tableMeta);
if (synonym == null) {
// means not synonym or no supplementary info
return columnList;
}
final List<DfColumnMeta> metaInfoList = synonym.getColumnMetaInfoList();
if (metaInfoList.isEmpty()) {
return metaInfoList;
}
if (synonym.isDBLink() && columnList.isEmpty()) {
columnList = metaInfoList;
} else if (metaInfoList.size() != columnList.size()) {
// for Oracle's bug(?), which is following:
// /- - - - - - - - - - - - - - - - - - - - - - - - - - -
// For example, Schema A, B are like this:
// A: FOO table
// B: FOO table, BAR synonym to A's FOO table
// BAR synonym's columns are from both A and B's FOO table.
// (means that BAR synonym has other table's columns)
// Why? my friend, the Oracle JDBC Driver!
// - - - - - - - - - -/
final StringSet columnSet = StringSet.createAsCaseInsensitive();
for (DfColumnMeta columnMeta : metaInfoList) {
columnSet.add(columnMeta.getColumnName());
}
final List<DfColumnMeta> filteredList = new ArrayList<DfColumnMeta>();
for (DfColumnMeta columnMeta : columnList) {
if (columnSet.contains(columnMeta.getColumnName())) {
filteredList.add(columnMeta);
}
}
columnList = filteredList;
}
return columnList;
}
Aggregations