/// <summary> /// Add the metadata for an entity. /// </summary> /// <param name="meta"></param> void AddClass(IClassMetadata meta) { var type = meta.GetMappedClass(EntityMode.Poco); // "Customer:#Breeze.Nhibernate.NorthwindIBModel": { var classKey = type.Name + ":#" + type.Namespace; var cmap = new Dictionary<string, object>(); _typeList.Add(cmap); cmap.Add("shortName", type.Name); cmap.Add("namespace", type.Namespace); var entityPersister = meta as IEntityPersister; var generator = entityPersister != null ? entityPersister.IdentifierGenerator : null; if (generator != null) { string genType = null; if (generator is IdentityGenerator) genType = "Identity"; else if (generator is Assigned) genType = "None"; else genType = "KeyGenerator"; cmap.Add("autoGeneratedKeyType", genType); // TODO find the real generator } var resourceName = Pluralize(type.Name); // TODO find the real name cmap.Add("defaultResourceName", resourceName); _resourceMap.Add(resourceName, classKey); var dataList = new List<Dictionary<string, object>>(); cmap.Add("dataProperties", dataList); var navList = new List<Dictionary<string, object>>(); cmap.Add("navigationProperties", navList); var persistentClass = _configuration.GetClassMapping(type); AddClassProperties(meta, persistentClass, dataList, navList); }
public static Core.Validator GetValidatorFromSession(ISessionFactory sessionFactory) { var allDefindedClasses = sessionFactory.GetAllClassMetadata(); Core.Validator validator = new Core.Validator(); foreach (KeyValuePair <string, IClassMetadata> pair in allDefindedClasses) { IClassMetadata metadata = pair.Value; foreach (string propertyName in metadata.PropertyNames) { IType propertyType = metadata.GetPropertyType(propertyName); StringType st = propertyType as StringType; if (st != null) { if (st.SqlType.Length > 0) { validator.AddRule(Rule.For(metadata.GetMappedClass(EntityMode.Poco)) .OnMember(propertyName) .MaxLength(st.SqlType.Length) .Message(String.Format( "Property {0} have a maximum length of {1}", propertyName, st.SqlType.Length))); } } } } return(validator); }
/// <summary> /// Add the metadata for an entity. /// </summary> /// <param name="meta"></param> void AddClass(IClassMetadata meta) { var type = meta.GetMappedClass(EntityMode.Poco); // "Customer:#Breeze.Nhibernate.NorthwindIBModel": { var classKey = type.Name + ":#" + type.Namespace; var cmap = new Dictionary <string, object>(); _typeList.Add(cmap); cmap.Add("shortName", type.Name); cmap.Add("namespace", type.Namespace); var persistentClass = _configuration.GetClassMapping(type); var superClass = persistentClass.Superclass; if (superClass != null) { var superType = superClass.MappedClass; var baseTypeName = superType.Name + ":#" + superType.Namespace; cmap.Add("baseTypeName", baseTypeName); } var entityPersister = meta as IEntityPersister; var generator = entityPersister != null ? entityPersister.IdentifierGenerator : null; if (generator != null) { string genType = null; if (generator is IdentityGenerator) { genType = "Identity"; } else if (generator is Assigned || generator is ForeignGenerator) { genType = "None"; } else { genType = "KeyGenerator"; } cmap.Add("autoGeneratedKeyType", genType); // TODO find the real generator } var resourceName = Pluralize(type.Name); // TODO find the real name cmap.Add("defaultResourceName", resourceName); _resourceMap.Add(resourceName, classKey); var dataList = new List <Dictionary <string, object> >(); cmap.Add("dataProperties", dataList); var navList = new List <Dictionary <string, object> >(); cmap.Add("navigationProperties", navList); AddClassProperties(meta, persistentClass, dataList, navList); }
/// <summary> /// Initialize and configure the data source using given properties. /// Called when space is started. /// </summary> /// <param name="properties">Propeties to initialize by.</param> public override void Init(Dictionary <string, string> properties) { base.Init(properties); _enumeratorLoadFetchSize = GetIntProperty("EnumeratorLoadFetchSize", _enumeratorLoadFetchSize); _initialLoadChunkSize = GetIntProperty("InitialLoadChunkSize", _initialLoadChunkSize); _performOrderById = GetBoolProperty("PerformOrderById", _performOrderById); _initialLoadThreadPoolSize = GetIntProperty("InitialLoadThreadPoolSize", _initialLoadThreadPoolSize); _useMerge = GetBoolProperty("UseMerge", _useMerge); // only configure a session factory if it is not injected if (_sessionFactory == null) { string nhibernateFile = GetFileProperty(NHibernateConfigProperty); string hbmDirectory = GetFileProperty(NHibernateHbmDirectory); string connectionString = GetProperty(NHibernateConnectionStringProperty); _sessionFactory = SessionFactoryBuilder.GetFactory(nhibernateFile, hbmDirectory, connectionString); } // only extract managed entries if it wasn't injected if (_managedEntries == null) { List <string> managedEntriesList = new List <string>(); IDictionary <string, IClassMetadata> allClassMetadata = _sessionFactory.GetAllClassMetadata(); foreach (string type in allClassMetadata.Keys) { managedEntriesList.Add(type); } ManagedEntries = managedEntriesList.ToArray(); } // only extract initial load entries if it wasn't injected if (_initialLoadEntries == null) { List <string> initialLoadEntriesList = new List <string>(); IDictionary <string, IClassMetadata> allClassMetadata = _sessionFactory.GetAllClassMetadata(); foreach (KeyValuePair <string, IClassMetadata> entry in allClassMetadata) { AbstractEntityPersister entityPersister = (AbstractEntityPersister)entry.Value; string mappedSuperClass = entityPersister.MappedSuperclass; if (mappedSuperClass != null) { IClassMetadata superClassMetadata = allClassMetadata[mappedSuperClass]; if (superClassMetadata.GetMappedClass(EntityMode.Map) != null) { //Filter out those who have their super classes mapped continue; } } initialLoadEntriesList.Add(entry.Key); } InitialLoadEntries = initialLoadEntriesList.ToArray(); } }
static ExplorerIcon GetIcon(ISessionFactory sessionFactory, IClassMetadata classMetadata, string propertyName) { var propertyType = classMetadata.GetPropertyType(propertyName); return propertyType.IsCollectionType ? ((ICollectionPersister)sessionFactory.GetCollectionMetadata( string.Format("{0}.{1}", classMetadata.GetMappedClass(EntityMode.Poco), propertyName))) .IsManyToMany ? ExplorerIcon.ManyToMany : ExplorerIcon.OneToMany : propertyType.IsAssociationType ? ExplorerIcon.ManyToOne : ExplorerIcon.Column; }
protected NodeData CreateColumnInfo(Identifier parentIdentifier, IClassMetadata classMetadata, String propertyName) { Type type = classMetadata.GetMappedClass(EntityMode.Poco); ColumnInfo columnInfo = Schema.GetColumnInfo(type, propertyName); NodeData nodeData = new NodeData { ReportColumn = new ReportColumn(type, new Identifier(parentIdentifier, propertyName)), Caption = columnInfo.Caption, Format = columnInfo.Format, ColumnType = columnInfo.ColumnType, IsHidden = columnInfo.IsHidden }; return(nodeData); }
/// <summary> /// Add the properties for an entity. /// </summary> /// <param name="meta"></param> /// <param name="pClass"></param> /// <param name="dataList">will be populated with the data properties of the entity</param> /// <param name="navList">will be populated with the navigation properties of the entity</param> void AddClassProperties(IClassMetadata meta, PersistentClass pClass, List<Dictionary<string, object>> dataList, List<Dictionary<string, object>> navList) { // maps column names to their related data properties. Used in MakeAssociationProperty to convert FK column names to entity property names. var relatedDataPropertyMap = new Dictionary<string, Dictionary<string, object>>(); var persister = meta as AbstractEntityPersister; var type = meta.GetMappedClass(EntityMode.Poco); var propNames = meta.PropertyNames; var propTypes = meta.PropertyTypes; var propNull = meta.PropertyNullability; for (int i = 0; i < propNames.Length; i++) { var propType = propTypes[i]; if (!propType.IsAssociationType) // skip association types until we handle all the data types, so the relatedDataPropertyMap will be populated. { var propName = propNames[i]; var propColumns = pClass.GetProperty(propName).ColumnIterator.ToList(); if (propType.IsComponentType) { // complex type var compType = (ComponentType)propType; var complexTypeName = AddComponent(compType, propColumns); var compMap = new Dictionary<string, object>(); compMap.Add("nameOnServer", propName); compMap.Add("complexTypeName", complexTypeName); compMap.Add("isNullable", propNull[i]); dataList.Add(compMap); } else { // data property var col = propColumns.Count() == 1 ? propColumns[0] as Column : null; var isKey = meta.HasNaturalIdentifier && meta.NaturalIdentifierProperties.Contains(i); var isVersion = meta.IsVersioned && i == meta.VersionProperty; var dmap = MakeDataProperty(propName, propType.Name, propNull[i], col, isKey, isVersion); dataList.Add(dmap); var columnNameString = GetPropertyColumnNames(persister, propName); relatedDataPropertyMap.Add(columnNameString, dmap); } } } // Hibernate identifiers are excluded from the list of data properties, so we have to add them separately if (meta.HasIdentifierProperty) { var dmap = MakeDataProperty(meta.IdentifierPropertyName, meta.IdentifierType.Name, false, null, true, false); dataList.Insert(0, dmap); var columnNameString = GetPropertyColumnNames(persister, meta.IdentifierPropertyName); relatedDataPropertyMap.Add(columnNameString, dmap); } else if (meta.IdentifierType != null && meta.IdentifierType.IsComponentType) { // composite key is a ComponentType var compType = (ComponentType)meta.IdentifierType; var compNames = compType.PropertyNames; for (int i = 0; i < compNames.Length; i++) { var propType = compType.Subtypes[i]; if (!propType.IsAssociationType) { var dmap = MakeDataProperty(compNames[i], propType.Name, compType.PropertyNullability[i], null, true, false); dataList.Insert(0, dmap); } else { var manyToOne = propType as ManyToOneType; //var joinable = manyToOne.GetAssociatedJoinable(this._sessionFactory); var propColumnNames = GetPropertyColumnNames(persister, compNames[i]); var assProp = MakeAssociationProperty(type, (IAssociationType)propType, compNames[i], propColumnNames, pClass, relatedDataPropertyMap, true); navList.Add(assProp); } } } // We do the association properties after the data properties, so we can do the foreign key lookups for (int i = 0; i < propNames.Length; i++) { //var propColumnNames = persister.GetPropertyColumnNames(i); var propType = propTypes[i]; if (propType.IsAssociationType) { // navigation property var propName = propNames[i]; //if (propColumnNames.Length == 0) // propColumnNames = persister.KeyColumnNames; var propColumnNames = GetPropertyColumnNames(persister, propName); var assProp = MakeAssociationProperty(type, (IAssociationType)propType, propName, propColumnNames, pClass, relatedDataPropertyMap, false); navList.Add(assProp); } } }
/// <summary> /// Add the properties for an entity. /// </summary> /// <param name="meta"></param> /// <param name="pClass"></param> /// <param name="dataList">will be populated with the data properties of the entity</param> /// <param name="navList">will be populated with the navigation properties of the entity</param> void AddClassProperties(IClassMetadata meta, PersistentClass pClass, List <Dictionary <string, object> > dataList, List <Dictionary <string, object> > navList) { // maps column names to their related data properties. Used in MakeAssociationProperty to convert FK column names to entity property names. var relatedDataPropertyMap = new Dictionary <string, Dictionary <string, object> >(); var persister = meta as AbstractEntityPersister; var type = meta.GetMappedClass(EntityMode.Poco); var propNames = meta.PropertyNames; var propTypes = meta.PropertyTypes; var propNull = meta.PropertyNullability; for (int i = 0; i < propNames.Length; i++) { var propType = propTypes[i]; if (!propType.IsAssociationType) // skip association types until we handle all the data types, so the relatedDataPropertyMap will be populated. { var propName = propNames[i]; var propColumns = pClass.GetProperty(propName).ColumnIterator.ToList(); if (propType.IsComponentType) { // complex type var compType = (ComponentType)propType; var complexTypeName = AddComponent(compType, propColumns); var compMap = new Dictionary <string, object>(); compMap.Add("nameOnServer", propName); compMap.Add("complexTypeName", complexTypeName); compMap.Add("isNullable", propNull[i]); dataList.Add(compMap); } else { // data property var col = propColumns.Count() == 1 ? propColumns[0] as Column : null; var isKey = meta.HasNaturalIdentifier && meta.NaturalIdentifierProperties.Contains(i); var isVersion = meta.IsVersioned && i == meta.VersionProperty; var dmap = MakeDataProperty(propName, propType.Name, propNull[i], col, isKey, isVersion); dataList.Add(dmap); var columnNameString = GetPropertyColumnNames(persister, propName); relatedDataPropertyMap.Add(columnNameString, dmap); } } } // Hibernate identifiers are excluded from the list of data properties, so we have to add them separately if (meta.HasIdentifierProperty) { var dmap = MakeDataProperty(meta.IdentifierPropertyName, meta.IdentifierType.Name, false, null, true, false); dataList.Insert(0, dmap); var columnNameString = GetPropertyColumnNames(persister, meta.IdentifierPropertyName); relatedDataPropertyMap.Add(columnNameString, dmap); } else if (meta.IdentifierType != null && meta.IdentifierType.IsComponentType) { // composite key is a ComponentType var compType = (ComponentType)meta.IdentifierType; var compNames = compType.PropertyNames; for (int i = 0; i < compNames.Length; i++) { var propType = compType.Subtypes[i]; if (!propType.IsAssociationType) { var dmap = MakeDataProperty(compNames[i], propType.Name, compType.PropertyNullability[i], null, true, false); dataList.Insert(0, dmap); } else { var manyToOne = propType as ManyToOneType; //var joinable = manyToOne.GetAssociatedJoinable(this._sessionFactory); var propColumnNames = GetPropertyColumnNames(persister, compNames[i]); var assProp = MakeAssociationProperty(type, (IAssociationType)propType, compNames[i], propColumnNames, pClass, relatedDataPropertyMap, true); navList.Add(assProp); } } } // We do the association properties after the data properties, so we can do the foreign key lookups for (int i = 0; i < propNames.Length; i++) { //var propColumnNames = persister.GetPropertyColumnNames(i); var propType = propTypes[i]; if (propType.IsAssociationType) { // navigation property var propName = propNames[i]; //if (propColumnNames.Length == 0) // propColumnNames = persister.KeyColumnNames; var propColumnNames = GetPropertyColumnNames(persister, propName); var assProp = MakeAssociationProperty(type, (IAssociationType)propType, propName, propColumnNames, pClass, relatedDataPropertyMap, false); navList.Add(assProp); } } }
protected NodeData CreateColumnInfo(Identifier parentIdentifier, IClassMetadata classMetadata, String propertyName) { Type type = classMetadata.GetMappedClass(EntityMode.Poco); ColumnInfo columnInfo = Schema.GetColumnInfo(type, propertyName); NodeData nodeData = new NodeData { ReportColumn = new ReportColumn(type, new Identifier(parentIdentifier, propertyName)), Caption = columnInfo.Caption, Format = columnInfo.Format, ColumnType = columnInfo.ColumnType, IsHidden = columnInfo.IsHidden }; return nodeData; }
public static PropertyInfo GetPk(this IClassMetadata model) { return(model.GetMappedClass(EntityMode.Poco).GetProperty(model.IdentifierPropertyName)); }