use of org.dbflute.logic.jdbc.metadata.info.DfTableMeta in project dbflute-core by dbflute.
the class DfSchemaInitializerPostgreSQL method prepareSortedTableList.
// ===================================================================================
// Drop Table
// ==========
@Override
protected List<DfTableMeta> prepareSortedTableList(Connection conn, List<DfTableMeta> viewList, List<DfTableMeta> otherList) {
// order for inherit tables
final List<Map<String, String>> resultList = selectInheritList(conn);
final Set<String> childSet = StringSet.createAsCaseInsensitive();
for (Map<String, String> elementMap : resultList) {
childSet.add(elementMap.get("child_name"));
}
final Set<String> parentSet = StringSet.createAsCaseInsensitive();
for (Map<String, String> elementMap : resultList) {
parentSet.add(elementMap.get("parent_name"));
}
final List<DfTableMeta> firstPriorityList = new ArrayList<DfTableMeta>();
final List<DfTableMeta> secondPriorityList = new ArrayList<DfTableMeta>();
final List<DfTableMeta> thirdPriorityList = new ArrayList<DfTableMeta>();
for (DfTableMeta meta : otherList) {
final String tableDbName = meta.getTableDbName();
if (childSet.contains(tableDbName)) {
if (!parentSet.contains(tableDbName)) {
// both inherited and inherits
secondPriorityList.add(meta);
} else {
// inherits any table
firstPriorityList.add(meta);
}
} else {
// no inheritance
thirdPriorityList.add(meta);
}
}
final List<DfTableMeta> sortedList = new ArrayList<DfTableMeta>();
// should be before dropping reference table
sortedList.addAll(viewList);
sortedList.addAll(firstPriorityList);
sortedList.addAll(secondPriorityList);
sortedList.addAll(thirdPriorityList);
return sortedList;
}
use of org.dbflute.logic.jdbc.metadata.info.DfTableMeta in project dbflute-core by dbflute.
the class DfConventionalTakeAsserter method throwTakeFinallyAssertionFailureEmptyTableException.
protected void throwTakeFinallyAssertionFailureEmptyTableException(final List<DfTableMeta> emptyTableList) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Found the empty table (no-data) after ReplaceSchema.");
br.addItem("Advice");
br.addElement("The tables should have at least one record");
br.addElement("by conventionalTakeAssertMap settings in replaceSchemaMap.dfprop:");
br.addElement("");
br.addElement(Srl.indent(2, _dispPropertiesProvider.get()));
br.addElement("");
br.addElement("So prepare the data (e.g. tsv or xls) for ReplaceSchema.");
br.addElement("");
br.addElement(" playsql");
br.addElement(" |-data");
br.addElement(" | |-common");
br.addElement(" | | |-tsv");
br.addElement(" | | |-xls");
br.addElement(" | |-ut");
br.addElement(" | | |-tsv");
br.addElement(" | | |-xls");
br.addElement(" ...");
br.addElement("");
br.addElement("Or adjust dfprop settings, for example,");
br.addElement("you can except the table if it cannot be help.");
br.addElement("(Of course, do after you ask your friends developing together)");
br.addItem("Empty Table");
for (DfTableMeta tableMeta : emptyTableList) {
br.addElement(tableMeta.getTableDispName());
}
final String msg = br.buildExceptionMessage();
throw new DfTakeFinallyAssertionFailureEmptyTableException(msg);
}
use of org.dbflute.logic.jdbc.metadata.info.DfTableMeta in project dbflute-core by dbflute.
the class DfTableExtractor method getTableMap.
public Map<String, DfTableMeta> getTableMap(DatabaseMetaData metaData, UnifiedSchema unifiedSchema) throws SQLException {
final List<DfTableMeta> tableList = getTableList(metaData, unifiedSchema);
final Map<String, DfTableMeta> map = DfCollectionUtil.newLinkedHashMap();
for (DfTableMeta tableInfo : tableList) {
map.put(tableInfo.getTableName(), tableInfo);
}
return map;
}
use of org.dbflute.logic.jdbc.metadata.info.DfTableMeta in project dbflute-core by dbflute.
the class DfTableExtractor method doGetTableList.
protected List<DfTableMeta> doGetTableList(DatabaseMetaData metaData, UnifiedSchema unifiedSchema) throws SQLException {
final String[] objectTypes = getRealObjectTypeTargetArray(unifiedSchema);
final List<DfTableMeta> tableList = new ArrayList<DfTableMeta>();
ResultSet rs = null;
try {
_log.info("...Getting tables:");
_log.info(" schema = " + unifiedSchema);
_log.info(" types = " + DfCollectionUtil.newArrayList(objectTypes));
final String catalogName = unifiedSchema.getPureCatalog();
final String schemaName = unifiedSchema.getPureSchema();
rs = metaData.getTables(catalogName, schemaName, "%", objectTypes);
while (rs.next()) {
// /- - - - - - - - - - - - - - - - - - - - - - - - - - - -
// basically uses getString() because
// a JDBC driver might return an unexpected accident
// (other methods are used only when an item can be trust)
// - - - - - - - - - -/
final String tableName = rs.getString("TABLE_NAME");
final String tableType = rs.getString("TABLE_TYPE");
final String tableCatalog;
{
final String plainCatalog = rs.getString("TABLE_CAT");
if (Srl.is_NotNull_and_NotTrimmedEmpty(plainCatalog)) {
// because PostgreSQL returns null
tableCatalog = plainCatalog;
} else {
tableCatalog = catalogName;
}
}
final String tableSchema = rs.getString("TABLE_SCHEM");
final String tableComment = rs.getString("REMARKS");
// create new original unified schema for this table
final UnifiedSchema tableUnifiedSchema = createAsDynamicSchema(tableCatalog, tableSchema);
if (isTableExcept(tableUnifiedSchema, tableName)) {
_log.info(tableName + " is excepted!");
continue;
}
if (isSystemTableForDBMS(tableName)) {
_log.info(tableName + " is excepted! {system table}");
continue;
}
final DfTableMeta tableMetaInfo = new DfTableMeta();
tableMetaInfo.setTableName(tableName);
tableMetaInfo.setTableType(tableType);
tableMetaInfo.setUnifiedSchema(tableUnifiedSchema);
tableMetaInfo.setTableComment(tableComment);
tableList.add(tableMetaInfo);
}
} finally {
if (rs != null) {
rs.close();
}
}
return tableList;
}
use of org.dbflute.logic.jdbc.metadata.info.DfTableMeta in project dbflute-core by dbflute.
the class DfAbsractDataWriter method prepareTableCaseTranslationIfNeeds.
protected void prepareTableCaseTranslationIfNeeds() {
if (_columnHandler.isEnableTableCaseTranslation()) {
return;
}
Connection conn = null;
try {
conn = _dataSource.getConnection();
final DatabaseMetaData metaData = conn.getMetaData();
final List<DfTableMeta> tableList = _tableHandler.getTableList(metaData, _unifiedSchema);
final List<String> tableNameList = new ArrayList<String>();
for (DfTableMeta meta : tableList) {
tableNameList.add(meta.getTableDbName());
}
_columnHandler.enableTableCaseTranslation(tableNameList);
} catch (SQLException e) {
String msg = "Failed to get meta data of tables.";
throw new IllegalStateException(msg, e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ignored) {
}
}
}
}
Aggregations