001    package org.apache.ojb.broker.accesslayer.sql;
002    
003    /* Copyright 2003-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    import org.apache.ojb.broker.metadata.ProcedureDescriptor;
019    import org.apache.ojb.broker.util.logging.Logger;
020    
021    /**
022     * Model a call to a stored procedure based on ProcedureDescriptors
023     *
024     * @see org.apache.ojb.broker.metadata.ProcedureDescriptor
025     * @author <a href="mailto:rburt3@mchsi.com">Randall Burt</a>
026     * @author <a href="mailto:rgallagh@bellsouth.net">Ron Gallagher</a>
027     * @version $Id: SqlProcedureStatement.java,v 1.1 2007-08-24 22:17:39 ewestfal Exp $
028     */
029    
030    public class SqlProcedureStatement implements SqlStatement
031    {
032    
033        /**
034         * The descriptor that defines the procedure to invoke.
035         */
036        private ProcedureDescriptor procedureDescriptor;
037    
038        /**
039         * The logger to utilize
040         */
041        private Logger logger;
042    
043        /**
044         * Create an instance of this object.
045         *
046         * @param procedureDescriptor the descriptor that defines the procedure to invoke.
047         * @param logger the logger to utilize
048         */
049        public SqlProcedureStatement(ProcedureDescriptor procedureDescriptor, Logger logger)
050        {
051            // Save the values.
052            this.procedureDescriptor = procedureDescriptor;
053            this.logger = logger;
054        }
055    
056        /**
057         * Get the syntax that is required to invoke the procedure that is defined
058         * by the <code>ProcedureDescriptor</code> that was passed to the
059         * constructor of this class.
060         *
061         * @see SqlStatement#getStatement()
062         */
063        public String getStatement()
064        {
065            StringBuffer sb = new StringBuffer(512);
066            int argumentCount = this.procedureDescriptor.getArgumentCount();
067            if (this.procedureDescriptor.hasReturnValue())
068            {
069                sb.append("{ ?= call ");
070            }
071            else
072            {
073                sb.append("{ call ");
074            }
075            sb.append(this.procedureDescriptor.getName());
076            sb.append("(");
077            for (int i = 0; i < argumentCount; i++)
078            {
079                if (i == 0)
080                {
081                    sb.append("?");
082                }
083                else
084                {
085                    sb.append(",?");
086                }
087            }
088            sb.append(") }");
089            return sb.toString();
090        }
091    }