use of org.apache.torque.engine.database.model.UnifiedSchema 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.apache.torque.engine.database.model.UnifiedSchema in project dbflute-core by dbflute.
the class DfSynonymExtractorOracle method createOwnerTableSetMap.
protected Map<UnifiedSchema, Set<String>> createOwnerTableSetMap(Map<String, DfSynonymMeta> synonymMap) {
final Map<UnifiedSchema, Set<String>> ownerTabSetMap = newLinkedHashMap();
for (DfSynonymMeta synonym : synonymMap.values()) {
final UnifiedSchema owner = synonym.getTableOwner();
if (synonym.isDBLink()) {
// Synonym of DB Link is out of target!
continue;
}
Set<String> tableSet = ownerTabSetMap.get(owner);
if (tableSet == null) {
tableSet = new LinkedHashSet<String>();
ownerTabSetMap.put(owner, tableSet);
}
tableSet.add(synonym.getTableName());
}
return ownerTabSetMap;
}
use of org.apache.torque.engine.database.model.UnifiedSchema in project dbflute-core by dbflute.
the class DfArrayExtractorOracle method setupFlatArrayInfo.
protected void setupFlatArrayInfo(StringKeyMap<DfTypeArrayInfo> flatArrayInfoMap, List<DfProcedureArgumentInfo> argInfoList, DfProcedureArgumentInfo argInfo, int index) {
final UnifiedSchema owner = UnifiedSchema.createAsDynamicSchema(null, argInfo.getTypeOwner());
final String realTypeName = buildArrayTypeName(argInfo);
final DfTypeArrayInfo arrayInfo = new DfTypeArrayInfo(owner, realTypeName);
final boolean nestedArray = reflectArrayElementType(argInfoList, index, arrayInfo);
flatArrayInfoMap.put(realTypeName, arrayInfo);
if (nestedArray) {
final int nextIndex = (index + 1);
final DfProcedureArgumentInfo nextArgInfo = argInfoList.get(nextIndex);
// recursive call
setupFlatArrayInfo(flatArrayInfoMap, argInfoList, nextArgInfo, nextIndex);
}
}
use of org.apache.torque.engine.database.model.UnifiedSchema in project dbflute-core by dbflute.
the class DfSchemaXmlSerializer method doHelpTableComment.
protected void doHelpTableComment(List<DfTableMeta> tableList, UnifiedSchema unifiedSchema) {
final DfDbCommentExtractor dbCommentExtractor = createDbCommentExtractor(unifiedSchema);
if (dbCommentExtractor != null) {
final Set<String> tableSet = new HashSet<String>();
for (DfTableMeta table : tableList) {
tableSet.add(table.getTableName());
}
try {
final Map<String, UserTabComments> tableCommentMap = dbCommentExtractor.extractTableComment(tableSet);
for (DfTableMeta table : tableList) {
table.acceptTableComment(tableCommentMap);
// *Synonym Processing is after loading synonyms.
}
} catch (RuntimeException ignored) {
_log.info("Failed to extract table comments: extractor=" + dbCommentExtractor, ignored);
}
try {
if (_columnCommentAllMap == null) {
_columnCommentAllMap = new LinkedHashMap<UnifiedSchema, Map<String, Map<String, UserColComments>>>();
}
final Map<String, Map<String, UserColComments>> columnCommentMap = _columnCommentAllMap.get(unifiedSchema);
final Map<String, Map<String, UserColComments>> extractedMap = dbCommentExtractor.extractColumnComment(tableSet);
if (columnCommentMap == null) {
_columnCommentAllMap.put(unifiedSchema, extractedMap);
} else {
// basically no way, schema is unique but just in case
// merge
columnCommentMap.putAll(extractedMap);
}
} catch (RuntimeException continued) {
_log.info("Failed to extract column comments: extractor=" + dbCommentExtractor, continued);
}
}
}
use of org.apache.torque.engine.database.model.UnifiedSchema 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;
}
Aggregations