public void VerifyTableNames() { var auditName = TestAssembly + ".Integration.Join.JoinWithAuditNameEntity_AUD"; var joinTableAudit = Cfg.GetClassMapping(auditName).JoinIterator.First().Table.Name; Assert.AreEqual("sec_versions", joinTableAudit); }
public void ChildRevColumnTypeShouldBeOfIntType() { var auditName = TestAssembly + ".Integration.Inheritance.Entities.ChildEntity_AUD"; var columns = Cfg.GetClassMapping(auditName).Key.ColumnIterator; Assert.AreEqual("int", ((Column)columns.Last()).SqlType); }
public void ExpectedTableNamesForComponent2() { var auditClass = Cfg.GetClassMapping(COMPONENT_2_AUDIT_JOIN_TABLE_NAME); Assert.IsNotNull(auditClass); Assert.AreEqual(COMPONENT_2_AUDIT_JOIN_TABLE_NAME, auditClass.Table.Name); }
public void VerifyChildIdColumnName() { var auditName = TestAssembly + ".Integration.Inheritance.Entities.ChildPrimaryKeyJoinEntity_AUD"; var keyColumn = (Column)Cfg.GetClassMapping(auditName).Key.ColumnIterator.First(); Assert.AreEqual("OtherId", keyColumn.Name); }
/// <summary> /// Converts a single result row /// </summary> /// <param name="o"></param> /// <param name="model"></param> /// <returns></returns> public Row ConvertResult(object o, Context model) { var row = new Row(); var trueType = NHibernateProxyHelper.GetClassWithoutInitializingProxy(o); var mapping = Cfg.GetClassMapping(trueType); row.Add(KV("Type", BuildTypeLink(trueType))); if (mapping == null) { // not a mapped type if (o is object[]) { row.AddRange(ConvertObjectArray((object[])o, model)); } else { row.Add(KV("Value", HttpUtility.HtmlEncode(Convert.ToString(o)))); } } else { var idProp = mapping.IdentifierProperty; var id = idProp.GetGetter(trueType).Get(o); row.Add(KV(idProp.Name, Convert.ToString(id))); row.AddRange(mapping.PropertyClosureIterator .SelectMany(p => ConvertProperty(o, trueType, p, model))); } return(row); }
/// <summary> /// Construye un LOCK para el esquema dado /// </summary> /// <param name="schema">Esquema de la base de datos</param> /// <returns>Consulta</returns> public string LOCK(Type type, string schema) { string tabla = string.Empty; if (schema == null) { tabla = GetSQLTable(type); } else { schema = "\"" + ((schema == "COMMON") ? schema : Convert.ToInt32(schema).ToString("0000")) + "\""; tabla = schema + ".\"" + Cfg.GetClassMapping(type).Table.Name + "\""; } //return String.Empty; switch (Cfg.GetProperty("dialect")) { // En PostgreSQL el LOCK se hace en el SELECT para hacerlo a nivel de registro // y no de tabla case "NHibernate.Dialect.PostgreSQL82Dialect": return(string.Empty); default: return("LOCK TABLE " + tabla + " IN ROW EXCLUSIVE MODE NOWAIT;"); } }
public string BuildCollectionLink(Type ct, Type fk, object fkValue) { var classMapping = Cfg.GetClassMapping(ct); var associations = classMapping.PropertyClosureIterator.Where(p => p.Type.IsAssociationType); var fkp = associations.FirstOrDefault(p => p.GetGetter(ct).ReturnType == fk); if (fkp != null) { var hql = string.Format("from {0} x where x.{1} = '{2}'", classMapping.EntityName, fkp.Name, fkValue); var url = string.Format("{0}?q={1}&MaxResults=10", RawUrl.Split('?')[0], HttpUtility.UrlEncode(hql)); return(UrlHelper.Link(url, "collection")); } // try many-to-many var collection = associations.FirstOrDefault(p => IsCollectionOf(p.GetGetter(ct).ReturnType, fk)); if (collection != null) { // assume generic collection var fkType = collection.GetGetter(ct).ReturnType.GetGenericArguments()[0]; var fkTypePK = GetPkGetter(fkType).PropertyName; var hql = string.Format("select x from {0} x join x.{1} y where y.{2} = '{3}'", classMapping.EntityName, collection.Name, fkTypePK, fkValue); var url = string.Format("{0}?q={1}&MaxResults=10", RawUrl.Split('?')[0], HttpUtility.UrlEncode(hql)); return(UrlHelper.Link(url, "collection")); } return(null); }
public void VerifyJoinColumnName() { var auditName = TestAssembly + ".Integration.Naming.JoinNamingRefIngEntity_AUD"; var columns = Cfg.GetClassMapping(auditName).GetProperty("Reference_Id").ColumnIterator; Assert.AreEqual(1, columns.Count()); Assert.AreEqual("jnree_column_reference", ((Column)columns.First()).Name); }
public string BuildEntityLink(Type entityType, object pkValue) { var hql = string.Format("from {0} x where x.{1} = '{2}'", Cfg.GetClassMapping(entityType).EntityName, GetPkGetter(entityType).PropertyName, pkValue); var url = string.Format("{0}?q={1}", RawUrl.Split('?')[0], HttpUtility.UrlEncode(hql)); var text = string.Format("{0}#{1}", entityType.Name, pkValue); return(UrlHelper.Link(url, text)); }
public void VerifyMapping() { var auditName = TestAssembly + ".Integration.Versioning.OptimisticLockEntity_AUD"; foreach (var property in Cfg.GetClassMapping(auditName).PropertyIterator) { Assert.AreNotEqual("Version", property.Name); } }
public void ShouldNotStoreVersionNumber() { var pc = Cfg.GetClassMapping(typeof(UnversionedOptimisticLockingFieldEntity).FullName + "_AUD"); foreach (var property in pc.PropertyIterator) { property.Name.Should().Not.Be.EqualTo("OptLocking"); } }
public Column GetTableIDColumn(Type type) { PersistentClass pclass; //Obtencion de la informaciĆ³n de mapeo pclass = Cfg.GetClassMapping(type); return((Column)((IList)(pclass.Identifier.ColumnIterator))[0]); }
public void VerifyAuditTableColumnsForNotAuditedEntity() { var table = Cfg.GetClassMapping(TestAssembly + ".Entities.Components.UniquePropsNotAuditedEntity_AUD").Table; table.GetColumn(new Column("Data1")) .Should().Not.Be.Null(); table.GetColumn(new Column("Data2")) .Should().Be.Null(); }
public void VerifyTableNames() { var auditName = TestAssembly + ".NetSpecific.Integration.JoinAuditTable.Animal_AUD"; var joinAuditTables = Cfg.GetClassMapping(auditName).JoinIterator; joinAuditTables.Count().Should().Be.EqualTo(2); joinAuditTables.Count(table => table.Table.Name.Equals("HeightTableAuditing")) .Should().Be.EqualTo(1); joinAuditTables.Count(table => table.Table.Name.Equals("WeightTableAuditing")) .Should().Be.EqualTo(1); }
public void VerifyEscapeEntityField() { var table = Cfg.GetClassMapping(TestAssembly + ".Integration.Naming.Quotation.QuotedFieldsEntity_AUD").Table; var column1 = columnByName(table, "select"); var column2 = columnByName(table, "from"); var column3 = columnByName(table, "where"); column1.IsQuoted.Should().Be.True(); column2.IsQuoted.Should().Be.True(); column3.IsQuoted.Should().Be.True(); }
/// <summary> /// Devuelve el nombre del campo identificador en la tabla /// </summary> /// <param name="type"></param> /// <returns></returns> public string GetTableID(Type type) { PersistentClass pclass; //Obtencion de la informaciĆ³n de mapeo pclass = Cfg.GetClassMapping(type); Column columna = (Column)((IList)(pclass.Identifier.ColumnCollection))[0]; return((columna != null) ? columna.Text : string.Empty); }
public void VerifyColumnScalePrecision() { var auditTable = Cfg.GetClassMapping("NHibernate.Envers.Tests.Integration.Basic.ScalePrecisionEntity_AUD").Table; var originalTable = Cfg.GetClassMapping(typeof(ScalePrecisionEntity)).Table; var testColumn = new Column("thenumber"); var scalePrecisionAuditColumn = auditTable.GetColumn(testColumn); var scalePrecisionColumn = originalTable.GetColumn(testColumn); scalePrecisionAuditColumn.Should().Not.Be.Null(); scalePrecisionAuditColumn.Precision.Should().Be.EqualTo(scalePrecisionColumn.Precision); scalePrecisionAuditColumn.Scale.Should().Be.EqualTo(scalePrecisionColumn.Scale); }
public string BuildTypeLink(Type entityType) { var mapping = Cfg.GetClassMapping(entityType); if (mapping == null) { return(entityType.Name); } var hql = string.Format("from {0}", mapping.EntityName); var url = string.Format("{0}?q={1}&MaxResults=10", RawUrl.Split('?')[0], HttpUtility.UrlEncode(hql)); return(UrlHelper.Link(url, entityType.Name)); }
public void VerifyColumnNames() { var auditName = TestAssembly + ".Integration.Naming.Ids.JoinEmbIdNamingRefIngEntity_AUD"; var xcolumns = Cfg.GetClassMapping(auditName).GetProperty("Reference_X").ColumnIterator; xcolumns.Should().Have.Count.EqualTo(1); ((Column)xcolumns.First()).Name.Should().Be.EqualTo("XX_Reference"); var ycolumns = Cfg.GetClassMapping(auditName).GetProperty("Reference_Y").ColumnIterator; ycolumns.Should().Have.Count.EqualTo(1); ((Column)ycolumns.First()).Name.Should().Be.EqualTo("YY_Reference"); }
public ICollection <Column> GetTableColumns(Type type) { System.Collections.ICollection props; List <Column> cols = new List <Column>(); props = Cfg.GetClassMapping(type).PropertyCollection; foreach (Property prop in props) { cols.Add((Column)(((IList)(prop.ColumnCollection))[0])); } return(cols); }
public void VerifyMapping() { var auditName = TestAssembly + ".Integration.Versioning.OptimisticLockEntity_AUD"; var versionColumnExists = false; foreach (var property in Cfg.GetClassMapping(auditName).PropertyIterator) { if (property.Name.Equals("Version")) { versionColumnExists = true; } } Assert.IsTrue(versionColumnExists); }
public ICollection <Column> GetTableColumns(Type type) { IEnumerable <Property> props; List <Column> cols = new List <Column>(); props = Cfg.GetClassMapping(type).PropertyIterator; foreach (Property prop in props) { cols.Add((Column)(((IList)(prop.ColumnIterator))[0])); } return(cols); }
public KeyValuePair <string, string> ConvertEntity(object o, Type entityType, Property p) { var assocType = (EntityType)p.Type; var o1 = p.GetGetter(entityType).Get(o); if (o1 == null) { return(KV(p.Name, null as string)); } var mapping = Cfg.GetClassMapping(assocType.GetAssociatedEntityName()); var pk = GetPkValue(mapping.MappedClass, o1); var getter = p.GetGetter(entityType); return(KV(p.Name, BuildEntityLink(getter.ReturnType, pk))); }
public Column GetTableColumn(Type type, string property) { System.Collections.ICollection cols; cols = Cfg.GetClassMapping(type).PropertyCollection; foreach (Property prop in cols) { if (prop.Name == property) { return((Column)(((IList)(prop.ColumnCollection))[0])); } } throw new Exception(String.Format(Messages.COLUMN_NOT_FOUND, property, type.Name)); }
public Column GetTableColumn(Type type, string property) { IEnumerable <Property> cols; cols = Cfg.GetClassMapping(type).PropertyIterator; foreach (Property prop in cols) { if (prop.Name == property) { return((Column)(((IList)(prop.ColumnIterator))[0])); } } throw new Exception(String.Format(Resources.Messages.COLUMN_NOT_FOUND, property, type.Name)); }
/// <summary> /// Devuelve el nombre del campo de la tabla asociado a la propiedad /// </summary> /// <param name="type">Tipo del objeto del que se quiere obtener la propiedad</param> /// <param name="property"></param> /// <returns></returns> public string GetTableField(Type type, string property) { System.Collections.ICollection cols; cols = Cfg.GetClassMapping(type).PropertyCollection; foreach (Property prop in cols) { if (prop.Name == property) { Column col = (Column)(((IList)(prop.ColumnCollection))[0]); return(col.Text); } } return(string.Empty); }
public void VerifyJoinColumnName() { var columns = Cfg.GetClassMapping(MIDDLE_VERSIONS_ENTITY_NAME).Table.ColumnIterator; bool id1Found = false; bool id2Found = false; foreach (var column in columns) { if (column.Name.Equals("VJT_ID")) { id1Found = true; } if (column.Name.Equals("STR_ID")) { id2Found = true; } } Assert.IsTrue(id1Found && id2Found); }
public void VerifyOverrideNotAudited() { var auditClass = Cfg.GetClassMapping(typeof(VersionsJoinTableRangeComponentTestEntity).FullName + "_AUD"); var auditColumn1Found = false; var auditColumn2Found = false; foreach (var column in auditClass.Table.ColumnIterator) { if (column.Name.Equals("STR1")) { auditColumn1Found = true; } if (column.Name.Equals("STR2")) { auditColumn2Found = true; } } Assert.IsTrue(auditColumn1Found && !auditColumn2Found); }
public void VerifyColumnNamesForComponent2() { var auditClass = Cfg.GetClassMapping(COMPONENT_2_AUDIT_JOIN_TABLE_NAME); var id1Found = false; var id2Found = false; foreach (var column in auditClass.Table.ColumnIterator) { if (column.Name.Equals("VJTRCTE2_ID")) { id1Found = true; } if (column.Name.Equals("VJTRTAE_ID")) { id2Found = true; } } Assert.IsTrue(id1Found && id2Found); }
public void ShouldHaveCorrectSchema() { var table = Cfg.GetClassMapping("VP_" + typeof(PropertiesTestEntity).FullName + "_VS").Table; var containsRevColumnName = false; var containsRevTypeColumnName = false; foreach (var column in table.ColumnIterator) { if (column.Name.Equals("ver_rev")) { containsRevColumnName = true; } if (column.Name.Equals("ver_rev_type")) { containsRevTypeColumnName = true; } } containsRevColumnName.Should().Be.True(); containsRevTypeColumnName.Should().Be.True(); }