Пример #1
0
        object GetFieldValue(SoodaObject obj, FieldInfo fi, bool isPrecommit)
        {
            object val = obj.GetFieldValue(fi.ClassUnifiedOrdinal);

            if (!fi.IsNullable && SqlBuilder.IsNullValue(val, fi))
            {
                if (!isPrecommit)
                {
                    throw new SoodaDatabaseException(obj.GetObjectKeyString() + "." + fi.Name + " cannot be null on commit.");
                }
                val = fi.PrecommitTypedValue;
                if (val == null)
                {
                    throw new SoodaDatabaseException(obj.GetObjectKeyString() + "." + fi.Name + " is null on precommit and no 'precommitValue' has been defined for it.");
                }
                if (val == SchemaInfo.NullPrecommitValue)
                {
                    val = null;
                }
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("Using precommit value of {0} for {1}.{2}", val, fi.Table.NameToken, fi.Name);
                }
            }
            return(val);
        }
Пример #2
0
        void DoInsertsForTable(SoodaObject obj, TableInfo table, bool isPrecommit)
        {
            if (table.IsDynamic && obj.GetFieldValue(table.Fields[table.Fields.Count - 1].ClassUnifiedOrdinal) == null)
            {
                // optimization: don't insert null dynamic fields
                return;
            }

            StringBuilder builder = new StringBuilder(500);

            builder.Append("insert into ");
            builder.Append(table.DBTableName);
            builder.Append('(');

            ArrayList par = new ArrayList();

            bool comma = false;

            foreach (FieldInfo fi in table.Fields)
            {
                if (fi.ReadOnly)
                {
                    continue;
                }
                if (comma)
                {
                    builder.Append(',');
                }
                comma = true;
                builder.Append(fi.DBColumnName);
            }

            builder.Append(") values (");
            comma = false;
            foreach (FieldInfo fi in table.Fields)
            {
                if (fi.ReadOnly)
                {
                    continue;
                }
                if (comma)
                {
                    builder.Append(',');
                }
                comma = true;
                object val = GetFieldValue(obj, fi, isPrecommit);
                builder.Append('{');
                builder.Append(par.Add(val));
                builder.Append(':');
                builder.Append(fi.DataType);
                builder.Append('}');
            }
            builder.Append(')');
            SqlBuilder.BuildCommandWithParameters(_updateCommand, true, builder.ToString(), par.ToArray(), false);
            FlushUpdateCommand(false);
        }
Пример #3
0
        void DoInsertsForTable(SoodaObject obj, TableInfo table, bool isPrecommit)
        {
            if (table.IsDynamic && obj.GetFieldValue(table.Fields[table.Fields.Count - 1].ClassUnifiedOrdinal) == null)
            {
                // optimization: don't insert null dynamic fields
                return;
            }

            StringBuilder builder = new StringBuilder(500);
            builder.Append("insert into ");
            builder.Append(table.DBTableName);
            builder.Append('(');

            ArrayList par = new ArrayList();

            bool comma = false;
            foreach (FieldInfo fi in table.Fields)
            {
                if (fi.ReadOnly)
                    continue;
                if (comma)
                    builder.Append(',');
                comma = true;
                builder.Append(fi.DBColumnName);
            }

            builder.Append(") values (");
            comma = false;
            foreach (FieldInfo fi in table.Fields)
            {
                if (fi.ReadOnly)
                    continue;
                if (comma)
                    builder.Append(',');
                comma = true;
                object val = GetFieldValue(obj, fi, isPrecommit);
                builder.Append('{');
                builder.Append(par.Add(val));
                builder.Append(':');
                builder.Append(fi.DataType);
                builder.Append('}');
            }
            builder.Append(')');
            SqlBuilder.BuildCommandWithParameters(_updateCommand, true, builder.ToString(), par.ToArray(), false);
            FlushUpdateCommand(false);
        }
Пример #4
0
 object GetFieldValue(SoodaObject obj, FieldInfo fi, bool isPrecommit)
 {
     object val = obj.GetFieldValue(fi.ClassUnifiedOrdinal);
     if (!fi.IsNullable && SqlBuilder.IsNullValue(val, fi))
     {
         if (!isPrecommit)
             throw new SoodaDatabaseException(obj.GetObjectKeyString() + "." + fi.Name + " cannot be null on commit.");
         val = fi.PrecommitTypedValue;
         if (val == null)
             throw new SoodaDatabaseException(obj.GetObjectKeyString() + "." + fi.Name + " is null on precommit and no 'precommitValue' has been defined for it.");
         if (val == SchemaInfo.NullPrecommitValue)
             val = null;
         if (logger.IsDebugEnabled)
         {
             logger.Debug("Using precommit value of {0} for {1}.{2}", val, fi.Table.NameToken, fi.Name);
         }
     }
     return val;
 }