[cvs] expresso commit by lhamel: restore default " AS " when
keyword isn't
JCorporate Ltd
jcorp at jcorporate.com
Mon Jan 3 21:55:53 UTC 2005
Log Message:
-----------
restore default " AS " when keyword isn't otherwise specified
Modified Files:
--------------
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj:
MultiDBObject.java
Revision Data
-------------
Index: MultiDBObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/MultiDBObject.java,v
retrieving revision 1.61
retrieving revision 1.62
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/MultiDBObject.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/MultiDBObject.java -u -r1.61 -r1.62
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/MultiDBObject.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/MultiDBObject.java
@@ -77,7 +77,6 @@
import com.jcorporate.expresso.core.misc.StringUtil;
import com.jcorporate.expresso.core.registry.RequestRegistry;
import com.jcorporate.expresso.core.security.filters.Filter;
-import com.jcorporate.expresso.core.registry.RequestRegistry;
import com.jcorporate.expresso.kernel.util.ClassLocator;
import com.jcorporate.expresso.kernel.util.FastStringBuffer;
import org.apache.log4j.Logger;
@@ -95,9 +94,10 @@
/**
- * This class handles joins the 'old' way. It is not deprectated, but
+ * This class handles SQL joins with java coding only. It is not deprectated, but
+ * @see com.jcorporate.expresso.core.dataobjects.jdbc.JoinedDataObject for a more flexible approach to joins
+ * which uses xml files.
*
- * @see com.jcorporate.expresso.core.dataobjects.jdbc.JoinedDataObject for a more modern, flexible approach to joins
* <p/>
* A MultiDBObject is a group of dbobjects that are "related" - e.g. defined
* as being part of a foreign-key/primary-key relationship. This may be
@@ -107,8 +107,7 @@
* After establishing the relationships between the objects, the MultiDBObject
* can have search criteria set for it & searchAndRetrieve operations done just
* like a 'regular' DBObject, but these operations affect the entire related
- * group of objects. At the moment, MultiDBObjects are read-only, though that
- * may change in the future.
+ * group of objects.
* <p/>
* Add 'model' objects, which may have criteria already set in their fields for a search,
* via addDBObj(). After a query (via searchAndRetrieveList()),
@@ -117,8 +116,14 @@
* models have been set with addDBObj()
* before the query. In order to access these instances, use getDBObject().
* <p/>
+ * <p>MultiDBObject gets the current database context from the request registry,
+ * and depends on the added objects to know about their userIDs (if applicable).
+ * This is typically accomplished automatically because the constructors for
+ * SecurDBObject will get UserID automatically from request registry.
+ * <p/>
* Creation date: (9/18/00 11:32:03 AM)
- * author Michael Nash
+ * @author Michael Nash
+ * @author Larry Hamel
*/
public class MultiDBObject {
@@ -317,12 +322,7 @@
public boolean buildFromClause() throws DBException {
boolean success = false;
FastStringBuffer fsb = new FastStringBuffer(256);
- DBConnection myConnection = null;
- DBConnection myCx = null;
- if (this.getConnection() != null) {
- myConnection = this.getConnection();
- }
- int dboCount = myDBObjects.size();
+ int dboCount = myDBObjects.size();
try {
// ----------------------------------------------------
@@ -412,34 +412,18 @@
String targetTable = oneObj.getJDBCMetaData().getTargetSQLTable(oneObj.getDataContext());
String tableName = getTableName(oneObj);
fsb.append(targetTable);
-// if (!targetTable.equals(tableName)) {
-// fsb.append(" AS " + tableName);
-// }
-/**
- * @TODO Compatibilite with JDBC driver
- *
- */
- // AS keyword to set table short name is not standard and not supported by all
- // SQL manipulation languages. This need to be set properly with each driver
- // Keyword to be set in expresso config file for table alias name syntax
-
- if (!targetTable.equals(tableName)) {
- if (oneObj.getLocalConnection() != null) {
- myCx = oneObj.getLocalConnection();
- } else {
- myCx = myConnection;
- }
- if (ConfigManager.getJdbcRequired(getDataContext()).getTableAliasKeyword() != null) {
- fsb.append(" " + ConfigManager.getJdbcRequired(getDataContext()).getTableAliasKeyword() + " " + tableName);
- } else {
- fsb.append(" " + tableName);
- }
-// if (("oracle.jdbc.driver.OracleDriver".equals(myCx.getDBDriver()))) {
-// fsb.append(" " + tableName);
-// } else {
-// fsb.append(" AS " + tableName);
-// }
- }
+ // AS keyword to set table short name is not standard and not supported by all
+ // SQL manipulation languages. This need to be set properly with each driver
+ // Keyword to be set in expresso config file for table alias name syntax
+
+ if (!targetTable.equals(tableName)) {
+ if (ConfigManager.getJdbcRequired(getDataContext()).getTableAliasKeyword() != null) {
+ fsb.append(
+ " " + ConfigManager.getJdbcRequired(getDataContext()).getTableAliasKeyword() + " " + tableName);
+ } else {
+ fsb.append(" AS " + tableName);
+ }
+ }
needComma = true;
}
@@ -463,26 +447,14 @@
String targetTable = oneObj.getJDBCMetaData().getTargetSQLTable(oneObj.getDataContext());
String tableName = getTableName(oneObj);
fsb.append(targetTable);
-// if (!targetTable.equals(tableName)) {
-// fsb.append(" AS " + tableName);
-// }
- if (!targetTable.equals(tableName)) {
- if (oneObj.getLocalConnection() != null) {
- myCx = oneObj.getLocalConnection();
- } else {
- myCx = myConnection;
- }
-// if (("oracle.jdbc.driver.OracleDriver".equals(myCx.getDBDriver()))) {
-// fsb.append(" " + tableName);
-// } else {
-// fsb.append(" AS " + tableName);
-// }
- if (ConfigManager.getJdbcRequired(getDataContext()).getTableAliasKeyword() != null) {
- fsb.append(" " + ConfigManager.getJdbcRequired(getDataContext()).getTableAliasKeyword() + " " + tableName);
- } else {
- fsb.append(" " + tableName);
- }
- }
+ if (!targetTable.equals(tableName)) {
+ if (ConfigManager.getJdbcRequired(getDataContext()).getTableAliasKeyword() != null) {
+ fsb.append(
+ " " + ConfigManager.getJdbcRequired(getDataContext()).getTableAliasKeyword() + " " + tableName);
+ } else {
+ fsb.append(" AS " + tableName);
+ }
+ }
needComma = true;
}
@@ -1258,9 +1230,9 @@
/**
* Return the name of the context/database connection that this DB object is
* using. If none is set, then we are using the "default" database/context.
- * @deprecated 12/2004; use getDataContext instead
*
* @return the name of the datacontext
+ * @deprecated 12/2004; use getDataContext instead
*/
public synchronized String getDBName() {
return getDataContext();
@@ -1473,6 +1445,21 @@
*
* @param sortKeyString A pipe-delimited list of key fields to sort
* the returned set by
+ * @return Vector A vector of new database objects retrieved by the search
+ * @throws DBException If the search could not be completed
+ * @deprecated Use searchAndRetrieveList(String) instead
+ */
+ public synchronized Vector searchAndRetrieve(String sortKeyString)
+ throws DBException {
+
+ return new Vector(searchAndRetrieveList(sortKeyString));
+ } /* searchAndRetrieve(String) */
+
+ /**
+ * Search and retrieve in a particular order
+ *
+ * @param sortKeyString A pipe-delimited list of key fields to sort
+ * the returned set by
* @return A list of new database objects retrieved by the search
* @throws DBException If the search could not be completed
*/
@@ -1769,180 +1756,6 @@
return recordSet;
}
- /**
- * get the SQL select statment to be executed, if searchAnd RetrieveList happenned
- * on this MULTIDBOBJETC
- *
- * @return String of select statement to be executed
- * @throws DBException If the search could not be completed
- */
- public synchronized String getSQLSelectStatement() throws DBException {
- boolean needComma = false;
- DBObject oneObj = null;
-
- HashMap rtrvListByTable = new HashMap();
- FastStringBuffer myStatement = new FastStringBuffer(256);
-
- DBConnectionPool myPool = null;
- DBConnection myConnection = null;
-
- try {
- if (localConnection != null) {
- myConnection = localConnection;
- } else {
- myPool = DBConnectionPool.getInstance(getDBName());
- myConnection = myPool.getConnection("com.jcorporate.expresso.core.dbobj.DBObject");
- }
-
- String fieldName = null;
-// FastStringBuffer myStatement = new FastStringBuffer(256);
- myStatement.append("SELECT ");
-
-
- if (selectDistinct) {
- myStatement.append(" ");
- myStatement.append("DISTINCT");
- myStatement.append(" ");
- }
-
- for (Enumeration eachObj = myDBObjects.elements();
- eachObj.hasMoreElements();) {
- oneObj = (DBObject) eachObj.nextElement();
-
- ArrayList retrievedFieldList = (ArrayList) rtrvListByTable.get(getTableName(oneObj));
- if (retrievedFieldList == null) {
- retrievedFieldList = new ArrayList();
- rtrvListByTable.put(getTableName(oneObj), retrievedFieldList);
- }
-
- if (oneObj.anyFieldsDistinct) {
- String oneFieldName = null;
- for (Iterator i = oneObj.getDistinctFieldArrayList().iterator();
- i.hasNext();
- ) {
- oneFieldName = (String) i.next();
- if (needComma) {
- myStatement.append(", ");
- }
- myStatement.append(" ");
- myStatement.append(myPool.getDistinctRowsetKeyword());
- myStatement.append(" ");
- myStatement.append(selectFieldString(oneObj, oneFieldName));
- retrievedFieldList.add(oneFieldName);
- needComma = true;
- }
- } else if (oneObj.anyFieldsToRetrieveMulti) {
- String oneFieldName = null;
- for (Iterator i = oneObj.getFieldsToRetrieveIterator();
- i.hasNext();
- ) {
- oneFieldName = (String) i.next();
- if (needComma) {
- myStatement.append(", ");
- }
- myStatement.append(selectFieldString(oneObj, oneFieldName));
- retrievedFieldList.add(oneFieldName);
- needComma = true;
- } /* for each field */
- } else {
- for (Iterator i = oneObj.getMetaData().getFieldListArray().iterator();
- i.hasNext();
- ) {
- fieldName = (String) i.next();
- DataFieldMetaData metaData =
- oneObj.getFieldMetaData(fieldName);
-
- if (!metaData.isVirtual()
- && !metaData.isBinaryObjectType()) {
- if (needComma) {
- myStatement.append(", ");
- }
-
- myStatement.append(selectFieldString(oneObj, fieldName));
- retrievedFieldList.add(fieldName);
- needComma = true;
- }
-
- /* if field is not virtual & not binary*/
- }
-
- /* for each field */
- }
- }
-
- myStatement.append(" FROM ");
- if (buildFromClause() &&
- fromClause != null &&
- fromClause.trim().length() > 0) {
- myStatement.append(fromClause);
- } else {
- throw new DBException(thisClass + "count()" +
- " :Building of FROM clause failed.");
- }
-
- String whereClause;
- if (customWhereClause != null) {
- if (appendCustomWhereClause) {
- whereClause = buildWhereClause(true) + " AND " + customWhereClause;
- } else {
- whereClause = " WHERE " + customWhereClause;
- }
- } else {
- whereClause = buildWhereClause(true);
- }
-
- myStatement.append(whereClause);
-
- appendCustomWhereClause = false;
-
-
- /* Add the ORDER BY clause if any sortKeys are specified */
- if (sortKeys.size() > 0) {
- myStatement.append(" ORDER BY ");
-
- boolean needComma2 = false;
-
- for (Enumeration e = sortKeys.elements(); e.hasMoreElements();) {
- if (needComma2) {
- myStatement.append(", ");
- }
-
- myStatement.append((String) e.nextElement());
- needComma2 = true;
- }
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Executing " + myStatement.toString());
- }
-
- return myStatement.toString();
- } finally {
- if (localConnection == null) {
- myPool.release(myConnection);
- }
- myStatement.release();
- }
-
- }
-
-
- /**
- * Search and retrieve in a particular order
- *
- * @param sortKeyString A pipe-delimited list of key fields to sort
- * the returned set by
- * @return Vector A vector of new database objects retrieved by the search
- * @throws DBException If the search could not be completed
- * @deprecated Use searchAndRetrieveList(String) instead
- */
- public synchronized Vector searchAndRetrieve(String sortKeyString)
- throws DBException {
-
- return new Vector(searchAndRetrieveList(sortKeyString));
- } /* searchAndRetrieve(String) */
-
-
/**
* This tells the buildWhereClause to either respect case (true) or
* ignore case (false). You can call this method before doing a search and
@@ -2036,8 +1849,8 @@
* setConnection(DBConnection) method) then that connection must be already
* associated with the correct db/context.
*
- * @deprecated 12/2004 v5.6; use setDataContext() instead
* @param newOther The name of the context or database to use
+ * @deprecated 12/2004 v5.6; use setDataContext() instead
*/
public synchronized void setDBName(String newOther)
throws DBException {
More information about the cvs
mailing list