use of org.dbflute.logic.jdbc.metadata.procedure.DfProcedureNativeTranslatorOracle in project dbflute-core by dbflute.
the class DfProcedureSynonymExtractorOracle method extractProcedureSynonymMap.
// ===================================================================================
// Extract
// =======
public Map<String, DfProcedureSynonymMeta> extractProcedureSynonymMap() {
_log.info("...Extracting procedure synonym");
final Map<String, DfProcedureSynonymMeta> procedureSynonymMap = StringKeyMap.createAsFlexibleOrdered();
final String sql = buildSynonymSelect();
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
conn = _dataSource.getConnection();
final Map<String, DfProcedureMeta> procedureMap = new LinkedHashMap<String, DfProcedureMeta>();
final List<DfProcedureMeta> procedureList = new ArrayList<DfProcedureMeta>();
final DfProcedureExtractor extractor = new DfProcedureExtractor();
extractor.suppressLogging();
for (UnifiedSchema unifiedSchema : _targetSchemaList) {
// get new procedure list because different instances is needed at this process
procedureList.addAll(extractor.getPlainProcedureList(_dataSource, unifiedSchema));
}
for (DfProcedureMeta metaInfo : procedureList) {
final String procedureKeyName = metaInfo.getProcedureFullQualifiedName();
procedureMap.put(procedureKeyName, metaInfo);
}
DfProcedureNativeTranslatorOracle translator = null;
st = conn.createStatement();
_log.info(sql);
rs = st.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");
final DfSynonymMeta synonymMetaInfo = new DfSynonymMeta();
// Basic
synonymMetaInfo.setSynonymOwner(synonymOwner);
synonymMetaInfo.setSynonymName(synonymName);
synonymMetaInfo.setTableOwner(tableOwner);
synonymMetaInfo.setTableName(tableName);
synonymMetaInfo.setDBLinkName(dbLinkName);
// Select-able?
judgeSynonymSelectable(synonymMetaInfo);
if (synonymMetaInfo.isSelectable()) {
// select-able synonyms are out of target
continue;
}
DfProcedureMeta procedureMeta = null;
if (dbLinkName != null && dbLinkName.trim().length() > 0) {
// synonym for DB link
if (translator == null) {
translator = new DfProcedureNativeTranslatorOracle(_dataSource);
}
procedureMeta = prepareProcedureToDBLink(tableOwner, tableName, dbLinkName, extractor, translator);
} else {
procedureMeta = findProcedureMeta(tableOwner, tableName, procedureMap);
}
if (procedureMeta == null) {
// may be package procedure or other schema's one
continue;
}
procedureMeta.setProcedureSynonym(true);
final DfProcedureSynonymMeta procedureSynonymMetaInfo = new DfProcedureSynonymMeta();
procedureSynonymMetaInfo.setProcedureMetaInfo(procedureMeta);
procedureSynonymMetaInfo.setSynonymMetaInfo(synonymMetaInfo);
final String synonymKey = buildSynonymMapKey(synonymOwner, synonymName);
procedureSynonymMap.put(synonymKey, procedureSynonymMetaInfo);
}
} catch (SQLException e) {
String msg = "Failed to get procedure synonyms: sql=" + sql;
throw new SQLFailureException(msg, e);
} finally {
if (st != null) {
try {
st.close();
} catch (SQLException ignored) {
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException ignored) {
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException ignored) {
}
}
}
return procedureSynonymMap;
}
use of org.dbflute.logic.jdbc.metadata.procedure.DfProcedureNativeTranslatorOracle in project dbflute-core by dbflute.
the class DfProcedureExtractor method setupProcedureToDBLinkIncluded.
// -----------------------------------------------------
// Included Procedure to DBLink
// ----------------------------
protected void setupProcedureToDBLinkIncluded(List<DfProcedureMeta> procedureList) {
if (_procedureToDBLinkDataSource == null) {
return;
}
final DfProcedureNativeTranslatorOracle translator = new DfProcedureNativeTranslatorOracle(_procedureToDBLinkDataSource);
final DfOutsideSqlProperties prop = getOutsideSqlProperties();
final List<String> procedureNameToDBLinkList = prop.getTargetProcedureNameToDBLinkList();
for (String propertyName : procedureNameToDBLinkList) {
final String packageName;
final String procedureName;
final String dbLinkName;
final String nameResource;
if (propertyName.contains(".")) {
packageName = Srl.substringLastFront(propertyName, ".");
nameResource = Srl.substringLastRear(propertyName, ".");
} else {
packageName = null;
nameResource = propertyName;
}
procedureName = Srl.substringLastFront(nameResource, "@");
dbLinkName = Srl.substringLastRear(nameResource, "@");
final DfProcedureMeta meta = translator.translateProcedureToDBLink(packageName, procedureName, dbLinkName, this);
if (meta == null) {
throwProcedureToDBLinkTranslationFailureException(propertyName, packageName, procedureName, dbLinkName);
}
meta.setIncludedProcedureToDBLink(true);
procedureList.add(meta);
}
}
Aggregations