You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2007/03/20 21:04:40 UTC
svn commit: r520547 -
/db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java
Author: arminw
Date: Tue Mar 20 13:04:40 2007
New Revision: 520547
URL: http://svn.apache.org/viewvc?view=rev&rev=520547
Log:
remove deprecate methods, use class AttributeTokenizer instead
Modified:
db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java
Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java?view=diff&rev=520547&r1=520546&r2=520547
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java Tue Mar 20 13:04:40 2007
@@ -1,7 +1,6 @@
package org.apache.ojb.broker.util;
import java.sql.SQLException;
-import java.util.StringTokenizer;
import org.apache.ojb.broker.PersistenceBrokerException;
import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
@@ -24,80 +23,73 @@
/**
* Helper class for all SQL related stuff.
*
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel </a>
* @version $Id$
*/
public class SqlHelper
{
- /** delimiters to tokenize attributes. */
- private static final String DELIMITERS = "( ),+-/*";
-
- /** do not try to reslve these. */
- private static final String NO_ATTRIBUTES = "count,min,max,avg,sum,upper,lower,distinct,as";
-
/** define the name of the pseudo column holding the class to be instantiated. */
- public static final String OJB_CLASS_COLUMN = "OJB_CLAZZ";
+ public static final String OJB_CLASS_COLUMN = "OJB_CLAZZ";
private static final char OJB_QUOTE_BEGIN_CHAR = '\'';
private static final char OJB_QUOTE_END_CHAR = '\'';
-
-
+
/**
- * remove functions and () from path <br>
- * ie: avg(amount) -> amount <br>
- * ie: sum (accounts.amount) -> accounts.amount <br>
- * ie: count(distinct id) as theCount-> id <br>
- *
- * @param aPath the path to the attribute
- */
- public static String cleanPath(String aPath)
- {
- StringTokenizer st = new StringTokenizer(aPath, DELIMITERS, false);
- String result = aPath;
-
- while (st.hasMoreTokens())
+ * Returns the name of the class to be instantiated.
+ *
+ * @param rsAndStmt The query result set instance.
+ * @return null if the column is not available.
+ */
+ public static String getOjbClassName(ResultSetAndStatement rsAndStmt)
+ {
+ String result = null;
+ if (rsAndStmt.m_sql != null && rsAndStmt.m_sql.isUseOjbClassColumn())
{
- String token = st.nextToken();
- if (isAttribute(token))
+ try
{
- result = token.trim();
- break;
+ result = rsAndStmt.m_rs.getString(OJB_CLASS_COLUMN);
+ }
+ catch (SQLException e)
+ {
+ throw new PersistenceBrokerException("Cannot access " + OJB_CLASS_COLUMN, e);
}
}
-
return result;
- }
-
- /**
- * Answer a StringTokenizer for anAttribute.
- * @param anAttribute the attribute to tokenize
- * @return StringTokenizer
+ }
+
+ /**
+ * Answer <tt>true</tt> if the string starts with OJB_QUOTE_BEGIN_CHAR
+ * and ends with the OJB_QUOTE_END_CHAR.
+ *
+ * @param aString
*/
- public static StringTokenizer tokenizeAttribute(String anAttribute)
+ private static boolean isQuoted(String aString)
{
-
- return new StringTokenizer(anAttribute, DELIMITERS, true);
+ return aString != null &&
+ aString.charAt(0) == OJB_QUOTE_BEGIN_CHAR &&
+ aString.charAt(aString.length() - 1) == OJB_QUOTE_END_CHAR;
}
-
+
/**
- * Answer <em>true</em> if anAttribute is not a token or a 'function'.
- * @param anAttribute the attribute to check
- * @return The result of the attribute check.
+ * Remove the OJB-Quotes from the String.
+ *
+ * @param aString
+ * @return String without OJB-Quotes
*/
- public static boolean isAttribute(String anAttribute)
+ public static String stripOjbQuotes(String aString)
{
- // look for delimiters
- if (DELIMITERS.indexOf(anAttribute) >= 0)
+ String result = aString;
+
+ if (isQuoted(aString))
{
- return false;
+ result = aString.substring(1, aString.length() - 1);
}
- //TODO: should be platform specific !?
- return NO_ATTRIBUTES.indexOf(anAttribute.toLowerCase()) < 0;
+ return result;
}
/**
* Check if the specified sql-string is a stored procedure
* or not.
+ *
* @param sql The sql query to check
* @return <em>True</em> if the query is a stored procedure, else <em>false</em> is returned.
*/
@@ -136,55 +128,5 @@
i++;
}
return true;
- }
-
- /**
- * Returns the name of the class to be instantiated.
- * @param rsAndStmt The query result set instance.
- * @return null if the column is not available
- */
- public static String getOjbClassName(ResultSetAndStatement rsAndStmt)
- {
- String result = null;
- if (rsAndStmt.m_sql != null && rsAndStmt.m_sql.isUseOjbClassColumn())
- {
- try
- {
- result = rsAndStmt.m_rs.getString(OJB_CLASS_COLUMN);
- }
- catch (SQLException e)
- {
- throw new PersistenceBrokerException("Cannot access " + OJB_CLASS_COLUMN, e);
- }
- }
- return result;
- }
-
- /**
- * answer true if the string starts with OJB_QUOTE_BEGIN_CHAR
- * and ends with the OJB_QUOTE_END_CHAR
- * @param aString
- */
- private static boolean isQuoted(String aString)
- {
- return aString != null &&
- aString.charAt(0) == OJB_QUOTE_BEGIN_CHAR &&
- aString.charAt(aString.length() - 1) == OJB_QUOTE_END_CHAR;
- }
-
- /**
- * Remove the OJB-Quotes from the String.
- * @param aString
- * @return String without OJB-Quotes
- */
- public static String stripOjbQuotes(String aString)
- {
- String result = aString;
-
- if (isQuoted(aString))
- {
- result = aString.substring(1, aString.length() - 1);
- }
- return result;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org