use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method createColumnValueTypeMap.
// ===================================================================================
// JDBC Handling
// =============
protected Map<String, ValueType> createColumnValueTypeMap(List<Column> columnList) {
final Map<String, ValueType> valueTypeMap = new LinkedHashMap<String, ValueType>();
for (Column column : columnList) {
final String columnName = column.getName();
// create value type for the column
final ValueType valueType;
if (column.isJavaNativeStringObject()) {
if (column.isDbTypeStringClob()) {
valueType = new StringClobType();
} else {
valueType = new StringType();
}
} else if (column.isJavaNativeDateObject()) {
// date types should be treated correctly
if (column.isJdbcTypeTime()) {
valueType = new TimeType();
} else if (column.isJdbcTypeTimestamp()) {
valueType = new TimestampType();
} else if (column.isJdbcTypeDate()) {
if (column.isDbTypeOracleDate()) {
valueType = new UtilDateAsTimestampType();
} else {
valueType = new UtilDateAsSqlDateType();
}
} else {
// no way
valueType = new TimestampType();
}
} else if (column.isJavaNativeBinaryObject()) {
// unsupported BLOG as loda data
valueType = new NullBytesType();
} else {
// other types are treated as string
// because ReplaceSchema can accept them
valueType = new StringType();
}
valueTypeMap.put(columnName, valueType);
}
return valueTypeMap;
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method buildOrderByClause.
protected String buildOrderByClause(Table table) {
final ForeignKey selfReferenceFK = table.getSelfReferenceForeignKey();
final String orderBy;
if (selfReferenceFK != null && selfReferenceFK.isSimpleKeyFK()) {
final Column firstColumn = table.getColumn(selfReferenceFK.getFirstLocalColumnName());
final String firstName = firstColumn.getColumnSqlNameDirectUse();
orderBy = buildOrderByNullsFirst(firstName);
} else {
orderBy = "";
}
return orderBy;
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfLReverseOutputHandler method setupXlsDataTable.
// ===================================================================================
// Xls Data
// ========
protected void setupXlsDataTable(DfDataSet dataSet, Table table, List<Map<String, String>> extractedList, int sheetNumber, List<String> sectionInfoList) {
final List<Map<String, String>> recordList;
{
final String tableInfo = " " + table.getTableDispName() + " (" + extractedList.size() + ")";
_log.info(tableInfo);
sectionInfoList.add(tableInfo);
if (extractedList.size() > _xlsLimit) {
// just in case
recordList = extractedList.subList(0, _xlsLimit);
} else {
recordList = extractedList;
}
}
final DfDataTable dataTable = new DfDataTable(resolveSheetName(table, sheetNumber));
final List<Column> columnList = table.getColumnList();
for (Column column : columnList) {
if (isExceptCommonColumn(column)) {
continue;
}
dataTable.addColumn(column.getName(), DfDtsColumnTypes.STRING);
}
for (Map<String, String> recordMap : recordList) {
final Set<String> columnNameSet = recordMap.keySet();
final DfDataRow dataRow = dataTable.addRow();
for (String columnName : columnNameSet) {
if (!dataTable.hasColumn(columnName)) {
// basically excepted common columns
continue;
}
final String value = recordMap.get(columnName);
dataRow.addValue(columnName, value);
}
}
dataSet.addTable(dataTable);
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfSPolicyTableStatementChecker method isIfTrue.
protected boolean isIfTrue(DfSPolicyStatement statement, DfSPolicyIfPart ifPart, Table table) {
final String ifItem = ifPart.getIfItem();
final String ifValue = ifPart.getIfValue();
final boolean notIfValue = ifPart.isNotIfValue();
if (ifItem.equalsIgnoreCase("tableName")) {
return isHitExp(toComparingTableName(table), ifValue) == !notIfValue;
} else if (ifItem.equalsIgnoreCase("alias")) {
return isHitExp(table.getAlias(), ifValue) == !notIfValue;
} else if (ifItem.equalsIgnoreCase("pk_dbType") || ifItem.equalsIgnoreCase("pkDbType")) {
// for compatible
if (table.hasPrimaryKey()) {
final List<Column> pkList = table.getPrimaryKey();
for (Column pk : pkList) {
// required here (for PK's something)
return isHitExp(pk.getDbType(), ifValue) == !notIfValue;
}
}
} else if (ifItem.equalsIgnoreCase("pk_size")) {
if (table.hasPrimaryKey()) {
final List<Column> pkList = table.getPrimaryKey();
for (Column pk : pkList) {
// required here (for PK's something)
return isHitExp(pk.getColumnSize(), ifValue) == !notIfValue;
}
}
} else if (ifItem.equalsIgnoreCase("pk_dbType_with_size")) {
if (table.hasPrimaryKey()) {
final List<Column> pkList = table.getPrimaryKey();
for (Column pk : pkList) {
// required here (for PK's something)
return isHitExp(toComparingDbTypeWithSize(pk), ifValue) == !notIfValue;
}
}
} else {
throwSchemaPolicyCheckIllegalIfThenStatementException(statement, "Unknown if-item: " + ifItem);
}
return false;
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfSPolicyWholeThemeChecker method determineSameWhatIfSameColumnName.
protected String determineSameWhatIfSameColumnName(Database database, Function<Column, Object> valueProvider, boolean ignoreEmpty) {
final List<Table> myTableList = toTableList(database);
for (Table myTable : myTableList) {
final List<Column> myColumnList = myTable.getColumnList();
for (Column myColumn : myColumnList) {
if (!isTargetColumn(myColumn)) {
continue;
}
for (Table yourTable : myTableList) {
if (myTable.equals(yourTable)) {
continue;
}
final String myColumnName = myColumn.getName();
final Column yourColumn = yourTable.getColumn(myColumnName);
if (yourColumn != null) {
if (!isTargetColumn(yourColumn)) {
continue;
}
final Object myValue = valueProvider.apply(myColumn);
final Object yourValue = valueProvider.apply(yourColumn);
if (ignoreEmpty && eitherEmpty(myValue, yourValue)) {
continue;
}
if (!isEqual(myValue, yourValue)) {
// different in spite of same column name
return toColumnExp(myColumn) + "=" + myValue + ", " + toColumnExp(yourColumn) + "=" + yourValue;
}
}
}
}
}
return null;
}
Aggregations