예제 #1
0
        private void BindColumns(HbmTimestamp timestampSchema, SimpleValue model, string propertyPath)
        {
            Table table = model.Table;

            if (timestampSchema.column != null)
            {
                Column col = new Column();
                col.Value = model;
                BindColumn(col, false);
                col.Name = mappings.NamingStrategy.ColumnName(timestampSchema.column);

                if (table != null)
                {
                    table.AddColumn(col);
                }

                model.AddColumn(col);
            }

            if (model.ColumnSpan == 0)
            {
                Column col = new Column();
                col.Value = model;
                BindColumn(col, false);
                col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath);
                model.Table.AddColumn(col);
                model.AddColumn(col);
            }
        }
예제 #2
0
        private void BindTimestamp(HbmTimestamp timestampSchema, PersistentClass rootClass, Table table, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            if (timestampSchema == null)
            {
                return;
            }

            string propertyName = timestampSchema.name;
            var    simpleValue  = new SimpleValue(table);

            new ColumnsBinder(simpleValue, Mappings).Bind(timestampSchema.Columns, false,
                                                          () =>
                                                          new HbmColumn
            {
                name = mappings.NamingStrategy.PropertyToColumnName(propertyName)
            });

            if (!simpleValue.IsTypeSpecified)
            {
                switch (timestampSchema.source)
                {
                case HbmTimestampSource.Vm:
                    simpleValue.TypeName = NHibernateUtil.DateTime.Name;
                    break;

                case HbmTimestampSource.Db:
                    simpleValue.TypeName = NHibernateUtil.DbTimestamp.Name;
                    break;

                default:
                    simpleValue.TypeName = NHibernateUtil.DateTime.Name;
                    break;
                }
            }

            var property = new Property(simpleValue);

            BindProperty(timestampSchema, property, inheritedMetas);

            // for version properties marked as being generated, make sure they are "always"
            // generated; "insert" is invalid. This is dis-allowed by the schema, but just to make
            // sure...

            if (property.Generation == PropertyGeneration.Insert)
            {
                throw new MappingException("'generated' attribute cannot be 'insert' for versioning property");
            }
            simpleValue.NullValue = timestampSchema.unsavedvalue == HbmTimestampUnsavedvalue.Null ? null : "undefined";
            rootClass.Version     = property;
            rootClass.AddProperty(property);
        }
예제 #3
0
        private void BindProperty(HbmTimestamp timestampSchema, Property property, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            property.Name = timestampSchema.name;

            if (property.Value.Type == null)
            {
                throw new MappingException("could not determine a property type for: " + property.Name);
            }

            property.PropertyAccessorName = timestampSchema.access ?? mappings.DefaultAccess;
            property.Cascade            = mappings.DefaultCascade;
            property.IsUpdateable       = true;
            property.IsInsertable       = true;
            property.IsOptimisticLocked = true;
            property.Generation         = Convert(timestampSchema.generated);

            if (property.Generation == PropertyGeneration.Always ||
                property.Generation == PropertyGeneration.Insert)
            {
                // generated properties can *never* be insertable...
                if (property.IsInsertable)
                {
                    // insertable simply because that is the user did not specify
                    // anything; just override it
                    property.IsInsertable = false;
                }

                // properties generated on update can never be updateable...
                if (property.IsUpdateable && property.Generation == PropertyGeneration.Always)
                {
                    // updateable only because the user did not specify
                    // anything; just override it
                    property.IsUpdateable = false;
                }
            }

            property.MetaAttributes = GetMetas(timestampSchema, inheritedMetas);

            LogMappedProperty(property);
        }