コード例 #1
0
 public void Rollback()
 {
     NotifyObservers(ROLLBACK_MESSAGE);
     _transaction.Rollback();
     _transaction.Dispose();
     _transaction = new SerializerTransactionDummy();
 }
コード例 #2
0
        internal bool Exists(String column, Object value, String table, ISerializerTransaction transaction)
        {
            AttributeWorker w = AttributeWorker.GetInstance(Target);
            StringBuilder   b = new StringBuilder();

            b.Append("SELECT ").Append(column).Append(" FROM ").Append(table).Append(" WHERE ").Append(column).Append("=");
            b.Append(SqlUtil.SqlConvert(value));

            DbCommand com = _connection.CreateCommand();

            transaction.Guard(com);
            com.CommandText = b.ToString();
            //Console.WriteLine(com.CommandText);


            DbDataReader r = com.ExecuteReader();

            if (r.Read())
            {
                r.Close();
                return(true);
            }
            r.Close();
            return(false);
        }
コード例 #3
0
        public IList <CsvPimaryKey> GetCSVKeys(Type type, String sqlString, ISerializerTransaction transaction)
        {
            List <CsvPimaryKey> ret = new List <CsvPimaryKey>();


            if (this._ipro != null)
            {
                this._ipro.InternalTotal = this.count(type, sqlString);
            }
            DbDataReader reader = CreateDataReader(type, sqlString, transaction);

            while (reader.Read())
            {
                CsvPimaryKey key = new CsvPimaryKey(type, reader, Target);
                ret.Add(key);

                if (this._ipro != null)
                {
                    this._ipro.advance();
                    if (this._ipro.IsCancelRequested)
                    {
                        break;
                    }
                }
            }

            reader.Close();
            return(ret);
        }
コード例 #4
0
 public void Commit()
 {
     NotifyObservers(COMMIT_MESSAGE);
     _transaction.Commit();
     _transaction.Dispose();
     _transaction = new SerializerTransactionDummy();
 }
コード例 #5
0
        internal void Delete(ISerializableObject iso, ISerializerTransaction transaction)
        {
            if (!IsManaged(iso))
            {
                return;
            }



            AttributeWorker w = AttributeWorker.GetInstance(Target);


            ResolverData <ISerializableObject> data = new ResolverData <ISerializableObject>();

            data.FieldsToResolve = AttributeWorker.RetrieveAllFields(iso.GetType());
            data.HandledItem     = iso;

            DeleteHandler h = new DeleteHandler(this);
            RelationResolver <ISerializableObject> res = new RelationResolver <ISerializableObject>();

            res.Handler = h;


            h.MODE = DeleteHandler.DOWNMODE;
            res.StartRelationResolving(data);


            _objectPool.DeleteObject(iso, _connection, transaction);

            h.MODE = DeleteHandler.UPMODE;
            res.StartRelationResolving(data);
        }
コード例 #6
0
        private DbDataReader CreateDataReader(Type type, String sqlString, ISerializerTransaction transaction)
        {
            DbCommand com = _connection.CreateCommand();

            transaction.Guard(com);
            com.CommandText = sqlString;
            DbDataReader reader = com.ExecuteReader();

            return(reader);
        }
コード例 #7
0
        //Zur Erzeugung eines DataReaders ohne explizite Tabellenangabe
        private DbDataReader CreateDataReader(Type type, IRestriction restriction, ISerializerTransaction transaction)
        {
            DbCommand com = _connection.CreateCommand();

            transaction.Guard(com);
            com.CommandText = GenerateSelectString(type, restriction);
            DbDataReader reader = com.ExecuteReader();

            return(reader);
        }
コード例 #8
0
        public void InsertObject(ISerializableObject iso, DbConnection connection, ISerializerTransaction transaction)
        {
            AttributeWorker w   = AttributeWorker.GetInstance(Target);
            DbCommand       com = connection.CreateCommand();

            com.CommandText = _owner.SerializeInsert(iso);
            transaction.Guard(com);
            //Console.WriteLine(com.CommandText);
            try
            {
                //Console.WriteLine(com.ExecuteNonQuery());
                com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new SerializerException("insert failed", ex);
            }



            FieldInfo autoincField;
            Guid      g = AttributeWorker.RowGuid(iso);

            if ((autoincField = w.GetAutoincField(iso.GetType())) != null)
            {
                StringBuilder b = new StringBuilder();

                b.Append("SELECT * FROM ").Append(w.GetTableMapping(iso.GetType(), _owner.Praefix)).Append(" WHERE ");
                b.Append(w.GetColumnMapping(AttributeWorker.RowGuid(iso.GetType()))).Append("='");
                b.Append(g.ToString()).Append("'");

                com.CommandText = b.ToString();
                DbDataReader r = com.ExecuteReader();

                if (r.Read())
                {
                    Object o = r[w.GetColumnMapping(w.GetAutoincField(iso.GetType()))];
                    autoincField.SetValue(iso, o);
                }
                else
                {
                    r.Close();
                    throw new SerializerException("Insert core method failed! error unknown...");
                }

                r.Close();
            }


            GenericWeakReference <ISerializableObject> tmp = new GenericWeakReference <ISerializableObject>(iso);

            _persistentObjects[g] = tmp;
            MemoriseKeys(iso, w, tmp);
        }
コード例 #9
0
        public void BeginTransaction()
        {
            if (!(_transaction is SerializerTransactionDummy))
            {
                throw new InvalidOperationException("a transaction is already started, commit first.");
            }

            _transaction = new SerializerTransaction(_serializer.DBConnection.BeginTransaction());

            NotifyObservers(BEGIN_TRANSACTION_MESSAGE);
        }
コード例 #10
0
        internal int CountRows <T>(IRestriction restriction, ISerializerTransaction transaction) where T : ISerializableObject
        {
            DbDataReader reader = CreateDataReader(typeof(T), restriction, transaction);

            int i = 0;

            while (reader.Read())
            {
                i++;
            }
            reader.Close();
            return(i);
        }
コード例 #11
0
        internal ISerializableObject Load(Type type, IRestriction restriction, ISerializerTransaction transaction)
        {
            bool found    = false;
            bool multiple = false;
            bool isLoaded = false;


            DbDataReader        reader = CreateDataReader(type, restriction, transaction);
            ISerializableObject data   = null;

            if (reader.Read())
            {
                data  = _objectPool.RetrieveObject(type, reader, ref isLoaded);
                found = true;
            }



            if (reader.Read())
            {
                multiple = true;
            }
            reader.Close();

            if (multiple)
            {
                throw new MultipleResultException("More than one Result found for the given Restriction ...");
            }

            if (data == null)
            {
                return(null);
            }

            bool doRelationLoading = found && isLoaded;//Gesucht: Kriterium wann das wirklich benötigt wird. Benötige ich  bei der Synchronisation die Relationen?


            if (doRelationLoading)
            {
                ResolverData <ISerializableObject> rData = new ResolverData <ISerializableObject>();
                rData.HandledItem     = data;
                rData.FieldsToResolve = AttributeWorker.RetrieveAllFields(data.GetType());

                LoadHandler handler = new LoadHandler(this);
                RelationResolver <ISerializableObject> res = new RelationResolver <ISerializableObject>();
                res.Handler = handler;
                res.StartRelationResolving(rData);
            }

            return(data);
        }
コード例 #12
0
        internal T Load <T>(IRestriction restriction, int readerPosition, ISerializerTransaction transaction) where T : ISerializableObject
        {
            if (readerPosition < 0)
            {
                throw new ArgumentOutOfRangeException("The passed reader position is less than 0.");
            }


            bool found    = false;
            bool isLoaded = false;


            DbDataReader reader = CreateDataReader(typeof(T), restriction, transaction);
            T            data   = default(T);



            for (int i = 0; i <= readerPosition; i++)
            {
                if (!reader.Read())
                {
                    reader.Close();
                    throw new ArgumentOutOfRangeException("The passed reader position is too big.");
                }
            }

            data  = (T)_objectPool.RetrieveObject(typeof(T), reader, ref isLoaded);
            found = true;
            reader.Close();

            if (data == null)
            {
                return(default(T));
            }

            bool doRelationLoading = found && isLoaded;

            if (doRelationLoading)
            {
                ResolverData <ISerializableObject> rData = new ResolverData <ISerializableObject>();
                rData.HandledItem     = data;
                rData.FieldsToResolve = AttributeWorker.RetrieveAllFields(data.GetType());

                LoadHandler handler = new LoadHandler(this);
                RelationResolver <ISerializableObject> res = new RelationResolver <ISerializableObject>();
                res.Handler = handler;
                res.StartRelationResolving(rData);
            }

            return(data);
        }
コード例 #13
0
        internal void UpdatePlain(ISerializableObject iso, ISerializerTransaction transaction)
        {
            UpdateStates state = _objectPool.UpdateObject(iso, _connection, transaction);

            if (state == UpdateStates.NO_ROWS_AFFECTED)
            {
                throw new SerializerException("entry could not be updated ...");
            }
            else if (state == UpdateStates.PRIMARYKEY_MODIFIED)
            {
                UpdateEventArgs args = new UpdateEventArgs(state);
                OnUpdateEvent(args);
            }
        }
コード例 #14
0
        internal IList <T> Select <T>(String sql, ISerializerTransaction transaction) where T : Type
        {
            List <T>  ret = new List <T>();
            DbCommand com = _connection.CreateCommand();

            com.CommandText = sql;
            DbDataReader reader = com.ExecuteReader();

            while (reader.Read())
            {
                ret.Add((T)reader[0]);
            }
            reader.Close();
            return(ret);
        }
コード例 #15
0
        public void DeleteObject(ISerializableObject iso, DbConnection connection, ISerializerTransaction transaction)
        {
            if (AttributeWorker.RowGuid(iso) == null)
            {
                throw new SerializerException();
            }

            DbCommand com = connection.CreateCommand();

            transaction.Guard(com);
            com.CommandText = _owner.Delete(iso);
            //Console.WriteLine(com.CommandText);
            //Console.WriteLine(com.ExecuteNonQuery());
            com.ExecuteNonQuery();

            _persistentObjects.Remove(AttributeWorker.RowGuid(iso));
        }
コード例 #16
0
        internal void Save(ISerializableObject iso, ISerializerTransaction transaction)
        {
            AttributeWorker w = AttributeWorker.GetInstance(Target);

            if (!IsManaged(iso))
            {
//                Console.WriteLine("SERIALIZE");
                _objectPool.InsertObject(iso, _connection, transaction);

                ResolverData <ISerializableObject> rData = new ResolverData <ISerializableObject>();
                rData.HandledItem     = iso;
                rData.FieldsToResolve = AttributeWorker.RetrieveAllFields(iso.GetType());

                LoadHandler handler = new LoadHandler(this);
                RelationResolver <ISerializableObject> res = new RelationResolver <ISerializableObject>();
                res.Handler = handler;
                res.StartRelationResolving(rData);
            }
            else
            {
//                Console.WriteLine("UPDATE");
                UpdateStates state = _objectPool.UpdateObject(iso, _connection, transaction);

                if (state == UpdateStates.NO_ROWS_AFFECTED)
                {
                    throw new SerializerException("entry could not be updated ...");
                }
                else if (state == UpdateStates.PRIMARYKEY_MODIFIED)
                {
                    UpdateEventArgs args = new UpdateEventArgs(state);
                    OnUpdateEvent(args);
                }

                ResolverData <ISerializableObject> data = new ResolverData <ISerializableObject>();
                data.HandledItem     = iso;
                data.FieldsToResolve = AttributeWorker.RetrieveAllFields(iso.GetType());

                RelationResolver <ISerializableObject> res = new RelationResolver <ISerializableObject>();
                res.Handler = new UpdateHandler(this);
                res.StartRelationResolving(data);
            }
        }
コード例 #17
0
 internal void Truncate(string table, ISerializerTransaction transaction)
 {
     //To Fill
 }
コード例 #18
0
        internal IList <String> selectWhatFromWhere <String>(string what, string from, string where, string value, ISerializerTransaction transaction)
        {
            List <String> ret = new List <String>();
            StringBuilder sb  = new StringBuilder();

            sb.Append("Select ").Append(what).Append(" From ").Append(from).Append(" WHERE ");
            if (value != null)
            {
                sb.Append(where).Append("='").Append(value).Append("'");
            }
            else
            {
                sb.Append(where).Append(" is NULL");
            }
            try
            {
                DbCommand com = _connection.CreateCommand();
                com.CommandText = sb.ToString();
                DbDataReader reader = com.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        ret.Add((String)reader[what]);
                    }
                    reader.Close();
                }
                catch (IndexOutOfRangeException)
                {
                    while (reader.Read())
                    {
                        ret.Add((String)reader[0]);
                    }
                    reader.Close();
                }
            }
            catch (Exception)
            {
                return(new List <String>());
            }

            return(ret);
        }
コード例 #19
0
 internal Connector(Serializer serializer)
 {
     _serializer  = serializer;
     _delegate    = new ObservableDelegate(this);
     _transaction = new SerializerTransactionDummy();
 }
コード例 #20
0
        public UpdateStates UpdateObject(ISerializableObject iso, DbConnection connection, ISerializerTransaction transaction)
        {
            UpdateStates    state = UpdateStates.UPDATED;
            AttributeWorker w     = AttributeWorker.GetInstance(Target);
            DbCommand       com   = connection.CreateCommand();
            Guid            g     = AttributeWorker.RowGuid(iso);
            GenericWeakReference <ISerializableObject> tmp;

            try
            {
                tmp = _persistentObjects[g];
            }
            catch (KeyNotFoundException ex)
            {
                throw new UpdateException("update failed. object is not known by the system and must be loaded first", ex);
            }
            com.CommandText = _owner.SerializeUpdate(iso, ref state, tmp);
            transaction.Guard(com);
            //Console.WriteLine(com.CommandText);
            try
            {
                if (com.ExecuteNonQuery() < 1)
                {
                    state = UpdateStates.NO_ROWS_AFFECTED;
                    return(state);
                }
                return(state);
            }
            catch (Exception ex)
            {
                throw new SerializerException("update failed", ex);
            }
        }
コード例 #21
0
        internal IList <ISerializableObject> LoadList(Type type, String sqlString, ISerializerTransaction transaction)
        {
            IList <CsvPimaryKey> tmp = GetCSVKeys(type, sqlString, transaction);

            return(new ListImpl <ISerializableObject>(this, tmp, type));
        }
        public void DeleteObject(ISerializableObject iso, DbConnection connection, ISerializerTransaction transaction)
        {
            if (AttributeWorker.RowGuid(iso) == null) throw new SerializerException();

            DbCommand com = connection.CreateCommand();
            transaction.Guard(com);
            com.CommandText = _owner.Delete(iso);
            //Console.WriteLine(com.CommandText);
            //Console.WriteLine(com.ExecuteNonQuery());
            com.ExecuteNonQuery();

            _persistentObjects.Remove(AttributeWorker.RowGuid(iso));
        }
        public UpdateStates UpdateObject(ISerializableObject iso, DbConnection connection, ISerializerTransaction transaction)
        {

            UpdateStates state = UpdateStates.UPDATED;
            AttributeWorker w = AttributeWorker.GetInstance(Target);
            DbCommand com = connection.CreateCommand();
            Guid g = AttributeWorker.RowGuid(iso);
            GenericWeakReference<ISerializableObject> tmp;
            try
            {
                tmp = _persistentObjects[g];
            }
            catch (KeyNotFoundException ex)
            {
                throw new UpdateException("update failed. object is not known by the system and must be loaded first", ex);
            }
            com.CommandText = _owner.SerializeUpdate(iso, ref state,tmp);
            transaction.Guard(com);
            //Console.WriteLine(com.CommandText);
            try
            {
                if (com.ExecuteNonQuery() < 1)
                {
                    state = UpdateStates.NO_ROWS_AFFECTED;
                    return state;
                }
                return state;
            }
            catch (Exception ex)
            {
                throw new SerializerException("update failed", ex);
            }
        }
        public void InsertObject(ISerializableObject iso, DbConnection connection, ISerializerTransaction transaction, string table)
        {
            AttributeWorker w = AttributeWorker.GetInstance(Target);
            DbCommand com = connection.CreateCommand();
            com.CommandText = _owner.SerializeInsert(iso,table);
            transaction.Guard(com);
            //Console.WriteLine(com.CommandText);
            try
            {
                //Console.WriteLine(com.ExecuteNonQuery());
                com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new SerializerException("insert failed", ex);
            }




            FieldInfo autoincField;
            Guid g = AttributeWorker.RowGuid(iso);

            if ((autoincField = w.GetAutoincField(iso.GetType())) != null)
            {
                StringBuilder b = new StringBuilder();

                b.Append("SELECT * FROM ").Append(w.GetTableMapping(iso.GetType(),_owner.Praefix)).Append(" WHERE ");
                b.Append(w.GetColumnMapping(AttributeWorker.RowGuid(iso.GetType()))).Append("='");
                b.Append(g.ToString()).Append("'");

                com.CommandText = b.ToString();
                DbDataReader r = com.ExecuteReader();

                if (r.Read())
                {
                    Object o = r[w.GetColumnMapping(w.GetAutoincField(iso.GetType()))];
                    autoincField.SetValue(iso, o);
                }
                else
                {
                    r.Close();
                    throw new SerializerException("Insert core method failed! error unknown...");
                }

                r.Close();

                /*com.CommandText = "SELECT @@IDENTITY";
                    Object o = com.ExecuteScalar();
                    Console.WriteLine("---->"+o);
                    if (o is DBNull)
                    {
                        throw new SerializerException();
                    }
                    
                    autoincField.SetValue(iso, Decimal.ToInt32((Decimal)o));
                 */


            }


            GenericWeakReference<ISerializableObject> tmp = new GenericWeakReference<ISerializableObject>(iso);
            _persistentObjects[g] = tmp;
            MemoriseKeys(iso, w, tmp);
        }
コード例 #25
0
        public IList <CsvPimaryKey> GetCSVKeys(Type type, string tableName, IRestriction restriction, ISerializerTransaction transaction)
        {
            string select = GenerateSelectString(type, tableName, restriction);

            return(GetCSVKeys(type, select, transaction));
        }
コード例 #26
0
        //Erlaubt es zur Laufzeit eine Klasse auf eine Tabelle zu mappen, welche einen anderen Namen hat als die zugehörige Klasse.
        internal IList <ISerializableObject> LoadList(Type type, string tableName, IRestriction restriction, ISerializerTransaction transaction)
        {
            IList <CsvPimaryKey> tmp = GetCSVKeys(type, tableName, restriction, transaction);

            return(new ListImpl <ISerializableObject>(this, tmp, type, tableName));
        }
コード例 #27
0
        internal IList <T> LoadList <T>(String sqlString, ISerializerTransaction transaction) where T : ISerializableObject
        {
            IList <CsvPimaryKey> tmp = GetCSVKeys(typeof(T), sqlString, transaction);

            return(new ListImpl <T>(this, tmp, typeof(T)));
        }
コード例 #28
0
 internal void InsertPlain(ISerializableObject iso, ISerializerTransaction transaction, string table)
 {
     _objectPool.InsertObject(iso, _connection, transaction, table);
 }
コード例 #29
0
        internal IList <T> LoadList <T>(IRestriction restriction, ISerializerTransaction transaction, string table) where T : ISerializableObject
        {
            IList <CsvPimaryKey> tmp = GetCSVKeys(typeof(T), table, restriction, transaction);

            return(new ListImpl <T>(this, tmp, typeof(T), table));
        }