public override bool ShouldCacheRelation(RelationInfo relation, ClassInfo classInfo)
 {
     if (classInfo.Cardinality == ClassCardinality.Small || classInfo.Cardinality == ClassCardinality.Medium)
         return true;
     else
         return false;
 }
        public SoodaObjectManyToManyCollection(SoodaTransaction transaction, int masterColumn, object masterValue, Type relationType, Sooda.Schema.RelationInfo relationInfo)
            : base(transaction, masterColumn == 0 ? relationInfo.GetRef1ClassInfo() : relationInfo.GetRef2ClassInfo())
        {
            this.relationInfo = relationInfo;
            this.masterValue = masterValue;
            this.masterColumn = masterColumn;
            this.relationType = relationType;

            _factory = transaction.GetFactory(classInfo);
        }
        public SoodaObjectManyToManyCollection(SoodaTransaction transaction, int masterColumn, object masterValue, Type relationType, Sooda.Schema.RelationInfo relationInfo)
            : base(transaction, masterColumn == 0 ? relationInfo.GetRef1ClassInfo() : relationInfo.GetRef2ClassInfo())
        {
            this.relationInfo = relationInfo;
            this.masterValue  = masterValue;
            this.masterColumn = masterColumn;
            this.relationType = relationType;

            _factory = transaction.GetFactory(classInfo);
        }
Пример #4
0
        internal void Resolve(SchemaInfo schemaInfo)
        {
            relationInfo = schemaInfo.FindRelationByName(Relation);
            if (relationInfo == null)
                throw new SoodaSchemaException("Relation " + Relation + " not found.");

            if (ForeignField != null)
            {
                if (relationInfo.Table.Fields[0].Name == ForeignField)
                    MasterField = 1;
                else
                    MasterField = 0;
            }
            if (MasterField == -1)
                throw new SoodaConfigException("You need to set either masterField or foreignField in <collectionManyToMany name='" + this.Name + "' />");
        }
Пример #5
0
        internal void Resolve(SchemaInfo schemaInfo)
        {
            relationInfo = schemaInfo.FindRelationByName(Relation);
            if (relationInfo == null)
            {
                throw new SoodaSchemaException("Relation " + Relation + " not found.");
            }

            if (ForeignField != null)
            {
                if (relationInfo.Table.Fields[0].Name == ForeignField)
                {
                    MasterField = 1;
                }
                else
                {
                    MasterField = 0;
                }
            }
            if (MasterField == -1)
            {
                throw new SoodaConfigException("You need to set either masterField or foreignField in <collectionManyToMany name='" + this.Name + "' />");
            }
        }
 public override bool ShouldCacheRelation(RelationInfo relation, ClassInfo classInfo)
 {
     return false;
 }
 public abstract bool ShouldCacheRelation(RelationInfo relation, ClassInfo resultClass);
 public bool GetExpirationTimeout(RelationInfo relation, ClassInfo resultClass, int itemCount, out TimeSpan expirationTimeout, out bool slidingExpiration)
 {
     expirationTimeout = _expirationTimeout;
     slidingExpiration = _slidingExpiration;
     return true;
 }
Пример #9
0
        public void GenerateRelationStub(CodeNamespace nspace, RelationInfo ri)
        {
            CodeDomListRelationTableGenerator gen = new CodeDomListRelationTableGenerator(ri);

            // public class RELATION_NAME_RelationTable : SoodaRelationTable
            CodeTypeDeclaration ctd = new CodeTypeDeclaration(ri.Name + "_RelationTable");
            ctd.BaseTypes.Add("SoodaRelationTable");
            nspace.Types.Add(ctd);

            // public RELATION_NAME_RelationTable() : base("RELATION_TABLE_NAME","LEFT_COLUMN_NAME","RIGHT_COLUMN_NAME") { }
            ctd.Members.Add(gen.Constructor_1());
            ctd.Members.Add(gen.Method_DeserializeTupleLeft());
            ctd.Members.Add(gen.Method_DeserializeTupleRight());

            CodeMemberField field;

            field = new CodeMemberField("Sooda.Schema.RelationInfo", "theRelationInfo");
            field.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            field.InitExpression =
                new CodeMethodInvokeExpression(
                new CodeMethodInvokeExpression(
                new CodeTypeReferenceExpression(Project.OutputNamespace.Replace(".", "") + "." + "_DatabaseSchema"), "GetSchema"), "FindRelationByName",
                new CodePrimitiveExpression(ri.Name));

            ctd.Members.Add(field);

            //public class RELATION_NAME_L_List : RELATION_NAME_Rel_List, LEFT_COLUMN_REF_TYPEList, ISoodaObjectList

            //OutputRelationHalfTable(nspace, "L", relationName, leftColumnName, leftColumnType, ref1ClassInfo, Project);
            //OutputRelationHalfTable(nspace, "R", relationName, rightColumnName, rightColumnType, ref2ClassInfo, Project);
        }
 public CodeDomListRelationTableGenerator(RelationInfo ri)
 {
     this.relationInfo = ri;
 }
Пример #11
0
        private void AutoDetectRelations(SchemaInfo si)
        {
            foreach (ClassInfo ci in new ArrayList(si.Classes))
            {
                if (ci.LocalTables[0].Fields.Count != 2)
                    continue;

                if (!(ci.LocalTables[0].Fields[0].IsPrimaryKey && ci.LocalTables[0].Fields[1].IsPrimaryKey))
                    continue;

                if (ci.LocalTables[0].Fields[0].References == null || ci.LocalTables[0].Fields[1].References == null)
                    continue;

                RelationInfo ri = new RelationInfo();
                ri.Name = ci.Name;
                ri.Table.DBTableName = ci.LocalTables[0].DBTableName;
                ri.Table.Fields.Add(ci.LocalTables[0].Fields[0]);
                ri.Table.Fields.Add(ci.LocalTables[0].Fields[1]);
                si.Relations.Add(ri);

                Console.WriteLine("Converting {0} to a relation", ci.Name);
                si.Classes.Remove(ci);
            }
        }
Пример #12
0
 private string GetLoadRefObjectSelectStatement(RelationInfo relationInfo, int masterColumn)
 {
     string query;
     if (cacheLoadRefObjectSelectStatement[masterColumn].TryGetValue(relationInfo, out query))
         return query;
     string soqlQuery = String.Format("select mt.{0}.* from {2} mt where mt.{1} = {{0}}",
         relationInfo.Table.Fields[masterColumn].Name,
         relationInfo.Table.Fields[1 - masterColumn].Name,
         relationInfo.Name);
     query = SoqlToSql(SoqlParser.ParseQuery(soqlQuery), relationInfo.Schema, false);
     cacheLoadRefObjectSelectStatement[masterColumn][relationInfo] = query;
     return query;
 }
Пример #13
0
        public override IDataReader LoadRefObjectList(SchemaInfo schema, RelationInfo relationInfo, int masterColumn, object masterValue, out TableInfo[] tables)
        {
            try
            {
                if (masterColumn == 0)
                    tables = relationInfo.GetRef1ClassInfo().UnifiedTables[0].ArraySingleton;
                else
                    tables = relationInfo.GetRef2ClassInfo().UnifiedTables[0].ArraySingleton;

                string query = GetLoadRefObjectSelectStatement(relationInfo, masterColumn);

                IDbCommand cmd = Connection.CreateCommand();
                try
                {
                    cmd.CommandTimeout = CommandTimeout;
                }
                catch (NotSupportedException e)
                {
                    logger.Debug("CommandTimeout not supported. {0}", e.Message);
                }

                if (Transaction != null)
                    cmd.Transaction = this.Transaction;

                SqlBuilder.BuildCommandWithParameters(cmd, false, query, new object[] { masterValue }, false);
                return TimedExecuteReader(cmd);
            }
            catch (Exception ex)
            {
                logger.Error("Exception in LoadRefObjectList: {0}", ex);
                throw;
            }
        }
Пример #14
0
 internal void PrecommitRelation(RelationInfo ri)
 {
     _precommittedClassOrRelation[ri.Name] = true;
 }
Пример #15
0
 internal bool HasBeenPrecommitted(RelationInfo ri)
 {
     return _precommittedClassOrRelation.Contains(ri.Name);
 }
 static int CompareNames(RelationInfo x, RelationInfo y)
 {
     return x.Name.CompareTo(y.Name);
 }
Пример #17
0
 public abstract IDataReader LoadRefObjectList(SchemaInfo schemaInfo, RelationInfo relationInfo, int masterColumn, object masterValue, out TableInfo[] tables);