Ejemplo n.º 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());
        }
Ejemplo n.º 2
0
        internal virtual String SerializeInsert(ISerializableObject iso, string table)
        {
            AttributeWorker w      = AttributeWorker.GetInstance(Target);
            StringBuilder   sql    = new StringBuilder();
            StringBuilder   values = new StringBuilder();

            sql.Append("INSERT INTO ").Append(table);
            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());
        }
Ejemplo n.º 3
0
        internal static String ComputeHashCode(String target, ISerializableObject iso)
        {
            AttributeWorker w = AttributeWorker.GetInstance(target);

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

            StringBuilder b = new StringBuilder();

            foreach (FieldInfo fi in fis)
            {
                if (w.IsPersistentField(fi) && !w.IsID(fi))
                {
                    Object val = fi.GetValue(iso);
                    b.Append(val);
                }
            }

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            Byte[] tmp = encoding.GetBytes(b.ToString());


            return(BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(tmp)).Replace("-", "").ToLower());
        }
Ejemplo n.º 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());
        }