private static string GetMaxLength(ISchemaProperty property) { switch (property.DataType) { case DbType.Binary: case DbType.AnsiString: case DbType.AnsiStringFixedLength: case DbType.String: case DbType.StringFixedLength: { // Custom Fixes for SQL Anywhere if (String.Equals(property.NativeType, "LONG BINARY", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONG VARBIT", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONG VARCHAR", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONG NVARCHAR", StringComparison.OrdinalIgnoreCase)) { return("Max"); } // Custom Fixes for MySQL... http://www.tutorialspoint.com/mysql/mysql-data-types.htm if (String.Equals(property.NativeType, "BLOB", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "TINYBLOB", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "TINYTEXT", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "MEDIUMBLOB", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "MEDIUMTEXT", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONGBLOB", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONGTEXT", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "ENUM", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "SET", StringComparison.OrdinalIgnoreCase)) { return(null); } if (String.Equals(property.NativeType, "timestamp", StringComparison.OrdinalIgnoreCase)) { return("8"); } if (String.Equals(property.NativeType, "text", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "ntext", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "image", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "xml", StringComparison.OrdinalIgnoreCase)) { return("Max"); } if (property.Size > 0) { return(property.Size.ToString()); } if (property.Size == -1) { return("Max"); } break; } } return(null); }
public override PropertyValue SetPropertyValue(IModelElement owner, ISchemaProperty property, object value, long?version) { if (!GraphNodeExists(owner.Id)) { throw new InvalidElementException(owner.Id); } var pid = owner.Id.CreateAttributeIdentity(property.Name); GraphNode propertyNode; _extendedGraph.GetGraphNode(pid, NodeType.Property, out propertyNode); // Potential old value if (propertyNode != null && Equals(propertyNode.Value, value)) { // Value already exists with the same value in the extendeed domain return(null); } if (!base.GraphNodeExists(owner.Id)) { var rel = owner as IModelRelationship; if (rel == null) { CreateEntity(owner.Id, (ISchemaEntity)owner.SchemaInfo); } else { CreateRelationship(rel.Id, (ISchemaRelationship)rel.SchemaInfo, rel.Start.Id, rel.End.Id); } } return(base.SetPropertyValueCore(owner, property, value, version, propertyNode)); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Adds a constraint to 'constraint'. /// </summary> /// <param name="property"> /// The property. /// </param> /// <param name="constraint"> /// The constraint. /// </param> ///------------------------------------------------------------------------------------------------- public void AddConstraint(ISchemaProperty property, IConstraint constraint) { var owner = property.Owner as ISchemaElement; if (owner == null) { return; } var interfaces = ReflectionHelper.GetInterfaces(constraint.GetType()); var constraintElementType = interfaces.Where(i => ReflectionHelper.IsGenericType(i, typeof(IValidationValueObjectConstraint <>))) .Select(i => ReflectionHelper.GetGenericArguments(i).First()) .FirstOrDefault(); if (constraintElementType != null) { var category = ((IValidationValueObjectConstraint)constraint).Category; AddConstraint(owner, new CheckPropertyConstraintProxy(property, constraintElementType, constraint, ConstraintKind.Validate, category)); } else { constraintElementType = interfaces.Where(i => ReflectionHelper.IsGenericType(i, typeof(ICheckValueObjectConstraint <>))) .Select(i => ReflectionHelper.GetGenericArguments(i).First()) .FirstOrDefault(); if (constraintElementType != null) { AddConstraint(owner, new CheckPropertyConstraintProxy(property, constraintElementType, constraint, ConstraintKind.Check, null)); } else { throw new HyperstoreException("Invalid constraint type for property " + property.Name); } } }
///------------------------------------------------------------------------------------------------- /// <summary> /// Adds a property. /// </summary> /// <exception cref="Exception"> /// Thrown when an exception error condition occurs. /// </exception> /// <param name="property"> /// The property definition. /// </param> /// <returns> /// An ISchemaProperty. /// </returns> /// <exception cref="System.Exception"> /// Duplicate property name. /// </exception> ///------------------------------------------------------------------------------------------------- protected ISchemaProperty DefineProperty(ISchemaProperty property) { Contract.Requires(property, "property"); lock (_propertiesByName) { if (GetProperty(property.Name) != null) { throw new Hyperstore.Modeling.MemoryStore.DuplicateElementException(ExceptionMessages.DuplicatePropertyName); } _properties.Add(property); _propertiesByName.TryAdd(property.Name, property); } var trace = DomainModel.Resolve <IHyperstoreTrace>(false); if (trace != null) { trace.WriteTrace(TraceCategory.Metadata, ExceptionMessages.CreatePropertyWithIdForMetaclassFormat, property.Name, property.Id, ((IModelElement)this).Id); } var constraint = property.PropertySchema as Hyperstore.Modeling.Metadata.Constraints.IConstraint; if (constraint != null && this.Schema.Constraints is IConstraintManagerInternal) { (this.Schema.Constraints as IConstraintManagerInternal).AddConstraint(property, constraint); } return(property); }
protected PropertyValue SetPropertyValueCore(IModelElement owner, ISchemaProperty property, object value, long?version, GraphNode oldNode) { DebugContract.Requires(owner); DebugContract.Requires(property); DebugContract.Requires(Session.Current); _trace.WriteTrace(TraceCategory.Hypergraph, "{0}.{1} = {2}", owner, property.Name, value); using (var tx = BeginTransaction()) { // Vérification si le owner existe if (!GraphNodeExists(owner.Id)) { throw new InvalidElementException(owner.Id); } var pid = owner.Id.CreateAttributeIdentity(property.Name); // Recherche si l'attribut existe var pnode = _storage.GetNode(pid) as GraphNode; if (pnode == null) { // N'existe pas encore. On crée l'attribut et une relation avec son owner pnode = new GraphNode(pid, property.Id, NodeType.Property, value: value, version: version); _storage.AddNode(pnode, owner.Id); DeferAddIndex(owner.SchemaInfo, owner.Id, property.Name, value); tx.Commit(); var oldPropertyNode = oldNode as GraphNode; return(new PropertyValue { Value = value, OldValue = oldPropertyNode != null ? oldPropertyNode.Value : property.DefaultValue, CurrentVersion = pnode.Version }); } var oldValue = pnode.Value; // TODO //if (version != null && pnode.Version != version) //{ // throw new ConflictException(ownerId, ownerMetadata, property, value, oldValue, version.Value, pnode.Version); //} if (Equals(oldValue, value)) { tx.Commit(); return(new PropertyValue { Value = value, OldValue = oldValue, CurrentVersion = pnode.Version }); } DeferRemoveIndex(owner.SchemaInfo, owner.Id, property.Name, oldValue); pnode = pnode.SetValue(value); _storage.UpdateNode(pnode); DeferAddIndex(owner.SchemaInfo, owner.Id, property.Name, value); tx.Commit(); return(new PropertyValue { Value = value, OldValue = oldValue, CurrentVersion = pnode.Version }); } }
///------------------------------------------------------------------------------------------------- /// <summary> /// Gets the attribute. /// </summary> /// <exception cref="InvalidElementException"> /// Thrown when an Invalid Element error condition occurs. /// </exception> /// <param name="ownerId"> /// The identifier that owns this item. /// </param> /// <param name="property"> /// The property. /// </param> /// <returns> /// The property value or null if not exists. /// </returns> ///------------------------------------------------------------------------------------------------- public PropertyValue GetPropertyValue(Identity ownerId, ISchemaProperty property) { DebugContract.Requires(ownerId); DebugContract.Requires(property); GraphNode v; if (!GraphNodeExists(ownerId)) { throw new InvalidElementException(ownerId); } var pid = ownerId.CreateAttributeIdentity(property.Name); if (!GetGraphNode(pid, NodeType.Property, out v) || v == null) { return(null); } var p = v as GraphNode; Debug.Assert(p != null); return(new PropertyValue { Value = p.Value, CurrentVersion = p.Version }); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Gets the property value. /// </summary> /// <param name="property"> /// The property. /// </param> /// <returns> /// The property value. /// </returns> ///------------------------------------------------------------------------------------------------- public PropertyValue GetPropertyValue(ISchemaProperty property) { Contract.Requires(property, "property"); var pv = DomainModel.GetPropertyValue(_id, property); SetCalculatedPropertySource(property.Name); return(pv); }
internal DynamicPropertyDescriptor(DynamicModelEntity owner, ISchemaProperty property) : base(property.Name, null) { DebugContract.Requires(owner); DebugContract.Requires(property); _element = owner; _property = property; }
///------------------------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ChangePropertyValueCommand" /> class. /// </summary> /// <param name="element"> /// The element. /// </param> /// <param name="propertySchema"> /// The property schema. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="version"> /// (Optional) The version (corresponding at UtcNow.Ticks) /// </param> ///------------------------------------------------------------------------------------------------- public ChangePropertyValueCommand(IModelElement element, ISchemaProperty propertySchema, object value, long?version = null) : base(element.DomainModel, version) { Contract.Requires(element, "element"); Contract.Requires(propertySchema, "propertySchema"); Value = value; Element = element; SchemaProperty = propertySchema; }
internal ConflictException(Identity ownerId, ISchemaElement ownerMetadata, ISchemaProperty property, object value, object conflictValue, long version, long conflictVersion) { OwnerId = ownerId; OwnerSchema = ownerMetadata; Property = property; Value = value; ConflictValue = conflictValue; Version = version; ConflictVersion = conflictVersion; }
///------------------------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="RemovePropertyCommand" /> class. /// </summary> /// <param name="domainModel"> /// The domain model. /// </param> /// <param name="ownerId"> /// The owner identifier. /// </param> /// <param name="ownerSchemaId"> /// The schema identifier that owns this item. /// </param> /// <param name="propertySchema"> /// The property schema. /// </param> /// <param name="version"> /// (Optional) the version. /// </param> ///------------------------------------------------------------------------------------------------- public RemovePropertyCommand(IDomainModel domainModel, Identity ownerId, Identity ownerSchemaId, ISchemaProperty propertySchema, long?version = null) : base(domainModel, version) { Contract.Requires(domainModel, "domainModel"); Contract.Requires(ownerId, "ownerId"); Contract.Requires(propertySchema, "propertySchema"); Contract.Requires(ownerSchemaId, "ownerSchemaId"); ElementId = ownerId; SchemaProperty = propertySchema; SchemaId = ownerSchemaId; }
///------------------------------------------------------------------------------------------------- /// <summary> /// Sets property value. /// </summary> /// <param name="property"> /// The property. /// </param> /// <param name="value"> /// The value. /// </param> ///------------------------------------------------------------------------------------------------- protected void SetPropertyValue(ISchemaProperty property, object value) { Contract.Requires(property, "property"); using (var session = EnsuresRunInSession()) { var cmd = new ChangePropertyValueCommand(this, property, value); Session.Current.Execute(cmd); if (session != null) { session.AcceptChanges(); } } }
///------------------------------------------------------------------------------------------------- /// <summary> /// Sets property value core. /// </summary> /// <param name="owner"> /// The owner. /// </param> /// <param name="propertyMetadata"> /// The property metadata. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="version"> /// The version. /// </param> /// <returns> /// A PropertyValue. /// </returns> ///------------------------------------------------------------------------------------------------- protected virtual PropertyValue SetPropertyValueCore(IModelElement owner, ISchemaProperty propertyMetadata, object value, long?version) { Contract.Requires(owner, "owner"); Contract.Requires(propertyMetadata, "propertyMetadata"); using (var session = EnsuresRunInSession()) { var r = InnerGraph.SetPropertyValue(owner, propertyMetadata, value, version); if (session != null) { session.AcceptChanges(); } return(r); } }
///------------------------------------------------------------------------------------------------- /// <summary> /// Gets property value. /// </summary> /// <param name="ownerId"> /// The identifier that owns this item. /// </param> /// <param name="property"> /// The property. /// </param> /// <returns> /// The property value. /// </returns> ///------------------------------------------------------------------------------------------------- public virtual PropertyValue GetPropertyValue(Identity ownerId, ISchemaProperty property) { Contract.Requires(ownerId, "ownerId"); Contract.Requires(property, "property"); CheckInitialized(); var prop = InnerGraph.GetPropertyValue(ownerId, property); if (prop == null || prop.CurrentVersion == 0) { prop = new PropertyValue { Value = property.DefaultValue, CurrentVersion = 0 }; } return(prop); }
private static bool ExcludeProperty(ISchemaProperty property) { if (property == null) { return(true); } if (property.NativeType.Equals("sql_variant", StringComparison.OrdinalIgnoreCase) || property.NativeType.Equals("geography", StringComparison.OrdinalIgnoreCase) || property.NativeType.Equals("geometry", StringComparison.OrdinalIgnoreCase) || property.NativeType.Equals("hierarchyid", StringComparison.OrdinalIgnoreCase)) { Trace.WriteLine(String.Format("Skipping Property '{0}.{1}' because the type '{2}' is not supported.", property.Entity.Name, property.Name, property.NativeType)); return(true); } // Exclude FK's. if (!_includeForeignKeysInModel && property.IsForeignKey) { return(true); } return(false); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Initializes the specified metadata. /// </summary> /// <param name="schemaElement"> /// The metadata. /// </param> /// <param name="domainModel"> /// The domain model. /// </param> ///------------------------------------------------------------------------------------------------- protected override void Initialize(ISchemaElement schemaElement, IDomainModel domainModel) { base.Initialize(schemaElement, domainModel); _propertyMetadataReference = new ReferenceHandler(this, Schema.Store.PrimitivesSchema.SchemaPropertyReferencesSchemaEntitySchema); _defaultValueProperty = ((IModelElement)this).SchemaInfo.GetProperty("DefaultValue"); }
public SerializationContext(ISchemaProperty schemaProperty, object value) { Contract.Requires(schemaProperty, "schemaProperty"); Schema = schemaProperty.PropertySchema; Value = value; }
ISchemaProperty ISchemaElement.DefineProperty(ISchemaProperty property) { return(DefineProperty(property)); }
PropertyValue IDomainModel.GetPropertyValue(Identity ownerId, ISchemaProperty propertySchema) { throw new NotImplementedException(); }
private static string GetNativeType(ISchemaProperty property) { string nativeType = property.NativeType; switch (property.DataType) { case DbType.Binary: case DbType.AnsiString: case DbType.AnsiStringFixedLength: case DbType.String: case DbType.StringFixedLength: { // SQL Anywhere if (String.Equals(property.NativeType, "LONG BINARY", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONG VARBIT", StringComparison.OrdinalIgnoreCase)) return "binary"; if (String.Equals(property.NativeType, "LONG VARCHAR", StringComparison.OrdinalIgnoreCase)) return "varchar"; if(String.Equals(property.NativeType, "LONG NVARCHAR", StringComparison.OrdinalIgnoreCase)) return "nvarchar"; if (property.NativeType != "text" && property.NativeType != "ntext" && property.NativeType != "timestamp" && property.NativeType != "image") if (property.Size == -1) nativeType += "(max)"; break; } case DbType.Int16: return "smallint"; case DbType.Int32: return "int"; case DbType.Int64: return "bigint"; case DbType.Double: return "float"; case DbType.Date: // SQL Anywhere provider doesn't support the type date: http://dcx.sybase.com/1201/en/dbprogramming/framework-adodotnet-development.html if (IsSqlAnywhere(property.Entity)) return "datetime"; break; case DbType.Decimal: return "numeric"; } return nativeType; }
private static bool ExcludeProperty(ISchemaProperty property) { if (property == null) return true; if (property.NativeType.Equals("sql_variant", StringComparison.OrdinalIgnoreCase) || property.NativeType.Equals("geography", StringComparison.OrdinalIgnoreCase) || property.NativeType.Equals("geometry", StringComparison.OrdinalIgnoreCase) || property.NativeType.Equals("hierarchyid", StringComparison.OrdinalIgnoreCase)) { Trace.WriteLine(String.Format("Skipping Property '{0}.{1}' because the type '{2}' is not supported.", property.Entity.Name, property.Name, property.NativeType)); return true; } // Exclude FK's. if(!_includeForeignKeysInModel && property.IsForeignKey) return true; return false; }
private static string GetNativeType(ISchemaProperty property) { string nativeType = property.NativeType; switch (property.DataType) { case DbType.Binary: case DbType.AnsiString: case DbType.AnsiStringFixedLength: case DbType.String: case DbType.StringFixedLength: { // SQL Anywhere if (String.Equals(property.NativeType, "LONG BINARY", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONG VARBIT", StringComparison.OrdinalIgnoreCase)) { return("binary"); } if (String.Equals(property.NativeType, "LONG VARCHAR", StringComparison.OrdinalIgnoreCase)) { return("varchar"); } if (String.Equals(property.NativeType, "LONG NVARCHAR", StringComparison.OrdinalIgnoreCase)) { return("nvarchar"); } if (property.NativeType != "text" && property.NativeType != "ntext" && property.NativeType != "timestamp" && property.NativeType != "image") { if (property.Size == -1) { nativeType += "(max)"; } } break; } case DbType.Int16: return("smallint"); case DbType.Int32: return("int"); case DbType.Int64: return("bigint"); case DbType.Double: return("float"); case DbType.Date: // SQL Anywhere provider doesn't support the type date: http://dcx.sybase.com/1201/en/dbprogramming/framework-adodotnet-development.html if (IsSqlAnywhere(property.Entity)) { return("datetime"); } break; case DbType.Decimal: return("numeric"); } return(nativeType); }
private static string GetMaxLength(ISchemaProperty property) { switch (property.DataType) { case DbType.Binary: case DbType.AnsiString: case DbType.AnsiStringFixedLength: case DbType.String: case DbType.StringFixedLength: { // Custom Fixes for SQL Anywhere if (String.Equals(property.NativeType, "LONG BINARY", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONG VARBIT", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONG VARCHAR", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONG NVARCHAR", StringComparison.OrdinalIgnoreCase)) return "Max"; // Custom Fixes for MySQL... http://www.tutorialspoint.com/mysql/mysql-data-types.htm if (String.Equals(property.NativeType, "BLOB", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "TINYBLOB", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "TINYTEXT", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "MEDIUMBLOB", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "MEDIUMTEXT", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONGBLOB", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "LONGTEXT", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "ENUM", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "SET", StringComparison.OrdinalIgnoreCase)) return null; if (String.Equals(property.NativeType, "timestamp", StringComparison.OrdinalIgnoreCase)) return "8"; if (String.Equals(property.NativeType, "text", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "ntext", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "image", StringComparison.OrdinalIgnoreCase) || String.Equals(property.NativeType, "xml", StringComparison.OrdinalIgnoreCase)) return "Max"; if (property.Size > 0) return property.Size.ToString(); if (property.Size == -1) return "Max"; break; } } return null; }
///------------------------------------------------------------------------------------------------- /// <summary> /// Sets the attribute. /// </summary> /// <param name="owner"> /// The owner. /// </param> /// <param name="property"> /// The property. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="version"> /// [out] The version. /// </param> /// <returns> /// true if it succeeds, false if it fails. /// </returns> ///------------------------------------------------------------------------------------------------- public virtual PropertyValue SetPropertyValue(IModelElement owner, ISchemaProperty property, object value, long?version) { return(SetPropertyValueCore(owner, property, value, version, null)); }
public CheckPropertyConstraintProxy(ISchemaProperty property, Type constraintElementType, object constraint, ConstraintKind kind, string category) : base(constraint, kind, category) { this._property = property; CheckHandler = CreateCheckHandler(constraintElementType); }
private static string GetSystemType(ISchemaProperty property) { if (property.BaseSystemType.Equals("System.Byte[]")) return "Binary"; if (property.BaseSystemType.Equals("System.Xml.XmlDocument")) return "String"; if (property.BaseSystemType.Equals("System.TimeSpan")) return "Time"; return property.BaseSystemType.Replace("System.", ""); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Releases the unmanaged resources used by the Hyperstore.Modeling.ModelElement and optionally /// releases the managed resources. /// </summary> /// <param name="disposing"> /// true to release both managed and unmanaged resources; false to release only unmanaged /// resources. /// </param> ///------------------------------------------------------------------------------------------------- protected override void Dispose(bool disposing) { base.Dispose(disposing); _propertyMetadataReference.Dispose(); _defaultValueProperty = null; }
PropertyValue IDomainModel.GetPropertyValue(Identity ownerId, ISchemaProperty propertyMetadata) { throw new NotSupportedException(); }
PropertyValue IUpdatableDomainModel.SetPropertyValue(IModelElement owner, ISchemaProperty propertyMetadata, object value, long?version) { return(SetPropertyValueCore(owner, propertyMetadata, value, version)); }