Exemple #1
0
        public SqlTransaction Persist(Queue <object[]> persistableObjects, Dictionary <string, object> contextualParameters)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            connection.Open();
            SqlTransaction transaction = connection.BeginTransaction();

            try
            {
                while (persistableObjects.Count > 0)
                {
                    object[] persistableObject = persistableObjects.Dequeue();
                    var      pos = from po in persistenceOperators
                                   where po.Name == (string)persistableObject[1]
                                   select po;
                    PersistenceOperator targetPO = pos.ElementAt(0);
                    targetPO.AttachedTransaction = transaction;
                    if (targetPO.Persist(persistableObject[0], contextualParameters) == 0)
                    {
                        try
                        {
                            transaction.Rollback();
                        }
                        catch (Exception)
                        {
                        }
                        throw new Exception(string.Format("A {0} couldnot be persisted", targetPO.SourceObjectName));
                    }
                }
                return(transaction);
                //transaction.Commit();
            }
            catch (Exception ex)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception ex2)
                {
                    throw ex2;
                }
                throw (ex);
            }
            finally
            {
                //transaction.Dispose();
                //connection.Close();
            }
        }
Exemple #2
0
 public SqlTransaction Persist(Queue <object> persistableObjects, Dictionary <string, object> contextualParameters, SqlTransaction transaction)
 {
     try
     {
         while (persistableObjects.Count > 0)
         {
             object persistableObject = persistableObjects.Dequeue();
             var    pos = from po in persistenceOperators
                          where po.SourceObjectName == persistableObject.GetType().FullName
                          select po;
             PersistenceOperator targetPO = pos.ElementAt(0);
             targetPO.AttachedTransaction = transaction;
             if (targetPO.Persist(persistableObject, contextualParameters) == 0)
             {
                 try
                 {
                     transaction.Rollback();
                 }
                 catch (Exception)
                 {
                 }
                 throw new Exception(string.Format("A {0} couldnot be persisted", targetPO.SourceObjectName));
             }
         }
         return(transaction);
         //transaction.Commit();
     }
     catch (Exception ex)
     {
         try
         {
             transaction.Rollback();
         }
         catch (Exception ex2)
         {
             throw ex2;
         }
         throw (ex);
     }
 }