Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

StoredProcedure.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Emmanuel Cecchet.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.common.sql;
00026 
00027 import java.sql.SQLException;
00028 
00029 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema;
00030 
00031 /**
00032  * A <code>StoredProcedure</code> is a SQL request with the following syntax:
00033  * 
00034  * <pre>
00035  * 
00036  *   {call &lt;procedure-name&gt;[&lt;arg1&gt;,&lt;arg2&gt;, ...]}
00037  *  
00038  * </pre>
00039  * 
00040  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00041  * @version 1.0
00042  */
00043 public class StoredProcedure extends AbstractRequest
00044 {
00045   private transient String procedureName = null;
00046 
00047   /**
00048    * Creates a new <code>StoredProcedure</code> instance.
00049    * 
00050    * @param sqlQuery the SQL request
00051    * @param escapeProcessing should the driver to escape processing before
00052    *          sending to the database ?
00053    * @param timeout an <code>int</code> value
00054    * @param lineSeparator the line separator used in the query
00055    * @see #parse
00056    */
00057   public StoredProcedure(String sqlQuery, boolean escapeProcessing,
00058       int timeout, String lineSeparator)
00059   {
00060     super(sqlQuery, escapeProcessing, timeout, lineSeparator);
00061     cacheable = RequestType.UNCACHEABLE;
00062     isParsed = false;
00063   }
00064 
00065   /**
00066    * @return <code>false</code>
00067    * @see org.objectweb.cjdbc.common.sql.AbstractRequest#isReadRequest()
00068    */
00069   public boolean isReadRequest()
00070   {
00071     return false;
00072   }
00073 
00074   /**
00075    * @return <code>false</code>
00076    * @see org.objectweb.cjdbc.common.sql.AbstractRequest#isWriteRequest()
00077    */
00078   public boolean isWriteRequest()
00079   {
00080     return false;
00081   }
00082 
00083   /**
00084    * @return <code>true</code>
00085    * @see org.objectweb.cjdbc.common.sql.AbstractRequest#isUnknownRequest()
00086    */
00087   public boolean isUnknownRequest()
00088   {
00089     return true;
00090   }
00091 
00092   /**
00093    * Get the stored procedure name
00094    * 
00095    * @return the stored procedure name
00096    */
00097   public String getProcedureName()
00098   {
00099     if (procedureName == null)
00100       try
00101       {
00102         parse(null, 0, true);
00103       }
00104       catch (SQLException e)
00105       {
00106         return null;
00107       }
00108     return procedureName;
00109   }
00110 
00111   /**
00112    * Just get the stored procedure name.
00113    * 
00114    * @see org.objectweb.cjdbc.common.sql.AbstractRequest#parse(org.objectweb.cjdbc.common.sql.schema.DatabaseSchema,
00115    *      int, boolean)
00116    */
00117   public void parse(DatabaseSchema schema, int granularity,
00118       boolean isCaseSensitive) throws SQLException
00119   {
00120     sqlQuery = sqlQuery.trim();
00121     if (sqlQuery.length() < 6) // 6='call x'
00122       throw new SQLException("Malformed stored procedure call '" + sqlQuery
00123           + "'");
00124 
00125     int parenthesis = sqlQuery.indexOf('(');
00126     if (parenthesis == -1)
00127       procedureName = sqlQuery.substring(5); // 5 = 'call '
00128     else
00129       procedureName = sqlQuery.substring(5, parenthesis); // 5 = 'call '
00130     // Remove possible extra spaces between call and procedure name
00131     procedureName = procedureName.trim();
00132   }
00133 
00134   /**
00135    * Always throws a <code>SQLException</code>: it is useless to parse a
00136    * stored procedure call since we can't know which tables are affected by this
00137    * procedure.
00138    * 
00139    * @see AbstractRequest#cloneParsing(AbstractRequest)
00140    */
00141   public void cloneParsing(AbstractRequest request)
00142   {
00143     throw new RuntimeException(
00144         "Unable to clone the parsing of a stored procedure call");
00145   }
00146 
00147 }

Generated on Mon Apr 11 22:01:35 2005 for C-JDBC by  doxygen 1.3.9.1