static TableInfo Prepare(FieldInfo fi)
        {
            ClassInfo ci = fi.ParentClass;
            if (ci.ContainsField(fi.Name))
                throw new SoodaSchemaException("Field " + fi.Name + " already exists in " + ci.Name);

            TableInfo table = new TableInfo();
            table.TableUsageType = TableUsageType.DynamicField;
            table.DBTableName = ci.Name + "_" + fi.Name;

            // copy primary key fields
            FieldInfo[] pks = ci.GetPrimaryKeyFields();
            for (int i = 0; i < pks.Length; i++)
            {
                FieldInfo pk = pks[i];
                table.Fields.Add(new FieldInfo {
                    Name = pk.Name,
                    DataType = pk.DataType,
                    Size = pk.Size,
                    Precision = pk.Precision,
                    References = pk.References,
                    IsPrimaryKey = true,
                    DBColumnName = i == 0 ? "id" : "id" + (i + 1) });
            }

            fi.DBColumnName = "value";
            table.Fields.Add(fi);

            return table;
        }
Exemplo n.º 2
0
        public override string GetSQLOrderBy(Sooda.Schema.FieldInfo fi, bool start)
        {
            switch (fi.DataType)
            {
            case FieldDataType.AnsiString:
                if (fi.Size > 4000)
                {
                    return(start ? "convert(varchar(3999), " : ")");
                }
                else
                {
                    return("");
                }

            case FieldDataType.String:
                if (fi.Size > 4000)
                {
                    return(start ? "convert(nvarchar(3999), " : ")");
                }
                else
                {
                    return("");
                }

            default:
                return("");
            }
        }
Exemplo n.º 3
0
 public void GenerateCreateTableField(TextWriter xtw, Sooda.Schema.FieldInfo fieldInfo)
 {
     xtw.Write('\t');
     xtw.Write(fieldInfo.DBColumnName);
     xtw.Write(' ');
     xtw.Write(GetSQLDataType(fieldInfo));
     xtw.Write(' ');
     xtw.Write(GetSQLNullable(fieldInfo));
 }
Exemplo n.º 4
0
 // for Oracle empty string is also null string
 public override bool IsNullValue(object val, Sooda.Schema.FieldInfo fi)
 {
     if (val == null)
     {
         return(true);
     }
     if (fi.DataType == FieldDataType.AnsiString || fi.DataType == FieldDataType.String)
     {
         return(((string)val).Length == 0);
     }
     return(false);
 }
Exemplo n.º 5
0
        public override string GetSQLDataType(Sooda.Schema.FieldInfo fi)
        {
            switch (fi.DataType)
            {
            case FieldDataType.Integer:
                return("int");

            case FieldDataType.String:
                return("varchar(" + fi.Size + ")");

            case FieldDataType.DateTime:
                return("datetime");

            default:
                throw new NotImplementedException(String.Format("Datatype {0} not supported for this database", fi.DataType.ToString()));
            }
        }
Exemplo n.º 6
0
        public override string GetSQLNullable(Sooda.Schema.FieldInfo fi)
        {
            switch (fi.DataType)
            {
            case FieldDataType.AnsiString:
            case FieldDataType.String:
                if (fi.Size < 4000)
                {
                    // IsNull works fine for Oracle clob, but for nvarchar2 isnull('') = true - contrary to ansi SQL-92
                    return("null");
                }
                break;

            default:
                break;
            }

            return(base.GetSQLNullable(fi));
        }
Exemplo n.º 7
0
 public virtual string GetSQLNullable(Sooda.Schema.FieldInfo fi)
 {
     if (fi.IsDynamic)
     {
         return("not null");
     }
     if (fi.IsNullable)
     {
         return("null");
     }
     if (fi.ReferencedClass == null || fi.IsPrimaryKey || fi.ParentRelation != null || fi.ReadOnly || fi.ParentClass.ReadOnly)
     {
         return("not null");
     }
     if (fi.PrecommitTypedValue == SchemaInfo.NullPrecommitValue)
     {
         return("null");
     }
     return("not null");
 }
Exemplo n.º 8
0
        public override string GetSQLOrderBy(Sooda.Schema.FieldInfo fi, bool start)
        {
            switch (fi.DataType)
            {
            case FieldDataType.AnsiString:
                if (fi.Size > 2000)
                {
                    return(start ? "cast(substr(" : ", 0, 2000) as varchar2(2000))");
                }
                return("");

            case FieldDataType.String:
                if (fi.Size > 2000)
                {
                    return(start ? "cast(substr(" : ", 0, 2000) as nvarchar2(2000))");
                }
                return("");

            default:
                return("");
            }
        }
        public static void Add(FieldInfo fi, SoodaTransaction transaction)
        {
            ClassInfo ci = fi.ParentClass;
            fi.ResolveReferences(ci.Schema);
            SqlDataSource ds = (SqlDataSource) transaction.OpenDataSource(ci.GetDataSource());

            LockCookie lockCookie = LockWrite(transaction);
            try
            {
                TableInfo table = Prepare(fi);
                fi.Table = table;

                StringWriter sw = new StringWriter();
                sw.Write("insert into SoodaDynamicField (class, field, type, nullable, fieldsize, precision) values ({0}, {1}, {2}, {3}, {4}, {5})");
                ds.ExecuteNonQuery(sw.ToString(), ci.Name, fi.Name, fi.TypeName, fi.IsNullable ? 1 : 0, NegativeToNull(fi.Size), NegativeToNull(fi.Precision));

                sw = new StringWriter();
                ds.SqlBuilder.GenerateCreateTable(sw, table, null, "");
                ds.ExecuteNonQuery(sw.ToString());

                sw = new StringWriter();
                ds.SqlBuilder.GeneratePrimaryKey(sw, table, null, "");
                ds.ExecuteNonQuery(sw.ToString());

                sw = new StringWriter();
                ds.SqlBuilder.GenerateForeignKeys(sw, table, "");
                string sql = sw.ToString();
                if (sql.Length > 0)
                    ds.ExecuteNonQuery(sql);

                ci.LocalTables.Add(table);
                Resolve(ci);
            }
            finally
            {
                transaction.Schema._rwLock.DowngradeFromWriterLock(ref lockCookie);
            }
        }
Exemplo n.º 10
0
        public void AddField(FieldInfo fi)
        {
            if (ContainsField(fi.Name))
                throw new SoodaSchemaException(String.Format("Duplicate field '{0}' found!", fi.Name));

            if (Fields == null)
                Fields = new List<FieldInfo>();

            Fields.Add(fi);
            Rehash();
        }
Exemplo n.º 11
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;
 }
        static int GetFieldRefCacheIndex(ClassInfo ci, FieldInfo fi0)
        {
            int p = 0;

            foreach (FieldInfo fi in ci.LocalFields)
            {
                if (fi == fi0)
                    return p;
                if (fi.ReferencedClass != null)
                    p++;
            }

            return -1;
        }
Exemplo n.º 13
0
        public static void Update(FieldInfo fi, SoodaTransaction transaction)
        {
            if (!fi.IsDynamic)
                throw new InvalidOperationException(fi.Name + " is not a dynamic field");
            ClassInfo ci = fi.ParentClass;
            SoodaDataSource ds = transaction.OpenDataSource(ci.GetDataSource());

            ds.ExecuteNonQuery("update SoodaDynamicField set nullable={0} where class={1} and field={2}", fi.IsNullable ? 1 : 0, ci.Name, fi.Name);
        }
Exemplo n.º 14
0
        public static void CreateIndex(FieldInfo fi, SoodaTransaction transaction)
        {
            SqlDataSource ds = (SqlDataSource) transaction.OpenDataSource(fi.ParentClass.GetDataSource());

            StringWriter sw = new StringWriter();
            ds.SqlBuilder.GenerateIndex(sw, fi, null, "");
            ds.ExecuteNonQuery(sw.ToString());
        }
Exemplo n.º 15
0
        static void Load(SoodaTransaction transaction)
        {
            SchemaInfo schema = transaction.Schema;
            HashSet<ClassInfo> affectedClasses = new HashSet<ClassInfo>();
            foreach (DataSourceInfo dsi in schema.DataSources)
            {
                if (!dsi.EnableDynamicFields)
                    continue;
                SoodaDataSource ds = transaction.OpenDataSource(dsi);
                using (IDataReader r = ds.ExecuteRawQuery("select class, field, type, nullable, fieldsize, precision from SoodaDynamicField"))
                {
                    while (r.Read())
                    {
                        string className = r.GetString(0);
                        ClassInfo ci = schema.FindClassByName(className);
                        if (ci == null)
                        {
                            logger.Warn("Ignoring a dynamic field of non-existent class {0} -- see the SoodaDynamicField table", className);
                            continue;
                        }

                        FieldInfo fi = new FieldInfo();
                        fi.ParentClass = ci;
                        fi.Name = r.GetString(1);
                        fi.TypeName = r.GetString(2);
                        fi.IsNullable = r.GetInt32(3) != 0;
                        if (!r.IsDBNull(4))
                            fi.Size = r.GetInt32(4);
                        if (!r.IsDBNull(5))
                            fi.Precision = r.GetInt32(5);

                        ci.LocalTables.Add(Prepare(fi));
                        affectedClasses.Add(ci);
                    }
                }
            }

            Resolve(schema, affectedClasses);
        }
Exemplo n.º 16
0
        internal void Resolve(SchemaInfo schema)
        {
            if (parentSchema == null)
                parentSchema = schema;

            OuterReferences = new List<FieldInfo>();

            // local fields - a sum of all tables local to the class

            LocalFields = new List<FieldInfo>();
            int localOrdinal = 0;
            int count = 0;
            foreach (TableInfo table in LocalTables)
            {
                foreach (FieldInfo fi in table.Fields)
                {
                    // add all fields from the root table + all non-key fields
                    // from other tables

                    if (table.OrdinalInClass == 0 || !fi.IsPrimaryKey)
                    {
                        // Console.WriteLine("Adding local field {0} to class {1}", fi.Name, Name);
                        LocalFields.Add(fi);
                        fi.ClassLocalOrdinal = localOrdinal++;
                    }
                }
                count++;
            }

            if (SubclassSelectorFieldName == null && InheritsFromClass != null)
            {
                for (ClassInfo ci = this; ci != null; ci = ci.InheritsFromClass)
                {
                    if (ci.SubclassSelectorFieldName != null)
                    {
                        SubclassSelectorFieldName = ci.SubclassSelectorFieldName;
                        break;
                    }
                }
            }

            UnifiedCollections = new List<CollectionBaseInfo>();
            LocalCollections = new List<CollectionBaseInfo>();
            for (ClassInfo ci = this; ci != null; ci = ci.InheritsFromClass)
            {
                if (ci.Collections1toN != null)
                {
                    foreach (CollectionOnetoManyInfo c in ci.Collections1toN)
                    {
                        UnifiedCollections.Add(c);
                        if (ci == this)
                            LocalCollections.Add(c);
                    }
                }

                if (ci.CollectionsNtoN != null)
                {
                    foreach (CollectionManyToManyInfo c in ci.CollectionsNtoN)
                    {
                        UnifiedCollections.Add(c);
                        if (ci == this)
                            LocalCollections.Add(c);
                    }
                }
            }

            // all inherited fields + local fields

            UnifiedFields = new List<FieldInfo>();

            int unifiedOrdinal = 0;
            foreach (TableInfo ti in UnifiedTables)
            {
                foreach (FieldInfo fi in ti.Fields)
                {
                    if (ti.OrdinalInClass == 0 || !fi.IsPrimaryKey)
                    {
                        UnifiedFields.Add(fi);
                        fi.ClassUnifiedOrdinal = unifiedOrdinal++;
                    }
                }
            }

            _orderedFieldNames = new string[UnifiedFields.Count];
            for (int i = 0; i < UnifiedFields.Count; ++i)
            {
                _orderedFieldNames[i] = UnifiedFields[i].Name;
            }

            if (SubclassSelectorFieldName != null)
            {
                SubclassSelectorField = FindFieldByName(SubclassSelectorFieldName);
                if (SubclassSelectorField == null)
                    throw new SoodaSchemaException("subclassSelectorField points to invalid field name " + SubclassSelectorFieldName + " in " + Name);
            }
            else if (InheritFrom != null)
            {
                throw new SoodaSchemaException(String.Format("Must use subclassSelectorFieldName when defining inherited class '{0}'", this.Name));
            }
            if (SubclassSelectorStringValue != null)
            {
                // TODO - allow other types based on the field type
                //
                if (SubclassSelectorField == null)
                    throw new SoodaSchemaException("subclassSelectorField is invalid");
                switch (SubclassSelectorField.DataType)
                {
                    case FieldDataType.Integer:
                        SubclassSelectorValue = Convert.ToInt32(SubclassSelectorStringValue);
                        break;

                    case FieldDataType.String:
                        SubclassSelectorValue = SubclassSelectorStringValue;
                        break;

                    default:
                        throw new SoodaSchemaException("Field data type not supported for subclassSelectorValue: " + SubclassSelectorField.DataType);
                }
            }

            List<FieldInfo> pkFields = new List<FieldInfo>();
            foreach (FieldInfo fi in UnifiedFields)
            {
                if (fi.IsPrimaryKey)
                    pkFields.Add(fi);
            }
            _primaryKeyFields = pkFields.ToArray();
        }
Exemplo n.º 17
0
 public abstract string GetSQLDataType(Sooda.Schema.FieldInfo fi);
Exemplo n.º 18
0
 public abstract string GetSQLOrderBy(Sooda.Schema.FieldInfo fi, bool start);
Exemplo n.º 19
0
 private void UpdateFieldFromDbSchema(TableInfo ti, FieldInfo fi, SchemaInfo dbSchema)
 {
     FieldInfo dbfi = FindDBColumnInfo(dbSchema, ti.DBTableName, fi.DBColumnName);
     if (dbfi == null)
     {
         Console.WriteLine("WARNING. FIELD NOT FOUND IN DB: " + ti.DBTableName + "," + fi.DBColumnName);
         return;
     }
     if (UpdateTypes)
         fi.DataType = dbfi.DataType;
     if (UpdateSizes)
         fi.Size = dbfi.Size;
     if (UpdateNullable)
         fi.IsNullable = dbfi.IsNullable;
     if (UpdatePrimaryKeys)
         fi.IsPrimaryKey = dbfi.IsPrimaryKey;
 }
Exemplo n.º 20
0
 internal void Merge(FieldInfo merge)
 {
     this.DataType = merge.DataType;
     if (merge.Description != null)
         this.Description = (this.Description != null ? this.Description + "\n" : "") + merge.Description;
     if (merge.Size != -1)
         this.Size = merge.Size;
     if (merge.Precision != -1)
         this.Precision = merge.Size;
     if (merge.References != null)
         this.References = merge.References;
     if (merge.PrecommitValue != null)
         this.PrecommitValue = merge.PrecommitValue;
     this.IsPrimaryKey = merge.IsPrimaryKey;
     this.IsNullable = merge.IsNullable;
     this.ReadOnly = merge.ReadOnly;
     this.ForceTrigger = merge.ForceTrigger;
     this.DeleteAction = merge.DeleteAction;
     this.IsLabel = merge.IsLabel;
     this.PrefetchLevel = merge.PrefetchLevel;
     this.FindMethod = merge.FindMethod;
     this.FindListMethod = merge.FindListMethod;
     if (merge.dbcolumn != null)
         this.DBColumnName = merge.dbcolumn;
 }
Exemplo n.º 21
0
        public FieldInfo DoClone()
        {
            FieldInfo fi = new FieldInfo();

            fi.Name = this.Name;
            fi.dbcolumn = this.dbcolumn;
            fi.IsNullable = this.IsNullable;
            fi.DataType = this.DataType;
            fi.Size = this.Size;
            fi.ForceTrigger = this.ForceTrigger;
            fi.ReadOnly = this.ReadOnly;

            return fi;
        }
Exemplo n.º 22
0
        private void DumpTable(SchemaInfo schemaInfo, string owner, string table)
        {
            Console.WriteLine("Dumping table {0}.{1}", owner, table);

            ClassInfo ci = new ClassInfo();
            ci.Name = MakePascalCase(table);

            TableInfo ti = new TableInfo();
            ci.LocalTables = new List<TableInfo>();
            ti.DBTableName = table;
            ci.LocalTables.Add(ti);

            foreach (DataRow r in dataSet.Tables["Columns"].Select("TABLE_NAME='" + table + "' and TABLE_OWNER='" + owner + "'", "ORDINAL_POSITION"))
            {
                try
                {
                    string columnName = r["COLUMN_NAME"].ToString();

                    FieldInfo fi = new FieldInfo();
                    fi.Name = MakePascalCase(columnName);
                    fi.DBColumnName = columnName;
                    GetSoodaFieldAttributes(fi, r, false);
                    ti.Fields.Add(fi);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("WARNING: {0}", ex.Message);
                }
            }

            bool hasPrimaryKey = false;

            foreach (DataRow r in dataSet.Tables["PrimaryKeys"].Select("TABLE_NAME='" + table + "' and TABLE_OWNER='" + owner + "'"))
            {
                string column = Convert.ToString(r["COLUMN_NAME"]);
                foreach (FieldInfo fi in ti.Fields)
                {
                    if (0 == String.Compare(fi.DBColumnName, column, true))
                    {
                        fi.IsPrimaryKey = true;
                        hasPrimaryKey = true;
                    }
                }
            }
            if (!hasPrimaryKey)
            {
                Console.WriteLine("WARNING: Created artificial primary key from the first column of the " + ti.DBTableName + " table. This may be incorrect.");
                ti.Fields[0].IsPrimaryKey = true;
            }
            schemaInfo.Classes.Add(ci);
        }
Exemplo n.º 23
0
        public static void Remove(FieldInfo fi, SoodaTransaction transaction)
        {
            if (!fi.IsDynamic)
                throw new InvalidOperationException(fi.Name + " is not a dynamic field");
            ClassInfo ci = fi.ParentClass;
            SoodaDataSource ds = transaction.OpenDataSource(ci.GetDataSource());

            LockCookie lockCookie = LockWrite(transaction);
            try
            {
                ds.ExecuteNonQuery("delete from SoodaDynamicField where class={0} and field={1}", ci.Name, fi.Name);
                ds.ExecuteNonQuery("drop table " + fi.Table.DBTableName);

                ci.LocalTables.Remove(fi.Table);
                Resolve(ci);
            }
            finally
            {
                transaction.Schema._rwLock.DowngradeFromWriterLock(ref lockCookie);
            }
        }
Exemplo n.º 24
0
        private void GetSoodaFieldAttributes(FieldInfo fi, DataRow r, bool recursive)
        {
            string typeName = r["TYPE_NAME"].ToString();

            switch (typeName)
            {
                case "int":
                case "smallint":
                case "tinyint":
                    fi.DataType = FieldDataType.Integer;
                    break;

                case "int identity":
                case "tinyint identity":
                case "smallint identity":
                    fi.DataType = FieldDataType.Integer;
                    _haveIdentityColumns = true;
                    break;

                case "char":
                case "varchar":
                    fi.DataType = FieldDataType.AnsiString;
                    fi.Size = Convert.ToInt32(r["PRECISION"]);
                    break;

                case "text":
                    fi.DataType = FieldDataType.AnsiString;
                    fi.Size = unchecked((1 << 31) - 1);
                    break;

                case "ntext":
                    fi.DataType = FieldDataType.String;
                    fi.Size = unchecked((1 << 31) - 1);
                    break;

                case "nchar":
                case "nvarchar":
                    fi.DataType = FieldDataType.String;
                    fi.Size = Convert.ToInt32(r["PRECISION"]);
                    break;

                case "datetime":
                    fi.DataType = FieldDataType.DateTime;
                    break;

                case "smallmoney":
                case "money":
                case "decimal":
                    fi.DataType = FieldDataType.Decimal;
                    break;

                case "float":
                case "numeric":
                case "real":
                    fi.DataType = FieldDataType.Double;
                    break;

                case "bigint":
                    fi.DataType = FieldDataType.Long;
                    break;

                case "image":
                    fi.DataType = FieldDataType.Image;
                    break;

                case "binary":
                case "varbinary":
                case "blob":
                    fi.DataType = FieldDataType.Blob;
                    break;

                case "bit":
                    fi.DataType = FieldDataType.Boolean;
                    break;

                case "uniqueidentifier":
                    fi.DataType = FieldDataType.Guid;
                    break;

                default:
                    if (recursive)
                        throw new Exception("Unable to determine the base type for " + typeName);

                    DataRow[] udt = dataSet.Tables["DataTypes"].Select("DATA_TYPE='" + r["DATA_TYPE"] + "' and USERTYPE < 256");
                    if (udt.Length < 1)
                        throw new Exception("Unsupported data type: " + typeName);
                    GetSoodaFieldAttributes(fi, udt[0], true);
                    break;
            }
            fi.IsNullable = (Convert.ToInt32(r["NULLABLE"]) != 0);
        }
 public CodeMemberMethod Method_TriggerFieldUpdate(FieldInfo fi, string methodPrefix)
 {
     CodeMemberMethod method = new CodeMemberMethod();
     method.Name = methodPrefix + "_" + fi.Name;
     if (fi.References != null)
     {
         method.Parameters.Add(new CodeParameterDeclarationExpression(fi.References, "oldValue"));
         method.Parameters.Add(new CodeParameterDeclarationExpression(fi.References, "newValue"));
     }
     else
     {
         method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "oldValue"));
         method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "newValue"));
     }
     method.Attributes = MemberAttributes.Family;
     method.Statements.Add(new CodeMethodInvokeExpression(This, methodPrefix, new CodePrimitiveExpression(fi.Name), Arg("oldValue"), Arg("newValue")));
     return method;
 }
Exemplo n.º 26
0
 public void GenerateIndex(TextWriter xtw, FieldInfo fi, string additionalSettings, string terminator)
 {
     string table = fi.Table.DBTableName;
     xtw.Write("create index {0} on {1} ({2})", GetIndexName(table, fi.DBColumnName), table, fi.DBColumnName);
     TerminateDDL(xtw, additionalSettings, terminator);
 }
 static CodeExpression GetFieldIsNullExpression(FieldInfo fi)
 {
     return new CodeMethodInvokeExpression(
         new CodeTypeReferenceExpression(typeof(Sooda.ObjectMapper.SoodaObjectImpl)),
         "IsFieldNull",
         new CodeThisReferenceExpression(),
         new CodePrimitiveExpression(fi.Table.OrdinalInClass),
         new CodePrimitiveExpression(fi.ClassUnifiedOrdinal)
         );
 }
Exemplo n.º 28
0
        public override string GetSQLDataType(Sooda.Schema.FieldInfo fi)
        {
            switch (fi.DataType)
            {
            case FieldDataType.Integer:
                return("int");

            case FieldDataType.AnsiString:
                if (fi.Size > 4000)
                {
                    return("text");
                }
                else
                {
                    return("varchar(" + fi.Size + ")");
                }

            case FieldDataType.String:
                if (fi.Size > 4000)
                {
                    return("ntext");
                }
                else
                {
                    return("nvarchar(" + fi.Size + ")");
                }

            case FieldDataType.Decimal:
                if (fi.Size < 0)
                {
                    return("decimal");
                }
                else if (fi.Precision < 0)
                {
                    return("decimal(" + fi.Size + ")");
                }
                else
                {
                    return("decimal(" + fi.Size + "," + fi.Precision + ")");
                }

            case FieldDataType.Guid:
                return("uniqueidentifier");

            case FieldDataType.Double:
                if (fi.Size < 0)
                {
                    return("float");
                }
                else if (fi.Precision < 0)
                {
                    return("float(" + fi.Size + ")");
                }
                else
                {
                    return("float(" + fi.Size + "," + fi.Precision + ")");
                }

            case FieldDataType.Float:
                if (fi.Size < 0)
                {
                    return("float");
                }
                else if (fi.Precision < 0)
                {
                    return("float(" + fi.Size + ")");
                }
                else
                {
                    return("float(" + fi.Size + "," + fi.Precision + ")");
                }

            case FieldDataType.DateTime:
                return("datetime");

            case FieldDataType.Image:
                return("image");

            case FieldDataType.Long:
                return("bigint");

            case FieldDataType.BooleanAsInteger:
                return("int");

            case FieldDataType.TimeSpan:
                return("int");

            case FieldDataType.Boolean:
                return("bit");

            case FieldDataType.Blob:
                return("varbinary(max)");

            default:
                throw new NotImplementedException(String.Format("Datatype {0} not supported for this database", fi.DataType.ToString()));
            }
        }
        static CodeMemberMethod _SetNull(FieldInfo fi)
        {
            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "_SetNull_" + fi.Name;
            method.Attributes = MemberAttributes.Final | MemberAttributes.Public;

            method.Statements.Add(
                new CodeAssignStatement(
                GetFieldValueExpression(fi), new CodePrimitiveExpression(null)));

            return method;
        }
Exemplo n.º 30
0
 public override string GetSQLOrderBy(Sooda.Schema.FieldInfo fi, bool start)
 {
     return("");
 }
Exemplo n.º 31
0
 static void FieldEquals(FieldInfo fi, object value, StringBuilder builder, ArrayList queryParams)
 {
     builder.Append(fi.DBColumnName);
     builder.Append("={");
     builder.Append(queryParams.Add(value));
     builder.Append(':');
     builder.Append(fi.DataType);
     builder.Append('}');
 }
Exemplo n.º 32
0
 public virtual bool IsNullValue(object val, Sooda.Schema.FieldInfo fi)
 {
     return(val == null);
 }
Exemplo n.º 33
0
        void GenerateFindMethod(CodeTypeDeclaration ctd, FieldInfo fi, bool withTransaction, bool list, string type)
        {
            CodeMemberMethod findMethod = new CodeMemberMethod();
            findMethod.Name = (list ? "FindListBy" : "FindBy") + fi.Name;
            findMethod.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            findMethod.ReturnType = new CodeTypeReference(Project.OutputNamespace.Replace(".", "") + "." + fi.ParentClass.Name + (list ? "List" : ""));

            CodeExpression transaction;
            if (withTransaction)
            {
                findMethod.Parameters.Add(
                    new CodeParameterDeclarationExpression(
                    new CodeTypeReference(typeof(SoodaTransaction)), "transaction")
                    );
                transaction = new CodeArgumentReferenceExpression("transaction");
            }
            else
            {
                transaction = new CodePropertyReferenceExpression(
                    new CodeTypeReferenceExpression(typeof(SoodaTransaction)),
                    "ActiveTransaction");
            }

            findMethod.Parameters.Add(
                new CodeParameterDeclarationExpression(
                    type,
                    MakeCamelCase(fi.Name))
                    );

            CodeExpression whereClause =
                new CodeObjectCreateExpression(
                new CodeTypeReference(typeof(SoodaWhereClause)),
                new CodePrimitiveExpression(fi.Name + " = {0}"),
                new CodeArrayCreateExpression(
                   typeof(object),
                   new CodeExpression[] { new CodeArgumentReferenceExpression(MakeCamelCase(fi.Name)) })
                   );

            findMethod.Statements.Add(
                new CodeMethodReturnStatement(
                    new CodeMethodInvokeExpression(
                    null, list ? "GetList" : "LoadSingleObject",
                    transaction,
                    whereClause)));
            ctd.Members.Add(findMethod);
        }
Exemplo n.º 34
0
        public override string GetSQLDataType(Sooda.Schema.FieldInfo fi)
        {
            switch (fi.DataType)
            {
            case FieldDataType.Integer:
            case FieldDataType.BooleanAsInteger:
            case FieldDataType.TimeSpan:
            case FieldDataType.Long:
                return("integer");

            case FieldDataType.AnsiString:
                if (fi.Size >= 4000)
                {
                    return("clob");
                }
                return("varchar2(" + fi.Size + ")");

            case FieldDataType.String:
                if (fi.Size >= 2000)
                {
                    return("nclob");
                }
                return("nvarchar2(" + fi.Size + ")");

            case FieldDataType.Decimal:
                if (fi.Size < 0)
                {
                    return("number");
                }
                if (fi.Precision < 0)
                {
                    return("number(" + fi.Size + ")");
                }
                return("number(" + fi.Size + "," + fi.Precision + ")");

            case FieldDataType.Double:
            case FieldDataType.Float:
                if (fi.Size < 0)
                {
                    return("float");
                }
                if (fi.Precision < 0)
                {
                    return("float(" + fi.Size + ")");
                }
                return("float(" + fi.Size + "," + fi.Precision + ")");

            case FieldDataType.DateTime:
                return("date");

            case FieldDataType.Image:
                return("blob");

            case FieldDataType.Boolean:
                return("number(1)");

            case FieldDataType.Blob:
                return("blob");

            default:
                throw new NotImplementedException(String.Format("Datatype {0} not supported for this database", fi.DataType));
            }
        }
Exemplo n.º 35
0
 void GenerateFindMethod(CodeTypeDeclaration ctd, FieldInfo fi, bool withTransaction, bool list)
 {
     if (!Project.WithSoql)
     {
         throw new SoodaCodeGenException("'" + (list ? "findList" : "find") + "' schema attribute on field " + fi.Name
             + " in class " + fi.ParentClass.Name + " is incompatible with --no-soql");
     }
     GenerateFindMethod(ctd, fi, withTransaction, list, fi.GetNullableFieldHandler().GetFieldType().Name);
     if (fi.ReferencedClass != null)
         GenerateFindMethod(ctd, fi, withTransaction, list, fi.ReferencedClass.Name);
 }
        public CodeTypeReference GetReturnType(PrimitiveRepresentation rep, FieldInfo fi)
        {
            switch (rep)
            {
                case PrimitiveRepresentation.Boxed:
                    return new CodeTypeReference(typeof(object));

                case PrimitiveRepresentation.SqlType:
                    Type t = fi.GetNullableFieldHandler().GetSqlType();
                    if (t == null)
                        return new CodeTypeReference(fi.GetNullableFieldHandler().GetFieldType());
                    else
                        return new CodeTypeReference(t);

                case PrimitiveRepresentation.RawWithIsNull:
                case PrimitiveRepresentation.Raw:
                    return new CodeTypeReference(fi.GetNullableFieldHandler().GetFieldType());

                case PrimitiveRepresentation.Nullable:
                    return new CodeTypeReference(fi.GetNullableFieldHandler().GetNullableType());

                default:
                    throw new NotImplementedException("Unknown PrimitiveRepresentation: " + rep);
            }
        }
Exemplo n.º 37
0
 void GenerateFindMethod(CodeTypeDeclaration ctd, FieldInfo fi, bool withTransaction)
 {
     if (fi.FindMethod)
         GenerateFindMethod(ctd, fi, withTransaction, false);
     if (fi.FindListMethod)
         GenerateFindMethod(ctd, fi, withTransaction, true);
 }
        static CodeMemberProperty _IsNull(FieldInfo fi)
        {
            CodeMemberProperty prop = new CodeMemberProperty();
            prop.Name = fi.Name + "_IsNull";
            prop.Attributes = MemberAttributes.Final | MemberAttributes.Public;
            prop.Type = new CodeTypeReference(typeof(bool));

            prop.GetStatements.Add(
                new CodeMethodReturnStatement(
                GetFieldIsNullExpression(fi)));

            return prop;
        }
Exemplo n.º 39
0
 public StringCollection GetBackRefCollections(FieldInfo fi)
 {
     StringCollection collections;
     _backRefCollections.TryGetValue(fi.NameTag, out collections);
     return collections;
 }
 static CodeExpression GetFieldValueForRead(FieldInfo fi)
 {
     CodeExpression fieldValues = new CodeMethodInvokeExpression(
         new CodeThisReferenceExpression(),
         "Get" + fi.ParentClass.Name + "FieldValuesForRead",
         new CodePrimitiveExpression(fi.Table.OrdinalInClass));
     if (fi.ParentClass.GetDataSource().EnableDynamicFields)
     {
         return new CodeMethodInvokeExpression(
             fieldValues,
             "GetBoxedFieldValue",
             new CodePrimitiveExpression(fi.ClassUnifiedOrdinal));
     }
     return new CodeFieldReferenceExpression(fieldValues, fi.Name);
 }
Exemplo n.º 41
0
 internal void AddBackRefCollection(FieldInfo fi, string name)
 {
     StringCollection sc = GetBackRefCollections(fi);
     if (sc == null)
     {
         sc = new StringCollection();
         _backRefCollections[fi.NameTag] = sc;
     }
     sc.Add(name);
 }
 static CodeExpression RefCacheExpression(ClassInfo ci, FieldInfo fi)
 {
     return new CodeArrayIndexerExpression(RefCacheArray(),
         new CodePrimitiveExpression(GetFieldRefCacheIndex(ci, fi)));
 }
Exemplo n.º 43
0
 void OutputColumn(string tableAlias, FieldInfo fi)
 {
     if (tableAlias.Length > 0)
     {
         Output.Write(tableAlias);
         Output.Write('.');
     }
     Output.Write(fi.DBColumnName);
 }