use of org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta in project dbflute-core by dbflute.
the class DfSchemaXmlSerializer method isAutoIncrementColumn.
// -----------------------------------------------------
// Auto Increment
// --------------
/**
* Get auto-increment column name.
* @param tableMeta The meta information of table from which to retrieve PK information.
* @param primaryKeyColumnInfo The meta information of primary-key column.
* @param conn Connection.
* @return Auto-increment column name. (NullAllowed)
* @throws SQLException When it fails to handle the SQL.
*/
protected boolean isAutoIncrementColumn(Connection conn, DfTableMeta tableMeta, DfColumnMeta primaryKeyColumnInfo) throws SQLException {
if (_autoIncrementExtractor.isAutoIncrementColumn(conn, tableMeta, primaryKeyColumnInfo)) {
return true;
}
if (canHandleSynonym(tableMeta)) {
final DfSynonymMeta synonym = getSynonymMetaInfo(tableMeta);
if (synonym != null && synonym.isAutoIncrement()) {
return true;
}
}
if (_identityMap == null) {
return false;
}
final String primaryKeyColumnName = primaryKeyColumnInfo.getColumnName();
final String columnName = _identityMap.get(tableMeta.getTableName());
return primaryKeyColumnName.equals(columnName);
}
use of org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta in project dbflute-core by dbflute.
the class DfSchemaXmlSerializer method loadSupplementarySynonymInfoIfNeeds.
// -----------------------------------------------------
// Synonym
// -------
protected void loadSupplementarySynonymInfoIfNeeds() {
// is only for main schema
final DfSynonymExtractor extractor = createSynonymExtractor();
if (extractor == null) {
return;
}
try {
_log.info("...Loading supplementary synonym informations");
_supplementarySynonymInfoMap = extractor.extractSynonymMap();
final StringBuilder sb = new StringBuilder();
sb.append("Finished loading synonyms:").append(ln()).append("[Supplementary Synonyms]");
final Set<Entry<String, DfSynonymMeta>> entrySet = _supplementarySynonymInfoMap.entrySet();
for (Entry<String, DfSynonymMeta> entry : entrySet) {
sb.append(ln()).append(" ").append(entry.getValue().toString());
}
_log.info(sb.toString());
} catch (RuntimeException ignored) {
_log.info("DfSynonymExtractor.extractSynonymMap() threw the exception!", ignored);
}
}
use of org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta in project dbflute-core by dbflute.
the class DfProcedureExtractor method isSynonymAllowedSchema.
protected boolean isSynonymAllowedSchema(DfProcedureSynonymMeta procedureSynonymMetaInfo) {
final DfSynonymMeta synonymMetaInfo = procedureSynonymMetaInfo.getSynonymMetaInfo();
final UnifiedSchema synonymOwner = synonymMetaInfo.getSynonymOwner();
final DfDatabaseProperties databaseProperties = getProperties().getDatabaseProperties();
final DfAdditionalSchemaInfo additionalSchemaInfo = databaseProperties.getAdditionalSchemaInfo(synonymOwner);
if (additionalSchemaInfo != null) {
return additionalSchemaInfo.hasObjectTypeSynonym();
} else {
// as main schema
return databaseProperties.hasObjectTypeSynonym();
}
}
use of org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta 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.DfSynonymMeta 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;
}
Aggregations