Exemple #1
0
        internal virtual String Delete(ISerializableObject iso)
        {
            AttributeWorker w   = AttributeWorker.GetInstance(Target);
            StringBuilder   sql = new StringBuilder();

            sql.Append("DELETE FROM ").Append(w.GetTableMapping(iso.GetType(), _praefix));
            sql.Append(" WHERE ");

            FieldInfo[] fis   = AttributeWorker.RetrieveAllFields(iso.GetType());
            bool        start = true;

            foreach (FieldInfo fi in fis)
            {
                if (w.IsID(fi))
                {
                    String col = w.GetColumnMapping(fi);
                    Object val = fi.GetValue(iso);

                    if (val == null)
                    {
                        throw new SerializerException("Not deletable ...");
                    }

                    if (!start)
                    {
                        sql.Append(" AND ");
                    }

                    start = false;
                    sql.Append(col).Append("=").Append(SqlUtil.SqlConvert(val));
                }
            }

            return(sql.ToString());
        }
Exemple #2
0
        //Hier Anknüpfungspunkt für Transparent
        internal virtual String SerializeInsert(ISerializableObject iso)
        {
            AttributeWorker w      = AttributeWorker.GetInstance(Target);
            StringBuilder   sql    = new StringBuilder();
            StringBuilder   values = new StringBuilder();

            sql.Append("INSERT INTO ").Append(w.GetTableMapping(iso.GetType(), _praefix));
            sql.Append(" (");

            FieldInfo[] fis = AttributeWorker.RetrieveAllFields(iso.GetType());

            bool start = true;

            foreach (FieldInfo fi in fis)
            {
                if (w.IsAutoincID(fi))
                {
                    continue;
                }

                try
                {
                    String col = w.GetColumnMapping(fi);
                    Object val = fi.GetValue(iso);



                    if (val == null && (w.IsID(fi) && !w.IsAutoincID(fi)))
                    {
                        throw new SerializerException("PRIMARY KEY FIELD NOT SET!!!!!!!!");
                    }

                    if (!start)
                    {
                        sql.Append(", ");
                        values.Append(", ");
                    }
                    else
                    {
                        start = false;
                    }

                    sql.Append(col);
                    values.Append(SqlUtil.SqlConvert(val));
                }
                catch (SerializerException) { }
            }

            sql.Append(") VALUES (");

            sql.Append(values);

            sql.Append(")");

            return(sql.ToString());
        }
Exemple #3
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);
        }
Exemple #4
0
        internal virtual String SerializeUpdate(ISerializableObject iso, ref UpdateStates state, GenericWeakReference <ISerializableObject> tmp)
        {
            AttributeWorker w   = AttributeWorker.GetInstance(Target);
            StringBuilder   sql = new StringBuilder();

            StringBuilder where = new StringBuilder();

            Guid      g = AttributeWorker.RowGuid(iso);
            FieldInfo f = AttributeWorker.RowGuid(iso.GetType());

            sql.Append("UPDATE ").Append(w.GetTableMapping(iso.GetType(), _praefix));
            sql.Append(" SET ");
            where.Append(" WHERE ").Append(AttributeWorker.GetInstance(Target).GetColumnMapping(f));
            where.Append("='").Append(g).Append("'");;

            FieldInfo[] fis = AttributeWorker.RetrieveAllFields(iso.GetType());



            bool start = true;

            foreach (FieldInfo fi in fis)
            {
                try
                {
                    String col = w.GetColumnMapping(fi);
                    Object val = fi.GetValue(iso);
                    Object oldVal;


                    if (w.IsAutoincID(fi))
                    {
                        continue;
                    }
                    if (AttributeWorker.IsRowGuid(fi))
                    {
                        continue;
                    }

                    if (w.IsID(fi))
                    {
                        oldVal = tmp.Properties[fi.Name];
                        if (!Object.Equals(val, oldVal))
                        {
                            state = UpdateStates.PRIMARYKEY_MODIFIED;
                        }
                        tmp.Properties[fi.Name] = val;
                    }

                    if (!start)
                    {
                        sql.Append(", ");
                    }
                    else
                    {
                        start = false;
                    }

                    sql.Append(col).Append("=").Append(SqlUtil.SqlConvert(val));
                }
                catch (SerializerException) { }
            }

            sql.Append(where);
            return(sql.ToString());
        }