public IEnumerable<string> GenerateDataDefintionLanguage(Dialect dialect)
        {
            var formatter = new DdlFormatter();

            foreach (var s in _versioningStrategy.EnsureDbObjectsStatements)
            {
                if (!String.IsNullOrWhiteSpace(s))
                {
                    yield return formatter.Format(s).TrimEnd();

                }
            }
            foreach (var m in _migrations)
            {
                foreach (var o in m.Operations)
                {
                    foreach (var s in o.GetStatements(dialect))
                    {
                        if (!String.IsNullOrWhiteSpace(s))
                        {
                            yield return formatter.Format(s).TrimEnd();
                        }
                    }
                }
                var updateVersionStatements = _versioningStrategy.GetUpdateVersionStatements(m.Version, m.Context);
                foreach (var s in updateVersionStatements)
                {
                    if (!String.IsNullOrWhiteSpace(s))
                    {
                        yield return formatter.Format(s).TrimEnd();
                    }
                }
            }
        }
 /// <inheritdoc/>
 public void Configure(IType type, IDictionary<string, string> parms, Dialect dialect)
 {
     if (!parms.TryGetValue(IdGenFunctionNameParam, out _idGenFunctionName))
         _idGenFunctionName = DefaultIdGenFunctionName;
     _targetTableName = parms[TargetTableNameParam];
     _targetTableIdColumnName = parms[TargetTableIdColumnNameParam];
 }
Example #3
0
        public override string SqlTriggerBody(
      Dialect dialect, IMapping p, 
      string defaultCatalog, string defaultSchema)
        {
            var auditTableName = dialect.QuoteForTableName(_auditTableName);
              var eDialect = (IExtendedDialect)dialect;

              string triggerSource = _action == TriggerActions.DELETE ?
            eDialect.GetTriggerOldDataAlias() :
            eDialect.GetTriggerNewDataAlias();

              var columns = new List<string>(_dataColumnNames);
              columns.AddRange(from ac in _auditColumns
                       select ac.Name);

              var values = new List<string>();
              values.AddRange(
            from columnName in _dataColumnNames
            select eDialect.QualifyColumn(
              triggerSource, columnName));
              values.AddRange(
            from auditColumn in _auditColumns
            select auditColumn.ValueFunction.Invoke(_action));

              return eDialect.GetInsertIntoString(auditTableName,
            columns, triggerSource, values);
        }
        public SessionSource(FluentConfiguration config)
        {
            configuration = config.Configuration;

            sessionFactory = config.BuildSessionFactory();
            dialect = Dialect.GetDialect(configuration.Properties);
        }
Example #5
0
 public override string SqlDropString(Dialect dialect,
     string defaultCatalog, string defaultSchema)
 {
     FinalizeAuditTable((IExtendedDialect)dialect);
       return auditTable.SqlDropString(dialect,
     defaultCatalog, defaultSchema);
 }
Example #6
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="config"></param>
        protected Renderer(Configuration config)
		{
            _config = config;
			_dialect = Dialect.GetDialect(config.Properties);
            _defaultSchema = config.GetProperty(NHibernate.Cfg.Environment.DefaultSchema);

		}
Example #7
0
 public override string SqlCreateString(Dialect dialect,
     IMapping p, string defaultCatalog, string defaultSchema)
 {
     FinalizeAuditTable((IExtendedDialect) dialect);
       return auditTable.SqlCreateString(
     dialect, p, defaultCatalog, defaultSchema);
 }
		/// <summary>
		/// Configures the TableGenerator by reading the value of <c>table</c>, 
		/// <c>column</c>, and <c>schema</c> from the <c>parms</c> parameter.
		/// </summary>
		/// <param name="type">The <see cref="IType"/> the identifier should be.</param>
		/// <param name="parms">An <see cref="IDictionary"/> of Param values that are keyed by parameter name.</param>
		/// <param name="dialect">The <see cref="Dialect"/> to help with Configuration.</param>
		public virtual void Configure(IType type, IDictionary<string, string> parms, Dialect.Dialect dialect)
		{
			tableName = PropertiesHelper.GetString(TableParamName, parms, DefaultTableName);
			columnName = PropertiesHelper.GetString(ColumnParamName, parms, DefaultColumnName);
			whereClause = PropertiesHelper.GetString(Where, parms, "");
			string schemaName = PropertiesHelper.GetString(PersistentIdGeneratorParmsNames.Schema, parms, null);
			string catalogName = PropertiesHelper.GetString(PersistentIdGeneratorParmsNames.Catalog, parms, null);

			if (tableName.IndexOf('.') < 0)
			{
				tableName = dialect.Qualify(catalogName, schemaName, tableName);
			}

			var selectBuilder = new SqlStringBuilder(100);
			selectBuilder.Add("select " + columnName)
				.Add(" from " + dialect.AppendLockHint(LockMode.Upgrade, tableName));
			if (string.IsNullOrEmpty(whereClause) == false)
			{
				selectBuilder.Add(" where ").Add(whereClause);
			}
			selectBuilder.Add(dialect.ForUpdateString);

			query = selectBuilder.ToString();

			columnType = type as PrimitiveType;
			if (columnType == null)
			{
				log.Error("Column type for TableGenerator is not a value type");
				throw new ArgumentException("type is not a ValueTypeType", "type");
			}

			// build the sql string for the Update since it uses parameters
			if (type is Int16Type)
			{
				columnSqlType = SqlTypeFactory.Int16;
			}
			else if (type is Int64Type)
			{
				columnSqlType = SqlTypeFactory.Int64;
			}
			else
			{
				columnSqlType = SqlTypeFactory.Int32;
			}

			parameterTypes = new[] {columnSqlType, columnSqlType};

			var builder = new SqlStringBuilder(100);
			builder.Add("update " + tableName + " set ")
				.Add(columnName).Add(" = ").Add(Parameter.Placeholder)
				.Add(" where ")
				.Add(columnName).Add(" = ").Add(Parameter.Placeholder);
			if (string.IsNullOrEmpty(whereClause) == false)
			{
				builder.Add(" and ").Add(whereClause);
			}

			updateSql = builder.ToSqlString();
		}
 public static string GetSqlType(this Column column, Dialect dialect)
 {
     if (!String.IsNullOrWhiteSpace(column.SqlType))
     {
         return column.SqlType;
     }
     return dialect.GetTypeName(column.SqlTypeCode);
 }
        /// <summary>
        /// Configures the specified type.
        /// </summary>
        /// <param name="type">The type to configure.</param>
        /// <param name="parms">The parameters.</param>
        /// <param name="dialect">The dialect.</param>
        public override void Configure( IType type, IDictionary<string, string> parms, Dialect dialect )
        {
            parms[TableParamName] = "HiValue";
            parms[ColumnParamName] = "HiValueKey";
            parms[MaxLo] = "1000";
            parms["schema"] = "CommonModule";

            base.Configure ( type, parms, dialect );
        }
Example #11
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="column"></param>
		/// <param name="config"></param>
		/// <param name="dialect"></param>
		internal ColumnInfo(Column column, Configuration config, Dialect dialect)
		{
			_name = column.Name;
			_nullable = column.IsNullable;
			_sqlType = column.GetSqlType(dialect, new Mapping(config));

            //as of NH2.0, the length column seems to be set at 255 for non-string-like columns, which makes no sense
            //therefore ignore NH length for non-string like columns, and use -1 which corresponds to the pre-2.0 behaviour
            _length = (this.SqlType.IndexOf("char", System.StringComparison.InvariantCultureIgnoreCase) > -1) ? column.Length : -1;
        }
Example #12
0
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			if (dialect is MySQLDialect)
				return false;
			if (dialect is InformixDialect)
				return false;
			if (dialect is SQLiteDialect)
				return false;

			return true;
		}
        protected void Initialize(Configuration nhibernateConfig, PersistenceModel model)
        {
            if( model == null ) throw new ArgumentNullException("model", "Model cannot be null");

            Configuration = nhibernateConfig;

            model.Configure(Configuration);

            SessionFactory = Configuration.BuildSessionFactory();
            dialect = Dialect.GetDialect(Configuration.Properties);
        }
		/// <summary>
		/// Configures the TableGenerator by reading the value of <c>table</c>, 
		/// <c>column</c>, and <c>schema</c> from the <c>parms</c> parameter.
		/// </summary>
		/// <param name="type">The <see cref="IType"/> the identifier should be.</param>
		/// <param name="parms">An <see cref="IDictionary"/> of Param values that are keyed by parameter name.</param>
		/// <param name="dialect">The <see cref="Dialect"/> to help with Configuration.</param>
		public virtual void Configure(IType type, IDictionary parms, Dialect.Dialect dialect)
		{
			tableName = PropertiesHelper.GetString(Table, parms, "hibernate_unique_key");
			columnName = PropertiesHelper.GetString(Column, parms, "next_hi");
			string schemaName = (string) parms[Schema];
			if (schemaName != null && tableName.IndexOf(StringHelper.Dot) < 0)
			{
				tableName = schemaName + "." + tableName;
			}

			query =
				"select " +
				columnName +
				" from " +
				dialect.AppendLockHint(LockMode.Upgrade, tableName) +
				dialect.ForUpdateString;

			columnType = type as ValueTypeType;
			if (columnType == null)
			{
				log.Error("Column type for TableGenerator is not a value type");
				throw new ArgumentException("type is not a ValueTypeType", "type");
			}

			// build the sql string for the Update since it uses parameters
			if (type is Int16Type)
			{
				columnSqlType = SqlTypeFactory.Int16;
			}
			else if (type is Int64Type)
			{
				columnSqlType = SqlTypeFactory.Int64;
			}
			else
			{
				columnSqlType = SqlTypeFactory.Int32;
			}

			parameterTypes = new SqlType[2] {columnSqlType, columnSqlType};

			SqlStringBuilder builder = new SqlStringBuilder();
			builder.Add("update " + tableName + " set ")
				.Add(columnName)
				.Add(" = ")
				.Add(Parameter.Placeholder)
				.Add(" where ")
				.Add(columnName)
				.Add(" = ")
				.Add(Parameter.Placeholder);

			updateSql = builder.ToSqlString();
		}
Example #15
0
        public override string SqlCreateString(Dialect dialect, IMapping p, string defaultCatalog, string defaultSchema)
        {
            IExtendedDialect eDialect = (IExtendedDialect) dialect;

              var buf = new StringBuilder();

              buf.AppendLine(eDialect.GetCreateTriggerHeaderString(
            _triggerName, _tableName, _action));

              buf.AppendLine(SqlTriggerBody(dialect, p, defaultCatalog, defaultSchema));

              buf.AppendLine(eDialect.GetCreateTriggerFooterString(
            _triggerName, _tableName, _action));

              return buf.ToString();
        }
 public void ExecuteMigrationScript(Dialect dialect, TextWriter log = null)
 {
     log = log ?? new StringWriter();
     using (var s = _sessionFactory.OpenStatelessSession())
     {
         var conn = s.Connection;
         foreach (var statement in GenerateDataDefintionLanguage(dialect))
         {
             log.WriteLine(statement);
             using (var cmd = conn.CreateCommand())
             {
                 cmd.CommandText = statement;
                 cmd.CommandType = CommandType.Text;
             }
         }
     }
 }
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			// It seems that SQLite has a nasty bug with coalesce

			// Following query does not work
			//    SELECT order0_.*
			//    FROM   Orders order0_ 
			//    WHERE  coalesce(order0_.Freight, 0) > @p0;

			// And this one works
			//    SELECT order0_.*
			//    FROM   Orders order0_ 
			//    WHERE  cast(coalesce(order0_.Freight, 0) as NUMERIC) > @p0;

			if (dialect is SQLiteDialect)
				return false;
			return base.AppliesTo(dialect);
		}
Example #18
0
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			var typeNames = (TypeNames)typeof(Dialect.Dialect).GetField("_typeNames", ReflectHelper.AnyVisibilityInstance).GetValue(Dialect);
			try
			{
				var value = AppliesTo();

				if (value == null) return true;
				
				typeNames.Get(value.Value);
			}
			catch (ArgumentException)
			{
				return false;
			}
			catch (Exception)
			{
				Assert.Fail("Probably a bug in the test case.");
			}

			return true;
		}
        /// <summary>
        /// This is the real core function that build the fragment of sql needed
        /// to build the criteria
        /// </summary>
        /// <param name="criteria"></param>
        /// <param name="criteriaQuery"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override NHibernate.SqlCommand.SqlString ToSqlString(
            NHibernate.ICriteria criteria,
            NHibernate.Expressions.ICriteriaQuery criteriaQuery,
            IDictionary <string, IFilter> enabledFilters)
        {
            //retrieve with projection the real name of the property.
            String[] PropertyColumn = criteriaQuery.GetColumnsUsingProjection(
                criteria, (String)mSqlFunctionParameter[mPropertyNamePosition]);
            NHibernate.Dialect.Dialect dialect = criteriaQuery.Factory.Dialect;
            mSqlFunctionParameter[mPropertyNamePosition] = PropertyColumn[0];
            if (!dialect.Functions.ContainsKey(mFunction))
            {
                //throw new ApplicationException("Current dialect does not support " + mFunction + " function");
                //Todo for now try to set the function but without the dialect.
                return(CreateQueryString(
                           BuildUnknownExpression(mFunction, mSqlFunctionParameter)));
            }
            ISQLFunction func             = (ISQLFunction)dialect.Functions[mFunction];
            String       functionResolved = func.Render(mSqlFunctionParameter, criteriaQuery.Factory);

            //Now we have the cast operation required.
            return(CreateQueryString(functionResolved));
        }
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			return appliesToThisDialect;
		}
Example #21
0
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			return dialect as MsSql2008Dialect != null;
		}
		protected virtual bool AppliesTo(Dialect.Dialect dialect)
		{
			return true;
		}
Example #23
0
 protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect)
 {
     // Specific to MsSql2000Dialect. Does not apply to MsSql2005Dialect
     return(dialect.GetType().Equals(typeof(MsSql2000Dialect)));
 }
 protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect)
 {
     return(dialect as MsSql2005Dialect != null);
 }
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			var cp = ConnectionProviderFactory.NewConnectionProvider(cfg.Properties);
			return !cp.Driver.SupportsMultipleQueries;
		}
 public SqliteDataBaseMetaData(
     DbConnection connection,
     NHibernate.Dialect.Dialect dialect
     ) : base(connection, dialect)
 {
 }
		/// <summary>
		/// The SQL required to remove the underlying database objects for a TableGenerator.
		/// </summary>
		/// <param name="dialect">The <see cref="Dialect"/> to help with creating the sql.</param>
		/// <returns>
		/// A <see cref="string"/> that will drop the database objects for the TableGenerator.
		/// </returns>
		public virtual string[] SqlDropString(Dialect.Dialect dialect)
		{
			return new[] {dialect.GetDropTableString(tableName)};
		}
Example #28
0
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			return (dialect is MsSql2005Dialect);
		}
Example #29
0
 protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect)
 {
     return(dialect is NHibernate.Dialect.MsSql2008Dialect || dialect is NHibernate.Dialect.MsSql2005Dialect);
 }
Example #30
0
 protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect)
 {
     return(dialect is MsSql2000Dialect);
 }
Example #31
0
 /// <summary>
 /// The SQL required to create the database objects for a TableGenerator.
 /// </summary>
 /// <param name="dialect">The <see cref="Dialect"/> to help with creating the sql.</param>
 /// <returns>
 /// An array of <see cref="String"/> objects that contain the Dialect specific sql to 
 /// create the necessary database objects and to create the first value as <c>1</c> 
 /// for the TableGenerator.
 /// </returns>
 public string[] SqlCreateStrings(Dialect.Dialect dialect)
 {
     // changed the first value to be "1" by default since an uninitialized Int32 is 0 - leaving
     // it at 0 would cause problems with an unsaved-value="0" which is what most people are
     // defaulting <id>'s with Int32 types at.
     return new string[]
         {
             "create table " + tableName + " ( " + columnName + " " + dialect.GetTypeName(columnSqlType) + " )",
             "insert into " + tableName + " values ( 1 )"
         };
 }
Example #32
0
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			return !(dialect is Oracle8iDialect);
		}
Example #33
0
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			return _OrignalDialectIsMsSql2005Dialect;
		}
Example #34
0
 protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect)
 {
     return(dialect as SQLiteDialect != null);
 }
Example #35
0
 /// <summary>
 /// The SQL required to remove the underlying database objects for a TableGenerator.
 /// </summary>
 /// <param name="dialect">The <see cref="Dialect"/> to help with creating the sql.</param>
 /// <returns>
 /// A <see cref="String"/> that will drop the database objects for the TableGenerator.
 /// </returns>
 public string SqlDropString(Dialect.Dialect dialect)
 {
     return dialect.GetDropTableString(tableName);
 }
 //private readonly Table _table;
 //private readonly Column _column;
 //public DropColumnOperation(Table table, Column column)
 //{
 //    _table = table;
 //    _column = column;
 //}
 //public IEnumerable<string> GetStatements(IMigrationContext context)
 //{
 //    var dialect = context.Dialect;
 //    var defaultSchema = context.DefaultSchema;
 //    var defaultCatalog = context.DefaultCatalog;
 //    if (!dialect.SupportsDropColumn)
 //    {
 //        throw new NotSupportedException(String.Format("{0} does not support dropping columns", dialect.GetType().Name));
 //    }
 //    var tableName = _table.GetQualifiedName(dialect, defaultCatalog, defaultSchema);
 //    var sb = new StringBuilder();
 //    sb.Append("alter table ")
 //        .Append(tableName)
 //        .Append(" ")
 //        .Append(dialect.DropColumnString)
 //        .Append(" ")
 //        .Append(_column.GetQuotedName(dialect));
 //    return new[]{sb.ToString()};
 //}
 public IEnumerable<string> GetStatements(Dialect dialect)
 {
     throw new System.NotImplementedException();
 }
Example #37
0
		protected override bool AppliesTo(Dialect.Dialect dialect)
		{
			return dialect is MsSql2008Dialect;
		}
Example #38
0
        protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect)
        {
            var cp = ConnectionProviderFactory.NewConnectionProvider(cfg.Properties);

            return(!cp.Driver.SupportsMultipleQueries);
        }
 /// <summary>
 /// Generates an IDbDataParameter for the IDbCommand.  It does not add the IDbDataParameter to the IDbCommand's
 /// Parameter collection.
 /// </summary>
 /// <param name="command">The IDbCommand to use to create the IDbDataParameter.</param>
 /// <param name="name">The name to set for IDbDataParameter.Name</param>
 /// <param name="parameter">The Parameter to convert to an IDbDataParameter.</param>
 /// <param name="dialect">The Dialect to use for Default lengths if needed.</param>
 /// <returns>An IDbDataParameter ready to be added to an IDbCommand.</returns>
 /// <remarks>
 /// This adds logic to ensure that a DbType.Boolean parameter is not created since
 /// ODP.NET doesn't support it.
 /// </remarks>
 protected override System.Data.IDbDataParameter GenerateParameter(IDbCommand command, string name, Parameter parameter, NHibernate.Dialect.Dialect dialect)
 {
     // if the parameter coming in contains a boolean then we need to convert it
     // to another type since ODP.NET doesn't support DbType.Boolean
     if (parameter.SqlType.DbType == DbType.Boolean)
     {
         parameter = new Parameter(parameter.Name, NHibernateUtil.Int16.SqlType);
     }
     return(base.GenerateParameter(command, name, parameter, dialect));
 }
Example #40
0
 protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect)
 {
     return((dialect is Dialect.SQLiteDialect) || (dialect is Dialect.MsSql2008Dialect));
 }