Пример #1
0
        public ExecutedHqlResults HqlToSql(string hql)
        {
            ExecutedHqlResults res = new ExecutedHqlResults();
            res.Body = string.Empty;
            try
            {

                System.Type qtType = System.Type.GetType("NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl, NHibernate");
                using (var session = sessionFactory.GetType().GetMethod("OpenSession",new System.Type[0]).Invoke(sessionFactory, new object[0]) as IDisposable)
                {
                    var qp = Activator.CreateInstance(System.Type.GetType("NHibernate.Engine.QueryParameters, NHibernate"));
                    if (qtType == null)
                    {
                        logger.Debug("Using classic translator");
                        StringBuilder sb = new StringBuilder();
                        IEnumerable queryTranslators =
                            getQuery.Invoke(session, new object[] { hql, false }) as IEnumerable;

                        foreach (var translator in queryTranslators)
                        {
                            IDbCommand cmd = (IDbCommand)prepareQueryCommand.Invoke(translator, new object[] { qp, false, session });
                            sb.AppendLine( cmd.CommandText);
                        }

                        res.Body = sb.ToString();
                    }
                    else
                    {
                        logger.Debug("Using ANTLR translator");

                        var tFilter = typeof(Dictionary<,>).MakeGenericType(typeof(string),System.Type.GetType("NHibernate.IFilter, NHibernate"));
                        var filter = Activator.CreateInstance(tFilter);
                        var translator = Activator.CreateInstance(qtType, "wb", hql, filter, sessionFactory);
                        qtType.GetMethod("Compile",new System.Type[]{typeof(IDictionary<string,string>),typeof(bool)}).Invoke(translator,new object[]{ new Dictionary<string,string>(),false});
                        //var chunks = qtType.GetMethod("List").Invoke(activator,new object[]{session,qp} ) as IEnumerable;
                        res.Body = qtType.GetProperty("SQLString").GetValue(translator, null) as string;
                    }
                }
            }
            catch (Exception e)
            {
                // sorry but some exception are not marked as serializable
                if( e.InnerException != null )
                    res.Exception = new Exception(e.InnerException.Message);
            }
            res.Body = res.Body.Replace(",", "\r\n,");
            return res;
        }
Пример #2
0
 public void Present(ExecutedHqlResults res)
 {
     model.Results = res;
     view.ShowResults(model.Results);
 }
Пример #3
0
 public void UpdateCanExecute(ExecutedHqlResults res)
 {
     CanExecute = res.Exception==null && !string.IsNullOrEmpty(res.Body.Trim());
 }
Пример #4
0
 public void ShowResults(ExecutedHqlResults executedHqlResults)
 {
     SetSQL(executedHqlResults.Body,null!=executedHqlResults.Exception? executedHqlResults.Exception.Message:"");
 }