private string GetClassTableName(PersistentClass model, HbmClass classSchema) { if (classSchema.table == null) return mappings.NamingStrategy.ClassToTableName(model.EntityName); else return mappings.NamingStrategy.TableName(classSchema.table.Trim()); }
private void BindTimestamp(HbmTimestamp timestampSchema, PersistentClass rootClass, Table table) { if (timestampSchema == null) return; string propertyName = timestampSchema.name; SimpleValue simpleValue = new SimpleValue(table); BindColumns(timestampSchema, simpleValue, propertyName); if (!simpleValue.IsTypeSpecified) simpleValue.TypeName = NHibernateUtil.Timestamp.Name; Mapping.Property property = new Mapping.Property(simpleValue); BindProperty(timestampSchema, property); // 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; rootClass.Version = property; rootClass.AddProperty(property); }
private Mapping.Collection CreateList(XmlNode node, string prefix, string path, PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas) { List list = new List(owner); BindCollection(node, list, prefix, path, containingType, inheritedMetas); return list; }
private Mapping.Collection CreateSet(XmlNode node, string prefix, string path, PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas) { Set setCollection = new Set(owner); BindCollection(node, setCollection, prefix, path, containingType, inheritedMetas); return setCollection; }
private Mapping.Collection CreateMap(XmlNode node, string prefix, string path, PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas) { Map map = new Map(owner); BindCollection(node, map, prefix, path, containingType, inheritedMetas); return map; }
public NHibernateTypeDescriptor(Type entityType, ICustomTypeDescriptor parent, Configuration nhibernateConfiguration, Type metaDataType) : base(parent) { Type metaDataType1 = metaDataType; while (entityType != null && entityType.Name.EndsWith("Proxy") && entityType.Assembly.GetName().Name.EndsWith("ProxyAssembly")) entityType = entityType.BaseType; this.entityType = entityType; this._nhibernateConfiguration = nhibernateConfiguration; _classMetadata = nhibernateConfiguration.GetClassMapping(this.entityType); _identifierCols = _classMetadata.Identifier.ColumnIterator; if (metaDataType1 != null) { var memberInfos = metaDataType1.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); foreach (var memberInfo in memberInfos) { var attributes = memberInfo.GetCustomAttributes(false).Cast<Attribute>(); if (attributes.Any()) _metaDataAttributes.Add(memberInfo.Name, attributes); } } }
private Mapping.Collection CreateIdentifierBag(XmlNode node, string prefix, string path, PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas) { IdentifierBag bag = new IdentifierBag(owner); BindCollection(node, bag, prefix, path, containingType, inheritedMetas); return bag; }
private void CreateIdentifierProperty(HbmId idSchema, PersistentClass rootClass, SimpleValue id) { if (idSchema.name != null) { string access = idSchema.access ?? mappings.DefaultAccess; id.SetTypeUsingReflection(rootClass.MappedClass.AssemblyQualifiedName, idSchema.name, access); Mapping.Property property = new Mapping.Property(id); property.Name = idSchema.name; if (property.Value.Type == null) throw new MappingException("could not determine a property type for: " + property.Name); property.PropertyAccessorName = idSchema.access ?? mappings.DefaultAccess; property.Cascade = mappings.DefaultCascade; property.IsUpdateable = true; property.IsInsertable = true; property.IsOptimisticLocked = true; property.Generation = PropertyGeneration.Never; property.MetaAttributes = GetMetas(idSchema); rootClass.IdentifierProperty = property; LogMappedProperty(property); } }
protected void BindSubclasses(IEnumerable<HbmSubclass> subclasses, PersistentClass persistentClass, IDictionary<string, MetaAttribute> inheritedMetas) { foreach (var subclass in subclasses) { new SubclassBinder(this).HandleSubclass(persistentClass, subclass, inheritedMetas); } }
private Mapping.Collection CreateList(XmlNode node, string prefix, string path, PersistentClass owner, System.Type containingType) { List list = new List(owner); BindCollection(node, list, prefix, path, containingType); return list; }
private Mapping.Collection CreateSet(XmlNode node, string prefix, string path, PersistentClass owner, System.Type containingType) { Set setCollection = new Set(owner); BindCollection(node, setCollection, prefix, path, containingType); return setCollection; }
private Mapping.Collection CreateIdentifierBag(XmlNode node, string prefix, string path, PersistentClass owner, System.Type containingType) { IdentifierBag bag = new IdentifierBag(owner); BindCollection(node, bag, prefix, path, containingType); return bag; }
private Mapping.Collection CreateMap(XmlNode node, string prefix, string path, PersistentClass owner, System.Type containingType) { Map map = new Map(owner); BindCollection(node, map, prefix, path, containingType); return map; }
/// <summary> /// Generates an IdentifierProperty representation of the for a given entity mapping. /// </summary> /// <param name="mappedEntity">The mapping definition of the entity.</param> /// <param name="generator">The identifier value generator to use for this identifier.</param> /// <returns>The appropriate IdentifierProperty definition.</returns> public static IdentifierProperty BuildIdentifierProperty(PersistentClass mappedEntity, IIdentifierGenerator generator) { string mappedUnsavedValue = mappedEntity.Identifier.NullValue; IType type = mappedEntity.Identifier.Type; Mapping.Property property = mappedEntity.IdentifierProperty; Cascades.IdentifierValue unsavedValue = UnsavedValueFactory.GetUnsavedIdentifierValue( mappedUnsavedValue, GetGetter(property), type, GetConstructor(mappedEntity) ); if (property == null) { // this is a virtual id property... return new IdentifierProperty( type, mappedEntity.HasEmbeddedIdentifier, unsavedValue, generator ); } else { return new IdentifierProperty( property.Name, null, // TODO H3: property.NodeName, type, mappedEntity.HasEmbeddedIdentifier, unsavedValue, generator ); } }
/// <summary> /// Wrapper class to produce an Ado.Net Datatable from any entity, /// and perform SqlBulkCopy operations /// </summary> public SqlEntityBulkCopy(string sqlCnnString, Type entityType) { if (Cfg == null) { //Note: The NHibernate.Cfg.Configuration is meant only as an initialization-time object. //Note: NHibernate.ISessionFactory is immutable and does not retain any association back to the Session Cfg = new Configuration(); //Cfg.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"); Cfg.SetProperty("dialect", "NHibernate.Dialect.MsSql2008Dialect"); Cfg.SetProperty("connection.provider", "NHibernate.Connection.DriverConnectionProvider"); Cfg.SetProperty("connection.driver_class", "NHibernate.Driver.SqlClientDriver"); Cfg.SetProperty("connection.connection_string", sqlCnnString); //add all the mappings embedded in this assembly Cfg.AddAssembly(typeof(SqlEntityBulkCopy).Assembly); var sessionFactory = Cfg.BuildSessionFactory(); SessionFactoryImpl = (ISessionFactoryImplementor)sessionFactory; } EntityType = entityType; //_session = SessionFactoryImpl.OpenSession(); _metaData = SessionFactoryImpl.GetClassMetadata(EntityType); _persistentClass = Cfg.GetClassMapping(EntityType); _sqlCnn = new SqlConnection(sqlCnnString); _sqlBulkCopy = new SqlBulkCopy(_sqlCnn); //Debug.WriteLine("EntityName = " + _metaData.EntityName); //Debug.WriteLine("IdentifierPropertyName = " + _metaData.IdentifierPropertyName); //Debug.WriteLine("IdentifierType = " + _metaData.IdentifierType); BuildDataTable(); BuildAndMapSqlBulkCopy(); }
public void HandleUnionSubclass(PersistentClass model, XmlNode subnode, IDictionary<string, MetaAttribute> inheritedMetas) { var unionSubclass = new UnionSubclass(model); BindClass(subnode, null, unionSubclass, inheritedMetas); inheritedMetas = GetMetas(subnode.SelectNodes(HbmConstants.nsMeta, namespaceManager), inheritedMetas, true); // get meta's from <union-subclass> // union subclass if (unionSubclass.EntityPersisterClass == null) unionSubclass.RootClazz.EntityPersisterClass = typeof(UnionSubclassEntityPersister); //table + schema names XmlAttribute schemaNode = subnode.Attributes["schema"]; string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value; XmlAttribute catalogNode = subnode.Attributes["catalog"]; string catalog = catalogNode == null ? mappings.CatalogName : catalogNode.Value; Table denormalizedSuperTable = unionSubclass.Superclass.Table; Table mytable = mappings.AddDenormalizedTable(schema, catalog, GetClassTableName(unionSubclass, subnode), unionSubclass.IsAbstract.GetValueOrDefault(), null, denormalizedSuperTable); ((ITableOwner)unionSubclass).Table = mytable; log.InfoFormat("Mapping union-subclass: {0} -> {1}", unionSubclass.EntityName, unionSubclass.Table.Name); // properties PropertiesFromXML(subnode, unionSubclass, inheritedMetas); model.AddSubclass(unionSubclass); mappings.AddClass(unionSubclass); }
protected void BindJoinedSubclasses(IEnumerable<HbmJoinedSubclass> joinedSubclasses, PersistentClass persistentClass, IDictionary<string, MetaAttribute> inheritedMetas) { foreach (var joinedSubclass in joinedSubclasses) { new JoinedSubclassBinder(this).HandleJoinedSubclass(persistentClass, joinedSubclass, inheritedMetas); } }
public void HandleUnionSubclass(PersistentClass model, HbmUnionSubclass unionSubclassMapping, IDictionary<string, MetaAttribute> inheritedMetas) { var unionSubclass = new UnionSubclass(model); BindClass(unionSubclassMapping, unionSubclass, inheritedMetas); inheritedMetas = GetMetas(unionSubclassMapping, inheritedMetas, true); // get meta's from <union-subclass> // union subclass if (unionSubclass.EntityPersisterClass == null) unionSubclass.RootClazz.EntityPersisterClass = typeof(UnionSubclassEntityPersister); //table + schema names string schema = unionSubclassMapping.schema ?? mappings.SchemaName; string catalog = unionSubclassMapping.catalog ?? mappings.CatalogName; Table denormalizedSuperTable = unionSubclass.Superclass.Table; Table mytable = mappings.AddDenormalizedTable(schema, catalog, GetClassTableName(unionSubclass, unionSubclassMapping.table), unionSubclass.IsAbstract.GetValueOrDefault(), null, denormalizedSuperTable); ((ITableOwner)unionSubclass).Table = mytable; log.InfoFormat("Mapping union-subclass: {0} -> {1}", unionSubclass.EntityName, unionSubclass.Table.Name); // properties new PropertiesBinder(mappings, unionSubclass, dialect).Bind(unionSubclassMapping.Properties, inheritedMetas); BindUnionSubclasses(unionSubclassMapping.UnionSubclasses, unionSubclass, inheritedMetas); model.AddSubclass(unionSubclass); mappings.AddClass(unionSubclass); }
public void HandleUnionSubclass(PersistentClass model, XmlNode subnode) { UnionSubclass unionSubclass = new UnionSubclass(model); BindClass(subnode, unionSubclass); // union subclass if (unionSubclass.EntityPersisterClass == null) unionSubclass.RootClazz.EntityPersisterClass = typeof(UnionSubclassEntityPersister); //table + schema names XmlAttribute schemaNode = subnode.Attributes["schema"]; string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value; XmlAttribute catalogNode = subnode.Attributes["catalog"]; string catalog = catalogNode == null ? mappings.CatalogName : catalogNode.Value; Table denormalizedSuperTable = unionSubclass.Superclass.Table; Table mytable = mappings.AddDenormalizedTable(schema, catalog, GetClassTableName(unionSubclass, subnode), unionSubclass.IsAbstract.GetValueOrDefault(), null, denormalizedSuperTable); ((ITableOwner)unionSubclass).Table = mytable; log.InfoFormat("Mapping union-subclass: {0} -> {1}", unionSubclass.EntityName, unionSubclass.Table.Name); // properties PropertiesFromXML(subnode, unionSubclass); model.AddSubclass(unionSubclass); mappings.AddClass(unionSubclass); }
public Mapping.Collection Create(ICollectionPropertiesMapping collectionMapping, string className, string propertyFullPath, PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas) { var collectionType = collectionMapping.GetType(); if (collectionType == typeof (HbmBag)) { return CreateBag((HbmBag)collectionMapping, className, propertyFullPath, owner, containingType, inheritedMetas); } else if (collectionType == typeof (HbmSet)) { return CreateSet((HbmSet)collectionMapping, className, propertyFullPath, owner, containingType, inheritedMetas); } else if (collectionType == typeof (HbmList)) { return CreateList((HbmList)collectionMapping, className, propertyFullPath, owner, containingType, inheritedMetas); } else if (collectionType == typeof (HbmMap)) { return CreateMap((HbmMap)collectionMapping, className, propertyFullPath, owner, containingType, inheritedMetas); } else if (collectionType == typeof (HbmIdbag)) { return CreateIdentifierBag((HbmIdbag)collectionMapping, className, propertyFullPath, owner, containingType, inheritedMetas); } else if (collectionType == typeof (HbmArray)) { return CreateArray((HbmArray)collectionMapping, className, propertyFullPath, owner, containingType, inheritedMetas); } else if (collectionType == typeof (HbmPrimitiveArray)) { return CreatePrimitiveArray((HbmPrimitiveArray)collectionMapping, className, propertyFullPath, owner, containingType, inheritedMetas); } throw new MappingException("Not supported collection mapping element:" + collectionType); }
public PocoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) : base(entityMetamodel, mappedEntity) { mappedClass = mappedEntity.MappedClass; proxyInterface = mappedEntity.ProxyInterface; islifecycleImplementor = typeof(ILifecycle).IsAssignableFrom(mappedClass); isValidatableImplementor = typeof(IValidatable).IsAssignableFrom(mappedClass); foreach (Mapping.Property property in mappedEntity.PropertyClosureIterator) { if (property.IsLazy) lazyPropertyNames.Add(property.Name); if (property.UnwrapProxy) unwrapProxyPropertyNames.Add(property.Name); } SetReflectionOptimizer(); Instantiator = BuildInstantiator(mappedEntity); if (hasCustomAccessors) { optimizer = null; } proxyValidator = Cfg.Environment.BytecodeProvider.ProxyFactoryFactory.ProxyValidator; }
/// <summary> /// Creates a specific Persister - could be a built in or custom persister. /// </summary> /// <param name="persisterClass"></param> /// <param name="model"></param> /// <param name="factory"></param> /// <returns></returns> public static IClassPersister Create( System.Type persisterClass, PersistentClass model, ISessionFactoryImplementor factory ) { ConstructorInfo pc; try { pc = persisterClass.GetConstructor( PersisterFactory.PersisterConstructorArgs ); } catch( Exception e ) { throw new MappingException( "Could not get constructor for " + persisterClass.Name, e ); } try { return ( IClassPersister ) pc.Invoke( new object[ ] {model, factory} ); } catch( TargetInvocationException tie ) { Exception e = tie.InnerException; if( e is HibernateException ) { throw e; } else { throw new MappingException( "Could not instantiate persister " + persisterClass.Name, e ); } } catch( Exception e ) { throw new MappingException( "Could not instantiate persister " + persisterClass.Name, e ); } }
public void BindId(HbmId idSchema, PersistentClass rootClass, Table table) { if (idSchema != null) { var id = new SimpleValue(table); new TypeBinder(id, Mappings).Bind(idSchema.Type); rootClass.Identifier = id; Func<HbmColumn> defaultColumn = () => new HbmColumn { name = idSchema.name ?? RootClass.DefaultIdentifierColumnName, length = idSchema.length }; new ColumnsBinder(id, Mappings).Bind(idSchema.Columns, false, defaultColumn); CreateIdentifierProperty(idSchema, rootClass, id); VerifiyIdTypeIsValid(id.Type, rootClass.EntityName); new IdGeneratorBinder(Mappings).BindGenerator(id, GetIdGenerator(idSchema)); id.Table.SetIdentifierValue(id); BindUnsavedValue(idSchema, id); } }
public AnnotationsMetadataReader(GlobalConfiguration globalCfg, PersistentClass pc) { this.globalCfg = globalCfg; this.pc = pc; _auditData = new ClassAuditingData(); }
protected void BindUnionSubclasses(IEnumerable<HbmUnionSubclass> unionSubclasses, PersistentClass persistentClass, IDictionary<string, MetaAttribute> inheritedMetas) { foreach (var unionSubclass in unionSubclasses) { new UnionSubclassBinder(this).HandleUnionSubclass(persistentClass, unionSubclass, inheritedMetas); } }
private Mapping.Collection CreateMap(HbmMap mapMapping, string prefix, string path, PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas) { var map = new Map(owner); BindCollection(mapMapping, map, prefix, path, containingType, inheritedMetas); AddMapSecondPass(mapMapping, map, inheritedMetas); return map; }
private Mapping.Collection CreateSet(HbmSet setMapping, string prefix, string path, PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas) { var setCollection = new Set(owner); BindCollection(setMapping, setCollection, prefix, path, containingType, inheritedMetas); AddSetSecondPass(setMapping, setCollection, inheritedMetas); return setCollection; }
private static SimpleValue CreateIdentifier(HbmId idSchema, PersistentClass rootClass, Table table) { SimpleValue iv = new SimpleValue(table); iv.TypeName = idSchema.type; rootClass.Identifier = iv; return iv; }
private Mapping.Collection CreateList(HbmList listMapping, string prefix, string path, PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas) { var list = new List(owner); BindCollection(listMapping, list, prefix, path, containingType, inheritedMetas); AddListSecondPass(listMapping, list, inheritedMetas); return list; }
private Mapping.Collection CreateBag(HbmBag bagMapping, string prefix, string path, PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas) { var bag = new Bag(owner); BindCollection(bagMapping, bag, prefix, path, containingType, inheritedMetas); AddCollectionSecondPass(bagMapping, bag, inheritedMetas); return bag; }
/// <summary> /// Тест наличия правил удаления для классов добавленных в Nhibernate. /// Чтобы исключить класс из проверки добавьте его в коллекцию IgnoreMissingClass /// </summary> public virtual void DeleteRuleExisitForNHMappedClasssTest(NHibernate.Mapping.PersistentClass mapping) { if (IgnoreMissingClass.ContainsKey(mapping.MappedClass)) { Assert.Ignore(IgnoreMissingClass[mapping.MappedClass]); } var exist = DeleteConfig.ClassDeleteRules.Any(i => i.ObjectClass == mapping.MappedClass); Assert.That(exist, "Класс {0} настроен в мапинге NHibernate, но для него отсутствуют правила удаления.", mapping.MappedClass); }
/// <summary> /// Adds a <see cref="Subclass"/> to the class hierarchy. /// </summary> /// <param name="subclass">The <see cref="Subclass"/> to add to the hierarchy.</param> public virtual void AddSubclass(Subclass subclass) { // Inheritable cycle detection (paranoid check) PersistentClass superclass = Superclass; while (superclass != null) { if (subclass.Name == superclass.Name) { throw new MappingException(string.Format("Circular inheritance mapping detected: {0} will have itself as superclass when extending {1}", subclass.Name, Name)); } superclass = superclass.Superclass; } subclasses.Add(subclass); }
public PrimitiveArray(PersistentClass owner) : base(owner) { }
public override void DeleteRuleExisitForNHMappedClasssTest(NHibernate.Mapping.PersistentClass mapping) { base.DeleteRuleExisitForNHMappedClasssTest(mapping); }
/// <summary> /// Initializes a new instance of the <see cref="Subclass"/> class. /// </summary> /// <param name="superclass">The <see cref="PersistentClass"/> that is the superclass.</param> public Subclass(PersistentClass superclass) { this.superclass = superclass; subclassId = superclass.NextSubclassId(); }
/// <summary> /// /// </summary> /// <param name="table"></param> /// <param name="owner"></param> public OneToOne(Table table, PersistentClass owner) : base(table) { identifier = owner.Key; entityName = owner.EntityName; }
/// <summary> /// /// </summary> /// <param name="owner"></param> protected IdentifierCollection(PersistentClass owner) : base(owner) { }
public Component(Collection collection) : base(collection.CollectionTable) { owner = collection.Owner; }
/// <summary> /// /// </summary> /// <param name="table"></param> public Component(Table table) : base(table) { this.owner = null; }
public Component(Join join) : base(join.Table) { owner = join.PersistentClass; }
/// <summary> /// Initializes a new instance of the <see cref="Map" /> class. /// </summary> /// <param name="owner">The <see cref="PersistentClass"/> that contains this map mapping.</param> public Map(PersistentClass owner) : base(owner) { }
public UnionSubclass(PersistentClass superclass) : base(superclass) { }
public OneToMany(PersistentClass owner) { referencingTable = (owner == null) ? null : owner.Table; }
public Array(PersistentClass owner) : base(owner) { }
/// <summary> /// A bag permits duplicates, so it has no primary key. /// </summary> /// <param name="owner">The <see cref="PersistentClass"/> that contains this bag mapping.</param> public Bag(PersistentClass owner) : base(owner) { }
/// <summary> /// /// </summary> /// <param name="owner"></param> public Component(PersistentClass owner) : base(owner.Table) { this.owner = owner; }
/// <summary> /// Initializes a new instance of the <see cref="List"/> class. /// </summary> /// <param name="owner">The <see cref="PersistentClass"/> that contains this list mapping.</param> public List(PersistentClass owner) : base(owner) { }
protected IndexedCollection(PersistentClass owner) : base(owner) { }
public Component(Component component) : base(component.Table) { owner = component.Owner; }
/// <summary> /// /// </summary> /// <param name="owner"></param> public IdentifierBag(PersistentClass owner) : base(owner) { }
public Component(Table table, PersistentClass owner) : base(table) { this.owner = owner; }
public JoinedSubclass(PersistentClass superclass) : base(superclass) { }
protected Collection(PersistentClass owner) { this.owner = owner; }
public SingleTableSubclass(PersistentClass superclass) : base(superclass) { }