use of org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta in project dbflute-core by dbflute.
the class DfSchemaHtmlDataProcedure method getAvailableSchemaProcedureMap.
public Map<String, List<DfProcedureMeta>> getAvailableSchemaProcedureMap(Supplier<DfSchemaSource> dataSourceProvider) throws SQLException {
if (_schemaProcedureMap != null) {
return _schemaProcedureMap;
}
final List<DfProcedureMeta> procedureList = getAvailableProcedureList(dataSourceProvider);
final Map<String, List<DfProcedureMeta>> schemaProcedureListMap = DfCollectionUtil.newLinkedHashMap();
final String mainName = "(main schema)";
for (DfProcedureMeta meta : procedureList) {
final UnifiedSchema procedureSchema = meta.getProcedureSchema();
final String schemaName;
if (procedureSchema != null) {
final String drivenSchema = procedureSchema.getDrivenSchema();
if (drivenSchema != null) {
schemaName = drivenSchema;
} else {
schemaName = procedureSchema.isMainSchema() ? mainName : procedureSchema.getSqlPrefixSchema();
}
} else {
schemaName = "(no schema)";
}
List<DfProcedureMeta> metaList = schemaProcedureListMap.get(schemaName);
if (metaList == null) {
metaList = DfCollectionUtil.newArrayList();
schemaProcedureListMap.put(schemaName, metaList);
}
metaList.add(meta);
}
_schemaProcedureMap = schemaProcedureListMap;
return _schemaProcedureMap;
}
use of org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta in project dbflute-core by dbflute.
the class DfProcedureExtractor method getPlainProcedureList.
// ===================================================================================
// Plain Procedure
// ===============
/**
* Get the list of plain procedures. <br>
* It selects procedures of specified schema only.
* @param dataSource Data source. (NotNull)
* @param unifiedSchema The unified schema that can contain catalog name and no-name mark. (NullAllowed)
* @return The list of procedure meta information. (NotNull)
*/
public List<DfProcedureMeta> getPlainProcedureList(DataSource dataSource, UnifiedSchema unifiedSchema) throws SQLException {
final List<DfProcedureMeta> metaInfoList = new ArrayList<DfProcedureMeta>();
String procedureName = null;
Connection conn = null;
ResultSet procedureRs = null;
try {
conn = dataSource.getConnection();
final DatabaseMetaData metaData = conn.getMetaData();
procedureRs = doGetProcedures(metaData, unifiedSchema);
setupProcedureMetaInfo(metaInfoList, procedureRs, unifiedSchema);
for (DfProcedureMeta metaInfo : metaInfoList) {
procedureName = metaInfo.getProcedureName();
ResultSet columnRs = null;
try {
columnRs = doGetProcedureColumns(metaData, metaInfo);
setupProcedureColumnMetaInfo(metaInfo, columnRs);
} catch (SQLException e) {
throw e;
} finally {
closeResult(columnRs);
}
}
} catch (SQLException e) {
throwProcedureListGettingFailureException(unifiedSchema, procedureName, e);
// unreachable
return null;
} catch (RuntimeException e) {
// for an unexpected exception from JDBC driver
throwProcedureListGettingFailureException(unifiedSchema, procedureName, e);
// unreachable
return null;
} finally {
closeResult(procedureRs);
closeConnection(conn);
}
return metaInfoList;
}
use of org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta in project dbflute-core by dbflute.
the class DfProcedureExtractor method setupProcedureMetaInfo.
protected void setupProcedureMetaInfo(List<DfProcedureMeta> procedureMetaInfoList, ResultSet procedureRs, UnifiedSchema unifiedSchema) throws SQLException {
boolean skippedPgCatalog = false;
while (procedureRs.next()) {
// /- - - - - - - - - - - - - - - - - - - - - - - -
// same policy as table process about JDBC handling
// (see DfTableHandler.java)
// - - - - - - - - - -/
final String procedureSchema = procedureRs.getString("PROCEDURE_SCHEM");
if (isDatabasePostgreSQL()) {
if (procedureSchema != null && procedureSchema.equals("pg_catalog")) {
// skip pg_catalog's procedures, that are embedded in PostgreSQL
// (they can be here when the user is 'postgres')
skippedPgCatalog = true;
continue;
}
}
final String procedurePackage;
final String procedureCatalog;
final String procedureName;
{
final String plainCatalog = procedureRs.getString("PROCEDURE_CAT");
if (isDatabaseOracle()) {
// because Oracle treats catalog as package
if (Srl.is_NotNull_and_NotTrimmedEmpty(plainCatalog)) {
procedurePackage = plainCatalog;
} else {
procedurePackage = null;
}
procedureCatalog = null;
} else {
procedurePackage = null;
if (Srl.is_NotNull_and_NotTrimmedEmpty(plainCatalog)) {
procedureCatalog = plainCatalog;
} else {
procedureCatalog = unifiedSchema.getPureCatalog();
}
}
final String plainName = procedureRs.getString("PROCEDURE_NAME");
if (Srl.is_NotNull_and_NotTrimmedEmpty(procedurePackage)) {
procedureName = procedurePackage + "." + plainName;
} else {
procedureName = plainName;
}
}
final Integer procedureType = Integer.valueOf(procedureRs.getString("PROCEDURE_TYPE"));
final String procedureComment = procedureRs.getString("REMARKS");
final DfProcedureMeta metaInfo = new DfProcedureMeta();
metaInfo.setProcedureCatalog(procedureCatalog);
metaInfo.setProcedureSchema(createAsDynamicSchema(procedureCatalog, procedureSchema));
metaInfo.setProcedureName(procedureName);
if (procedureType == DatabaseMetaData.procedureResultUnknown) {
metaInfo.setProcedureType(DfProcedureType.procedureResultUnknown);
} else if (procedureType == DatabaseMetaData.procedureNoResult) {
metaInfo.setProcedureType(DfProcedureType.procedureNoResult);
} else if (procedureType == DatabaseMetaData.procedureReturnsResult) {
metaInfo.setProcedureType(DfProcedureType.procedureReturnsResult);
} else {
String msg = "Unknown procedureType: type=" + procedureType + " procedure=" + procedureName;
throw new IllegalStateException(msg);
}
metaInfo.setProcedureComment(procedureComment);
metaInfo.setProcedurePackage(procedurePackage);
metaInfo.setProcedureFullQualifiedName(buildProcedureFullQualifiedName(metaInfo));
metaInfo.setProcedureSchemaQualifiedName(buildProcedureSchemaQualifiedName(metaInfo));
procedureMetaInfoList.add(metaInfo);
}
if (skippedPgCatalog) {
_log.info("*Skipped pg_catalog's procedures");
}
}
use of org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta in project dbflute-core by dbflute.
the class DfProcedureExtractor method handleDuplicateProcedure.
// -----------------------------------------------------
// Duplicate Procedure
// -------------------
/**
* @param second The second procedure being processed current loop. (NotNull)
* @param procedureHandlingMap The handling map of procedure. (NotNull)
* @return Does it skip to register the second procedure?
*/
protected boolean handleDuplicateProcedure(DfProcedureMeta second, Map<String, DfProcedureMeta> procedureHandlingMap) {
final String procedureKeyName = second.buildProcedureKeyName();
final DfProcedureMeta first = procedureHandlingMap.get(procedureKeyName);
if (first == null) {
// not duplicate
return false;
}
final UnifiedSchema firstSchema = first.getProcedureSchema();
final UnifiedSchema secondSchema = second.getProcedureSchema();
// basically select the one of main schema.
if (!firstSchema.equals(secondSchema)) {
if (firstSchema.isMainSchema()) {
showDuplicateProcedure(first, second, true, "main schema");
// use first so skip
return true;
} else if (secondSchema.isMainSchema()) {
procedureHandlingMap.remove(procedureKeyName);
showDuplicateProcedure(first, second, false, "main schema");
// use second so NOT skip (override)
return false;
}
}
// if both are additional schema or main schema, it selects first.
showDuplicateProcedure(first, second, true, "first one");
return true;
}
use of org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta in project dbflute-core by dbflute.
the class DfProcedureExtractor method doSetupSourceInfo.
// ===================================================================================
// Source Info
// ===========
protected void doSetupSourceInfo(DataSource dataSource, List<DfProcedureMeta> metaInfoList, DfProcedureSupplementExtractor extractor, UnifiedSchema unifiedSchema, boolean reflectParamsToHash) {
final Map<String, DfProcedureSourceInfo> sourceInfoMap = extractor.extractProcedureSourceInfo(unifiedSchema);
if (sourceInfoMap == null) {
return;
}
log("...Reflecting source info to procedure meta: schema=" + unifiedSchema.getCatalogSchema());
for (DfProcedureMeta procedureMeta : metaInfoList) {
final UnifiedSchema procedureSchema = procedureMeta.getProcedureSchema();
if (!unifiedSchema.equals(procedureSchema)) {
continue;
}
final DfProcedureSourceInfo sourceInfo = sourceInfoMap.get(procedureMeta.getProcedureName());
if (sourceInfo == null) {
continue;
}
if (reflectParamsToHash) {
sourceInfo.setSupplementCode(procedureMeta.getColumnDefinitionIndentity());
}
showReflectedSourceInfo(procedureMeta, sourceInfo);
procedureMeta.setProcedureSourceInfo(sourceInfo);
}
}
Aggregations