public void TablesUniquelyNamedOnlyWithinThread()
		{
			var uniqueIntegerList = new System.Collections.Concurrent.ConcurrentBag<int>();
			var method = new ThreadStart(() =>
			                             {
				                             Table tbl1 = new Table();
				                             Table tbl2 = new Table();

				                             // Store these values for later comparison
				                             uniqueIntegerList.Add(tbl1.UniqueInteger);
				                             uniqueIntegerList.Add(tbl2.UniqueInteger);

				                             // Ensure that within a thread we have unique integers
				                             Assert.AreEqual(tbl1.UniqueInteger + 1, tbl2.UniqueInteger);
			                             });

			var thread1 = new CrossThreadTestRunner(method);
			var thread2 = new CrossThreadTestRunner(method);

			thread1.Start();
			thread2.Start();

			thread1.Join();
			thread2.Join();

			// There should in total be 4 tables, but only two distinct identifiers.
			Assert.AreEqual(4, uniqueIntegerList.Count);
			Assert.AreEqual(2, uniqueIntegerList.Distinct().Count());
		}
Exemple #2
0
   public AuditTable(Table dataTable, 
 INamingStrategy namingStrategy,
 IAuditColumnSource auditColumnSource)
   {
       _auditTable = BuildAuditTable(dataTable,
       namingStrategy, auditColumnSource);
   }
		public void TablesUniquelyNamed()
		{
			Table tbl1 = new Table();
			Table tbl2 = new Table();

			Assert.AreEqual(tbl1.UniqueInteger + 1, tbl2.UniqueInteger);
		}
		public static string BuildSqlDropIndexString(Dialect.Dialect dialect, Table table, string name, string defaultCatalog, string defaultSchema)
		{
			string ifExists = dialect.GetIfExistsDropConstraint(table, name);
			string drop = string.Format("drop index {0}", StringHelper.Qualify(table.GetQualifiedName(dialect, defaultCatalog, defaultSchema), name));
			string end = dialect.GetIfExistsDropConstraintEnd(table, name);
			return ifExists + Environment.NewLine + drop + Environment.NewLine + end;
		}
Exemple #5
0
		internal IndexInfo(Table table, Index index)
		{
			_name = MakeName("IX_", table.Name, index.ColumnIterator);
			_columns = CollectionUtils.Map<Column, string>(
				index.ColumnIterator,
				delegate(Column column) { return column.Name; });
		}
        public void QuotedTableNameWithoutSchemaWithSqlLite()
        {
            Table tbl = new Table();
            tbl.Name = "`name`";

            Assert.AreEqual("\"name\"", tbl.GetQualifiedName(dialect));
        }
Exemple #7
0
 public AuditTable(Table dataTable,
     INamingStrategy namingStrategy,
     IAuditColumnSource auditColumnSource)
 {
     this.auditColumnSource = auditColumnSource;
       auditTable = BuildAuditTable(dataTable, namingStrategy);
 }
        public void QuotedTableNameWithSqlLite()
        {
            Table tbl = new Table();
            tbl.Name = "`Group`";

            Assert.AreEqual("\"Group\"", tbl.GetQualifiedName(dialect));
        }
		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);
			}
		}
Exemple #10
0
		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);
		}
        public IEnumerable<AuditColumn> GetAuditColumns(Table dataTable)
        {
            var userStamp = new AuditColumn()
              {
            Name = "AuditUser",
            SqlType = "sysname",
            Length = 50,
            IsNullable = false,
            IncludeInPrimaryKey = true,
            ValueFunction = delegate(TriggerActions action)
            {
              return "system_user";
            }
              };

              var timeStamp = new AuditColumn()
              {
            Name = "AuditTimestamp",
            Value = new SimpleValue()
            {
              TypeName = NHibernateUtil.DateTime.Name
            },
            IsNullable = false,
            IncludeInPrimaryKey = true,
            ValueFunction = delegate(TriggerActions action)
            {
              return "getdate()";
            }
              };

              var operation = new AuditColumn()
              {
            Name = "AuditOperation",
            Value = new SimpleValue()
            {
              TypeName = NHibernateUtil.AnsiChar.Name
            },
            Length = 1,
            IsNullable = false,
            IncludeInPrimaryKey = false,
            ValueFunction = delegate(TriggerActions action)
            {
              switch (action)
              {
            case TriggerActions.INSERT:
              return "'I'";
            case TriggerActions.UPDATE:
              return "'U'";
            case TriggerActions.DELETE:
              return "'D'";
            default:
              throw new ArgumentOutOfRangeException("action");
              }
            }
              };

              return new AuditColumn[] {
            userStamp, timeStamp, operation
              };
        }
		public void UnmatchingColumns()
		{

			Table primaryTable = new Table();
			primaryTable.Name = "pktable";
			primaryTable.PrimaryKey = new PrimaryKey();
			Column pkColumn = new Column( NHibernateUtil.Int16, 0 );
			pkColumn.Name = "pk_column";

			primaryTable.PrimaryKey.AddColumn( pkColumn );

			Table fkTable = new Table();
			fkTable.Name = "fktable";

			ForeignKey fk = new ForeignKey();
			Column fkColumn1 = new Column( NHibernateUtil.Int16, 0 );
			fkColumn1.Name = "col1";

			Column fkColumn2 = new Column( NHibernateUtil.Int16, 0 );
			fkColumn2.Name = "col2";

			fk.AddColumn( fkColumn1 );
			fk.AddColumn( fkColumn2 );
			
			fk.Table = fkTable;

			fk.ReferencedTable = primaryTable;

		}
		public void UnmatchingColumns()
		{
			Table primaryTable = new Table("pktable");
			primaryTable.PrimaryKey = new PrimaryKey();
			SimpleValue sv = new SimpleValue();
			sv.TypeName = NHibernateUtil.Int16.Name;
			Column pkColumn = new Column("pk_column");
			pkColumn.Value = sv;

			primaryTable.PrimaryKey.AddColumn(pkColumn);

			Table fkTable = new Table("fktable");

			ForeignKey fk = new ForeignKey();
			sv = new SimpleValue();
			sv.TypeName = NHibernateUtil.Int16.Name;
			Column fkColumn1 = new Column("col1");
			fkColumn1.Value = sv;

			sv = new SimpleValue();
			sv.TypeName = NHibernateUtil.Int16.Name;
			Column fkColumn2 = new Column("col2");
			fkColumn2.Value = sv;

			fk.AddColumn(fkColumn1);
			fk.AddColumn(fkColumn2);

			fk.Table = fkTable;

			fk.ReferencedTable = primaryTable;
			Assert.Throws<FKUnmatchingColumnsException>(() => fk.AlignColumns());
		}
		private static void BindIndex(string indexAttribute, Table table, Column column)
		{
			if (indexAttribute != null && table != null)
			{
				var tokens = indexAttribute.Split(',');
				System.Array.ForEach(tokens, t => table.GetOrCreateIndex(t.Trim()).AddColumn(column));
			}
		}
Exemple #15
0
		private static SimpleValue CreateIdentifier(HbmId idSchema, PersistentClass rootClass, Table table)
		{
			SimpleValue iv = new SimpleValue(table);
			iv.TypeName = idSchema.type;
			rootClass.Identifier = iv;

			return iv;
		}
Exemple #16
0
        protected void CreateIndex(Table table, IEnumerable<Column> columns)
        {
            string indexName = string.Format("IX_{0}{1}", table.Name,
                StringUtilities.Combine(columns, "", delegate(Column c) { return c.Name; }));

            CollectionUtils.ForEach(columns,
                delegate(Column c) { table.GetOrCreateIndex(indexName).AddColumn(c); });
        }
		private static void BindUniqueKey(string uniqueKeyAttribute, Table table, Column column)
		{
			if (uniqueKeyAttribute != null && table != null)
			{
				var tokens = uniqueKeyAttribute.Split(',');
				System.Array.ForEach(tokens, t => table.GetOrCreateUniqueKey(t.Trim()).AddColumn(column));
			}
		}
        public void QuotedSchemaNameWithUnqoutedTableInSqlLite()
        {
            Table tbl = new Table();
            tbl.Schema = "`schema`";
            tbl.Name = "name";

            Assert.AreEqual("\"schema_name\"", tbl.GetQualifiedName(dialect));
            Assert.AreEqual("\"schema_table\"", dialect.Qualify("", "\"schema\"", "table"));
        }
		public IndexOrUniqueKeySecondPass(Table table, string indexName, string[] columns, ExtendedMappings mappings)
		{
			this.table = table;
			this.indexName = indexName;
			this.columns = columns;
			this.mappings = mappings;
			column = null;
			unique = false;
		}
		public static Table FillTable(string schema, string catalog, string realTableName, string logicalName,
		                              bool? isAbstract,
		                              IList<string[]> uniqueConstraints,
		                              string constraints,
		                              Table denormalizedSuperTable,
		                              ExtendedMappings mappings)
		{
			throw new NotImplementedException();
		}
 protected static void BindIndex(string indexAttribute, Table table, Column column)
 {
     if (indexAttribute != null && table != null)
     {
         StringTokenizer tokens = new StringTokenizer(indexAttribute, ", ");
         foreach (string token in tokens)
             table.GetOrCreateIndex(token).AddColumn(column);
     }
 }
Exemple #22
0
 protected virtual Table BuildAuditTable(Table dataTable,
     INamingStrategy namingStrategy)
 {
     var auditTableName = namingStrategy.GetAuditTableName(dataTable);
       var auditTable = new Table(auditTableName);
       CopyColumns(dataTable, auditTable);
       CopyPrimaryKey(dataTable, auditTable);
       return auditTable;
 }
		public void SchemaNameQuoted()
		{
			Table tbl = new Table();
			tbl.Schema = "`schema`";
			tbl.Name = "name";

			Dialect.Dialect dialect = new Dialect.MsSql2000Dialect();

			Assert.AreEqual( "[schema].name", tbl.GetQualifiedName( dialect ) );
		}
Exemple #24
0
		public void Bug()
		{
			Table table1 = new Table("ATABLE");

			Column table1ITestManyA = new Column("itestmanyaid");
			Column table1ITestManyB = new Column("itestmanybid");
			string t1Fk = table1.UniqueColumnString(new object[] { table1ITestManyA }, "BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyA");
			string t2Fk = table1.UniqueColumnString(new object[] { table1ITestManyB }, "BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyB");
			Assert.AreNotEqual(t1Fk, t2Fk, "Different columns in differents tables create the same FK name.");
		}
		public SimpleValue Make()
		{
			Validate();
			log.DebugFormat("building SimpleValue for {0}", propertyName);
			if (table == null)
			{
				table = columns[0].Table;
			}
			return FillSimpleValue(new SimpleValue(table));
		}
        public void QuotedCatalogSchemaNameWithSqlLite()
        {
            Table tbl = new Table();
            tbl.Catalog = "dbo";
            tbl.Schema = "`schema`";
            tbl.Name = "`name`";

            Assert.AreEqual("\"dbo_schema_name\"", tbl.GetQualifiedName(dialect));
            Assert.AreEqual("\"dbo_schema_table\"", dialect.Qualify("dbo", "\"schema\"", "\"table\""));
        }
		private void BindKey(JoinedSubclass subclass, HbmKey keyMapping, Table mytable)
		{
			// TODO : property-ref ?? 
			SimpleValue key = new DependantValue(mytable, subclass.Identifier);
			subclass.Key = key;
			key.IsCascadeDeleteEnabled = keyMapping.ondelete == HbmOndelete.Cascade;
			key.ForeignKeyName = keyMapping.foreignkey;

			new ValuePropertyBinder(key, Mappings).BindSimpleValue(keyMapping, subclass.EntityName, false);
		}
Exemple #28
0
 protected virtual void AddAuditColumns(Table auditTable,
     IEnumerable<AuditColumn> auditColumns)
 {
     foreach (var column in auditColumns)
       {
     auditTable.AddColumn(column);
     if (column.IncludeInPrimaryKey)
       auditTable.PrimaryKey.AddColumn(column);
       }
 }
		internal ForeignKeyInfo(Table table, ForeignKey fk, Configuration config)
			: base("FK_", table.Name, fk.ColumnIterator, null)
		{
			//note: the fk object has a ReferencedTable property, but it doesn't always seem to be set
			//the reference class property is always set, so we use it instead to get the referenced table 
			Table referencedTable = config.GetClassMapping(fk.ReferencedEntityName).Table;
			_referencedTable = referencedTable.Name;
			_referencedColumns = CollectionUtils.Map<Column, string>(
                referencedTable.PrimaryKey.ColumnIterator,
				delegate(Column column) { return column.Name; });
		}
		private void UpdateForeignKeyReferences(PersistentClass classMapping, Table table)
		{
			foreach (ForeignKey key in table.ForeignKeyIterator)
			{
				if (key.ReferencedEntityName != typeof(IUser).FullName)
					continue;

				key.ReferencedEntityName = userType.FullName;
				key.ReferencedTable = classMapping.Table;
			}
		}
        public IIdentifierGenerator CreateIdentifierGenerator(Dialect.Dialect dialect, string defaultCatalog,
                                                              string defaultSchema, RootClass rootClass)
        {
            var @params = new Dictionary <string, string>();

            //if the hibernate-mapping did not specify a schema/catalog, use the defaults
            //specified by properties - but note that if the schema/catalog were specified
            //in hibernate-mapping, or as params, they will already be initialized and
            //will override the values set here (they are in identifierGeneratorProperties)
            if (!string.IsNullOrEmpty(defaultSchema))
            {
                @params[PersistentIdGeneratorParmsNames.Schema] = defaultSchema;
            }
            if (!string.IsNullOrEmpty(defaultCatalog))
            {
                @params[PersistentIdGeneratorParmsNames.Catalog] = defaultCatalog;
            }

            //pass the entity-name, if not a collection-id
            if (rootClass != null)
            {
                @params[IdGeneratorParmsNames.EntityName] = rootClass.EntityName;
            }

            //init the table here instead of earlier, so that we can get a quoted table name
            //TODO: would it be better to simply pass the qualified table name, instead of
            //      splitting it up into schema/catalog/table names
            string tableName = Table.GetQuotedName(dialect);

            @params[PersistentIdGeneratorParmsNames.Table] = tableName;

            //pass the column name (a generated id almost always has a single column and is not a formula)
            string columnName = ((Column)ColumnIterator.First()).GetQuotedName(dialect);

            @params[PersistentIdGeneratorParmsNames.PK] = columnName;

            if (rootClass != null)
            {
                StringBuilder tables      = new StringBuilder();
                bool          commaNeeded = false;
                foreach (Table identityTable in rootClass.IdentityTables)
                {
                    if (commaNeeded)
                    {
                        tables.Append(StringHelper.CommaSpace);
                    }
                    commaNeeded = true;
                    tables.Append(identityTable.GetQuotedName(dialect));
                }
                @params[PersistentIdGeneratorParmsNames.Tables] = tables.ToString();
            }
            else
            {
                @params[PersistentIdGeneratorParmsNames.Tables] = tableName;
            }

            if (identifierGeneratorProperties != null)
            {
                ArrayHelper.AddAll(@params, identifierGeneratorProperties);
            }

            return(IdentifierGeneratorFactory.Create(identifierGeneratorStrategy, Type, @params, dialect));
        }
 public virtual bool IsClassOrSuperclassTable(Table closureTable)
 {
     return(Table == closureTable);
 }
 /// <summary>
 /// Adds a <see cref="Table"/> that a subclass is stored in.
 /// </summary>
 /// <param name="table">The <see cref="Table"/> the subclass is stored in.</param>
 public virtual void AddSubclassTable(Table table)
 {
     subclassTables.Add(table);
 }
 public SimpleValue(Table table)
 {
     this.table = table;
 }