use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfSPolicyWholeThemeChecker method determineSameWhatIfSameColumnAlias.
protected String determineSameWhatIfSameColumnAlias(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;
}
if (!myColumn.hasAlias()) {
continue;
}
for (Table yourTable : myTableList) {
if (myTable.equals(yourTable)) {
continue;
}
final String myColumnAlias = myColumn.getAlias();
final List<Column> yourColumnList = yourTable.getColumnList();
for (Column yourColumn : yourColumnList) {
if (!isTargetColumn(yourColumn)) {
continue;
}
if (!yourColumn.hasAlias()) {
continue;
}
if (myColumnAlias.equals(yourColumn.getAlias())) {
// same column alias
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 alias
return toColumnExp(myColumn) + "=" + myValue + ", " + toColumnExp(yourColumn) + "=" + yourValue;
}
}
}
}
}
}
return null;
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfPmbMetaData method adjustPropertyMetaFinally.
// ===================================================================================
// Adjustment
// ==========
public void adjustPropertyMetaFinally(AppData schemaData) {
// basically this adjusts property types for auto-detected properties
// it should be called after initialization
// (not called by procedure)
final DfLanguageDependency lang = getBasicProperties().getLanguageDependency();
final DfLanguagePropertyPackageResolver packageResolver = lang.getLanguagePropertyPackageResolver();
final Set<String> autoDetectedPropertyNameSet = getAutoDetectedPropertyNameSet();
if (autoDetectedPropertyNameSet == null || autoDetectedPropertyNameSet.isEmpty()) {
return;
}
final Map<String, String> propertyNameTypeMap = getPropertyNameTypeMap();
for (String propertyName : autoDetectedPropertyNameSet) {
// loop for auto-detected properties
final String beforeType = propertyNameTypeMap.get(propertyName);
String afterType = null;
if (isPropertyTypeList(propertyName) && isPropertyOptionClassification(propertyName, schemaData)) {
if (isPropertyOptionClassificationFixedElement(propertyName)) {
// :cls(Maihama.Sea) or :cls(Maihama.Sea, Land)
// e.g. /*pmb.maihamaList:cls(Maihama.Sea)*/ or /*pmb.maihamaList:cls(Maihama.Sea, Land)*/
// no adjustment because fixed element list needs List<String> as framework-internal property
} else {
// list property by public setter, wants to be e.g. List<CDef.Maihama>
final String classificationName = getPropertyOptionClassificationName(propertyName, schemaData);
final String plainType = "$$CDef$$." + classificationName;
// ParameterBean has the "import" clause of language-embedded utility
afterType = packageResolver.resolvePackageNameExceptUtil(plainType);
}
} else if (!beforeType.contains("CDef")) {
final Column refColumn = getPropertyOptionReferenceColumn(propertyName, schemaData);
if (refColumn != null) {
// not CDef and reference
afterType = refColumn.getJavaNative();
final String utilPrefix = "java.util.";
if (Srl.startsWith(afterType, utilPrefix) && Srl.count(afterType, ".") == 2) {
// ParameterBean has the "import" clause of language-embedded utility
afterType = Srl.substringFirstRear(afterType, utilPrefix);
}
}
}
if (afterType != null) {
final String finalType;
if (isPropertyTypeList(propertyName)) {
final DfLanguageGrammar grammar = getLanguageGrammar();
final String beginMark = grammar.getGenericBeginMark();
final String endMark = grammar.getGenericEndMark();
final String prefix = Srl.substringFirstFront(beforeType, "List" + beginMark);
final String suffix = Srl.substringLastRear(beforeType, endMark);
finalType = prefix + "List" + beginMark + afterType + endMark + suffix;
} else {
finalType = afterType;
}
// override
propertyNameTypeMap.put(propertyName, finalType);
}
}
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfPmbMetaData method getPropertyOptionClassificationColumn.
protected Column getPropertyOptionClassificationColumn(String propertyName, AppData schemaData) {
final Column column = getPropertyOptionReferenceColumn(propertyName, schemaData);
if (column == null) {
// no way
String msg = "The reference column should exist at this timing:";
msg = msg + " property=" + _className + "." + propertyName;
throw new IllegalStateException(msg);
}
if (!column.hasClassification()) {
// no way
String msg = "The reference column should have a classification at this timing:";
msg = msg + " property=" + _className + "." + propertyName + " column=" + column;
throw new IllegalStateException(msg);
}
return column;
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfPmbPropertyOptionReference method getPmbMetaDataPropertyOptionReferenceColumn.
// ===================================================================================
// Reference Column
// ================
public Column getPmbMetaDataPropertyOptionReferenceColumn(AppData appData) {
if (appData == null) {
return null;
}
final Database database = appData.getDatabase();
if (database == null) {
return null;
}
final String refPrefix = OPTION_PREFIX;
final String refSuffix = OPTION_SUFFIX;
final String option;
{
final String optionExp = getPmbMetaDataPropertyOption();
if (optionExp == null) {
return null;
}
final List<String> splitOption = splitOption(optionExp);
String firstOption = null;
for (String element : splitOption) {
if (element.startsWith(refPrefix) && element.endsWith(refSuffix)) {
firstOption = element;
break;
}
}
if (firstOption == null) {
return null;
}
option = firstOption;
}
final ScopeInfo scope = Srl.extractScopeFirst(option, refPrefix, refSuffix);
final String content = scope.getContent().trim();
final String delimiter = ".";
final String tableName;
final String columnName;
if (content.contains(".")) {
tableName = Srl.substringFirstFront(content, delimiter);
columnName = Srl.substringFirstRear(content, delimiter);
} else {
tableName = content;
columnName = null;
}
final Table table = database.getTable(tableName);
if (table == null) {
throwParameterBeanReferenceTableNotFoundException(option, tableName);
}
final String columnKeyName;
if (columnName != null) {
columnKeyName = columnName;
} else {
if (_pmbMetaData.isPropertyTypeList(_propertyName) && Srl.endsWith(_propertyName, "List")) {
// e.g. statusList to status
columnKeyName = Srl.substringLastFront(_propertyName, "List");
} else {
columnKeyName = _propertyName;
}
}
final Column column = table.getColumn(columnKeyName);
if (column == null) {
throwParameterBeanReferenceColumnNotFoundException(option, tableName, columnName);
}
return column;
}
use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method createColumnValueTypeMap.
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 load 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;
}
Aggregations