Example #1
0
        public object Translate(Artifact source)
        {
            var result = new SQLModel.Batch();

            var context = new SQLTranslationContext(this);

            var identifier = source.MetaData.Children.First(c => c.Name == "identifiers").Children.First(c => c.Name == "identifier");

            context.StartArtifact(identifier.GetAttribute <string>("root"));
            try
            {
                // Libraries
                foreach (LibraryRef libraryRef in source.Libraries)
                {
                    // Okay to pass null for the verification context here, each of the referenced libraries should already be verified at this point.
                    result.Statements.AddRange(TranslateLibrary(context, libraryRef.Name, LibraryFactory.ResolveLibrary(libraryRef, null)));
                }

                // TODO: Parameters

                // ExpressionDefs
                foreach (ExpressionDef expression in source.Expressions)
                {
                    result.Statements.Add(TranslateExpressionDef(context, source.MetaData.Name, expression));
                }

                // Criteria
                // Criteria are translated as "create view <artifact name>_<condition><conditionNumber>"
                int conditionNumber = 0;
                foreach (ASTNode condition in source.Conditions)
                {
                    conditionNumber++;
                    result.Statements.Add(TranslateCondition(context, source.MetaData.Name, String.Format("Condition{0}", conditionNumber), condition));
                }

                // TODO: Assertion

                return(result);
            }
            finally
            {
                context.EndArtifact();
            }
        }
		public object Translate(Artifact source)
		{
            var result = new SQLModel.Batch();

			var context = new SQLTranslationContext(this);

			var identifier = source.MetaData.Children.First(c => c.Name == "identifiers").Children.First(c => c.Name == "identifier");
			context.StartArtifact(identifier.GetAttribute<string>("root"));
			try
			{
				// Libraries
				foreach (LibraryRef libraryRef in source.Libraries)
				{
					// Okay to pass null for the verification context here, each of the referenced libraries should already be verified at this point.
					result.Statements.AddRange(TranslateLibrary(context, libraryRef.Name, LibraryFactory.ResolveLibrary(libraryRef, null)));
				}

				// TODO: Parameters

				// ExpressionDefs
				foreach (ExpressionDef expression in source.Expressions) 
				{
					result.Statements.Add(TranslateExpressionDef(context, source.MetaData.Name, expression));
				}

				// Criteria
				// Criteria are translated as "create view <artifact name>_<condition><conditionNumber>"
				int conditionNumber = 0;
				foreach (ASTNode condition in source.Conditions) 
				{
					conditionNumber++;
					result.Statements.Add(TranslateCondition(context, source.MetaData.Name, String.Format("Condition{0}", conditionNumber), condition));
				}

				// TODO: Assertion

				return result;
			}
			finally
			{
				context.EndArtifact();
			}
		}
Example #3
0
        public void Write(Stream outputStream, object artifact)
        {
            SQLModel.Batch batch = artifact as SQLModel.Batch;
            if (artifact == null)
            {
                throw new ArgumentException("SQL Artifact Writer expects an object of type SQLModel.Batch");
            }

            // Emit using TSQLTextEmitter, though in theory we could emit using any emitter, the translator would have to be aware of the dialectic differences as well.
            // Easiest solution would probably be a translator per language type.
            var emitter = new TSQLTextEmitter();

            emitter.UseQuotedIdentifiers = true;

            using (var sw = new StreamWriter(outputStream))
            {
                sw.Write(emitter.Emit(batch));
            }
        }