예제 #1
0
파일: Model.csdl.cs 프로젝트: daszat/zetbox
        /// <summary>
        /// returns a &lt;Property/&gt; element describing the property 
        /// without regards for the IsList flag.
        /// </summary>
        /// therefore it can be used both when defining a type (IsList == 
        /// false) and when defining the CollectionEntry (IsList == true)
        internal static string PlainPropertyDefinitionFromValueType(ValueTypeProperty prop, string name, string implementationSuffix)
        {
            string type = prop.GetElementTypeString();
            string maxlength = String.Empty;
            string precScaleAttr = String.Empty;
            string concurrency = String.Empty;

            // strip nullable "?"
            if (prop.IsNullable() && type.EndsWith("?"))
            {
                type = type.Substring(0, type.Length - 1);
            }

            switch (type)
            {
                case "bool":
                    type = "Boolean";
                    break;
                case "decimal":
                    type = "Decimal";
                    break;
                case "double":
                    type = "Double";
                    break;
                case "int":
                    type = "Int32";
                    break;
                case "string":
                    type = "String";
                    break;
            }

            if (prop is EnumerationProperty)
            {
                type = "Int32";
                name += implementationSuffix;
            }

            if (prop is StringProperty)
            {
                maxlength = String.Format("MaxLength=\"{0}\" ", ((StringProperty)prop).GetMaxLength());
            }

            if (prop is DecimalProperty)
            {
                DecimalProperty dp = (DecimalProperty)prop;
                // must have one space at the end
                precScaleAttr = String.Format("Precision=\"{0}\" Scale=\"{1}\" ", dp.Precision, dp.Scale);
            }

            if (prop.ObjectClass is ObjectClass && ((ObjectClass)prop.ObjectClass).ImplementsIChangedBy() && prop.Name == "ChangedOn")
            {
                concurrency = "ConcurrencyMode=\"Fixed\"";
            }

            return String.Format("<Property Name=\"{0}\" Type=\"{1}\" Nullable=\"{2}\" {3}{4} {5}/>",
                name, type, prop.IsNullable() ? "true" : "false", maxlength, precScaleAttr, concurrency);
        }
예제 #2
0
파일: Cases.cs 프로젝트: jrgcubano/zetbox
        public void DoChangeValueTypeProperty_To_Nullable(ObjectClass objClass, ValueTypeProperty prop, string prefix)
        {
            var tblName = db.GetTableName(objClass.Module.SchemaName, objClass.TableName);
            var colName = Construct.NestedColumnName(prop, prefix);

            db.AlterColumn(tblName, colName, prop.GetDbType(), prop.GetSize(), prop.GetScale(), prop.IsNullable(), null);
        }
예제 #3
0
파일: Cases.cs 프로젝트: jrgcubano/zetbox
        public void DoChangeValueTypeProperty_To_NotNullable(ObjectClass objClass, ValueTypeProperty prop, string prefix)
        {
            var tblName = db.GetTableName(objClass.Module.SchemaName, objClass.TableName);
            var colName = Construct.NestedColumnName(prop, prefix);

            if (db.CheckColumnContainsNulls(tblName, colName))
            {
                Log.ErrorFormat("column '{0}.{1}' contains NULL values, cannot set NOT NULLABLE", tblName, colName);
            }
            else
            {
                db.AlterColumn(tblName, colName, prop.GetDbType(), prop.GetSize(), prop.GetScale(), prop.IsNullable(), null);
            }
        }
예제 #4
0
파일: Cases.cs 프로젝트: jrgcubano/zetbox
 public bool IsNewValueTypePropertyNullable(ValueTypeProperty prop)
 {
     return prop.IsNullable() && savedSchema.FindPersistenceObject<ValueTypeProperty>(prop.ExportGuid) == null;
 }
예제 #5
0
파일: Cases.cs 프로젝트: jrgcubano/zetbox
 public bool IsChangeValueTypeProperty_To_Nullable(ValueTypeProperty prop)
 {
     var saved = savedSchema.FindPersistenceObject<ValueTypeProperty>(prop.ExportGuid);
     if (saved == null) return false;
     return !saved.IsNullable() && prop.IsNullable();
 }
예제 #6
0
파일: Cases.cs 프로젝트: jrgcubano/zetbox
        public void DoMoveValueTypeProperty(ObjectClass objClass, ValueTypeProperty prop, string prefix)
        {
            var saved = savedSchema.FindPersistenceObject<ValueTypeProperty>(prop.ExportGuid);

            // Refleced changed hierarchie
            var currentOriginObjClass = schema.FindPersistenceObject<ObjectClass>(saved.ObjectClass.ExportGuid);
            var movedUp = IsParentOf(objClass, currentOriginObjClass);
            var movedDown = IsParentOf(currentOriginObjClass, objClass);

            var tblName = db.GetTableName(objClass.Module.SchemaName, objClass.TableName);
            var srcTblName = db.GetTableName(saved.Module.SchemaName, ((ObjectClass)saved.ObjectClass).TableName);
            var colName = Construct.NestedColumnName(prop, prefix);
            var srcColName = Construct.NestedColumnName(saved, prefix); // TODO: What if prefix has changed
            var dbType = prop.GetDbType();
            var size = prop.GetSize();
            var scale = prop.GetScale();
            var defConstr = SchemaManager.GetDefaultConstraint(prop);

            if (movedUp)
            {
                Log.InfoFormat("Moving property '{0}' from '{1}' up to '{2}'", prop.Name, saved.ObjectClass.Name, objClass.Name);
                db.CreateColumn(tblName, colName, dbType, size, scale, true, defConstr);

                db.CopyColumnData(srcTblName, srcColName, tblName, colName);

                if (!prop.IsNullable())
                {
                    if (db.CheckColumnContainsNulls(tblName, colName))
                    {
                        Log.ErrorFormat("column '{0}.{1}' contains NULL values, cannot set NOT NULLABLE", tblName, colName);
                    }
                    else
                    {
                        db.AlterColumn(tblName, colName, dbType, size, scale, prop.IsNullable(), defConstr);
                    }
                }

                if (db.CheckColumnExists(srcTblName, srcColName))
                    db.DropColumn(srcTblName, srcColName);
            }
            else if (movedDown)
            {
                Log.InfoFormat("Moving property '{0}' from '{1}' down to '{2}' (dataloss possible)", prop.Name, saved.ObjectClass.Name, objClass.Name);
                db.CreateColumn(tblName, colName, dbType, size, scale, true, defConstr);

                db.CopyColumnData(srcTblName, srcColName, tblName, colName);

                if (!prop.IsNullable())
                {
                    db.AlterColumn(tblName, colName, dbType, size, scale, prop.IsNullable(), defConstr);
                }

                if (db.CheckColumnExists(srcTblName, srcColName))
                    db.DropColumn(srcTblName, srcColName);
            }
            else
            {
                Log.ErrorFormat("Moving property '{2}' from '{0}' to '{1}' is not supported. ObjectClasses are not in the same hierarchy. Will only create destination column.", saved.ObjectClass.Name, prop.ObjectClass.Name, prop.Name);
                db.CreateColumn(tblName, colName, dbType, size, scale, true, defConstr);
            }
        }
예제 #7
0
        /// <summary>
        /// returns a &lt;Property/&gt; element describing the property
        /// without regards for the IsList flag.
        /// </summary>
        /// therefore it can be used both when defining a type (IsList ==
        /// false) and when defining the CollectionEntry (IsList == true)
        internal static string PlainPropertyDefinitionFromValueType(ValueTypeProperty prop, string name, string implementationSuffix)
        {
            string type          = prop.GetElementTypeString();
            string maxlength     = String.Empty;
            string precScaleAttr = String.Empty;
            string concurrency   = String.Empty;

            // strip nullable "?"
            if (prop.IsNullable() && type.EndsWith("?"))
            {
                type = type.Substring(0, type.Length - 1);
            }

            switch (type)
            {
            case "bool":
                type = "Boolean";
                break;

            case "decimal":
                type = "Decimal";
                break;

            case "double":
                type = "Double";
                break;

            case "int":
                type = "Int32";
                break;

            case "string":
                type = "String";
                break;
            }

            if (prop is EnumerationProperty)
            {
                type  = "Int32";
                name += implementationSuffix;
            }

            if (prop is StringProperty)
            {
                maxlength = String.Format("MaxLength=\"{0}\" ", ((StringProperty)prop).GetMaxLength());
            }

            if (prop is DecimalProperty)
            {
                DecimalProperty dp = (DecimalProperty)prop;
                // must have one space at the end
                precScaleAttr = String.Format("Precision=\"{0}\" Scale=\"{1}\" ", dp.Precision, dp.Scale);
            }

            if (prop.ObjectClass is ObjectClass && ((ObjectClass)prop.ObjectClass).ImplementsIChangedBy() && prop.Name == "ChangedOn")
            {
                concurrency = "ConcurrencyMode=\"Fixed\"";
            }

            return(String.Format("<Property Name=\"{0}\" Type=\"{1}\" Nullable=\"{2}\" {3}{4} {5}/>",
                                 name, type, prop.IsNullable() ? "true" : "false", maxlength, precScaleAttr, concurrency));
        }
예제 #8
0
파일: Cases.cs 프로젝트: daszat/zetbox
        public void DoChangeValueTypeProperty_To_Nullable(ObjectClass objClass, ValueTypeProperty prop, string prefix)
        {
            var savedProp = savedSchema.FindPersistenceObject<ValueTypeProperty>(prop.ExportGuid);

            if (!PreMigration(PropertyMigrationEventType.ChangeToNullable, savedProp, prop))
                return;

            var tblName = objClass.GetTableRef(db);
            var colName = Construct.ColumnName(prop, prefix);

            db.AlterColumn(tblName, colName, prop.GetDbType(), prop.GetSize(), prop.GetScale(), prop.IsNullable(), null);

            PostMigration(PropertyMigrationEventType.ChangeToNullable, savedProp, prop);
        }
예제 #9
0
파일: Cases.cs 프로젝트: daszat/zetbox
        public void DoChangeValueTypeProperty_To_NotNullable(ObjectClass objClass, ValueTypeProperty prop, string prefix)
        {
            var savedProp = savedSchema.FindPersistenceObject<ValueTypeProperty>(prop.ExportGuid);

            if (!PreMigration(PropertyMigrationEventType.ChangeToNotNullable, savedProp, prop))
                return;

            var tblName = objClass.GetTableRef(db);
            var colName = Construct.ColumnName(prop, prefix);
            var def = SchemaManager.GetDefaultConstraint(prop);

            if (def == null && db.CheckColumnContainsNulls(tblName, colName))
            {
                Log.ErrorFormat("column '{0}.{1}' contains NULL values and has no default contraint, cannot set NOT NULLABLE", tblName, colName);
            }
            else
            {
                if (def != null)
                {
                    var isSimplyCheckable = objClass.GetTableMapping() == TableMapping.TPT || objClass.BaseObjectClass == null;
                    var classes = objClass.AndChildren(c => c.SubClasses).Select(cls => Construct.DiscriminatorValue(cls)).ToList();

                    WriteDefaultValue(tblName, colName, def, isSimplyCheckable ? null : classes);
                }
                db.AlterColumn(tblName, colName, prop.GetDbType(), prop.GetSize(), prop.GetScale(), prop.IsNullable(), null /* don't change contraints */);
            }

            PostMigration(PropertyMigrationEventType.ChangeToNotNullable, savedProp, prop);
        }