protected bool SetupInternalSelectMethodSequenceNextVal(MethodInfo methodInfo)
        {
            if (!"SelectNextVal".Equals(methodInfo.Name))
            {
                return(false);
            }
            DBMeta dbmeta = FindDBMeta();

            if (!dbmeta.HasSequence)
            {
                String msg = "If the method 'SelectNextVal()' exists, DBMeta.HasSequence should return true:";
                msg = msg + " dbmeta.HasSequence=" + dbmeta.HasSequence + " method=" + methodInfo;
                throw new SystemException(msg);
            }
            String nextValueSql = dbmeta.SequenceNextValSql;

            if (nextValueSql == null)
            {
                String msg = "If the method 'SelectNextVal()' exists, nextValueSql should not be null:";
                msg = msg + " nextValueSql=" + nextValueSql + " method=" + methodInfo;
                throw new SystemException(msg);
            }
            SetupSelectMethodByManual(methodInfo, nextValueSql);
            return(true);
        }
 protected ReferrerInfo cri(String propName
                            , DBMeta localDbm, DBMeta referrerDbm
                            , Map <ColumnInfo, ColumnInfo> localReferrerColumnInfoMap
                            , bool oneToOne) // createReferrerInfo()
 {
     return(new ReferrerInfo(propName, localDbm, referrerDbm, localReferrerColumnInfoMap, oneToOne));
 }
Esempio n. 3
0
 // ===============================================================================
 //                                                                     Constructor
 //                                                                     ===========
 public ColumnInfo(DBMeta dbmeta, String columnDbName, String columnSqlName
                   , String columnSynonym, String columnAlias, bool notNull, String propertyName
                   , Type propertyType, bool primary, String columnDbType, int?columnSize
                   , int?columnDecimalDigits, bool commonColumn, OptimisticLockType optimisticLockType
                   , String columnComment, List <String> foreignPropList, List <String> referrerPropList)
 {
     AssertObjectNotNull("dbmeta", dbmeta);
     AssertObjectNotNull("columnDbName", columnDbName);
     AssertObjectNotNull("columnSqlName", columnSqlName);
     AssertObjectNotNull("propertyName", propertyName);
     AssertObjectNotNull("propertyType", propertyType);
     AssertObjectNotNull("optimisticLockType", optimisticLockType);
     this.dbmeta              = dbmeta;
     this.columnDbName        = columnDbName;
     this.columnSqlName       = columnSqlName;
     this.columnSynonym       = columnSynonym;
     this.columnAlias         = columnAlias;
     this.notNull             = notNull;
     this.propertyName        = propertyName;
     this.propertyType        = propertyType;
     this.primary             = primary;
     this.columnDbType        = columnDbType;
     this.columnSize          = columnSize;
     this.columnDecimalDigits = columnDecimalDigits;
     this.commonColumn        = commonColumn;
     this.optimisticLockType  = optimisticLockType;
     this.columnComment       = columnComment;
     this.foreignPropList     = foreignPropList != null ? foreignPropList : EMPTY_LIST;
     this.referrerPropList    = referrerPropList != null ? referrerPropList : EMPTY_LIST;
 }
        protected void assertAliasName(String aliasName)
        {
            if (aliasName == null || aliasName.Trim().Length == 0)
            {
                throwDerivedReferrerInvalidAliasNameException();
            }
            DBMeta dbmeta = DBMetaInstanceHandler.FindDBMeta(_baseCB.TableDbName);

            PropertyInfo[] properties         = dbmeta.EntityType.GetProperties();
            String         targetPropertyName = aliasName.Replace("_", "").ToLower();
            bool           existsSetterMethod = false;

            foreach (PropertyInfo property in properties)
            {
                if (!property.CanWrite)
                {
                    continue;
                }
                if (targetPropertyName.Equals(property.Name.ToLower()))
                {
                    existsSetterMethod = true;
                    break;
                }
            }
            if (!existsSetterMethod)
            {
                throwDerivedReferrerEntityPropertyNotFoundException(aliasName, dbmeta.EntityType);
            }
        }
 protected ForeignInfo cfi(String propName
                           , DBMeta localDbm, DBMeta foreignDbm
                           , Map <ColumnInfo, ColumnInfo> localForeignColumnInfoMap
                           , int relNo, bool oneToOne, bool bizOneToOne) // createForeignInfo()
 {
     return(new ForeignInfo(propName, localDbm, foreignDbm, localForeignColumnInfoMap, relNo, oneToOne, bizOneToOne));
 }
Esempio n. 6
0
        public virtual DaoReadable ByName(String tableFlexibleName)
        {
            AssertStringNotNullAndNotTrimmedEmpty("tableFlexibleName", tableFlexibleName);
            DBMeta dbmeta = DBMetaInstanceHandler.FindDBMeta(tableFlexibleName);

            return(InternalSelect <DaoReadable>(GetDaoType(dbmeta)));
        }
Esempio n. 7
0
 // ===============================================================================
 //                                                                     Constructor
 //                                                                     ===========
 public UniqueInfo(DBMeta dbmeta, List <ColumnInfo> uniqueColumnList, bool primary)
 {
     AssertObjectNotNull("dbmeta", dbmeta);
     AssertObjectNotNull("uniqueColumnList", uniqueColumnList);
     this.dbmeta           = dbmeta;
     this.uniqueColumnList = uniqueColumnList;
     this.primary          = primary;
 }
 protected Object CreateRelationRowInstance(DBMeta dbmeta)
 {
     if (dbmeta != null)
     {
         return(dbmeta.NewEntity());
     }
     return(null);
 }
        protected bool IsRelationProperty(PropertyInfo pi, DBMeta dbmeta)
        {
            String propertyName = pi.Name;

            if (dbmeta.HasForeign(propertyName) || dbmeta.HasReferrer(propertyName))
            {
                return(true);
            }
            return(_beanAnnotationReader.GetRelnoAttribute(pi) != null);
        }
Esempio n. 10
0
        protected void InjectSequenceToPrimaryKeyIfNeeds(Entity entity)
        {
            DBMeta dbmeta = entity.DBMeta;

            if (!dbmeta.HasSequence || dbmeta.HasCompoundPrimaryKey || entity.HasPrimaryKeyValue)
            {
                return;
            }
            SetupNextValueToPrimaryKey(entity);
        }
Esempio n. 11
0
        // ===============================================================================
        //                                                                   Assist Helper
        //                                                                   =============
        protected static Type GetDaoType(DBMeta dbmeta)
        {
            String daoTypeName = dbmeta.DaoTypeName;

            if (daoTypeName == null)
            {
                String msg = "The dbmeta.DaoTypeName should not return null: dbmeta=" + dbmeta;
                throw new SystemException(msg);
            }
            return(ForName(daoTypeName, AppDomain.CurrentDomain.GetAssemblies()));
        }
        // ===============================================================================
        //                                                                     Find DBMeta
        //                                                                     ===========
        public static DBMeta FindDBMeta(String tableFlexibleName)   // accept quoted name and schema prefix
        {
            DBMeta dbmeta = ByTableFlexibleName(tableFlexibleName);

            if (dbmeta == null)
            {
                String msg = "The DB meta was not found by the table flexible name: " + tableFlexibleName;
                msg = msg + " key=" + tableFlexibleName + " instanceMap=" + _tableDbNameInstanceMap;
                throw new DBMetaNotFoundException(msg);
            }
            return(dbmeta);
        }
        protected override void SetupProperty(Type beanType, IDatabaseMetaData dbMetaData, IDbms dbms)
        {
            if (!IsEntity(beanType))
            {
                base.SetupProperty(beanType, dbMetaData, dbms);
                return;
            }
            Entity entity = (Entity)ClassUtil.NewInstance(beanType);
            DBMeta dbmeta = entity.DBMeta;

            foreach (PropertyInfo pi in beanType.GetProperties())
            {
                IPropertyType  pt        = null;
                RelnoAttribute relnoAttr = _beanAnnotationReader.GetRelnoAttribute(pi);
                if (relnoAttr != null)
                {
                    if (!_relation)
                    {
                        IRelationPropertyType rpt = CreateRelationPropertyType(beanType, pi, relnoAttr, dbMetaData, dbms);
                        AddRelationPropertyType(rpt);
                    }
                }
                else
                {
                    if (pi.CanWrite)
                    {
                        pt = CreatePropertyTypeExtension(pi, dbmeta);
                        if (pt != null)
                        {
                            AddPropertyType(pt);
                            if (pt.IsPrimaryKey)
                            {
                                _primaryKeyList.add(pt);
                            }
                        }
                    }
                }
                if (IdentifierGenerator == null)
                {
                    IDAttribute idAttr = _beanAnnotationReader.GetIdAttribute(pi, dbms);
                    if (idAttr != null)
                    {
                        _identifierGenerator = Seasar.Dao.Id.IdentifierGeneratorFactory.CreateIdentifierGenerator(pi.Name, dbms, idAttr);
                        if (pt != null)
                        {
                            _primaryKeys    = new string[] { pt.ColumnName };
                            pt.IsPrimaryKey = true;
                        }
                    }
                }
            }
        }
        protected bool IsPersistentProperty(PropertyInfo pi, DBMeta dbmeta)
        {
            String propertyName = pi.Name;

            if (dbmeta.HasColumn(propertyName) || _beanAnnotationReader.GetColumn(pi) != null)
            {
                if (!IsElementOfNoPersistentProps(pi))
                {
                    return(true);
                }
            }
            return(false);
        }
        protected override void SetupRelationKeyValue(RelationRowCreationResource res)
        {
            IRelationPropertyType rpt = res.RelationPropertyType;
            IBeanMetaData         bmd = rpt.BeanMetaData;
            DBMeta dbmeta             = FindDBMeta(bmd.BeanType, bmd.TableName);

            for (int i = 0; i < rpt.KeySize; ++i)
            {
                String columnName = rpt.GetMyKey(i) + res.BaseSuffix;

                if (!res.ContainsColumnName(columnName))
                {
                    continue;
                }
                if (!res.HasRowInstance())
                {
                    Object row;
                    if (dbmeta != null)
                    {
                        row = dbmeta.NewEntity();
                    }
                    else
                    {
                        row = NewRelationRow(rpt);
                    }
                    res.Row = row;
                }
                if (!res.ContainsRelKeyValueIfExists(columnName))
                {
                    continue;
                }
                Object value = res.ExtractRelKeyValue(columnName);
                if (value == null)
                {
                    // basically no way
                    // because this is not called if the referred value
                    // is null (then it must be no relation key)
                    // @see InternalBeanListMetaDataResultSetHandler
                    continue;
                }

                String        yourKey = rpt.GetYourKey(i);
                IPropertyType pt      = bmd.GetPropertyTypeByColumnName(yourKey);
                PropertyInfo  pi      = pt.PropertyInfo;
                pi.SetValue(res.Row, value, null);
                continue;
            }
        }
        public static DBMeta FindDBMeta(Type rowType, String tableName)
        {
            DBMeta dbmeta = FindCachedDBMeta(rowType);

            if (dbmeta != null)
            {
                return(dbmeta);
            }
            try {
                dbmeta = DBMetaInstanceHandler.FindDBMeta(tableName);
            } catch (DBMetaNotFoundException) {
                return(null);
            }
            CacheDBMeta(rowType, dbmeta);
            return(dbmeta);
        }
        public static DBMeta FindDBMeta(Object row)
        {
            if (!(row is Entity))
            {
                return(null);
            }
            Entity entity = (Entity)row;
            DBMeta dbmeta = FindCachedDBMeta(entity.GetType());

            if (dbmeta != null)
            {
                return(dbmeta);
            }
            dbmeta = entity.DBMeta;
            CacheDBMeta(entity, dbmeta);
            return(dbmeta);
        }
Esempio n. 18
0
        protected String BuildBehaviorSqlPackageName()
        {
            DBMeta dbmeta            = DBMetaInstanceHandler.FindDBMeta(_tableDbName);
            String behaviorTypeName  = dbmeta.BehaviorTypeName;
            String outsideSqlPackage = DBFluteConfig.GetInstance().OutsideSqlPackage;

            if (outsideSqlPackage != null && outsideSqlPackage.Trim().Length > 0)
            {
                String behaviorClassName = behaviorTypeName.Substring(behaviorTypeName.LastIndexOf(".") + ".".Length);
                String tmp       = behaviorTypeName.Substring(0, behaviorTypeName.LastIndexOf("."));
                String exbhvName = tmp.Contains(".") ? tmp.Substring(tmp.LastIndexOf(".") + ".".Length) : tmp;
                return(FilterBehaviorSqlPackageName(outsideSqlPackage + "." + exbhvName + "." + behaviorClassName));
            }
            else
            {
                return(FilterBehaviorSqlPackageName(behaviorTypeName));
            }
        }
Esempio n. 19
0
        // ===================================================================================
        //                                                                       Lock Override
        //                                                                       =============
        public override SqlClause lockForUpdate()
        {
            DBMeta dbmeta = DBMetaInstanceHandler.FindDBMeta(_tableName);

            if (dbmeta.HasPrimaryKey)
            {
                String primaryKeyColumnName = dbmeta.PrimaryUniqueInfo.FirstColumn.ColumnDbName;
                _lockSqlSuffix = " for update of " + _tableName + "." + primaryKeyColumnName;
            }
            else
            {
                String randomColumnName = dbmeta.ColumnInfoList.get(0).ColumnDbName;
                _lockSqlSuffix = " for update of " + _tableName + "." + randomColumnName;
            }

            _lockSqlSuffix = " for update";
            return(this);
        }
        /**
         * @param cb Condition-bean. (NotNull)
         * @param entity Entity. (NotNull)
         * @return The two-way SQL of query update. (NullAllowed: If the set of modified properties is empty, return null.)
         */
        protected String buildQueryUpdateTwoWaySql(ConditionBean cb, Entity entity)
        {
            Map <String, String> columnParameterMap = new LinkedHashMap <String, String>();
            DBMeta dbmeta = DBMetaInstanceHandler.FindDBMeta(entity.TableDbName);

            System.Collections.Generic.IDictionary <String, Object> modifiedPropertyNames = entity.ModifiedPropertyNames;
            if (modifiedPropertyNames.Count == 0)
            {
                return(null);
            }
            String currentPropertyName = null;

            foreach (String propertyName in modifiedPropertyNames.Keys)
            {
                currentPropertyName = propertyName;
                ColumnInfo   columnInfo = dbmeta.FindColumnInfo(propertyName);
                String       columnName = columnInfo.ColumnDbName;
                PropertyInfo getter     = columnInfo.FindProperty();
                Object       value      = getter.GetValue(entity, null);
                if (value != null)
                {
                    columnParameterMap.put(columnName, "/*entity." + propertyName + "*/null");
                }
                else
                {
                    columnParameterMap.put(columnName, "null");
                }
            }
            if (dbmeta.HasVersionNo)
            {
                ColumnInfo columnInfo = dbmeta.VersionNoColumnInfo;
                String     columnName = columnInfo.ColumnDbName;
                columnParameterMap.put(columnName, columnName + " + 1");
            }
            if (dbmeta.HasUpdateDate)
            {
                ColumnInfo   columnInfo = dbmeta.UpdateDateColumnInfo;
                PropertyInfo setter     = columnInfo.FindProperty();
                setter.SetValue(entity, DateTime.Now, null);
                String columnName = columnInfo.ColumnDbName;
                columnParameterMap.put(columnName, "/*entity." + columnInfo.PropertyName + "*/null");
            }
            return(cb.SqlClause.getClauseQueryUpdate(columnParameterMap));
        }
        // ===============================================================================
        //                                                                   Cached DBMeta
        //                                                                   =============
        protected static DBMeta GetCachedDBMeta(String tableDbName)   // lazy-load (thank you koyak!)
        {
            DBMeta dbmeta = _tableDbNameInstanceMap.get(tableDbName);

            if (dbmeta != null)
            {
                return(dbmeta);
            }
            lock (_tableDbNameInstanceMap) {
                dbmeta = _tableDbNameInstanceMap.get(tableDbName);
                if (dbmeta != null)
                {
                    return(dbmeta);
                }
                String entityName = _tableDbNameClassNameMap.get(tableDbName);
                _tableDbNameInstanceMap.put(tableDbName, GetDBMeta(entityName));
                return(_tableDbNameInstanceMap.get(tableDbName));
            }
        }
        protected IPropertyType CreatePropertyTypeExtension(PropertyInfo pi, DBMeta dbmeta)
        {
            if (IsRelationProperty(pi, dbmeta))
            {
                return(null);
            }
            String        columnName = GetPropertyTypeColumnName(pi);
            IValueType    valueType  = ValueTypes.GetValueType(pi.PropertyType);
            IPropertyType pt         = new PropertyTypeImpl(pi, valueType, columnName);

            if (dbmeta.HasPrimaryKey && dbmeta.HasColumn(pt.ColumnName))
            {
                if (dbmeta.FindColumnInfo(pt.ColumnName).IsPrimary)
                {
                    pt.IsPrimaryKey = true;
                }
            }
            pt.IsPersistent = IsPersistentProperty(pi, dbmeta);
            return(pt);
        }
        protected override void RegisterRelationValue(RelationRowCreationResource res, String columnName)
        {
            IPropertyType pt    = res.CurrentPropertyType;
            Object        value = null;

            if (res.ContainsRelKeyValueIfExists(columnName))
            {
                // if this column is relation key, it gets the value from relation key values
                // for performance and avoiding twice getting same column value
                value = res.ExtractRelKeyValue(columnName);
            }
            else
            {
                IValueType         valueType      = pt.ValueType;
                Map <String, int?> selectIndexMap = GetSelectIndexMap();
                if (selectIndexMap != null)
                {
                    value = GetValue(res.DataReader, columnName, valueType, selectIndexMap);
                }
                else
                {
                    value = valueType.GetValue(res.DataReader, columnName);
                }
            }
            if (value != null)
            {
                res.IncrementValidValueCount();
                DBMeta dbmeta       = FindDBMeta(res.Row);
                String propertyName = pt.PropertyName;
                if (dbmeta != null && dbmeta.HasEntityPropertySetupper(propertyName))
                {
                    dbmeta.SetupEntityProperty(propertyName, res.Row, value);
                }
                else
                {
                    PropertyInfo pd = pt.PropertyInfo;
                    pd.SetValue(res.Row, value, null);
                }
            }
        }
Esempio n. 24
0
        // ===============================================================================
        //                                                                     Constructor
        //                                                                     ===========
        public ReferrerInfo(String referrerPropertyName, DBMeta localDBMeta, DBMeta referrerDBMeta
                            , Map <ColumnInfo, ColumnInfo> localReferrerColumnInfoMap
                            , bool oneToOne)
        {
            AssertObjectNotNull("referrerPropertyName", referrerPropertyName);
            AssertObjectNotNull("localDBMeta", localDBMeta);
            AssertObjectNotNull("referrerDBMeta", referrerDBMeta);
            AssertObjectNotNull("localReferrerColumnInfoMap", localReferrerColumnInfoMap);
            this.referrerPropertyName       = referrerPropertyName;
            this.localDBMeta                = localDBMeta;
            this.referrerDBMeta             = referrerDBMeta;
            this.localReferrerColumnInfoMap = localReferrerColumnInfoMap;
            Set <ColumnInfo> keySet = localReferrerColumnInfoMap.keySet();

            referrerLocalColumnInfoMap = new LinkedHashMap <ColumnInfo, ColumnInfo>();
            foreach (ColumnInfo key in localReferrerColumnInfoMap.keySet())
            {
                ColumnInfo value = localReferrerColumnInfoMap.get(key);
                referrerLocalColumnInfoMap.put(value, key);
            }
            this.oneToOne = oneToOne;
        }
Esempio n. 25
0
        // ===============================================================================
        //                                                                     Constructor
        //                                                                     ===========
        public ForeignInfo(String foreignPropertyName, DBMeta localDBMeta, DBMeta foreignDBMeta
                           , Map <ColumnInfo, ColumnInfo> localForeignColumnInfoMap
                           , int relationNo, bool oneToOne, bool bizOneToOne)
        {
            AssertObjectNotNull("foreignPropertyName", foreignPropertyName);
            AssertObjectNotNull("localDBMeta", localDBMeta);
            AssertObjectNotNull("foreignDBMeta", foreignDBMeta);
            AssertObjectNotNull("localForeignColumnInfoMap", localForeignColumnInfoMap);
            _foreignPropertyName       = foreignPropertyName;
            _localDBMeta               = localDBMeta;
            _foreignDBMeta             = foreignDBMeta;
            _localForeignColumnInfoMap = localForeignColumnInfoMap;
            Set <ColumnInfo> keySet = localForeignColumnInfoMap.keySet();

            _foreignLocalColumnInfoMap = new LinkedHashMap <ColumnInfo, ColumnInfo>();
            foreach (ColumnInfo key in localForeignColumnInfoMap.keySet())
            {
                ColumnInfo value = localForeignColumnInfoMap.get(key);
                _foreignLocalColumnInfoMap.put(value, key);
            }
            _relationNo  = relationNo;
            _oneToOne    = oneToOne;
            _bizOneToOne = bizOneToOne;
        }
 protected static void CacheDBMeta(Type type, DBMeta dbmeta)
 {
     System.Collections.Generic.IDictionary <Type, DBMeta> dbmetaCache = FindDBMetaCache();
     dbmetaCache.Add(type, dbmeta);
 }
        // ===============================================================================
        //                                                                     Constructor
        //                                                                     ===========
        public AbstractConditionBean()
        {
            DBMeta dbmeta = DBMetaInstanceHandler.FindDBMeta(TableDbName);

            _sqlClause = new SqlClausePostgreSql(dbmeta.TableSqlName);
        }
        protected String buildInvocationExpressionWithoutKakko(IMethodInvocation invocation, String invokeClassName, String invokeMethodName)
        {
            if (invokeClassName.Contains("OutsideSql") && invokeClassName.Contains("Executor"))   // OutsideSql Executor Handling and CSharp Only Contains
            {
                try {
                    String originalName = invokeClassName;
                    if (IsSpecifiedOutsideSql())
                    {
                        OutsideSqlContext outsideSqlContext = GetOutsideSqlContext();
                        String            tableDbName       = outsideSqlContext.TableDbName;
                        DBMeta            dbmeta            = DBMetaInstanceHandler.FindDBMeta(tableDbName);
                        String            behaviorTypeName  = dbmeta.BehaviorTypeName;
                        String            behaviorClassName = behaviorTypeName.Substring(behaviorTypeName.LastIndexOf(".") + ".".Length);
                        invokeClassName = behaviorClassName + ".OutsideSql()";
                        if (originalName.Contains("OutsideSqlEntityExecutor"))   // CSharp Only Contains
                        {
                            invokeClassName = invokeClassName + ".EntityHandling()";
                        }
                        else if (originalName.Contains("OutsideSqlPagingExecutor"))     // CSharp Only Contains
                        {
                            if (outsideSqlContext.IsAutoPagingLogging)
                            {
                                invokeClassName = invokeClassName + ".AutoPaging()";
                            }
                            else
                            {
                                invokeClassName = invokeClassName + ".ManualPaging()";
                            }
                        }
                        else if (originalName.Contains("OutsideSqlCursorExecutor"))     // CSharp Only Contains
                        {
                            invokeClassName = invokeClassName + ".CursorHandling()";
                        }
                    }
                    else
                    {
                        invokeClassName = "OutsideSql";
                    }
                } catch (Exception ignored) {
                    Log("Ignored exception occurred: msg=" + ignored.Message);
                }
            }
            String invocationExpressionWithoutKakko = invokeClassName + "." + invokeMethodName;

            if ("SelectPage".Equals(invokeMethodName))   // Special Handling!
            {
                bool resultTypeInteger = false;
                if (IsSpecifiedOutsideSql())
                {
                    OutsideSqlContext outsideSqlContext = GetOutsideSqlContext();
                    Type resultType = outsideSqlContext.ResultType;
                    if (resultType != null)
                    {
                        if (typeof(int).IsAssignableFrom(resultType))
                        {
                            resultTypeInteger = true;
                        }
                    }
                }
                if (resultTypeInteger || "SelectCount".Equals(invocation.Method.Name))
                {
                    invocationExpressionWithoutKakko = invocationExpressionWithoutKakko + "():count";
                }
                else
                {
                    invocationExpressionWithoutKakko = invocationExpressionWithoutKakko + "():paging";
                }
            }
            return(invocationExpressionWithoutKakko);
        }
        protected String resolveFixedConditionOverRelation(String fixedCondition)
        {
            String relationBeginMark = getRelationBeginMark();
            String relationEndMark   = getRelationEndMark();
            String remainder         = fixedCondition;

            while (true)
            {
                IndexOfInfo relationBeginIndex = Srl.indexOfFirst(remainder, relationBeginMark);
                if (relationBeginIndex == null)
                {
                    break;
                }
                remainder = relationBeginIndex.substringRear();
                IndexOfInfo relationEndIndex = Srl.indexOfFirst(remainder, relationEndMark);
                if (relationEndIndex == null)
                {
                    break;
                }

                // analyze:
                // - $$over($$localTable$$.memberStatus)$$
                // - $$over($$foreignTable$$.memberStatus, DISPLAY_ORDER)$$
                // - $$over(PURCHASE.product.productStatus)$$
                String relationExp = relationEndIndex.substringFront();
                String pointTable;
                String targetRelation;
                String secondArg;
                {
                    IndexOfInfo separatorIndex = Srl.indexOfFirst(relationExp, ".");
                    if (separatorIndex != null)
                    {
                        pointTable = separatorIndex.substringFrontTrimmed();
                        IndexOfInfo argIndex = Srl.indexOfFirst(separatorIndex.substringRearTrimmed(), ",");
                        targetRelation = argIndex != null?argIndex.substringFrontTrimmed() : separatorIndex
                                             .substringRearTrimmed();

                        secondArg = argIndex != null?argIndex.substringRearTrimmed() : null;
                    }
                    else
                    {
                        IndexOfInfo argIndex = Srl.indexOfFirst(relationExp, ",");
                        pointTable = argIndex != null?argIndex.substringFrontTrimmed() : Srl.trim(relationExp);

                        targetRelation = null;
                        secondArg      = argIndex != null?argIndex.substringRearTrimmed() : null;
                    }
                }

                ConditionQuery relationPointCQ;
                ConditionQuery columnTargetCQ;
                if (Srl.equalsPlain(pointTable, getLocalTableMark()))
                {
                    relationPointCQ = _localCQ;
                    if (targetRelation != null)
                    {
                        columnTargetCQ = invokeColumnTargetCQ(relationPointCQ, targetRelation);
                    }
                    else
                    {
                        String notice = "The relation on fixed condition is required if the table is not referrer.";
                        throwIllegalFixedConditionOverRelationException(notice, pointTable, null, fixedCondition);
                        return(null); // unreachable
                    }
                }
                else if (Srl.equalsPlain(pointTable, getForeignTableMark()))
                {
                    relationPointCQ = _foreignCQ;
                    columnTargetCQ  = relationPointCQ;
                    if (targetRelation == null)
                    {
                        String notice = "The relation on fixed condition is required if the table is not referrer.";
                        throwIllegalFixedConditionOverRelationException(notice, pointTable, null, fixedCondition);
                        return(null); // unreachable
                    }
                    // prepare fixed InlineView
                    if (_inlineViewResourceMap == null)
                    {
                        _inlineViewResourceMap = new LinkedHashMap <String, InlineViewResource>();
                    }
                    InlineViewResource resource;
                    if (_inlineViewResourceMap.containsKey(targetRelation))
                    {
                        resource = _inlineViewResourceMap.get(targetRelation);
                    }
                    else
                    {
                        resource = new InlineViewResource();
                        _inlineViewResourceMap.put(targetRelation, resource);
                    }
                    String columnName;
                    {
                        IndexOfInfo rearIndex = Srl.indexOfFirst(relationEndIndex.substringRearTrimmed(), ".");
                        if (rearIndex == null || rearIndex.getIndex() > 0)
                        {
                            String notice = "The OverRelation variable should continue to column after the variable.";
                            throwIllegalFixedConditionOverRelationException(notice, pointTable, targetRelation,
                                                                            fixedCondition);
                            return(null); // unreachable
                        }
                        String      columnStart = rearIndex.substringRear();
                        IndexOfInfo indexInfo   = Srl.indexOfFirst(columnStart, " ", ",", ")", "\n", "\t");
                        columnName = indexInfo != null?indexInfo.substringFront() : columnStart;
                    }
                    // the secondArg should be a column DB name, and then rear column is alias name
                    String resolvedColumn = secondArg != null ? secondArg + " as " + columnName : columnName;
                    resource.addAdditionalColumn(resolvedColumn);
                    List <String> splitList     = Srl.splitList(targetRelation, ".");
                    DBMeta        currentDBMeta = _dbmetaProvider.provideDBMeta(_foreignCQ.getTableDbName());
                    foreach (String element in splitList)
                    {
                        ForeignInfo foreignInfo = currentDBMeta.FindForeignInfo(element);
                        resource.addJoinInfo(foreignInfo);
                        currentDBMeta = foreignInfo.ForeignDBMeta;
                    }
                }
                else
                {
                    DBMeta pointDBMeta;
                    try {
                        pointDBMeta = _dbmetaProvider.provideDBMeta(pointTable);
                    } catch (DBMetaNotFoundException e) {
                        String notice = "The table for relation on fixed condition does not exist.";
                        throwIllegalFixedConditionOverRelationException(notice, pointTable, targetRelation, fixedCondition,
                                                                        e);
                        return(null); // unreachable
                    }
                    ConditionQuery referrerQuery = _localCQ.xgetReferrerQuery();
                    while (true)
                    {
                        if (referrerQuery == null) // means not found
                        {
                            break;
                        }
                        if (Srl.equalsPlain(pointDBMeta.TableDbName, referrerQuery.getTableDbName()))
                        {
                            break;
                        }
                        referrerQuery = referrerQuery.xgetReferrerQuery();
                    }
                    relationPointCQ = referrerQuery;
                    if (relationPointCQ == null)
                    {
                        String notice = "The table for relation on fixed condition was not found in the scope.";
                        throwIllegalFixedConditionOverRelationException(notice, pointTable, targetRelation, fixedCondition);
                        return(null); // unreachable
                    }
                    if (targetRelation != null)
                    {
                        columnTargetCQ = invokeColumnTargetCQ(relationPointCQ, targetRelation);
                    }
                    else
                    {
                        columnTargetCQ = relationPointCQ;
                    }
                }

                String relationVariable = relationBeginMark + relationExp + relationEndMark;
                String relationAlias    = columnTargetCQ.xgetAliasName();
                fixedCondition = replaceString(fixedCondition, relationVariable, relationAlias);

                // after case for loop
                remainder = relationEndIndex.substringRear();

                // for prevent from processing same one
                remainder = replaceString(remainder, relationVariable, relationAlias);
            }
            return(fixedCondition);
        }
        // ===================================================================================
        //                                                            Resolve Fixed InlineView
        //                                                            ========================
        public String resolveFixedInlineView(String foreignTableSqlName)
        {
            if (_inlineViewResourceMap == null || _inlineViewResourceMap.isEmpty())
            {
                return(foreignTableSqlName); // not uses InlineView
            }
            // alias is required because foreignTableSqlName may be (normal) InlineView
            String                    baseAlias   = "dffixedbase";
            String                    baseIndent  = "                    ";
            StringBuilder             joinSb      = new StringBuilder();
            Map <ForeignInfo, String> relationMap = new HashMap <ForeignInfo, String>();
            List <String>             additionalRealColumnList = new ArrayList <String>();
            int groupIndex = 0;

            foreach (InlineViewResource resource in _inlineViewResourceMap.values())
            {
                List <ForeignInfo> joinInfoList    = resource.getJoinInfoList();
                String             aliasBase       = "dffixedjoin";
                String             preForeignAlias = null;
                String             foreignAlias    = null;
                int joinIndex = 0;
                foreach (ForeignInfo joinInfo in joinInfoList)
                {
                    if (relationMap.containsKey(joinInfo))           // already joined
                    {
                        preForeignAlias = relationMap.get(joinInfo); // update previous alias
                        continue;
                    }
                    String foreignTable;
                    String localAlias;
                    {
                        DBMeta foreignDBMeta = joinInfo.ForeignDBMeta;
                        foreignTable    = foreignDBMeta.TableSqlName;
                        localAlias      = (preForeignAlias != null ? preForeignAlias : baseAlias);
                        foreignAlias    = aliasBase + "_" + groupIndex + "_" + joinIndex;
                        preForeignAlias = foreignAlias;
                    }
                    joinSb.append(ln()).append(baseIndent);
                    joinSb.append("     left outer join ").append(foreignTable).append(" ").append(foreignAlias);
                    joinSb.append(" on ");
                    Map <ColumnInfo, ColumnInfo> columnInfoMap = joinInfo.LocalForeignColumnInfoMap;
                    int columnIndex = 0;
                    foreach (Entry <ColumnInfo, ColumnInfo> localForeignEntry in columnInfoMap.entrySet())
                    {
                        ColumnInfo localColumnInfo   = localForeignEntry.getKey();
                        ColumnInfo foreignColumninfo = localForeignEntry.getValue();
                        if (columnIndex > 0)
                        {
                            joinSb.append(" and ");
                        }
                        joinSb.append(localAlias).append(".").append(localColumnInfo.ColumnDbName);
                        joinSb.append(" = ").append(foreignAlias).append(".").append(foreignColumninfo.ColumnDbName);
                        ++columnIndex;
                    }
                    relationMap.put(joinInfo, foreignAlias);
                    ++joinIndex;
                }
                Set <String> additionalColumnSet = resource.getAdditionalColumnSet();
                foreach (String columnName in additionalColumnSet)
                {
                    additionalRealColumnList.add(foreignAlias + "." + columnName); // latest alias is target
                }
                ++groupIndex;
            }
            StringBuilder sqlSb = new StringBuilder();

            sqlSb.append("(select ").append(baseAlias).append(".*");
            foreach (String columnName in additionalRealColumnList)
            {
                sqlSb.append(", ").append(columnName);
            }
            sqlSb.append(ln()).append(baseIndent);
            sqlSb.append("   from ").append(foreignTableSqlName).append(" ").append(baseAlias);
            sqlSb.append(joinSb);
            sqlSb.append(ln()).append(baseIndent);
            sqlSb.append(")");
            return(sqlSb.toString());
        }