Click here to Skip to main content
15,884,099 members
Articles / Programming Languages / XML

DBKeeperNet - Keeps Your DB Schema Up-to-date

Rate me:
Please Sign up or sign in to vote.
4.88/5 (14 votes)
26 Aug 2014BSD4 min read 50.4K   575   89  
An article describing a simple .NET library which simply keeps your database schema up-to-date.
using System;
using DbKeeperNet.Engine.Extensions.DatabaseServices;
using System.Globalization;
using DbKeeperNet.Engine.Resources;

namespace DbKeeperNet.Engine.Extensions.Preconditions
{
    /// <summary>
    /// Condition verifies that Oracle sequence with specified
    /// name doesn't exist in database.
    /// </summary>
    /// <remarks>
    /// Condition reference name is <c>OraDbSequenceNotFound</c>.
    /// This is Oracle specific (see <see cref="OracleDatabaseService"/>).
    /// 
    /// It has one parameter which should contain tested database
    /// sequence name.
    /// </remarks>
    /// <example>
    /// Following example shows how to reference this condition in the
    /// update script XML.
    /// <code>
    /// <![CDATA[
    /// <Precondition FriendlyName="Sequence SEQ_for_me not found" Precondition="OraDbSequenceNotFound">
    ///   <Param>SEQ_for_me</Param>
    /// </Precondition>
    /// ]]>
    /// </code>
    /// </example>
    public sealed class OraDbSequenceNotFound: IPrecondition
    {
        #region IPrecondition Members

        public string Name
        {
            get { return "OraDbSequenceNotFound"; }
        }

        public bool CheckPrecondition(IUpdateContext context, PreconditionParamType[] param)
        {
            OracleDatabaseService service = context.DatabaseService as OracleDatabaseService;
            
            if (service == null)
                throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, PreconditionMessages.OnlyOracleSupport, Name));
            if ((param == null) || (param.Length == 0) || (String.IsNullOrEmpty(param[0].Value)))
                throw new ArgumentNullException(@"param", String.Format(CultureInfo.CurrentCulture, PreconditionMessages.SequenceNameEmpty, Name));

            return !service.SequenceExists(param[0].Value);
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Team Leader NCR
Czech Republic Czech Republic
I'm software developer since 1996. I started with assembler on Intel 8051 CPUs, during years I was interested in C, C++, Sybase PowerBuilder, PHP, Sybase Anywhere Database, MSSQL server and multiplatform development.

Currently I'm developing in C++ and C# (this is my favorit and I spent some time with MCPD achievement). I'm also interested in design patterns.

Comments and Discussions