Exemplo n.º 1
0
        public List <TDataObject> Query <TDataObject>([CanBeNull] IDBPredicate cond)
            where TDataObject : IDataObject, new()
        {
            using (var scope = DBScope("Custom query for " + typeof(TDataObject)))
            {
                using (var c = scope.Connection.CreateCommand())
                {
                    var sc = new SqlSerializationContext(c);
                    DataObjectInfo <TDataObject> .AppendQuerySql(sc, cond);

                    sc.Finish();
                    using (var r = c.LexExecuteReader())
                    {
                        var res = DataObjectInfo <TDataObject> .FullRead(r, 1);

                        if (typeof(TDataObject).GetInterface(typeof(IIntKeyedDataObject).Name) != null)
                        {
                            // TODO: Cache them
//                            foreach (var i in res)
//                            {
//                                CacheIt<TDataObject>(i as IIntKeyedDataObject);
//                            }
                        }
                        return(res);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public TDataObject QuerySingleOrDefault <TDataObject>([NotNull] IDBPredicate cond)
            where TDataObject : IDataObject, new()
        {
            using (var scope = DBScope("Custom query for " + typeof(TDataObject)))
            {
                using (var c = scope.Connection.CreateCommand())
                {
                    var sc = new SqlSerializationContext(c);
                    DataObjectInfo <TDataObject> .AppendQuerySql(sc, cond);

                    sc.Finish();
                    using (var r = c.ExecuteReader())
                    {
                        if (r.Read())
                        {
                            if (r.Read())
                            {
                                throw new InvalidOperationException("Too many objects");
                            }
                            return(DataObjectInfo <TDataObject> .Read(r));
                        }
                        return(default(TDataObject));
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static void AppendQuerySql([NotNull] SqlSerializationContext context, [CanBeNull] IDBPredicate cond)
 {
     context.Write(SelectSql);
     cond = cond != null ? new AndCondtion(AliveRecordsFilter, cond) : AliveRecordsFilter;
     context.Write(" WHERE ");
     cond.Write(context);
 }
Exemplo n.º 4
0
 public UpdateOperation(IDBPredicate condition, params IDBPropertyAssignementBase[] assignements)
 {
     if (assignements == null || assignements.Length == 0)
     {
         throw new ArgumentNullException("assignements");
     }
     _Assignements = assignements;
     _Condition    = condition;
 }
Exemplo n.º 5
0
        private static AndCondition GetQueryForObject(SECURED_OBJECT_TYPE objectType, int objectID, int?operationID, DateTime?targetDate)
        {
            var name = objectType.GetSecurityAtr().Name;

            var conds = new IDBPredicate[operationID != null ? 3 : 2];

            conds[0] = new CompareCondition <int>(new PropertyCondition <int>(name + "Ref"), new ValueCondition <int>(objectID), COMPARE_KIND.EQUAL);
            conds[1] = new DateTimeBetweenCondition(new ValueCondition <DateTime>(targetDate ?? DateTime.Now), DataObject.Schema.DateSince, DataObject.Schema.DateTill);
            if (operationID != null)
            {
                conds[2] = new CompareCondition <int>(new PropertyCondition <int>(name + "OperationRef"), new ValueCondition <int>(operationID.Value), COMPARE_KIND.EQUAL);
            }
            return(new AndCondition(conds));
        }
Exemplo n.º 6
0
 public void Append(IDBPredicate cond)
 {
     _Conds.Add(cond);
 }
Exemplo n.º 7
0
 public SubSelectCondition(string[] fieldNames, IDBPredicate cond)
 {
     FieldNames = fieldNames;
     Condition  = cond;
 }
Exemplo n.º 8
0
 public SubSelectCondition(string fieldName, IDBPredicate cond)
     : this(new[] { fieldName }, cond)
 {
 }
Exemplo n.º 9
0
        public static void AppendLookupSql([NotNull] SqlSerializationContext context, [NotNull] IIntKeyedDataObject owner, [NotNull] Type detailType, [CanBeNull] IDBPredicate condition)
        {
            var r = Get(__Infos, owner.GetType(), detailType);

            if (r.IsEmpty)
            {
                throw new DMError("Couldnt found relation between {0} and {1}", owner.GetType(), detailType);
            }
            if (owner.ID <= 0)
            {
                throw new DMError("{0} has invalid ID = {1}", owner.GetType().Name, owner.ID);
            }

            context.Write("SELECT ID FROM [{0}] where ([{1}] = {2}) and sysState = 0", r.TableName, r.RefColumnName, context.AddParameter(owner.ID));
            if (condition != null)
            {
                context.Write(" AND (");
                condition.Write(context);
                context.Write(")");
            }
        }
Exemplo n.º 10
0
 public List <int> LookupMany2ManyIds <TDataObject>([NotNull] IIntKeyedDataObject firstPart, [CanBeNull] IDBPredicate condition)
 {
     using (var scope = DBScope("Looking up many-2-many ids between " + firstPart.GetType().Name + " and " + typeof(TDataObject).Name))
     {
         using (var c = scope.Connection.CreateCommand())
         {
             var sc = new SqlSerializationContext(c);
             LookupHelper.AppendMMLookupSql(sc, firstPart, typeof(TDataObject));
             sc.Finish();
             return(c.FullReadInts());
         }
     }
 }
Exemplo n.º 11
0
 public List <int> LookupIds <TDataObject>([NotNull] IIntKeyedDataObject owner, [CanBeNull] IDBPredicate condition)
     where TDataObject : IDataObject
 {
     using (var scope = DBScope("Looking up ids of " + owner.GetType().Name + " for " + typeof(TDataObject).Name))
     {
         using (var c = scope.Connection.CreateCommand())
         {
             var sc = new SqlSerializationContext(c);
             LookupHelper.AppendLookupSql(sc, owner, typeof(TDataObject), condition);
             sc.Finish();
             return(c.FullReadInts());
         }
     }
 }
Exemplo n.º 12
0
 public List <int> LookupMany2ManyIds <TDataObject>([NotNull] IIntKeyedDataObject firstPart, [CanBeNull] IDBPredicate condition)
 {
     using (var scope = DBScope(Translations.DatabaseModel_LookupMany2ManyIds_Looking_up_many_2_many_ids_between_ + firstPart.GetType().Name + Translations.DatabaseModel_LookupMany2ManyIds__and_ + typeof(TDataObject).Name))
     {
         using (var c = scope.Connection.CreateCommand())
         {
             var sc = new SqlSerializationContext(c);
             LookupHelper.AppendMMLookupSql(sc, firstPart, typeof(TDataObject));
             sc.Finish();
             return(c.FullReadInts());
         }
     }
 }
Exemplo n.º 13
0
 public static void AppendSelectRangeSql([NotNull] SqlSerializationContext context, int from, int to, IDBPredicate st)
 {
     context.Write(__SelectRangeSqlTemplate_1, context.AddParameter(from), context.AddParameter(to));
     if (st != null)
     {
         st.Write(context);
     }
     context.Write(Environment.NewLine);
     context.Write(__SelectRangeSqlTemplate_2);
 }