use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class AbstractConditionQuery method doRegIQ.
protected void doRegIQ(ConditionKey key, Object value, ConditionValue cvalue, String columnDbName, ConditionOption option) {
if (!prepareQueryChecked(key, value, cvalue, columnDbName).newClause()) {
return;
}
final DBMeta dbmeta = xgetDBMetaProvider().provideDBMetaChecked(asTableDbName());
final ColumnInfo columnInfo = dbmeta.findColumnInfo(columnDbName);
final String propertyName = columnInfo.getPropertyName();
final String uncapPropName = initUncap(propertyName);
// If Java, it is necessary to use uncapPropName!
final String location = xgetLocation(uncapPropName);
key.setupConditionValue(xcreateQueryModeProvider(), cvalue, value, location, option);
final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
final ColumnFunctionCipher cipher = xgetSqlClause().findColumnFunctionCipher(columnInfo);
if (isBaseQuery()) {
xgetSqlClause().registerBaseTableInlineWhereClause(columnSqlName, key, cvalue, cipher, option);
} else {
final String aliasName = xgetAliasName();
xgetSqlClause().registerOuterJoinInlineWhereClause(aliasName, columnSqlName, key, cvalue, cipher, option, _onClause);
}
}
use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class HpCalcSpecification method buildStatementAsSqlName.
// ===================================================================================
// Statement
// =========
/**
* {@inheritDoc}
*/
public String buildStatementAsSqlName(String aliasName) {
// e.g. VaryingUpdate, VaryingQueryUdpate
final ColumnSqlName columnSqlName = getResolvedSpecifiedColumnSqlName();
if (columnSqlName == null) {
// very rare case, e.g. DreamCruise
String msg = "Specified column is not found or too many columns are specified: " + aliasName;
throw new IllegalConditionBeanOperationException(msg);
}
final String columnExp = (aliasName != null ? aliasName : "") + columnSqlName.toString();
final boolean removeCalcAlias = aliasName == null;
return doBuildStatement(columnExp, null, removeCalcAlias);
}
use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class AbstractSqlClause method processSelectClauseRelation.
protected int processSelectClauseRelation(StringBuilder sb, int selectIndex) {
if (_pkOnlySelectForcedlyEnabled) {
return selectIndex;
}
for (Entry<String, Map<String, SelectedRelationColumn>> entry : getSelectedRelationColumnMap().entrySet()) {
final String tableAliasName = entry.getKey();
final Map<String, SelectedRelationColumn> relationColumnMap = entry.getValue();
Map<String, SpecifiedColumn> foreginSpecifiedMap = null;
if (_specifiedSelectColumnMap != null) {
foreginSpecifiedMap = _specifiedSelectColumnMap.get(tableAliasName);
}
final boolean validSpecifiedForeign = foreginSpecifiedMap != null && !foreginSpecifiedMap.isEmpty();
boolean finishedForeignIndent = false;
for (SelectedRelationColumn selectColumnInfo : relationColumnMap.values()) {
final ColumnInfo columnInfo = selectColumnInfo.getColumnInfo();
final String columnDbName = columnInfo.getColumnDbName();
if (validSpecifiedForeign && !foreginSpecifiedMap.containsKey(columnDbName)) {
continue;
}
if (canBeNullObjectSpecifiedColumn(columnInfo)) {
registerColumnNullObject(tableAliasName, columnInfo);
continue;
}
final String realColumnName = selectColumnInfo.buildRealColumnSqlName();
final String columnAliasName = selectColumnInfo.buildColumnAliasName();
final String relationNoSuffix = selectColumnInfo.getRelationNoSuffix();
final String onQueryName;
++selectIndex;
if (_useSelectIndex) {
final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
onQueryName = buildSelectIndexAlias(columnSqlName, columnAliasName, selectIndex, relationNoSuffix);
registerSelectIndex(relationNoSuffix, columnAliasName, onQueryName, selectIndex);
} else {
onQueryName = columnAliasName;
}
if (!finishedForeignIndent) {
sb.append(ln()).append(" ");
finishedForeignIndent = true;
}
sb.append(", ");
sb.append(decryptSelectColumnIfNeeds(columnInfo, realColumnName)).append(" as ").append(onQueryName);
getSelectClauseRealColumnAliasMap().put(realColumnName, onQueryName);
if (validSpecifiedForeign && foreginSpecifiedMap.containsKey(columnDbName)) {
final SpecifiedColumn specifiedColumn = foreginSpecifiedMap.get(columnDbName);
// basically for queryInsert()
specifiedColumn.setOnQueryName(onQueryName);
}
}
}
return selectIndex;
}
use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class AbstractSqlClause method processSelectClauseLocal.
protected int processSelectClauseLocal(StringBuilder sb) {
final String basePointAliasName = getBasePointAliasName();
final DBMeta dbmeta = getDBMeta();
final Map<String, SpecifiedColumn> localSpecifiedMap;
if (_specifiedSelectColumnMap != null) {
localSpecifiedMap = _specifiedSelectColumnMap.get(basePointAliasName);
} else {
localSpecifiedMap = null;
}
final List<ColumnInfo> columnInfoList;
final boolean validSpecifiedLocal;
final boolean selectClauseTypeUniqueScalar = isSelectClauseTypeUniqueScalar();
// unique scalar, has PK, specified scalar, specified column
ColumnInfo specifiedUniqueScalarColumnInfo = null;
if (selectClauseTypeUniqueScalar) {
// it always has union-query because it's handled before this process
if (dbmeta.hasPrimaryKey()) {
columnInfoList = new ArrayList<ColumnInfo>();
columnInfoList.addAll(dbmeta.getPrimaryInfo().getPrimaryColumnList());
if (isSelectClauseTypeSpecifiedScalar()) {
final ColumnInfo specifiedColumn = getSpecifiedColumnInfoAsOne();
if (specifiedColumn != null && !specifiedColumn.isPrimary()) {
specifiedUniqueScalarColumnInfo = specifiedColumn;
columnInfoList.add(specifiedColumn);
}
// derivingSubQuery is handled after this process
}
} else {
// all columns are target if no-PK and unique-scalar and union-query
columnInfoList = dbmeta.getColumnInfoList();
}
// because specified columns are fixed here
validSpecifiedLocal = false;
} else {
columnInfoList = dbmeta.getColumnInfoList();
validSpecifiedLocal = localSpecifiedMap != null && !localSpecifiedMap.isEmpty();
}
// because 1 origin in JDBC
int selectIndex = 0;
boolean needsDelimiter = false;
for (ColumnInfo columnInfo : columnInfoList) {
final String columnDbName = columnInfo.getColumnDbName();
final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
if (_pkOnlySelectForcedlyEnabled && !columnInfo.isPrimary()) {
continue;
}
if (validSpecifiedLocal && !localSpecifiedMap.containsKey(columnDbName)) {
// a case for scalar-select has been already resolved here
continue;
}
if (canBeNullObjectSpecifiedColumn(columnInfo)) {
registerColumnNullObject(basePointAliasName, columnInfo);
continue;
}
if (needsDelimiter) {
sb.append(", ");
} else {
sb.append("select");
appendSelectHint(sb);
sb.append(" ");
needsDelimiter = true;
}
final String realAliasName;
if (selectClauseTypeUniqueScalar) {
if (specifiedUniqueScalarColumnInfo != null && columnInfo.equals(specifiedUniqueScalarColumnInfo)) {
// has PK, specified column in unique scalar
// might be relation column
realAliasName = getSpecifiedColumnTableAliasNameAsOne();
} else {
// has no PK
realAliasName = basePointAliasName;
}
} else {
realAliasName = basePointAliasName;
}
final String realColumnName = realAliasName + "." + columnSqlName;
final String onQueryName;
++selectIndex;
if (_useSelectIndex) {
final String entityNo = BASE_POINT_HANDLING_ENTITY_NO;
onQueryName = buildSelectIndexAlias(columnSqlName, null, selectIndex, entityNo);
registerSelectIndex(entityNo, columnDbName, onQueryName, selectIndex);
} else {
onQueryName = columnSqlName.toString();
}
sb.append(decryptSelectColumnIfNeeds(columnInfo, realColumnName)).append(" as ").append(onQueryName);
getSelectClauseRealColumnAliasMap().put(realColumnName, onQueryName);
if (validSpecifiedLocal && localSpecifiedMap.containsKey(columnDbName)) {
final SpecifiedColumn specifiedColumn = localSpecifiedMap.get(columnDbName);
// basically for queryInsert()
specifiedColumn.setOnQueryName(onQueryName);
}
}
return selectIndex;
}
use of org.dbflute.dbmeta.name.ColumnSqlName 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);
}
Aggregations