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 br...@apache.org on 2003/04/16 20:00:31 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/util SqlHelper.java
brj 2003/04/16 11:00:31
Modified: src/java/org/apache/ojb/broker/accesslayer/sql
SqlQueryStatement.java
src/java/org/apache/ojb/broker/util SqlHelper.java
Log:
fixed problem with splitting path
Revision Changes Path
1.36 +7 -6 db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
Index: SqlQueryStatement.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- SqlQueryStatement.java 10 Apr 2003 20:37:25 -0000 1.35
+++ SqlQueryStatement.java 16 Apr 2003 18:00:31 -0000 1.36
@@ -251,19 +251,20 @@
*/
protected boolean appendColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate, StringBuffer buf)
{
- String functionName = aPathInfo.function;
+ String prefix = aPathInfo.prefix;
+ String suffix = aPathInfo.suffix;
String colName = getColName(aTableAlias, aPathInfo ,translate);
- if (functionName != null) // rebuild function contains (
+ if (prefix != null) // rebuild function contains (
{
- buf.append(functionName);
+ buf.append(prefix);
}
buf.append(colName);
- if (functionName != null) // rebuild function
+ if (suffix != null) // rebuild function
{
- buf.append(")");
+ buf.append(suffix);
}
return true;
1.8 +27 -15 db-ojb/src/java/org/apache/ojb/broker/util/SqlHelper.java
Index: SqlHelper.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/SqlHelper.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SqlHelper.java 4 Apr 2003 19:15:55 -0000 1.7
+++ SqlHelper.java 16 Apr 2003 18:00:31 -0000 1.8
@@ -70,15 +70,26 @@
*/
public class SqlHelper
{
+ /**
+ * Helper Class for a split column<br>
+ * ie: sum (distinct amount) as theAmount
+ * <pre>
+ * prefix = 'sum (distinct '
+ * column = 'amount'
+ * suffix = ') as theAmount'
+ * </pre>
+ */
public static final class PathInfo
{
public String column;
- public String function;
+ public String prefix;
+ public String suffix;
- PathInfo(String aColumn, String aFunction)
+ PathInfo(String aPrefix, String aColumn, String aSuffix)
{
column = aColumn;
- function = aFunction;
+ prefix = aPrefix;
+ suffix = aSuffix;
}
}
@@ -86,7 +97,7 @@
* remove functions and () from path <br>
* ie: avg(amount) -> amount <br>
* ie: sum (accounts.amount) -> accounts.amount <br>
- * ie: count(distinct id) -> id <br>
+ * ie: count(distinct id) as theCount-> id <br>
* @param aPath the path to the attribute
*/
public static String cleanPath(String aPath)
@@ -96,11 +107,11 @@
/**
- * Split a path into column and function, the functionPart contains all info
+ * Split a path into column , prefix and suffix, the prefix contains all info
* up to the column<br>
- * ie: avg(amount) -> amount ,avg( <br>
- * ie: sum (accounts.amount) -> accounts.amount , sum( <br>
- * ie: count(distinct id) -> id , count(distinct <br>
+ * ie: avg(amount) -> amount , avg( , ) <br>
+ * ie: sum (accounts.amount) as theSum -> accounts.amount , sum( , ) as theSum <br>
+ * ie: count(distinct id) -> id , count(distinct , ) <br>
* @param aPath
* @return PathInfo
*/
@@ -109,33 +120,34 @@
int braceBegin;
int braceEnd;
int colBegin;
- String functionName;
+ String prefix = null;
+ String suffix = null;
String colName;
if (aPath == null)
{
- return new PathInfo(null, null);
+ return new PathInfo(null, null, null);
}
braceBegin = aPath.indexOf("(");
braceEnd = aPath.lastIndexOf(")");
if (braceBegin >= 0 && braceEnd >= 0)
{
- colBegin = aPath.indexOf(" ", braceBegin);
+ colBegin = aPath.lastIndexOf(" ", braceEnd);
if (colBegin < 0)
{
colBegin = braceBegin;
}
- functionName = aPath.substring(0, colBegin + 1);
+ prefix = aPath.substring(0, colBegin + 1);
colName = aPath.substring(colBegin + 1, braceEnd).trim();
+ suffix = aPath.substring(braceEnd);
}
else
{
- functionName = null;
colName = aPath;
}
- return new PathInfo(colName, functionName);
+ return new PathInfo(prefix, colName, suffix);
}