public override IQueryElement VisitIndex_attribute([NotNull] QueryGrammarParser.Index_attributeContext context) { IndexAttribute indexAttribute = new IndexAttribute(); indexAttribute.Name = context.NAME().GetText(); return(indexAttribute); }
private static void AddIndexColumn( string indexName, IndexOptions indexOptions, int column, PrimitivePropertyConfiguration propertyConfiguration) { var indexAttribute = new IndexAttribute(indexName, column) { IsClustered = indexOptions.HasFlag(IndexOptions.Clustered), IsUnique = indexOptions.HasFlag(IndexOptions.Unique) }; var annotation = GetIndexAnnotation(propertyConfiguration); if (annotation != null) { var attributes = annotation.Indexes.ToList(); attributes.Add(indexAttribute); annotation = new IndexAnnotation(attributes); } else { annotation = new IndexAnnotation(indexAttribute); } propertyConfiguration.HasColumnAnnotation(IndexAnnotation.AnnotationName, annotation); }
private static IndexAnnotation CreateIndexAnnotation(bool?isUnique = false, string name = null, int?order = null) { IndexAttribute indexAttribute; if (!string.IsNullOrWhiteSpace(name) && order.HasValue) { indexAttribute = new IndexAttribute(name, order.Value); } else if (!string.IsNullOrWhiteSpace(name)) { indexAttribute = new IndexAttribute(name); } else { indexAttribute = new IndexAttribute(); } if (isUnique.HasValue && isUnique.Value) { indexAttribute.IsUnique = true; } var indexAnnotation = new IndexAnnotation(indexAttribute); return(indexAnnotation); }
private void PopulateDocument(AttributeValue value, IndexAttribute Attributes) { string fieldName; if (value.DataType != FieldDataType.Empty) { switch (value.Type) { case AttributeValueType.Null: _filterDocument[Attributes.Name] = null; break; case AttributeValueType.Single: var singleAttValue = value as SingleAttributeValue; if (singleAttValue != null) { fieldName = Attributes.Name; _filterDocument[fieldName] = singleAttValue.Value; } break; } } }
public void PopulateIndexConfiguration(Dictionary <string, object> configValues, out ICloneable configuration) { IndexConfiguration indexConf = new IndexConfiguration(); if (configValues.ContainsKey(ConfigType.Name.ToString())) { indexConf.Name = configValues[ConfigType.Name.ToString()].ToString(); } IndexAttribute attribute = new IndexAttribute(); if (configValues.ContainsKey(ConfigType.Attribute.ToString())) { attribute.Name = (string)configValues[ConfigType.Attribute.ToString()]; } if (configValues.ContainsKey(ConfigType.SortOrder.ToString())) { attribute.Order = (string)configValues[ConfigType.SortOrder.ToString()]; } indexConf.Attributes = attribute; if (configValues.ContainsKey(ConfigType.JournalEnabled.ToString())) { indexConf.JournalEnabled = (bool)configValues[ConfigType.JournalEnabled.ToString()]; } if (configValues.ContainsKey(ConfigType.CachePolicy.ToString())) { indexConf.CachePolicy = (string)configValues[ConfigType.CachePolicy.ToString()]; } configuration = indexConf; }
/// <summary> /// Constructs a new aggregate entity type configuration with standard configuration /// </summary> public AggregateEntityTypeConfiguration() : base() { this.Property(m => m.ID).HasDatabaseGeneratedOption ( DatabaseGeneratedOption.Identity ); var indexAttribute = new IndexAttribute() { IsUnique = true }; // Apply a maximum length and an index to the lookup key this.Property(m => m.LookupKey) .HasMaxLength(150) .HasColumnAnnotation ( "Index", new IndexAnnotation(indexAttribute) ); this.Map ( m => { m.ToTable ( typeof(TEntity).Name.Pluralize() ); } ); }
internal EntityIndex(EntityType entityType, IndexAttribute attr) : base(attr.Name, attr.NativeName) { this.Initialize(entityType); if (EntityType == null) { throw new InvalidOperationException("EntityType is null."); } // set... _hasUniqueValues = attr.HasUniqueValues; // setup the fields... if (attr.ColumnNativeNames == null) { throw new InvalidOperationException("'attr.ColumnNativeNames' is null."); } if (attr.ColumnNativeNames.Length == 0) { throw new InvalidOperationException("'attr.ColumnNativeNames' is zero-length."); } // add... AddColumns(entityType, attr.ColumnNativeNames, this.Fields); this.IncludedFields = new EntityFieldCollection(entityType); AddColumns(entityType, attr.IncludedColumns, this.IncludedFields); this.ComputedFields = new EntityFieldCollection(entityType); AddColumns(entityType, attr.ComputedColumns, this.ComputedFields); }
public CFG_Account() { HasKey((Account d) => d.Id).Property((Account d) => d.Id).HasDatabaseGeneratedOption(new DatabaseGeneratedOption?(DatabaseGeneratedOption.Identity)); StringPropertyConfiguration stringPropertyConfiguration = Property((Account d) => d.BadgeNumber).IsRequired().HasMaxLength(new int?(16)); IndexAttribute indexAttribute = new IndexAttribute() { IsUnique = true }; stringPropertyConfiguration.HasColumnAnnotation("Index", new IndexAnnotation(indexAttribute)); Property((Account d) => d.FirstName).IsRequired().HasMaxLength(new int?(64)); Property((Account d) => d.LastName).IsRequired().HasMaxLength(new int?(64)); Property((Account d) => d.MiddleName).HasMaxLength(new int?(64)); Property((Account d) => d.Rank).HasMaxLength(new int?(32)); StringPropertyConfiguration stringPropertyConfiguration1 = Property((Account d) => d.LogonID).IsRequired().HasMaxLength(new int?(32)); IndexAttribute indexAttribute1 = new IndexAttribute() { IsUnique = true }; stringPropertyConfiguration1.HasColumnAnnotation("Index", new IndexAnnotation(indexAttribute1)); Property((Account d) => d.Password).IsRequired().HasMaxLength(new int?(32)); Property((Account d) => d.PIN).HasMaxLength(new int?(8)); Property((Account d) => d.Photo).HasColumnType("image"); Property((Account d) => d.Email).HasMaxLength(new int?(64)); }
public void IsCompatibleWith_returns_true_if_other_is_same_or_null() { var attribute = new IndexAttribute(); Assert.True(attribute.IsCompatibleWith(attribute)); Assert.True(attribute.IsCompatibleWith(null)); }
public IndexParam(IndexAttribute indexAttr, params PropertyInfo[] properties) { IndexName = indexAttr.Name; IsUnique = indexAttr.IsUnique; IsClustered = indexAttr.IsClustered; PropertyNames = properties.Select(prop => prop.Name).ToArray(); }
/// <summary> /// Returns true if this annotation does not conflict with the given annotation such that /// the two can be combined together using the <see cref="M:System.Data.Entity.Infrastructure.Annotations.IndexAnnotation.MergeWith(System.Object)" /> method. /// </summary> /// <remarks> /// Each index annotation contains at most one <see cref="T:System.ComponentModel.DataAnnotations.Schema.IndexAttribute" /> with a given name. /// Two annotations are considered compatible if each IndexAttribute with a given name is only /// contained in one annotation or the other, or if both annotations contain an IndexAttribute /// with the given name. /// </remarks> /// <param name="other">The annotation to compare.</param> /// <returns>A CompatibilityResult indicating whether or not this annotation is compatible with the other.</returns> public virtual CompatibilityResult IsCompatibleWith(object other) { if (object.ReferenceEquals((object)this, other) || other == null) { return(new CompatibilityResult(true, (string)null)); } IndexAnnotation indexAnnotation = other as IndexAnnotation; if (indexAnnotation == null) { return(new CompatibilityResult(false, Strings.IncompatibleTypes((object)other.GetType().Name, (object)typeof(IndexAnnotation).Name))); } foreach (IndexAttribute index in (IEnumerable <IndexAttribute>)indexAnnotation._indexes) { IndexAttribute newIndex = index; IndexAttribute me = this._indexes.SingleOrDefault <IndexAttribute>((Func <IndexAttribute, bool>)(i => i.Name == newIndex.Name)); if (me != null) { CompatibilityResult compatibilityResult = me.IsCompatibleWith(newIndex, false); if (!(bool)compatibilityResult) { return(compatibilityResult); } } } return(new CompatibilityResult(true, (string)null)); }
public static PersistIndexAttribute FromPayload(IndexAttribute indexAttribute) { return(new PersistIndexAttribute() { Name = indexAttribute.Name }); }
public static IEnumerable <PropertyToken> GetTokensFrom <T>(T instance, params IContentMapper[] mappers) { var properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var property in properties) { var attributes = property.GetCustomAttributes(typeof(IndexAttribute), true); if (attributes != null && attributes.Length > 0) { IndexAttribute attr = (IndexAttribute)attributes[0]; object value = null; if (instance != null) { value = GetValue(instance, property, mappers); } // Value can be converted using IContentMapper, so try to retrieve the correct type converter var actualType = value == null ? property.PropertyType : value.GetType(); TypeConverter conv = TypeDescriptor.GetConverter(actualType); yield return(new PropertyToken { Name = property.Name, Store = attr.Store, Tokenize = attr.Tokenize, Value = conv.ConvertToString(value) }); } } }
public CFG_Case() { HasKey((Case d) => d.Id).Property((Case d) => d.Id).HasDatabaseGeneratedOption(new DatabaseGeneratedOption?(DatabaseGeneratedOption.Identity)); StringPropertyConfiguration stringPropertyConfiguration = Property((Case d) => d.CaseNumber).IsRequired().HasMaxLength(new int?(32)); IndexAttribute indexAttribute = new IndexAttribute() { IsUnique = true }; stringPropertyConfiguration.HasColumnAnnotation("Index", new IndexAnnotation(indexAttribute)); Property((Case d) => d.PurgeFileName).HasMaxLength(new int?(256)); Property((Case d) => d.FirstName).IsRequired().HasMaxLength(new int?(32)); Property((Case d) => d.LastName).IsRequired().HasMaxLength(new int?(32)); Property((Case d) => d.MiddleName).HasMaxLength(new int?(32)); Property((Case d) => d.Gender).IsRequired().HasMaxLength(new int?(1)); Property((Case d) => d.SSN).HasMaxLength(new int?(16)); Property((Case d) => d.HairColor).HasMaxLength(new int?(16)); Property((Case d) => d.EyeColor).HasMaxLength(new int?(16)); Property((Case d) => d.PassportID).HasMaxLength(new int?(64)); Property((Case d) => d.Country).HasMaxLength(new int?(64)); Property((Case d) => d.LicenseID).HasMaxLength(new int?(64)); Property((Case d) => d.LicenseState).HasMaxLength(new int?(64)); Property((Case d) => d.Email).HasMaxLength(new int?(128)); Property((Case d) => d.ResolutionCode).HasMaxLength(new int?(32)); Property((Case d) => d.ResolutionDesc).HasMaxLength(new int?(64)); Property((Case d) => d.CasePicture).HasColumnType("image"); Property((Case d) => d.DLPicture).HasColumnType("image"); Property((Case d) => d.PassportPicture).HasColumnType("image"); }
public IndexBuilderArgument(IndexAttribute indexAttr, params string[] propertyNames) { this.PropertyNames = propertyNames; this.IndexName = indexAttr.Name; this.IsUnique = indexAttr.IsUnique; this.IsClustered = indexAttr.IsClustered; }
public void IndexAttribute_Ctor_AsExpected() { var i = new IndexAttribute(true, "myIndex"); i.IsUnique.Should().BeTrue(); i.IndexName.Should().Be("myIndex"); }
private void ProcessIsUnique(IndexDef indexDef, IndexAttribute attribute) { if (attribute.unique.HasValue) { indexDef.IsUnique = attribute.Unique; } }
public void MergeWith_returns_same_instance_if_other_is_same_or_null() { var attribute = new IndexAttribute(); Assert.Same(attribute, attribute.MergeWith(attribute)); Assert.Same(attribute, attribute.MergeWith(null)); }
internal static CompatibilityResult IsCompatibleWith( this IndexAttribute me, IndexAttribute other, bool ignoreOrder = false) { if (object.ReferenceEquals((object)me, (object)other) || other == null) { return(new CompatibilityResult(true, (string)null)); } string errorMessage = (string)null; if (me.Name != other.Name) { errorMessage = Strings.ConflictingIndexAttributeProperty((object)"Name", (object)me.Name, (object)other.Name); } if (!ignoreOrder && me.Order != -1 && (other.Order != -1 && me.Order != other.Order)) { errorMessage = (errorMessage == null ? "" : errorMessage + Environment.NewLine + "\t") + Strings.ConflictingIndexAttributeProperty((object)"Order", (object)me.Order, (object)other.Order); } if (me.IsClusteredConfigured && other.IsClusteredConfigured && me.IsClustered != other.IsClustered) { errorMessage = (errorMessage == null ? "" : errorMessage + Environment.NewLine + "\t") + Strings.ConflictingIndexAttributeProperty((object)"IsClustered", (object)me.IsClustered, (object)other.IsClustered); } if (me.IsUniqueConfigured && other.IsUniqueConfigured && me.IsUnique != other.IsUnique) { errorMessage = (errorMessage == null ? "" : errorMessage + Environment.NewLine + "\t") + Strings.ConflictingIndexAttributeProperty((object)"IsUnique", (object)me.IsUnique, (object)other.IsUnique); } return(new CompatibilityResult(errorMessage == null, errorMessage)); }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { if (modelBuilder == null) { throw new ArgumentNullException("modelBuilder"); } EntityTypeConfiguration <TUser> configuration = modelBuilder.Entity <TUser>().ToTable("Employees"); configuration.HasMany <TUserRole>(u => u.Roles).WithRequired().HasForeignKey <TKey>(ur => ur.EmployeeId); configuration.HasMany <TUserClaim>(u => u.Claims).WithRequired().HasForeignKey <TKey>(uc => uc.EmployeeId); configuration.HasMany <TUserLogin>(u => u.Logins).WithRequired().HasForeignKey <TKey>(ul => ul.EmployeeId); IndexAttribute indexAttribute = new IndexAttribute("UserNameIndex") { IsUnique = true }; configuration.Property((Expression <Func <TUser, string> >)(u => u.UserName)).IsRequired().HasMaxLength(0x100).HasColumnAnnotation("Index", new IndexAnnotation(indexAttribute)); configuration.Property((Expression <Func <TUser, string> >)(u => u.Email)).HasMaxLength(0x100); modelBuilder.Entity <TUserRole>().HasKey(r => new { EmployeeId = r.EmployeeId, RoleId = r.RoleId }).ToTable("EmployeeRoles"); modelBuilder.Entity <TUserLogin>().HasKey(l => new { LoginProvider = l.LoginProvider, ProviderKey = l.ProviderKey, EmployeeId = l.EmployeeId }).ToTable("EmployeeLogins"); modelBuilder.Entity <TUserClaim>().HasKey(c => new { ClaimType = c.ClaimType, ClaimValue = c.ClaimValue, EmployeeId = c.EmployeeId }).ToTable("EmployeeClaims"); EntityTypeConfiguration <TRole> configuration2 = modelBuilder.Entity <TRole>().ToTable("Roles"); IndexAttribute attribute2 = new IndexAttribute("RoleNameIndex") { IsUnique = true }; configuration2.Property((Expression <Func <TRole, string> >)(r => r.Name)).IsRequired().HasMaxLength(0x100).HasColumnAnnotation("Index", new IndexAnnotation(attribute2)); configuration2.HasMany <TUserRole>(r => r.Users).WithRequired().HasForeignKey <TKey>(ur => ur.RoleId); }
public static void AssertConfiguration(this IndexAttribute indexAttribute, string name, int?order, bool?isUnique, bool?isClustered) { Assert.Equal(name, indexAttribute.Name); if (order.HasValue) { Assert.Equal(order.Value, indexAttribute.Order); } if (isClustered.HasValue) { Assert.Equal(isClustered.Value, indexAttribute.IsClustered); } else { Assert.False(indexAttribute.IsClusteredConfigured); } if (isUnique.HasValue) { Assert.Equal(isUnique.Value, indexAttribute.IsUnique); } else { Assert.False(indexAttribute.IsUniqueConfigured); } }
public void Process(AddForeignKeyIndexAction action) { var type = action.Type; Func <IndexDef, bool> predicate = i => i.IsSecondary && i.KeyFields.Count == 1 && i.KeyFields[0].Key == action.Field.Name; if (type.Indexes.Any(predicate)) { return; } var queue = new Queue <TypeDef>(); var interfaces = new HashSet <TypeDef>(); queue.Enqueue(type); while (queue.Count > 0) { var item = queue.Dequeue(); foreach (var @interface in context.ModelDef.Types.FindInterfaces(item.UnderlyingType)) { queue.Enqueue(@interface); interfaces.Add(@interface); } } if (interfaces.SelectMany(i => i.Indexes).Any(predicate)) { return; } var attribute = new IndexAttribute(action.Field.Name); var indexDef = context.ModelDefBuilder.DefineIndex(type, attribute); type.Indexes.Add(indexDef); }
public RegisteredReportEntityConfiguration() : base() { var indexAttribute = new IndexAttribute() { IsUnique = true }; HasKey ( m => new { m.Id } ); // Configure the primary key constraints Property(m => m.Id) .HasColumnAnnotation ( "Index", new IndexAnnotation(indexAttribute) ); Map ( m => { m.ToTable("RegisteredReports"); } ); }
private static void CheckMissingProperties( IndexAttribute indexAttribute, IConventionEntityType entityType, InvalidOperationException innerException) { foreach (var propertyName in indexAttribute.PropertyNames) { var property = entityType.FindProperty(propertyName); if (property == null) { if (indexAttribute.Name == null) { throw new InvalidOperationException( CoreStrings.UnnamedIndexDefinedOnNonExistentProperty( entityType.DisplayName(), indexAttribute.PropertyNames.Format(), propertyName), innerException); } throw new InvalidOperationException( CoreStrings.NamedIndexDefinedOnNonExistentProperty( indexAttribute.Name, entityType.DisplayName(), indexAttribute.PropertyNames.Format(), propertyName), innerException); } } }
private static void CheckIgnoredProperties( IndexAttribute indexAttribute, IConventionEntityType entityType) { foreach (var propertyName in indexAttribute.PropertyNames) { if (entityType.Builder.IsIgnored(propertyName, fromDataAnnotation: true)) { if (indexAttribute.Name == null) { throw new InvalidOperationException( CoreStrings.UnnamedIndexDefinedOnIgnoredProperty( entityType.DisplayName(), indexAttribute.PropertyNames.Format(), propertyName)); } throw new InvalidOperationException( CoreStrings.NamedIndexDefinedOnIgnoredProperty( indexAttribute.Name, entityType.DisplayName(), indexAttribute.PropertyNames.Format(), propertyName)); } } }
private static void MergeLists( ICollection <IndexAttribute> existingIndexes, IEnumerable <IndexAttribute> newIndexes, PropertyInfo propertyInfo) { foreach (IndexAttribute newIndex in newIndexes) { IndexAttribute index = newIndex; if (index == null) { throw new ArgumentNullException("indexAttribute"); } IndexAttribute other = existingIndexes.SingleOrDefault <IndexAttribute>((Func <IndexAttribute, bool>)(i => i.Name == index.Name)); if (other == null) { existingIndexes.Add(index); } else { CompatibilityResult compatibilityResult = index.IsCompatibleWith(other, false); if ((bool)compatibilityResult) { existingIndexes.Remove(other); existingIndexes.Add(index.MergeWith(other, false)); } else { string str = Environment.NewLine + "\t" + compatibilityResult.ErrorMessage; throw new InvalidOperationException(propertyInfo == (PropertyInfo)null ? Strings.ConflictingIndexAttribute((object)other.Name, (object)str) : Strings.ConflictingIndexAttributesOnProperty((object)propertyInfo.Name, (object)propertyInfo.ReflectedType.Name, (object)other.Name, (object)str)); } } } }
public void Start() { float start = JHSTime.Time; LOG.Info("Loading database service ..."); try { XmlConfigurator.Configure(new Uri(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs/Net4Log.xml"))); config = new Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs/hibernate.xml")); Type[] typelist = GetTypesInNamespace(Assembly.GetExecutingAssembly(), "LoginServer.MYSQL.Tables"); bool Added = false; for (int i = 0; i < typelist.Length; i++) { Added = false; string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"; xml += "<hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\">"; xml += "<class name=\"LoginServer.MYSQL.Tables." + typelist[i].Name + ", LoginServer\" table=\"" + typelist[i].Name.ToLower() + "\">"; foreach (PropertyInfo prop in typelist[i].GetProperties()) { if (prop.GetCustomAttribute(typeof(IndexAttribute)) != null && !Added) { IndexAttribute att = (IndexAttribute)prop.GetCustomAttribute(typeof(IndexAttribute)); if (!att.IsEnum) { xml += "<id name=\"" + prop.Name + "\" column=\"" + prop.Name + "\" type=\"" + prop.PropertyType.Name + "\">"; if (att.IsAutoGenerate) { xml += "<generator class=\"native\"></generator>"; } xml += "</id>"; } else { xml += "<property name=\"" + prop.Name + "\" type =\"" + att.ClassName + "\" />"; } Added = true; } else { xml += "<property name=\"" + prop.Name + "\" column=\"" + prop.Name + "\" type =\"" + prop.PropertyType.Name + "\"></property>"; } } xml += "</class>"; xml += "</hibernate-mapping>"; config.AddXmlString(xml); } factory = config.BuildSessionFactory(); } catch (Exception e) { Console.WriteLine(e); } Timer aTimer = new Timer(); aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); aTimer.Interval = UpdateEvery * 1000; aTimer.Enabled = true; LOG.Info("Finished loading database service, time-consuming:" + (JHSTime.Time - start) + " sec."); }
public ConsolidatedIndex(string table, IndexAttribute index) { DebugCheck.NotEmpty(table); DebugCheck.NotNull(index); _table = table; _index = index; }
public void TypeId_returns_different_values_for_different_instances() { Assert.NotEqual(new IndexAttribute().TypeId, new IndexAttribute().TypeId); var index = new IndexAttribute(); Assert.Equal(index.TypeId, index.TypeId); }
public ConsolidatedIndex(string table, string column, IndexAttribute index) : this(table, index) { DebugCheck.NotEmpty(table); DebugCheck.NotEmpty(column); DebugCheck.NotNull(index); _columns[index.Order] = column; }
/// <summary> Write a Index XML Element from attributes in a member. </summary> public virtual void WriteIndex(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, IndexAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass) { writer.WriteStartElement( "index" ); // Attribute: <column> if(attribute.Column != null) writer.WriteAttributeString("column", GetAttributeValue(attribute.Column, mappedClass)); // Attribute: <type> if(attribute.Type != null) writer.WriteAttributeString("type", GetAttributeValue(attribute.Type, mappedClass)); // Attribute: <length> if(attribute.Length != -1) writer.WriteAttributeString("length", attribute.Length.ToString()); WriteUserDefinedContent(writer, member, null, attribute); System.Collections.ArrayList memberAttribs = GetSortedAttributes(member); int attribPos; // Find the position of the IndexAttribute (its <sub-element>s must be after it) for(attribPos=0; attribPos<memberAttribs.Count; attribPos++) if( memberAttribs[attribPos] is IndexAttribute && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position ) break; // found int i = attribPos + 1; // Element: <column> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(ColumnAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is IndexAttribute ) break; // Following attributes are for this Index if( memberAttrib is ColumnAttribute ) WriteColumn(writer, member, memberAttrib as ColumnAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(ColumnAttribute), attribute); writer.WriteEndElement(); }