Exemplo n.º 1
0
        internal static ExecChainer Create(
            Chainer prev,
            ExecArgument executable,
            string returnValueToVariable,
            ParameterArgument[] arguments)
        {
            if (executable.Exception != null)
            {
                executable.Exception.ObjectName = prev.GetRoot().Name;
                executable.Exception.Arguments  = "executable = null";
                executable.Exception.Method     = Text.Method.Exec;
                throw executable.Exception;
            }

            QueryTalkException exception;
            var      root    = prev.GetRoot();
            Variable inliner = null;

            if (executable.Original is System.String)
            {
                inliner = root.TryGetVariable((string)executable.Original,
                                              out exception, Variable.SearchType.Inliner);
            }
            exception = null;

            // stored procedure, SQL batch, mapped stored procedure
            if (inliner == null)
            {
                var cpass = PassChainer.Create(new InternalRoot(), executable);
                return(new ExecChainer((Chainer)prev, cpass, returnValueToVariable));
            }
            // inliner: stored procedure, procedure, SQL
            else
            {
                if (inliner.DT == DT.InProcedure)
                {
                    return(new ExecChainer(prev, inliner, returnValueToVariable, arguments));
                }
                else if (inliner.DT == DT.InStoredProcedure)
                {
                    return(new ExecChainer(prev, inliner, returnValueToVariable, arguments));
                }
                else if (inliner.DT == DT.InSql)
                {
                    return(new ExecChainer(prev, inliner, returnValueToVariable, arguments));
                }
                else
                {
                    exception = inliner.DT.InvalidInlinerException(typeof(ExecChainer).ToString(),
                                                                   inliner.Name, _inliners);
                    exception.ObjectName = root.Name;
                    exception.Method     = Text.Method.Exec;
                    throw exception;
                }
            }
        }
Exemplo n.º 2
0
        // common method for processing the connection data
        internal static ConnectionData GetConnectionData(Assembly client,
                                                         ConnectBy connectBy, // explicitly given query key
                                                         DbNode node,         // database object bound to database map key (very likely to be given)
                                                         Chainer chainObject) // chain object that is very likely to have no connection data (except when .ConnectBy is called inside the compilable)
        {
            ConnectionKey connectionKey = null;

            if (connectBy != null)
            {
                connectionKey = ((IConnectable)connectBy).ConnectionKey;
            }
            else if (node != null)
            {
                connectionKey = ((IConnectable)node).ConnectionKey;
                if (connectionKey != null)
                {
                    ((IConnectable)node).ResetConnectionKey();   // always clean it up after the getter provide the ConnectionKey
                }
            }
            else if (chainObject != null)
            {
                var root = chainObject.GetRoot();

                // root: in cases when connection data is stored into compilable object
                //   example:
                //     s.River.Select().ConnectBy().Go()
                if (root.ConnectionKey != null)
                {
                    connectionKey      = root.ConnectionKey;
                    root.ConnectionKey = null;
                }

                // root.Node: in cases when the compilable is based on the mapped object
                //   example:
                //     s.River.Select().Go()
                else if (root.Node != null)
                {
                    connectionKey = ((IConnectable)root.Node).ConnectionKey;
                    if (connectionKey != null)
                    {
                        ((IConnectable)root.Node).ResetConnectionKey();   // always clean it up after the getter provide the ConnectionKey
                    }
                }
            }

            return(ConnectionManager.InvokeConnectionFunc(client, connectionKey));
        }
Exemplo n.º 3
0
        internal NameChainer(Chainer prev,
                             Designer.IsolationLevel embeddedTransactionIsolationLevel = Designer.IsolationLevel.Default)
            : base(prev)
        {
            // check root reuse
            var root = prev.GetRoot();

            if (root.IsUsed)
            {
                if (root.Node != null && root.Node.IsUsed)
                {
                    throw new QueryTalkException("NameChainer.ctor",
                                                 QueryTalkExceptionType.RootReuseDisallowed, String.Format("root = {0}", root.Name));
                }

                root.ClearForReuse();
            }

            root.SetAsUsed();
            root.EmbeddedTransactionIsolationLevel = embeddedTransactionIsolationLevel;
        }
Exemplo n.º 4
0
        internal static BeginCursorChainer TryGetBeginCursor(Chainer fetchOrEndCursorObject)
        {
            var isFetchNext = fetchOrEndCursorObject is BeginCursorFetchNextChainer;
            int skipCounter = 0;

            // anticipated:
            //   fetchOrEndCursorObject should not be null
            var node = fetchOrEndCursorObject;

            while (true)
            {
                node = node.Prev;
                if (node == null)
                {
                    throw new QueryTalkException("CBeginCursor.TryGetBeginCursor", QueryTalkExceptionType.InvalidCursorBlock,
                                                 null, isFetchNext ? Text.Method.BeginCursorFetchNext : Text.Method.EndCursor)
                          .SetObjectName(fetchOrEndCursorObject.GetRoot().Name);
                }

                if (node is EndCursorChainer)
                {
                    ++skipCounter;
                    continue;
                }

                if (node is BeginCursorChainer)
                {
                    if (skipCounter > 0)
                    {
                        --skipCounter;
                        continue;
                    }

                    // match
                    return((BeginCursorChainer)node);
                }
            }
        }