Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
  * either express or implied. See the License for the specific language
  * governing permissions and limitations under the License.
  */
 package org.dbflute.cbean.sqlclause.subquery;
 
 import java.util.List;
 

Author(s):
jflute
Since:
0.9.7.2 (2010/06/20 Sunday)
 
 public class ExistsReferrer extends AbstractSubQuery {
 
     // ===================================================================================
     //                                                                         Constructor
     //                                                                         ===========
     public ExistsReferrer(SubQueryPath subQueryPathColumnRealNameProvider localRealNameProvider,
             ColumnSqlNameProvider subQuerySqlNameProviderint subQueryLevelSqlClause subQuerySqlClauseString subQueryIdentity,
             DBMeta subQueryDBMetaGearedCipherManager cipherManager) {
         super(subQueryPathlocalRealNameProvidersubQuerySqlNameProvidersubQueryLevelsubQuerySqlClausesubQueryIdentity,
                 subQueryDBMetacipherManager);
     }
 
     // ===================================================================================
     //                                                                        Build Clause
     //                                                                        ============
     
Build the clause of sub-query by single primary key.

Parameters:
correlatedColumnDbName The DB name of correlated column that is main-query table's column. (NotNull)
relatedColumnDbName The DB name of related column that is sub-query table's column. (NotNull)
correlatedFixedCondition The fixed condition as correlated condition. (NullAllowed)
existsOption The option of ExistsReferrer. (basically for NotExistsReferrer) (NullAllowed: if null, means ExistsReferrer)
Returns:
The clause of sub-query. (NotNull)
 
     public String buildExistsReferrer(String correlatedColumnDbNameString relatedColumnDbNameString correlatedFixedCondition,
             String existsOption) {
         existsOption = existsOption != null ? existsOption + " " : "";
         final String subQueryClause;
         if (isSinglePrimaryKey(correlatedColumnDbNamerelatedColumnDbName)) {
             final ColumnSqlName relatedColumnSqlName = .provide(relatedColumnDbName);
             final ColumnRealName correlatedColumnRealName = .provide(correlatedColumnDbName);
             subQueryClause = buildSubQueryClause(correlatedColumnRealNamerelatedColumnSqlNamecorrelatedFixedCondition);
         } else { // compound primary keys
             final List<StringcolumnDbNameSplit = Srl.splitListTrimmed(correlatedColumnDbName",");
             final ColumnRealName[] correlatedColumnRealNames = new ColumnRealName[columnDbNameSplit.size()];
             for (int i = 0; i < columnDbNameSplit.size(); i++) {
                 correlatedColumnRealNames[i] = .provide(columnDbNameSplit.get(i));
             }
             final List<StringrelatedColumnSplit = Srl.splitListTrimmed(relatedColumnDbName",");
             final ColumnSqlName[] relatedColumnSqlNames = new ColumnSqlName[relatedColumnSplit.size()];
             for (int i = 0; i < relatedColumnSplit.size(); i++) {
                 relatedColumnSqlNames[i] = .provide(relatedColumnSplit.get(i));
             }
             subQueryClause = buildSubQueryClause(correlatedColumnRealNamesrelatedColumnSqlNamescorrelatedFixedCondition);
         }
         final String beginMark = resolveSubQueryBeginMark() + ln();
         final String endMark = resolveSubQueryEndMark();
         final String endIndent = "       ";
         return existsOption + "exists (" + beginMark + subQueryClause + ln() + endIndent + ")" + endMark;
     }
 
     // -----------------------------------------------------
     //                                       SubQuery Clause
     //                                       ---------------
     
Build the clause of sub-query by single primary key.

Parameters:
correlatedColumnRealName The real name of correlated column that is main-query table's column. (NotNull)
relatedColumnSqlName The real name of related column that is sub-query table's column. (NotNull)
correlatedFixedCondition The fixed condition as correlated condition. (NullAllowed)
Returns:
The clause of sub-query. (NotNull)
 
     protected String buildSubQueryClause(ColumnRealName correlatedColumnRealNameColumnSqlName relatedColumnSqlName,
             String correlatedFixedCondition) {
         final String localAliasName = getSubQueryLocalAliasName();
         final String selectClause = "select " + ColumnRealName.create(localAliasNamerelatedColumnSqlName);
         final String fromWhereClause =
                 buildCorrelationFromWhereClause(selectClauselocalAliasNamecorrelatedColumnRealNamerelatedColumnSqlName,
                         correlatedFixedCondition);
        return doBuildSubQueryClause(selectClausefromWhereClause);
    }

    
Build the clause of sub-query by compound primary key.

Parameters:
correlatedColumnRealNames The real names of correlated column that is main-query table's column. (NotNull)
relatedColumnSqlNames The real names of related column that is sub-query table's column. (NotNull)
correlatedFixedCondition The fixed condition as correlated condition. (NullAllowed)
Returns:
The clause of sub-query. (NotNull)
    protected String buildSubQueryClause(ColumnRealName[] correlatedColumnRealNamesColumnSqlName[] relatedColumnSqlNames,
            String correlatedFixedCondition) {
        // only single column allowed (no problem because of select clause for exists)
        final ColumnSqlName firstSqlName = relatedColumnSqlNames[0];
        final String localAliasName = getSubQueryLocalAliasName();
        final String selectClause = "select " + ColumnRealName.create(localAliasNamefirstSqlName);
        final String fromWhereClause =
                buildCorrelationFromWhereClause(selectClauselocalAliasNamecorrelatedColumnRealNamesrelatedColumnSqlNames,
                        correlatedFixedCondition);
        return doBuildSubQueryClause(selectClausefromWhereClause);
    }
    protected String doBuildSubQueryClause(String selectClauseString fromWhereClause) {
        final String subQueryClause = selectClause + " " + fromWhereClause;
        return resolveSubQueryLevelVariable(subQueryClause);
    }
New to GrepCode? Check out our FAQ X