use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class ScalarCondition method assertScalarConditionColumnType.
protected void assertScalarConditionColumnType(String function, String derivedColumnDbName) {
if ("sum".equalsIgnoreCase(function) || "avg".equalsIgnoreCase(function)) {
final ColumnInfo columnInfo = _subQueryDBMeta.findColumnInfo(derivedColumnDbName);
final Class<?> deriveColumnType = columnInfo.getObjectNativeType();
if (!columnInfo.isObjectNativeTypeNumber()) {
throwScalarConditionUnmatchedColumnTypeException(function, derivedColumnDbName, deriveColumnType);
}
}
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class AbstractDBMeta method doConvertToColumnValueMap.
protected Map<String, Object> doConvertToColumnValueMap(Entity entity, boolean pkOnly) {
final List<ColumnInfo> columnInfoList = pkOnly ? getPrimaryInfo().getPrimaryColumnList() : getColumnInfoList();
final MetaHandlingEntityToMapMapper mapper = createMetaHandlingEntityToMapMapper(entity);
return mapper.mappingToColumnValueMap(columnInfoList);
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class AbstractSqlClause method getClauseQueryInsert.
// ===================================================================================
// Query Update
// ============
// -----------------------------------------------------
// Query Insert
// ------------
public String getClauseQueryInsert(Map<String, String> fixedValueQueryExpMap, SqlClause resourceSqlClause) {
// at first, this should be called (before on-query name handling)
// because an on-query name of mapped info are set in this process
final String resourceViewClause = resourceSqlClause.getClause();
if (_specifiedSelectColumnMap == null) {
String msg = "The specified columns for query-insert are required.";
throw new IllegalConditionBeanOperationException(msg);
}
final Map<String, SpecifiedColumn> elementMap = _specifiedSelectColumnMap.get(getBasePointAliasName());
if (elementMap == null || elementMap.isEmpty()) {
String msg = "The specified columns of inserted table for query-insert are required.";
throw new IllegalConditionBeanOperationException(msg);
}
final DBMeta dbmeta = getDBMeta();
final StringBuilder intoSb = new StringBuilder();
final StringBuilder selectSb = new StringBuilder();
final String resourceAlias = "dfres";
int index = 0;
final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
for (ColumnInfo columnInfo : columnInfoList) {
final String columnDbName = columnInfo.getColumnDbName();
final SpecifiedColumn specifiedColumn = elementMap.get(columnDbName);
final String onQueryName;
if (specifiedColumn != null) {
onQueryName = specifiedColumn.getValidMappedOnQueryName();
} else if (fixedValueQueryExpMap.containsKey(columnDbName)) {
final String fixedValueQueryExp = fixedValueQueryExpMap.get(columnDbName);
if (fixedValueQueryExp != null) {
onQueryName = encryptIfNeeds(columnInfo, fixedValueQueryExp);
} else {
// it uses null literal on query
// because the SQL analyzer blocks null parameters
// (the analyzer should do it for condition-bean)
onQueryName = "null";
}
} else {
continue;
}
if (onQueryName == null || onQueryName.trim().length() == 0) {
// no way
String msg = "The on-query name for query-insert is required: " + specifiedColumn;
throw new IllegalConditionBeanOperationException(msg);
}
final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
if (index > 0) {
intoSb.append(", ");
selectSb.append(", ");
}
intoSb.append(columnSqlName);
if (specifiedColumn != null) {
selectSb.append(resourceAlias).append(".");
}
selectSb.append(onQueryName);
++index;
}
final String subQueryIdentity = "queryInsertResource";
final String subQueryBeginMark = resolveSubQueryBeginMark(subQueryIdentity);
final String subQueryEndMark = resolveSubQueryEndMark(subQueryIdentity);
final StringBuilder mainSb = new StringBuilder();
mainSb.append("insert into ").append(dbmeta.getTableSqlName());
mainSb.append(" (").append(intoSb).append(")").append(ln());
mainSb.append("select ").append(selectSb).append(ln());
mainSb.append(" from (").append(subQueryBeginMark).append(ln());
mainSb.append(resourceViewClause).append(ln());
mainSb.append(" ) ").append(resourceAlias).append(subQueryEndMark);
final String sql = mainSb.toString();
return processSubQueryIndent(sql);
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class DerivedReferrer method setupOptionAttribute.
protected void setupOptionAttribute(DerivedReferrerOption option) {
ColumnInfo columnInfo = _subQuerySqlClause.getSpecifiedColumnInfoAsOne();
if (columnInfo == null) {
columnInfo = _subQuerySqlClause.getSpecifiedDerivingColumnInfoAsOne();
}
// basically not null (checked before)
option.xsetTargetColumnInfo(columnInfo);
option.xjudgeDatabase(_subQuerySqlClause);
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class SqlClauseMySql method buildMatchCondition.
// [DBFlute-0.9.5]
// ===================================================================================
// Full-Text Search
// ================
/**
* Build a condition string of match statement for full-text search. <br>
* Bind variable is unused because the condition value should be literal in MySQL.
* @param textColumnList The list of text column. (NotNull, NotEmpty, StringColumn, TargetTableColumn)
* @param conditionValue The condition value embedded without binding (by MySQL restriction) but escaped. (NotNull)
* @param modifier The modifier of full-text search. (NullAllowed: If the value is null, No modifier specified)
* @param tableDbName The DB name of the target table. (NotNull)
* @param aliasName The alias name of the target table. (NotNull)
* @return The condition string of match statement. (NotNull)
*/
public String buildMatchCondition(List<ColumnInfo> textColumnList, String conditionValue, FullTextSearchModifier modifier, String tableDbName, String aliasName) {
assertTextColumnList(textColumnList);
assertVariousTextSearchResource(conditionValue, modifier, tableDbName, aliasName);
final StringBuilder sb = new StringBuilder();
int index = 0;
for (ColumnInfo columnInfo : textColumnList) {
if (columnInfo == null) {
continue;
}
assertTextColumnTable(tableDbName, columnInfo);
assertTextColumnType(tableDbName, columnInfo);
final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
if (index > 0) {
sb.append(",");
}
sb.append(aliasName).append(".").append(columnSqlName);
++index;
}
sb.insert(0, "match(").append(") against ('");
sb.append(escapeMatchConditionValue(conditionValue)).append("'");
if (modifier != null) {
sb.append(" ").append(modifier.code());
}
sb.append(")");
return sb.toString();
}
Aggregations