[cvs] expresso commit by rimovm: -Got RequestRegistry working with
normal
JCorporate Ltd
jcorp at jcorp2.servlets.net
Thu Nov 4 02:31:50 PST 2004
Log Message:
-----------
-Got RequestRegistry working with normal DBObjects. setContext() is now called. setUid() is NOT due to backwards compatibility issues.
-New UserInfo implementation that is a 80% implementation of a map-based user info. SuperUser now uses that so it doesn't cause
any database accesses when it is referred to.
-Removed Javadoc Errors
Modified Files:
--------------
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects:
BaseDataObject.java
DataObject.java
SynchronizedDataObject.java
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/jdbc:
JoinedDataObject.java
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj:
DBObject.java
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc:
ConfigManager.java
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/security:
SuperUser.java
User.java
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/ui:
CacheAutoElement.java
DefaultAutoElement.java
expresso/expresso-web/expresso/doc:
ChangeLog.xml
Revision Data
-------------
Index: BaseDataObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/BaseDataObject.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/BaseDataObject.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/BaseDataObject.java -u -r1.11 -r1.12
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/BaseDataObject.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/BaseDataObject.java
@@ -64,6 +64,8 @@
package com.jcorporate.expresso.core.dataobjects;
import org.apache.oro.text.regex.Pattern;
+import java.util.Iterator;
+import com.jcorporate.expresso.core.db.*;
/**
@@ -72,7 +74,9 @@
* @version $Revision$ on $Date$
*/
-abstract public class BaseDataObject implements DataObject, java.io.Serializable {
+abstract public class BaseDataObject implements DataObject
+ , java.io.Serializable
+{
/**
@@ -80,7 +84,7 @@
*/
protected String currentStatus = BaseDataObject.STATUS_NEW;
- protected Pattern globalMask = null;
+ protected Pattern globalMask = null;
public BaseDataObject() {
}
@@ -96,16 +100,16 @@
*/
public void setStatus(String newStatus) {
if (newStatus.equalsIgnoreCase(DataObject.STATUS_NEW) ||
- newStatus.equalsIgnoreCase(DataObject.STATUS_CURRENT) ||
- newStatus.equalsIgnoreCase(DataObject.STATUS_UPDATED) ||
- newStatus.equalsIgnoreCase(DataObject.STATUS_DELETED)) {
+ newStatus.equalsIgnoreCase(DataObject.STATUS_CURRENT) ||
+ newStatus.equalsIgnoreCase(DataObject.STATUS_UPDATED) ||
+ newStatus.equalsIgnoreCase(DataObject.STATUS_DELETED)) {
currentStatus = newStatus;
} else {
throw new IllegalArgumentException("Unknown status '" + newStatus +
- "'");
+ "'");
}
- } /* setStatus(String) */
-
+ }
+ /* setStatus(String) */
/**
@@ -125,42 +129,68 @@
*/
public String getStatus() {
return currentStatus;
- } /* getStatus() */
+ }
+ /* getStatus() */
- /**
- * Set a regular expression "mask" for this base data object that specifies it's
- * valid values. The mask should already be compiled by the regular
- * expression compiler
- * @param newMask The compiled regular expression mask
- *
- *
- * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
- */
- public void setGlobalMask(Pattern newMask) {
- globalMask = newMask;
- }
+ /**
+ * Set a regular expression "mask" for this base data object that specifies it's
+ * valid values. The mask should already be compiled by the regular
+ * expression compiler
+ * @param newMask The compiled regular expression mask
+ *
+ *
+ * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
+ */
+ public void setGlobalMask(Pattern newMask) {
+ globalMask = newMask;
+ }
- /**
- * Get the compiled regular expression for this base data object.
- * @return the precompiled regular expression mask
- *
- * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
- */
- public Pattern getGlobalMask() {
- return globalMask;
- }
+ /**
+ * Get the compiled regular expression for this base data object.
+ * @return the precompiled regular expression mask
+ *
+ * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
+ */
+ public Pattern getGlobalMask() {
+ return globalMask;
+ }
+
+
+ /**
+ * Return boolean if the data object has a mask set
+ *
+ * @return True if the data object mask is set, else false if it is not
+ *
+ * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
+ */
+ public boolean isGlobalMasked() {
+ return globalMask != null;
+ }
+ /* isMasked() */
+ /**
+ * {@inheritDoc}
+ * @throws DataException upon setField error.
+ */
+ public void setFieldsWithDefaults() throws DataException {
- /**
- * Return boolean if the data object has a mask set
- *
- * @return True if the data object mask is set, else false if it is not
- *
- * author Yves Henri AMAIZO <amy_amaizo at compuserve.com>
- */
- public boolean isGlobalMasked() {
- return globalMask != null;
- } /* isMasked() */
+ DataObjectMetaData metadata = this.getMetaData();
+ for (Iterator it = metadata.getFieldListArray()
+ .iterator(); it.hasNext(); ) {
+ String fieldname = (String)it.next();
+ String fieldValue = null;
+ try {
+ fieldValue = this.getField(fieldname);
+ } catch (DBException ex) {
+ throw new DataException("Error getting field current value.",ex);
+ }
+
+ if ((fieldValue == null) || (fieldValue.length() == 0)) {
+ fieldValue = metadata.getDefaultValue(fieldname);
+ if ( fieldValue != null ) this.set(fieldname, fieldValue);
+ }
+ }
+ }
}
Index: DataObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/DataObject.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/DataObject.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/DataObject.java -u -r1.20 -r1.21
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/DataObject.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/DataObject.java
@@ -86,31 +86,31 @@
* @version $Revision$ on $Date$
* @since Expresso 5.0
*/
-public interface DataObject extends Cacheable, ContextNested {
+public interface DataObject extends Cacheable, ContextNested
+{
/**
* Constant describing that this dbobject is new.
*/
- public static final String STATUS_NEW = "NEW";
+ static final String STATUS_NEW = "NEW";
/**
* Status constant indicating that this dbobject currently reflects what's
* in the database back end.
*/
- public static final String STATUS_CURRENT = "CURRENT";
+ static final String STATUS_CURRENT = "CURRENT";
/**
* Status constant indicating that this dbobject has been modified and
* does not match the back-end database.
*/
- public static final String STATUS_UPDATED = "UPDATED";
+ static final String STATUS_UPDATED = "UPDATED";
/**
* Status indicating that this DBObject has been deleted.
*/
- public static final String STATUS_DELETED = "DELETED";
-
+ static final String STATUS_DELETED = "DELETED";
/**
@@ -121,7 +121,7 @@
* @return The object if it isn't null for the data value or null.
* @throws DBException upon error
*/
- public DataField getDataField(String fieldName) throws DBException;
+ DataField getDataField(String fieldName) throws DBException;
/**
@@ -133,7 +133,7 @@
* requirements, a WeakHashMap is recommended</p>
* @return a built DataObjectMetaData for this database object
*/
- public DataObjectMetaData getMetaData();
+ DataObjectMetaData getMetaData();
/**
* Retrieves the metadata for a particular field name
@@ -142,8 +142,7 @@
* field.
* @throws IllegalArgumentException if the fieldName does not exist.
*/
- public DataFieldMetaData getFieldMetaData(String fieldName);
-
+ DataFieldMetaData getFieldMetaData(String fieldName);
/**
@@ -153,7 +152,7 @@
* @return Object or null.
* @throws DataException
*/
- public Object get(String fieldName) throws DataException;
+ Object get(String fieldName) throws DataException;
/**
* Directly sets the field value without getting the datafield object
@@ -161,7 +160,17 @@
* @param o the object value to set it to.
* @throws DataException
*/
- public void set(String fieldName, Object o) throws DataException;
+ void set(String fieldName, Object o) throws DataException;
+
+ /**
+ * Sets the fields of this object with the default values defined in
+ * the metadata. The behavior of this function is such that it only
+ * populates fields if there is no current value set. This is
+ * the same behavior that existed previously in DefaultAutoElement.
+ * @throws DataException upon setField error.
+ * @since Expresso 5.6
+ */
+ void setFieldsWithDefaults() throws DataException;
/**
* Checks to see if two data objects are equal. This is extremely important
@@ -169,33 +178,33 @@
* @param otherObject the other object to compare to.
* @return true if the two objects are considered equal
*/
- public boolean equals(Object otherObject);
+ boolean equals(Object otherObject);
/**
* Adds the record to the defined data source.
* @throws DBException
*/
- public void add() throws DBException;
+ void add() throws DBException;
/**
* Updates the record to the defined datasource
* @throws DBException
*/
- public void update() throws DBException;
+ void update() throws DBException;
/**
* Deletes this defined record.
* @throws DBException
*/
- public void delete() throws DBException;
+ void delete() throws DBException;
/**
* Clears all currently loaded fields
* @throws DBException
*/
- public void clear() throws DBException;
+ void clear() throws DBException;
/**
@@ -205,7 +214,7 @@
* connection.
* @return java.lang.String... the context we've mapped to.
*/
- public String getMappedDataContext();
+ String getMappedDataContext();
/**
@@ -215,7 +224,7 @@
* @param attributeName The name of the attribute being defined
* @param attributeValue The object to store under this attribute name
*/
- public void setAttribute(String attributeName, Object attributeValue);
+ void setAttribute(String attributeName, Object attributeValue);
/**
* Return an "attribute". Attributes are temporary (e.g. not stored in the DBMS)
@@ -224,14 +233,14 @@
* @param attributeName The attribute name to check
* @return the object associated with this attribute
*/
- public Object getAttribute(String attributeName);
+ Object getAttribute(String attributeName);
/**
* Returns a <b>Read Only</b> Map containing all the current attributes set
* for this particular data object instance.
* @return Read Only <code>java.util.Map</code>
*/
- public Map getAllAttributes();
+ Map getAllAttributes();
/**
@@ -241,7 +250,7 @@
* @throws DBException upon error
* @throws IllegalArgumentException if fieldname is invalid
*/
- public String getField(String fieldName) throws DBException;
+ String getField(String fieldName) throws DBException;
/**
* Use this function to acquire the Executor interface that is associated
@@ -249,7 +258,7 @@
* @return DataExecutorInterface or null if no Executor has been associated
* with this object
*/
- public DataExecutorInterface getExecutor();
+ DataExecutorInterface getExecutor();
/**
* Use this function to acquire the DataQueryInterface that is associated
@@ -257,7 +266,7 @@
* @return DataQueryInterface or null if no QueryInterface has been
* associated with this object
*/
- public DataQueryInterface getQueryInterface();
+ DataQueryInterface getQueryInterface();
/**
* Check that a given value is valid for a given field.
@@ -270,21 +279,21 @@
* @param fieldValue Value of the field to be evaluated
* @throws DBException If the value is not valid
*/
- public void checkField(String fieldName, String fieldValue) throws DBException;
+ void checkField(String fieldName, String fieldValue) throws DBException;
/**
* Retrieve the status code of the dataobject.
* @return java.lang.String
*/
- public String getStatus();
+ String getStatus();
/**
* Sets the status of the object.
* @param statusValue the new status code.
*/
- public void setStatus(String statusValue);
+ void setStatus(String statusValue);
/**
* Retrieve a list of valid value object for this particular dbobject
@@ -292,20 +301,20 @@
* @return java.util.List of valid values
* @throws DBException upon error
*/
- public java.util.List getValidValuesList(String fieldName) throws DBException;
+ java.util.List getValidValuesList(String fieldName) throws DBException;
/**
* Sets the DataObject's locale
* @param newLocale the New locale object
*/
- public void setLocale(java.util.Locale newLocale);
+ void setLocale(java.util.Locale newLocale);
/**
* Retrieve the DBObject's current locale
* @return java.util.Locale
*/
- public java.util.Locale getLocale();
+ java.util.Locale getLocale();
/**
@@ -318,7 +327,7 @@
* @param newMax The maximum number of records to retrieve.
* @throws DBException If the max number is less than 0
*/
- public void setMaxRecords(int newMax) throws DBException;
+ void setMaxRecords(int newMax) throws DBException;
/**
@@ -328,7 +337,7 @@
* @return The maximum number of records that should be retrieved, or zero
* if no max has been set
*/
- public int getMaxRecords();
+ int getMaxRecords();
/**
@@ -346,7 +355,7 @@
*
* author Peter Pilgrim <peterp at xenonsoft dot demon dot co dot uk>
*/
- public void setOffsetRecord(int newOffset) throws DBException;
+ void setOffsetRecord(int newOffset) throws DBException;
/**
@@ -361,7 +370,7 @@
*
* @see #setOffsetRecord(int)
*/
- public int getOffsetRecord();
+ int getOffsetRecord();
/**
* Performs a datasource search so that the criteria set in the DataObject
@@ -372,7 +381,7 @@
* objects were found.
* @throws DBException upon error performing the search
*/
- public ArrayList searchAndRetrieveList(String sortOrder) throws DBException;
+ ArrayList searchAndRetrieveList(String sortOrder) throws DBException;
/**
* Performs a datasource search so that the criteria set in the DataObject
@@ -381,7 +390,7 @@
* objects were found.
* @throws DBException upon error performing the search
*/
- public ArrayList searchAndRetrieveList() throws DBException;
+ ArrayList searchAndRetrieveList() throws DBException;
/**
@@ -391,7 +400,7 @@
* is filled with the first data object found.
* @throws DBException upon error performing the search
*/
- public boolean find() throws DBException;
+ boolean find() throws DBException;
/**
* Just like find, but only retrieves the count, not the records themselves.
@@ -399,24 +408,24 @@
* @return integer Count of the records matching the criteria
* @throws DBException If the search could not be completed
*/
- public int count() throws DBException;
+ int count() throws DBException;
+
+ /**
+ * Sets the DataObject's global mask
+ * @param newGlobalMask the New global mask object
+ */
+ void setGlobalMask(Pattern newGlobalMask);
+
+ /**
+ * Retrieve the DBObject's current global mask
+ * @return String
+ */
+ Pattern getGlobalMask();
- /**
- * Sets the DataObject's global mask
- * @param newGlobalMask the New global mask object
- */
- public void setGlobalMask(Pattern newGlobalMask);
-
- /**
- * Retrieve the DBObject's current global mask
- * @return String
- */
- public Pattern getGlobalMask();
-
- /**
- * Return boolean if the data object has a mask set
- *
- * @return True if the data object mask is set, else false if it is not
- */
- public boolean isGlobalMasked();
+ /**
+ * Return boolean if the data object has a mask set
+ *
+ * @return True if the data object mask is set, else false if it is not
+ */
+ boolean isGlobalMasked();
}
Index: SynchronizedDataObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/SynchronizedDataObject.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/SynchronizedDataObject.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/SynchronizedDataObject.java -u -r1.8 -r1.9
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/SynchronizedDataObject.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/SynchronizedDataObject.java
@@ -234,6 +234,13 @@
return target.getDataContext();
}
+ /**
+ * {@inheritDoc}
+ * @throws DataException upon setField error.
+ */
+ public synchronized void setFieldsWithDefaults() throws DataException {
+ target.setFieldsWithDefaults();
+ }
/**
* Returns the name of the physical database that we're talking with. This
Index: JoinedDataObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/jdbc/JoinedDataObject.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/jdbc/JoinedDataObject.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/jdbc/JoinedDataObject.java -u -r1.36 -r1.37
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/jdbc/JoinedDataObject.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dataobjects/jdbc/JoinedDataObject.java
@@ -1,65 +1,65 @@
/* ====================================================================
-* The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
-*
-* Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-* 1. Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-*
-* 2. Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in
-* the documentation and/or other materials provided with the
-* distribution.
-*
-* 3. The end-user documentation included with the redistribution,
-* if any, must include the following acknowledgment:
-* "This product includes software developed by Jcorporate Ltd.
-* (http://www.jcorporate.com/)."
-* Alternately, this acknowledgment may appear in the software itself,
-* if and wherever such third-party acknowledgments normally appear.
-*
-* 4. "Jcorporate" and product names such as "Expresso" must
-* not be used to endorse or promote products derived from this
-* software without prior written permission. For written permission,
-* please contact info at jcorporate.com.
-*
-* 5. Products derived from this software may not be called "Expresso",
-* or other Jcorporate product names; nor may "Expresso" or other
-* Jcorporate product names appear in their name, without prior
-* written permission of Jcorporate Ltd.
-*
-* 6. No product derived from this software may compete in the same
-* market space, i.e. framework, without prior written permission
-* of Jcorporate Ltd. For written permission, please contact
-* partners at jcorporate.com.
-*
-* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
-* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
-* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
-* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
-* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-* SUCH DAMAGE.
-* ====================================================================
-*
-* This software consists of voluntary contributions made by many
-* individuals on behalf of the Jcorporate Ltd. Contributions back
-* to the project(s) are encouraged when you make modifications.
-* Please send them to support at jcorporate.com. For more information
-* on Jcorporate Ltd. and its products, please see
-* <http://www.jcorporate.com/>.
-*
-* Portions of this software are based upon other open source
-* products and are subject to their respective licenses.
+ * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
+ *
+ * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by Jcorporate Ltd.
+ * (http://www.jcorporate.com/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. "Jcorporate" and product names such as "Expresso" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written permission,
+ * please contact info at jcorporate.com.
+ *
+ * 5. Products derived from this software may not be called "Expresso",
+ * or other Jcorporate product names; nor may "Expresso" or other
+ * Jcorporate product names appear in their name, without prior
+ * written permission of Jcorporate Ltd.
+ *
+ * 6. No product derived from this software may compete in the same
+ * market space, i.e. framework, without prior written permission
+ * of Jcorporate Ltd. For written permission, please contact
+ * partners at jcorporate.com.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Jcorporate Ltd. Contributions back
+ * to the project(s) are encouraged when you make modifications.
+ * Please send them to support at jcorporate.com. For more information
+ * on Jcorporate Ltd. and its products, please see
+ * <http://www.jcorporate.com/>.
+ *
+ * Portions of this software are based upon other open source
+ * products and are subject to their respective licenses.
*/
package com.jcorporate.expresso.core.dataobjects.jdbc;
@@ -88,7 +88,7 @@
import com.jcorporate.expresso.services.dbobj.Setup;
import org.apache.log4j.Logger;
import org.apache.oro.text.regex.Pattern;
-
+import com.jcorporate.expresso.core.dbobj.RequestContext;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -121,32 +121,36 @@
* Modify by Yves Henri AMAIZO <amy_amaizo at compuserve.com>
* @since $DatabaseSchema $Date$
*/
-public class JoinedDataObject implements DataObject, Defineable, Securable, NestableDataObject {
- private static final transient String thisClass = JoinedDataObject.class.getName() +
- ".";
+public class JoinedDataObject implements DataObject, Defineable, Securable
+ , NestableDataObject
+{
+ private static final transient String thisClass = JoinedDataObject.class.
+ getName() +
+ ".";
- public static final int UNSPECIFIED_JOIN = -1;
+ public static final int UNSPECIFIED_JOIN = -1;
/**
* Static variables for join type
*/
- public static final int INNER_JOIN = 0;
+ public static final int INNER_JOIN = 0;
/**
* Static field to indicate RIGHT_JOIN type
*/
- public static final int RIGHT_JOIN = 1;
+ public static final int RIGHT_JOIN = 1;
/**
* Static field to indicate LEFT_JOIN type
*/
- public static final int LEFT_JOIN = 2;
+ public static final int LEFT_JOIN = 2;
/**
* The logger instance.
*/
- private static transient final Logger log = Logger.getLogger(JoinedDataObject.class);
+ private static transient final Logger log = Logger.getLogger(
+ JoinedDataObject.class);
/**
* Local connection that we use if it's initialized, but if it's null we
@@ -252,9 +256,10 @@
/**
* Creates a new JoinedDataObject object.
+ * @param request based on the controller request object as most likely implemented.
*/
- public JoinedDataObject(ControllerRequest request) {
- setDataContext(request.getDataContext());
+ public JoinedDataObject(RequestContext request) {
+ setDataContext(request.getDBName());
setRequestingUid(request.getUid());
}
@@ -295,7 +300,7 @@
public JoinedDataObject(JoinedDigesterBean definition,
String definitionName) throws DataException {
thisDefinitionName = definitionName;
- initWithBean(definition,definitionName);
+ initWithBean(definition, definitionName);
}
/**
@@ -318,18 +323,19 @@
try {
if (this.getMetaData() == null) {
JoinedDataObjectMetaData metadata = constructMetadata();
- definitions.put(getDefinitionName(),metadata);
+ definitions.put(getDefinitionName(), metadata);
initializeXML(metadata);
}
myDataObjects = ((JoinedDataObjectMetaData)this
- .getMetaData()).createNestedDataObjects();
+ .getMetaData()).createNestedDataObjects();
} catch (Throwable t) {
if (definitions.containsKey(getDefinitionName())) {
definitions.remove(getDefinitionName());
}
log.error("Error initializing data object", t);
- throw new DataException("Error initializing joined data object",t);
+ throw new DataException("Error initializing joined data object"
+ , t);
}
}
}
@@ -351,7 +357,9 @@
* @param definitionName the name of the definition
* @throws DataException upon error
*/
- protected synchronized void initWithBean(JoinedDigesterBean digesterBean, String definitionName) throws DataException {
+ protected synchronized void initWithBean(JoinedDigesterBean digesterBean
+ , String definitionName) throws
+ DataException {
if (log.isDebugEnabled()) {
log.debug("Initializing new JoinedDataObject");
}
@@ -359,8 +367,8 @@
try {
if (getMetaData() == null) {
JoinedDataObjectMetaData metadata = constructMetadata();
- definitions.put(definitionName,metadata);
- initializeFromJoinedDigesterBean(digesterBean,metadata);
+ definitions.put(definitionName, metadata);
+ initializeFromJoinedDigesterBean(digesterBean, metadata);
}
this.myDataObjects = ((JoinedDataObjectMetaData)this
@@ -370,7 +378,8 @@
definitions.remove(this.getDefinitionName());
}
log.error("Error initializing data object", t);
- throw new DataException("Error initializing joined data object",t);
+ throw new DataException("Error initializing joined data object"
+ , t);
}
}
@@ -383,32 +392,34 @@
* @param metadata the meatadata to load the digester bean into
* @throws DataException upon error
*/
- protected void initializeFromJoinedDigesterBean(JoinedDigesterBean digesterBean,
- JoinedDataObjectMetaData metadata) throws DataException{
+ protected void initializeFromJoinedDigesterBean(JoinedDigesterBean
+ digesterBean,
+ JoinedDataObjectMetaData metadata) throws DataException {
metadata.setSelectDistinct(digesterBean.isDistinct());
metadata.setDescription(digesterBean.getDescription());
List l = digesterBean.getDataObjects();
- for (Iterator i = l.iterator(); i.hasNext();) {
+ for (Iterator i = l.iterator(); i.hasNext(); ) {
JoinedDigesterBean.DigesterJoinedDataObject oneObj =
- (JoinedDigesterBean.DigesterJoinedDataObject)i.next();
+ (JoinedDigesterBean.DigesterJoinedDataObject) i.next();
try {
Class c = ClassLocator.loadClass(oneObj.getClassName());
- metadata.addDataObject(c, oneObj.getDefinitionName(),oneObj.getAlias(),
+ metadata.addDataObject(c, oneObj.getDefinitionName()
+ , oneObj.getAlias(),
oneObj.getFieldExpressionList());
- }
- catch (ClassNotFoundException ex) {
- throw new DataException("Error parsing definition: unable to locate class: "
- + oneObj.getClassName());
+ } catch (ClassNotFoundException ex) {
+ throw new DataException(
+ "Error parsing definition: unable to locate class: "
+ + oneObj.getClassName());
}
}
metadata.setPermissions(digesterBean.getPermissions());
List r = digesterBean.getRelations();
- for (Iterator i = r.iterator(); i.hasNext();) {
+ for (Iterator i = r.iterator(); i.hasNext(); ) {
JoinedDigesterBean.DigesterJoinRelations oneRelation =
- (JoinedDigesterBean.DigesterJoinRelations)i.next();
+ (JoinedDigesterBean.DigesterJoinRelations) i.next();
try {
String joinType = oneRelation.getJoinType();
@@ -425,11 +436,10 @@
}
metadata.setForeignKey(oneRelation.getLocalAlias(),
- oneRelation.getLocalKey(),
- oneRelation.getForeignAlias(),
- oneRelation.getForeignKey(), joinValue);
- }
- catch (DBException ex) {
+ oneRelation.getLocalKey(),
+ oneRelation.getForeignAlias(),
+ oneRelation.getForeignKey(), joinValue);
+ } catch (DBException ex) {
throw new DataException("Error setting keys for join", ex);
}
}
@@ -441,25 +451,26 @@
* @param metadata the metadata object to fill out with the XML data
* @throws DataException
*/
- protected void initializeXML(JoinedDataObjectMetaData metadata) throws DataException {
+ protected void initializeXML(JoinedDataObjectMetaData metadata) throws
+ DataException {
if (log.isDebugEnabled()) {
- log.debug("Initializing XML metadata for: " + this.getDefinitionName());
+ log.debug("Initializing XML metadata for: "
+ + this.getDefinitionName());
}
-
String fileLocation = this.getDefinitionName();
java.net.URL def = this.getClass().getResource(fileLocation);
if (def == null) {
- throw new DataException("Unable to load metadata at: " + fileLocation);
+ throw new DataException("Unable to load metadata at: "
+ + fileLocation);
}
-
JoinedDigesterBean digesterBean = new JoinedDigesterBean();
digesterBean.loadJoinData(def);
- initializeFromJoinedDigesterBean(digesterBean,metadata);
+ initializeFromJoinedDigesterBean(digesterBean, metadata);
}
- /**
+ /**
* Retrieves all the attributes for this data object
*
* @return a map of all the attributes for this instance of the data object
@@ -515,11 +526,12 @@
/**
* Set a custom WHERE clause
- * @param customWhereClause
+ * @param customWhereClause the custom where clause to use.
* @param append if true the supplied WHERE clause will be appended to the one
* generated, else it will replace it
*/
- public synchronized void setCustomWhereClause(String customWhereClause, boolean append) {
+ public synchronized void setCustomWhereClause(String customWhereClause
+ , boolean append) {
this.customWhereClause = customWhereClause;
this.appendCustomWhere = append;
@@ -532,7 +544,7 @@
* @param newContext A valid data context name.
*/
public void setDataContext(String newContext) {
- for (Iterator i = myDataObjects.keySet().iterator(); i.hasNext();) {
+ for (Iterator i = myDataObjects.keySet().iterator(); i.hasNext(); ) {
String key = (String) i.next();
DataObject oneobj = (DataObject) myDataObjects.get(key);
@@ -562,23 +574,24 @@
* @param o The Object to set it by.
* @throws DataException
*/
- public void setDataField(String fieldName, DataField o)
- throws DataException {
+ public void setDataField(String fieldName, DataField o) throws
+ DataException {
DataField field = (DataField)this.myFields.get(fieldName);
-
if (field != null && !(o instanceof JoinedDataField)) {
- throw new IllegalStateException("Can't be setting a joined data field with a non-joined data field");
+ throw new IllegalStateException(
+ "Can't be setting a joined data field with a non-joined data field");
}
if (field != null) {
- this.myFields.put(fieldName,o);
+ this.myFields.put(fieldName, o);
} else {
JoinedDataObjectMetaData metadata = this.getJoinMetaData();
String[] location = metadata.getObjectAndField(fieldName);
- DataObject localObject = (DataObject)this.myDataObjects.get(location[0]);
- localObject.set(location[1],o);
+ DataObject localObject = (DataObject)this.myDataObjects.get(
+ location[0]);
+ localObject.set(location[1], o);
}
}
@@ -600,34 +613,39 @@
}
JoinedDataObjectMetaData metadata = this.getJoinMetaData();
- String rightKey = (String)metadata.foreignKeyToPrimaryKeyMap.get(fieldName);
- String leftKey = (String)metadata.primaryToForeignKeyMap.get(fieldName);
+ String rightKey = (String) metadata.foreignKeyToPrimaryKeyMap.get(
+ fieldName);
+ String leftKey = (String) metadata.primaryToForeignKeyMap.get(fieldName);
String location[] = metadata.getObjectAndField(fieldName);
DataObject oneObj = (DataObject) myDataObjects.get(location[0]);
JoinedDataField joinField = null;
- if ((rightKey == null || rightKey.length() == 0) && (leftKey == null || leftKey.length() ==0 )) {
+ if ((rightKey == null || rightKey.length() == 0)
+ && (leftKey == null || leftKey.length() == 0)) {
field = oneObj.getDataField(location[1]);
if (field.getFieldMetaData().isVirtual()) {
field.setValue(oneObj.getField(location[1]));
}
return field;
- } else if ((rightKey != null && rightKey.length() > 0) && (leftKey == null || leftKey.length() ==0 )) {
+ } else if ((rightKey != null && rightKey.length() > 0)
+ && (leftKey == null || leftKey.length() == 0)) {
//We have left key... set right key as well.
String rightLocation[] = metadata.getObjectAndField(rightKey);
joinField = (JoinedDataField)this.myFields.get(fieldName);
if (joinField == null) {
- joinField = JoinedDataField.getInstance(this,(DataObject)this.myDataObjects.get(location[0])
- ,location[1],
- (DataObject)this.myDataObjects.get(rightLocation[0]),rightLocation[1]);
+ joinField = JoinedDataField.getInstance(this
+ , (DataObject)this.myDataObjects.get(location[0])
+ , location[1],
+ (DataObject)this.myDataObjects.get(rightLocation[0])
+ , rightLocation[1]);
}
//
//We need to put it in twice since a lookup of either the left or the right
//key should return the joined data object
//
- this.myFields.put(fieldName,joinField);
+ this.myFields.put(fieldName, joinField);
this.myFields.put(rightKey, joinField);
} else {
@@ -635,17 +653,17 @@
String leftLocation[] = metadata.getObjectAndField(leftKey);
joinField = (JoinedDataField)this.myFields.get(leftKey);
if (joinField == null) {
- joinField = JoinedDataField.getInstance(this,(DataObject)this.myDataObjects.get(leftLocation[0])
- ,leftLocation[1],
- (DataObject)this.myDataObjects.get(location[0]),location[1]);
+ joinField = JoinedDataField.getInstance(this
+ , (DataObject)this.myDataObjects.get(leftLocation[0])
+ , leftLocation[1],
+ (DataObject)this.myDataObjects.get(location[0]), location[1]);
}
-
//
//We need to put it in twice since a lookup of either the left or the right
//key should return the joined data object
//
- this.myFields.put(fieldName,joinField);
+ this.myFields.put(fieldName, joinField);
this.myFields.put(leftKey, joinField);
}
@@ -679,21 +697,25 @@
* @return The metadata for the field name.
*/
public DataFieldMetaData getFieldMetaData(String fieldName) {
- StringTokenizer stok = new StringTokenizer(StringUtil.notNull(fieldName), ".");
+ StringTokenizer stok = new StringTokenizer(StringUtil.notNull(fieldName)
+ , ".");
if (!stok.hasMoreTokens()) {
- throw new IllegalArgumentException("Field name must be proper format");
+ throw new IllegalArgumentException(
+ "Field name must be proper format");
}
- JDBCDataObject dataobject = (JDBCDataObject) this.myDataObjects.get(stok.nextToken());
+ JDBCDataObject dataobject = (JDBCDataObject)this.myDataObjects.get(stok.
+ nextToken());
if (!stok.hasMoreTokens()) {
- throw new IllegalArgumentException("Field name must be proper format");
+ throw new IllegalArgumentException(
+ "Field name must be proper format");
}
if (dataobject == null) {
- throw new IllegalArgumentException("Unable to find specified data object in this Join");
+ throw new IllegalArgumentException(
+ "Unable to find specified data object in this Join");
}
-
return dataobject.getFieldMetaData(stok.nextToken());
}
@@ -706,13 +728,11 @@
* @throws DataException
* @throws IllegalArgumentException if filedName is improperly formatted
*/
- public void set(String fieldName, Object o)
- throws DataException {
+ public void set(String fieldName, Object o) throws DataException {
try {
this.getDataField(fieldName).setValue(o);
- }
- catch (DBException ex) {
+ } catch (DBException ex) {
throw new DataException("Unable to set field value for field "
+ fieldName + " value " + o.toString());
}
@@ -730,29 +750,26 @@
public Object get(String fieldName) throws DataException {
try {
return this.getDataField(fieldName).getValue();
- }
- catch (DBException ex) {
+ } catch (DBException ex) {
throw new DataException("Error retrieving data field", ex);
}
}
-
-
/**
* Retrieve the key used for this join
* @return java.lang.String
*/
public String getKey() {
- JoinedDataObjectMetaData metadata = (JoinedDataObjectMetaData)this.getMetaData();
+ JoinedDataObjectMetaData metadata = (JoinedDataObjectMetaData)this.
+ getMetaData();
String alias = metadata.getPrimaryAlias();
JDBCDataObject primaryObject = null;
try {
primaryObject = this.getByShortName(alias);
return primaryObject.getKey();
- }
- catch (DataException ex) {
+ } catch (DataException ex) {
log.error("Error dataobject by name: " + alias, ex);
return "";
}
@@ -787,15 +804,15 @@
* @return java.lang.String
*/
public String getMappedDataContext() {
- JoinedDataObjectMetaData metadata = (JoinedDataObjectMetaData)this.getMetaData();
+ JoinedDataObjectMetaData metadata = (JoinedDataObjectMetaData)this.
+ getMetaData();
String alias = metadata.getPrimaryAlias();
JDBCDataObject primaryObject = null;
try {
primaryObject = this.getByShortName(alias);
return primaryObject.getMappedDataContext();
- }
- catch (DataException ex) {
+ } catch (DataException ex) {
log.error("Error dataobject by name: " + alias, ex);
return "";
}
@@ -856,8 +873,8 @@
public ArrayList getDataObjects() {
ArrayList al = new ArrayList(this.myDataObjects.size());
JoinedDataObjectMetaData metadata = this.getJoinMetaData();
- for (Iterator i = metadata.getAliasesInOrder().iterator(); i.hasNext();) {
- String oneAlias = (String)i.next();
+ for (Iterator i = metadata.getAliasesInOrder().iterator(); i.hasNext(); ) {
+ String oneAlias = (String) i.next();
al.add(this.myDataObjects.get(oneAlias));
}
@@ -884,6 +901,7 @@
offsetRecord = newOffset;
}
+
/* setOffsetRecord(int) */
/**
@@ -899,6 +917,7 @@
public int getOffsetRecord() {
return offsetRecord;
}
+
/* getOffsetRecord() */
/**
@@ -908,7 +927,7 @@
*/
public DataQueryInterface getQueryInterface() {
throw new java.lang.UnsupportedOperationException(
- "Method getQueryInterface() not yet implemented.");
+ "Method getQueryInterface() not yet implemented.");
}
/**
@@ -918,15 +937,15 @@
* other ones have the same status as the primary]
*/
public String getStatus() {
- JoinedDataObjectMetaData metadata = (JoinedDataObjectMetaData)this.getMetaData();
+ JoinedDataObjectMetaData metadata = (JoinedDataObjectMetaData)this.
+ getMetaData();
String alias = metadata.getPrimaryAlias();
JDBCDataObject primaryObject = null;
try {
primaryObject = this.getByShortName(alias);
return primaryObject.getStatus();
- }
- catch (DataException ex) {
+ } catch (DataException ex) {
log.error("Error dataobject by name: " + alias, ex);
return "";
}
@@ -937,27 +956,27 @@
* @param newValue see BaseDataObject for possible values
*/
public void setStatus(String newValue) {
- JoinedDataObjectMetaData metadata = (JoinedDataObjectMetaData)this.getMetaData();
+ JoinedDataObjectMetaData metadata = (JoinedDataObjectMetaData)this.
+ getMetaData();
String alias = metadata.getPrimaryAlias();
JDBCDataObject primaryObject = null;
try {
primaryObject = this.getByShortName(alias);
primaryObject.setStatus(newValue);
- }
- catch (DataException ex) {
+ } catch (DataException ex) {
log.error("Error dataobject by name: " + alias, ex);
}
}
- /**
- * Retrieve a list of valid value object for this particular dbobject
- * @param fieldName name of the field to retrieve the list for. Should be
- * of the format [shortname].[fieldname]
- * @return java.util.List of valid values
- * @throws DBException upon error
+ /**
+ * Retrieve a list of valid value object for this particular dbobject
+ * @param fieldName name of the field to retrieve the list for. Should be
+ * of the format [shortname].[fieldname]
+ * @return java.util.List of valid values
+ * @throws DBException upon error
*/
public List getValidValuesList(String fieldName) throws DBException {
@@ -984,21 +1003,23 @@
connection = localConnection;
localConn = true;
} else {
- DBConnectionPool myPool = DBConnectionPool.getInstance(this.getMappedDataContext());
+ DBConnectionPool myPool = DBConnectionPool.getInstance(this.
+ getMappedDataContext());
connection = myPool.getConnection("Joined DataObject Add");
connection.setAutoCommit(false);
}
JoinedDataObjectMetaData joinMetadata = this.getJoinMetaData();
try {
- String allAliases[] = (String[])joinMetadata.getAliasesInOrder()
- .toArray(new String[myDataObjects.size()]);
+ String allAliases[] = (String[]) joinMetadata.getAliasesInOrder()
+ .toArray(new String[myDataObjects.size()]);
//Ok, now work backwards so we can get autoincs from right tables
//and apply it to foreign keys in the left tables.
for (int i = (allAliases.length - 1); i >= 0; i--) {
String oneAlias = allAliases[i];
- JDBCDataObject oneObject = (JDBCDataObject)this.myDataObjects.get(oneAlias);
+ JDBCDataObject oneObject = (JDBCDataObject)this.myDataObjects.
+ get(oneAlias);
oneObject.setConnection(connection, this.getDataContext());
if (!oneObject.find()) {
oneObject.add();
@@ -1012,21 +1033,27 @@
JDBCObjectMetaData metadata = oneObject.getJDBCMetaData();
for (Iterator j = metadata
- .getKeyFieldListArray().iterator(); j.hasNext();) {
- String oneFieldName = (String)j.next();
+ .getKeyFieldListArray().iterator(); j.hasNext(); ) {
+ String oneFieldName = (String) j.next();
//
//We only have to worry about autoinc fields since they're the
//part that haven't been set
//
- if (metadata.getFieldMetadata(oneFieldName).isAutoIncremented()) {
- String rightFieldName = allAliases[i] + "." + oneFieldName;
- String leftFieldName = (String)joinMetadata.primaryToForeignKeyMap.get(rightFieldName);
+ if (metadata.getFieldMetadata(oneFieldName).
+ isAutoIncremented()) {
+ String rightFieldName = allAliases[i] + "."
+ + oneFieldName;
+ String leftFieldName = (String) joinMetadata.
+ primaryToForeignKeyMap.get(
+ rightFieldName);
if (leftFieldName != null && leftFieldName.length() > 0) {
- String location[] = joinMetadata.getObjectAndField(leftFieldName);
- JDBCDataObject leftObject = (JDBCDataObject)this.myDataObjects.get(location[0]);
+ String location[] = joinMetadata.getObjectAndField(
+ leftFieldName);
+ JDBCDataObject leftObject = (JDBCDataObject)this.
+ myDataObjects.get(location[0]);
leftObject.set(location[1],
- oneObject.get(oneFieldName));
+ oneObject.get(oneFieldName));
}
}
@@ -1041,11 +1068,11 @@
// connection.commit();
// }
} catch (DBException ex) {
- log.error("Error adding JoinedDataObject",ex);
+ log.error("Error adding JoinedDataObject", ex);
// if (localConnection == null && connection != null) {
- if (!localConn) {
- connection.rollback();
- connection.release();
+ if (!localConn) {
+ connection.rollback();
+ connection.release();
} else {
throw ex;
}
@@ -1055,12 +1082,10 @@
// }
}
-
setStatus(BaseDataObject.STATUS_CURRENT);
}
-
/**
* Retrieve a list of valid value object for this particular dbobject
* @param fieldName name of the field to retrieve the list for.
@@ -1068,15 +1093,15 @@
* @throws DBException upon error
* @throws IllegalArgumentException if unable to parse the fieldName
*/
- public void checkField(String fieldName, String fieldValue)
- throws DBException {
+ public void checkField(String fieldName, String fieldValue) throws
+ DBException {
checkInitialized();
- String location[] =this.getJoinMetaData().getObjectAndField(fieldName);
+ String location[] = this.getJoinMetaData().getObjectAndField(fieldName);
DataObject oneObj = (DataObject) myDataObjects.get(location[0]);
- oneObj.checkField(location[1],fieldValue);
+ oneObj.checkField(location[1], fieldValue);
}
@@ -1088,8 +1113,7 @@
* @return boolean: true if the operation is allowed, or false if it is not
* @see #isAllowed
*/
- public boolean checkAllowed(String requestedFunction)
- throws DBException {
+ public boolean checkAllowed(String requestedFunction) throws DBException {
try {
isAllowed(requestedFunction);
} catch (SecurityException de) {
@@ -1098,7 +1122,8 @@
}
return true;
- } /* checkAllowed(String) */
+ }
+ /* checkAllowed(String) */
/**
* Clears all currently loaded fields
@@ -1107,8 +1132,8 @@
public void clear() throws DBException {
checkInitialized();
- for (Iterator i = this.myDataObjects.values().iterator(); i.hasNext();) {
- JDBCDataObject oneObj = (JDBCDataObject)i.next();
+ for (Iterator i = this.myDataObjects.values().iterator(); i.hasNext(); ) {
+ JDBCDataObject oneObj = (JDBCDataObject) i.next();
oneObj.clear();
}
}
@@ -1138,10 +1163,12 @@
checkInitialized();
isAllowed(SecuredDBObject.SEARCH);
- DBConnectionPool myPool = DBConnectionPool.getInstance(this.getMappedDataContext());;
+ DBConnectionPool myPool = DBConnectionPool.getInstance(this.
+ getMappedDataContext()); ;
DBConnection myConnection = null;
- JDBCDataObject primaryObject = (JDBCDataObject)this.getJoinMetaData().getDataObjectsInOrder().get(0);
+ JDBCDataObject primaryObject = (JDBCDataObject)this.getJoinMetaData().
+ getDataObjectsInOrder().get(0);
ArrayList keyFields = primaryObject.getMetaData().getKeyFieldListArray();
//
@@ -1156,11 +1183,15 @@
myStatement.append(" COUNT(*) FROM ");
} else {
DataFieldMetaData keymetadata = primaryObject
- .getFieldMetaData((String)keyFields.get(0));
+ .getFieldMetaData((String)
+ keyFields.get(0));
myStatement.append("SELECT ");
myStatement.append(getDistinct(myPool));
- myStatement.append("COUNT( " + primaryObject.getJDBCMetaData().getTargetSQLTable(primaryObject.getDataContext()) + "."
- + keymetadata.getName() +") FROM ");
+ myStatement.append("COUNT( "
+ + primaryObject.getJDBCMetaData().
+ getTargetSQLTable(primaryObject.
+ getDataContext()) + "."
+ + keymetadata.getName() + ") FROM ");
}
myStatement.append(this.buildFromClause());
@@ -1183,7 +1214,6 @@
myConnection = myPool.getConnection(this.getDefinitionName());
}
-
myConnection.execute(myStatement.toString());
if (myConnection.next()) {
@@ -1196,7 +1226,7 @@
throw de;
} catch (Exception e) {
log.error("Error performing count.", e);
- throw new DataException("Exception performing count",e);
+ throw new DataException("Exception performing count", e);
} finally {
myStatement.release();
if (localConnection == null && myConnection != null) {
@@ -1247,7 +1277,6 @@
myConnection = myPool.getConnection(this.getDefinitionName());
}
-
myConnection.executeUpdate(myStatement.toString());
} catch (DBException de) {
@@ -1255,7 +1284,7 @@
throw de;
} catch (Exception e) {
log.error("Error performing count.", e);
- throw new DataException("Exception performing count",e);
+ throw new DataException("Exception performing count", e);
} finally {
myStatement.release();
if (localConnection == null && myConnection != null) {
@@ -1283,7 +1312,7 @@
boolean returnValue = true;
- for (Iterator i = myDataObjects.keySet().iterator(); i.hasNext();) {
+ for (Iterator i = myDataObjects.keySet().iterator(); i.hasNext(); ) {
String oneObjName = (String) i.next();
if (!other.myDataObjects.containsKey(oneObjName)) {
@@ -1291,7 +1320,8 @@
}
DataObject myObj = (DataObject) myDataObjects.get(oneObjName);
- DataObject otherObj = (DataObject) other.myDataObjects.get(oneObjName);
+ DataObject otherObj = (DataObject) other.myDataObjects.get(
+ oneObjName);
returnValue &= myObj.equals(otherObj);
@@ -1308,10 +1338,9 @@
*
* @return a hash code value for this object.
*/
- public int hashCode()
- {
+ public int hashCode() {
int returnValue = 0;
- for (Iterator i = myDataObjects.keySet().iterator(); i.hasNext();) {
+ for (Iterator i = myDataObjects.keySet().iterator(); i.hasNext(); ) {
String oneObjName = (String) i.next();
DataObject myObj = (DataObject) myDataObjects.get(oneObjName);
@@ -1341,9 +1370,9 @@
test.setDataContext(this.getDataContext());
ArrayList fieldList = this.getMetaData().getFieldListArray();
- for (Iterator i = fieldList.iterator(); i.hasNext();) {
- String fieldName = (String)i.next();
- test.set(fieldName,this.getDataField(fieldName).getValue());
+ for (Iterator i = fieldList.iterator(); i.hasNext(); ) {
+ String fieldName = (String) i.next();
+ test.set(fieldName, this.getDataField(fieldName).getValue());
}
//
@@ -1354,11 +1383,11 @@
if (al.size() == 0) {
return false;
} else {
- JoinedDataObject oneObj = (JoinedDataObject)al.get(0);
+ JoinedDataObject oneObj = (JoinedDataObject) al.get(0);
for (Iterator i = fieldList.iterator();
- i.hasNext();) {
- String fieldName = (String)i.next();
- this.set(fieldName,oneObj.get(fieldName));
+ i.hasNext(); ) {
+ String fieldName = (String) i.next();
+ this.set(fieldName, oneObj.get(fieldName));
}
}
@@ -1378,8 +1407,7 @@
* Modify by Yves Henri AMAIZO <amy_amaizo at compuserve.com>
* @since $DatabaseSchema $Date$
*/
- public ArrayList searchAndRetrieveList(String sortOrder)
- throws DBException {
+ public ArrayList searchAndRetrieveList(String sortOrder) throws DBException {
boolean needComma = false;
isAllowed(SecuredDBObject.SEARCH);
@@ -1393,7 +1421,8 @@
myConnection = localConnection;
} else {
myPool = DBConnectionPool.getInstance(getDataContext());
- myConnection = myPool.getConnection("JoinedDataObject.searchAndRetrieveList()");
+ myConnection = myPool.getConnection(
+ "JoinedDataObject.searchAndRetrieveList()");
}
recordSet = new ArrayList();
@@ -1401,11 +1430,13 @@
FastStringBuffer myStatement = new FastStringBuffer(256);
myStatement.append("SELECT ");
- if (myConnection.getLimitationPosition() == DBConnection.LIMITATION_AFTER_SELECT &&
- (offsetRecord > 0 || maxRecords > 0)) {
+ if (myConnection.getLimitationPosition()
+ == DBConnection.LIMITATION_AFTER_SELECT &&
+ (offsetRecord > 0 || maxRecords > 0)) {
// Insert limitation stub after table nomination
- String limitStub = JDBCUtil.getInstance().makeLimitationStub(myConnection,this);
+ String limitStub = JDBCUtil.getInstance().makeLimitationStub(
+ myConnection, this);
myStatement.append(" ");
myStatement.append(limitStub);
@@ -1414,31 +1445,36 @@
myStatement.append(this.getDistinct(myPool));
- Iterator eachObj = this.getJoinMetaData().getDataObjectsInOrder().iterator();
- Iterator eachAlias = this.getJoinMetaData().getAliasesInOrder().iterator();
+ Iterator eachObj = this.getJoinMetaData().getDataObjectsInOrder().
+ iterator();
+ Iterator eachAlias = this.getJoinMetaData().getAliasesInOrder().
+ iterator();
JDBCDataObject oneObj = null;
String oneAlias;
- while(eachObj.hasNext()) {
+ while (eachObj.hasNext()) {
oneObj = (JDBCDataObject) eachObj.next();
oneAlias = (String) eachAlias.next();
JDBCObjectMetaData metadata = oneObj.getJDBCMetaData();
- ArrayList retrievedFieldList = (ArrayList) rtrvListByTable.get(metadata.getTargetSQLTable(oneObj.getDataContext()));
+ ArrayList retrievedFieldList = (ArrayList) rtrvListByTable.get(
+ metadata.getTargetSQLTable(oneObj.getDataContext()));
if (retrievedFieldList == null) {
retrievedFieldList = new ArrayList();
- rtrvListByTable.put(metadata.getTargetSQLTable(oneObj.getDataContext()), retrievedFieldList);
+ rtrvListByTable.put(metadata.getTargetSQLTable(oneObj.
+ getDataContext()), retrievedFieldList);
}
- List fieldsToRetrieve = this.getJoinMetaData().getFieldsToRetrieve(oneAlias);
+ List fieldsToRetrieve = this.getJoinMetaData().
+ getFieldsToRetrieve(oneAlias);
if (fieldsToRetrieve != null) {
if (fieldsToRetrieve.isEmpty()) {
// we don't want to include any fields from this table
continue;
}
JoinedDataObjectMetaData.FieldList fieldList = null;
- for (Iterator i = fieldsToRetrieve.iterator(); i.hasNext();) {
- fieldList = (JoinedDataObjectMetaData.FieldList)i.next();
+ for (Iterator i = fieldsToRetrieve.iterator(); i.hasNext(); ) {
+ fieldList = (JoinedDataObjectMetaData.FieldList) i.next();
String fieldExpression = fieldList.getFieldExpression();
fieldName = fieldList.getFieldName();
boolean isExpression = fieldList.isExpression();
@@ -1454,7 +1490,8 @@
// add the expression 'as-is' to the select
myStatement.append(fieldExpression);
} else {
- myStatement.append(selectFieldString(oneObj, fieldName));
+ myStatement.append(selectFieldString(oneObj
+ , fieldName));
}
retrievedFieldList.add(fieldName);
needComma = true;
@@ -1464,9 +1501,9 @@
/* for each field */
} else {
for (Iterator i = metadata.getFieldListArray().iterator();
- i.hasNext();
- ) {
- fieldName = (String)i.next();
+ i.hasNext();
+ ) {
+ fieldName = (String) i.next();
DataFieldMetaData metaData =
oneObj.getFieldMetaData(fieldName);
@@ -1476,7 +1513,8 @@
myStatement.append(", ");
}
- myStatement.append(selectFieldString(oneObj, fieldName));
+ myStatement.append(selectFieldString(oneObj
+ , fieldName));
retrievedFieldList.add(fieldName);
needComma = true;
}
@@ -1491,11 +1529,13 @@
myStatement.append(" FROM ");
myStatement.append(this.buildFromClause());
- if (myConnection.getLimitationPosition() == DBConnection.LIMITATION_AFTER_TABLE &&
- (offsetRecord > 0 || maxRecords > 0)) {
+ if (myConnection.getLimitationPosition()
+ == DBConnection.LIMITATION_AFTER_TABLE &&
+ (offsetRecord > 0 || maxRecords > 0)) {
// Insert limitation stub after table nomination
- String limitStub = JDBCUtil.getInstance().makeLimitationStub(myConnection,this);
+ String limitStub = JDBCUtil.getInstance().makeLimitationStub(
+ myConnection, this);
myStatement.append(" ");
myStatement.append(limitStub);
myStatement.append(" ");
@@ -1512,11 +1552,13 @@
buildWhereClauseBuffer(true, myStatement);
}
- if (myConnection.getLimitationPosition() == DBConnection.LIMITATION_AFTER_WHERE &&
- (offsetRecord > 0 || maxRecords > 0)) {
+ if (myConnection.getLimitationPosition()
+ == DBConnection.LIMITATION_AFTER_WHERE &&
+ (offsetRecord > 0 || maxRecords > 0)) {
// Insert limitation stub after table nomination
- String limitStub = JDBCUtil.getInstance().makeLimitationStub(myConnection,this);
+ String limitStub = JDBCUtil.getInstance().makeLimitationStub(
+ myConnection, this);
myStatement.append(" ");
myStatement.append(limitStub);
@@ -1535,10 +1577,12 @@
//If there's limitation syntax on, then the first record will be the
//maximum record.
if (retrieveCount < offsetRecord && offsetRecord > 0 &&
- myConnection.getLimitationPosition() == DBConnection.LIMITATION_DISABLED) {
+ myConnection.getLimitationPosition()
+ == DBConnection.LIMITATION_DISABLED) {
continue;
} else if (retrieveCount == offsetRecord && offsetRecord > 0 &&
- myConnection.getLimitationPosition() == DBConnection.LIMITATION_DISABLED) {
+ myConnection.getLimitationPosition()
+ == DBConnection.LIMITATION_DISABLED) {
recordCount = 0; //Reset count for counting for max records.
continue; //Skip this record... next one, we will start loading.
}
@@ -1559,43 +1603,49 @@
// eachObj = this.getJoinMetaData().getDataObjectsInOrder().iterator();
eachAlias = this.getJoinMetaData().getAliasesInOrder().iterator();
- while(eachAlias.hasNext()) {
- oneAlias = (String)eachAlias.next();
- oneObj = (JDBCDataObject)myObj.myDataObjects.get(oneAlias);
+ while (eachAlias.hasNext()) {
+ oneAlias = (String) eachAlias.next();
+ oneObj = (JDBCDataObject) myObj.myDataObjects.get(oneAlias);
JDBCObjectMetaData objectMetadata = oneObj.getJDBCMetaData();
- ArrayList retrievedFieldList = (ArrayList) rtrvListByTable.get(objectMetadata.getTargetSQLTable(oneObj.getDataContext()));
-
+ ArrayList retrievedFieldList = (ArrayList) rtrvListByTable.
+ get(objectMetadata.getTargetSQLTable(oneObj.
+ getDataContext()));
for (Iterator it = retrievedFieldList.iterator();
- it.hasNext();) {
+ it.hasNext(); ) {
fieldName = (String) it.next();
- DataFieldMetaData metaData = oneObj.getFieldMetaData(fieldName);
+ DataFieldMetaData metaData = oneObj.getFieldMetaData(
+ fieldName);
- if (!metaData.isVirtual() && !metaData.isBinaryObjectType()) {
+ if (!metaData.isVirtual()
+ && !metaData.isBinaryObjectType()) {
try {
oneFieldValue = myConnection.getString(i);
} catch (DBException de) {
- String myName = (thisClass + "searchAndRetrieve()");
- throw new DBException(myName +
- ":Error retrieving field '" +
- objectMetadata.getTargetSQLTable(oneObj.getDataContext()) +
- "." + fieldName + "'",
- de);
+ String myName = (thisClass
+ + "searchAndRetrieve()");
+ throw new DBException(myName +
+ ":Error retrieving field '" +
+ objectMetadata.getTargetSQLTable(oneObj.
+ getDataContext()) +
+ "." + fieldName + "'",
+ de);
}
i++;
if (log.isDebugEnabled()) {
log.debug("Setting " +
- objectMetadata.getTargetTable() + "." +
- fieldName + " to " + oneFieldValue);
+ objectMetadata.getTargetTable() + "." +
+ fieldName + " to " + oneFieldValue);
}
myObj.set(oneAlias + "." + fieldName, oneFieldValue);
}
}
- } /* each db object */
+ }
+ /* each db object */
myObj.setDataContext(getDataContext());
@@ -1633,7 +1683,7 @@
* @throws DBException upon data access error.
*/
public ArrayList searchAndRetrieveList() throws DBException {
- return searchAndRetrieveList(null);
+ return searchAndRetrieveList(null);
}
/**
@@ -1651,12 +1701,16 @@
* Modify by Yves Henri AMAIZO <amy_amaizo at compuserve.com>
* @since $DatabaseSchema $Date$
*/
- protected String selectFieldString(JDBCDataObject oneObj, String fieldName)
- throws DBException {
+ protected String selectFieldString(JDBCDataObject oneObj, String fieldName) throws
+ DBException {
checkInitialized();
return StringUtil.replaceStringOnce(oneObj.selectFieldString(fieldName),
- fieldName, oneObj.getJDBCMetaData().getTargetSQLTable(oneObj.getDataContext()) + "." + fieldName);
+ fieldName
+ , oneObj.getJDBCMetaData().
+ getTargetSQLTable(oneObj.
+ getDataContext()) + "." + fieldName);
}
+
/* selectFieldString(String) */
/**
@@ -1675,15 +1729,16 @@
connection = localConnection;
localConn = true;
} else {
- DBConnectionPool myPool = DBConnectionPool.getInstance(this.getMappedDataContext());
+ DBConnectionPool myPool = DBConnectionPool.getInstance(this.
+ getMappedDataContext());
connection = myPool.getConnection("Joined DataObject Update");
connection.setAutoCommit(false);
}
try {
- for(Iterator i = this.myDataObjects.values().iterator(); i.hasNext();) {
- JDBCDataObject oneObj = (JDBCDataObject)i.next();
+ for (Iterator i = this.myDataObjects.values().iterator(); i.hasNext(); ) {
+ JDBCDataObject oneObj = (JDBCDataObject) i.next();
oneObj.setConnection(connection, this.getDataContext());
this.addOrUpdate(oneObj);
}
@@ -1694,21 +1749,21 @@
}
} catch (DBException ex) {
- log.error("Error executing SQL statement",ex);
+ log.error("Error executing SQL statement", ex);
// if (localConnection == null && connection != null) {
- if (!localConn) {
- connection.rollback();
- connection.release();
+ if (!localConn) {
+ connection.rollback();
+ connection.release();
} else {
throw ex;
}
} catch (Throwable t) {
- log.error("Error updating join",t);
+ log.error("Error updating join", t);
if (!localConn) {
connection.rollback();
connection.release();
}
- throw new DataException("Error updating join",t);
+ throw new DataException("Error updating join", t);
} finally {
// if (localConnection == null && connection != null) {
// if (!localConn) {
@@ -1718,8 +1773,8 @@
//Reset the local connections so they don't behave like they're in
//a transaction after this.
- for(Iterator i = this.myDataObjects.values().iterator(); i.hasNext();) {
- JDBCDataObject oneObj = (JDBCDataObject)i.next();
+ for (Iterator i = this.myDataObjects.values().iterator(); i.hasNext(); ) {
+ JDBCDataObject oneObj = (JDBCDataObject) i.next();
oneObj.setConnection(null, this.getDataContext());
}
@@ -1732,33 +1787,37 @@
* @throws DBException
* @param testObject the JDBCObject to add or update.
*/
- public synchronized void addOrUpdate(JDBCDataObject testObject)
- throws DBException {
- JDBCDataObject searchObj = (JDBCDataObject)DataObjectFactory.createDataObject(testObject
- .getClass(),this.getDataContext(),this.getRequestingUid());
+ public synchronized void addOrUpdate(JDBCDataObject testObject) throws
+ DBException {
+ JDBCDataObject searchObj = (JDBCDataObject) DataObjectFactory.
+ createDataObject(testObject
+ .getClass(), this.getDataContext(), this.getRequestingUid());
searchObj.setDataContext(getDataContext());
String oneFieldName = null;
- for (Iterator i = searchObj.getMetaData().getKeyFieldListArray().iterator(); i.hasNext();) {
+ for (Iterator i = searchObj.getMetaData().getKeyFieldListArray().
+ iterator(); i.hasNext(); ) {
oneFieldName = (String) i.next();
searchObj.set(oneFieldName, testObject.getField(oneFieldName));
}
- if (searchObj.find()) {
+ if (searchObj.find()) {
- // special case: if there are no fields besides key
- // fields, then do nothing since key fields never update this way
- if (testObject.getMetaData().getKeyFieldListArray().size() == testObject.getMetaData().getFieldListArray().size()) {
- // do nothing
- // @todo add logic for virtual fields
- } else {
- testObject.getExecutor().update(testObject,true);
- }
+ // special case: if there are no fields besides key
+ // fields, then do nothing since key fields never update this way
+ if (testObject.getMetaData().getKeyFieldListArray().size()
+ == testObject.getMetaData().getFieldListArray().size()) {
+ // do nothing
+ // @todo add logic for virtual fields
} else {
- testObject.add();
+ testObject.getExecutor().update(testObject, true);
}
- } /* addOrUpdate() */
+ } else {
+ testObject.add();
+ }
+ }
+ /* addOrUpdate() */
/**
* Retrieve the JDBCDataObject as defined by the 'short name'
@@ -1766,8 +1825,8 @@
* @return JDBCDataObject
* @throws DataException upon error
*/
- private JDBCDataObject getByShortName(String shortName)
- throws DataException {
+ private JDBCDataObject getByShortName(String shortName) throws
+ DataException {
StringUtil.assertNotBlank(shortName, "Short name may not be blank");
JDBCDataObject oneObj = (JDBCDataObject) myDataObjects.get(shortName);
@@ -1780,7 +1839,6 @@
}
-
/**
* Builds a 'FROM' clause using ANSI 'JOIN' syntax.
*
@@ -1800,8 +1858,8 @@
* @since $DatabaseSchema $Date$
*/
private String buildJoin(String leftShortName, String leftColumn,
- String rightShortName, String rightColumn, int joinType)
- throws DBException {
+ String rightShortName, String rightColumn
+ , int joinType) throws DBException {
checkInitialized();
JDBCDataObject leftDBObj = getByShortName(leftShortName);
JDBCDataObject rightDBObj = getByShortName(rightShortName);
@@ -1821,51 +1879,55 @@
try {
switch (joinType) {
- case INNER_JOIN:
- buffer.append(" INNER JOIN ");
- break;
+ case INNER_JOIN:
+ buffer.append(" INNER JOIN ");
+ break;
- case RIGHT_JOIN:
- buffer.append(" RIGHT JOIN ");
- break;
+ case RIGHT_JOIN:
+ buffer.append(" RIGHT JOIN ");
+ break;
- case LEFT_JOIN:
- buffer.append(" LEFT JOIN ");
- break;
+ case LEFT_JOIN:
+ buffer.append(" LEFT JOIN ");
+ break;
- case UNSPECIFIED_JOIN:
- throw new IllegalArgumentException("BuildJoin does not support Unspecified joins");
+ case UNSPECIFIED_JOIN:
+ throw new IllegalArgumentException(
+ "BuildJoin does not support Unspecified joins");
}
- buffer.append(rightDBObj.getJDBCMetaData().getTargetSQLTable(rightDBObj.getDataContext()));
- buffer.append(" ON ");
- buffer.append(leftDBObj.getJDBCMetaData().getTargetSQLTable(leftDBObj.getDataContext()));
- buffer.append(".");
- buffer.append(leftColumn);
- buffer.append(" = ");
- buffer.append(rightDBObj.getJDBCMetaData().getTargetSQLTable(rightDBObj.getDataContext()));
- buffer.append(".");
- buffer.append(rightColumn);
- buffer.append(" ");
- boolean addAnd = false;
-
- for (int i=0; i<leftCols.size(); i++) {
- if (addAnd) {
- buffer.append(" AND ");
- }
- buffer.append(leftDBObj.getJDBCMetaData().getTargetTable());
- buffer.append(".");
- buffer.append((String)leftCols.get(i));
- buffer.append(" = ");
- buffer.append(rightDBObj.getJDBCMetaData().getTargetTable());
- buffer.append(".");
- buffer.append((String)rightCols.get(i));
- addAnd = true;
- }
- buffer.append(") ");
+ buffer.append(rightDBObj.getJDBCMetaData().getTargetSQLTable(
+ rightDBObj.getDataContext()));
+ buffer.append(" ON ");
+ buffer.append(leftDBObj.getJDBCMetaData().getTargetSQLTable(
+ leftDBObj.getDataContext()));
+ buffer.append(".");
+ buffer.append(leftColumn);
+ buffer.append(" = ");
+ buffer.append(rightDBObj.getJDBCMetaData().getTargetSQLTable(
+ rightDBObj.getDataContext()));
+ buffer.append(".");
+ buffer.append(rightColumn);
+ buffer.append(" ");
+ boolean addAnd = false;
- return buffer.toString();
+ for (int i = 0; i < leftCols.size(); i++) {
+ if (addAnd) {
+ buffer.append(" AND ");
+ }
+ buffer.append(leftDBObj.getJDBCMetaData().getTargetTable());
+ buffer.append(".");
+ buffer.append((String) leftCols.get(i));
+ buffer.append(" = ");
+ buffer.append(rightDBObj.getJDBCMetaData().getTargetTable());
+ buffer.append(".");
+ buffer.append((String) rightCols.get(i));
+ addAnd = true;
+ }
+ buffer.append(") ");
+
+ return buffer.toString();
} catch (DBException ex) {
throw new DBException("Error building join string", ex);
} finally {
@@ -1906,7 +1968,7 @@
public void setRequestingUid(int newUid) {
this.uid = newUid;
- for (Iterator i = this.myDataObjects.keySet().iterator(); i.hasNext();) {
+ for (Iterator i = this.myDataObjects.keySet().iterator(); i.hasNext(); ) {
String key = (String) i.next();
@@ -1926,18 +1988,20 @@
* @throws com.jcorporate.expresso.core.db.DBException
*/
public void isAllowed(String requestedFunction) throws SecurityException,
- com.jcorporate.expresso.core.db.DBException {
+ com.jcorporate.expresso.core.db.DBException {
checkInitialized();
//First check for any values from the permissions map
//If such operations are flat not allowed for this join, then
//we return immediately
- Boolean override = (Boolean)getJoinMetaData().getPermissions().get(requestedFunction);
+ Boolean override = (Boolean) getJoinMetaData().getPermissions().get(
+ requestedFunction);
if (override != null && override.booleanValue() == false) {
- throw new SecurityException("Method: " + requestedFunction + " not allowed");
+ throw new SecurityException("Method: " + requestedFunction
+ + " not allowed");
}
- for (Iterator i = this.myDataObjects.keySet().iterator(); i.hasNext();) {
+ for (Iterator i = this.myDataObjects.keySet().iterator(); i.hasNext(); ) {
String key = (String) i.next();
DataObject value = (DataObject) myDataObjects.get(key);
@@ -1945,12 +2009,13 @@
((Securable) value).isAllowed(requestedFunction);
} else {
String insecureAllowed = Setup
- .getValue(this.getDataContext()
- , com.jcorporate.expresso.core.ExpressoSchema.class.getName(),
- "insecureDBMaint");
+ .getValue(this.getDataContext()
+ , com.jcorporate.expresso.core.ExpressoSchema.class.getName(),
+ "insecureDBMaint");
if (!"y".equalsIgnoreCase(insecureAllowed)) {
- throw new SecurityException("Insecured Database Object Access Not Allowed");
+ throw new SecurityException(
+ "Insecured Database Object Access Not Allowed");
}
}
}
@@ -1964,7 +2029,7 @@
private void checkInitialized() {
if (!isInitialized()) {
throw new IllegalStateException("Defineable DataObject must " +
- "be initialized with setDefinition() prior to use");
+ "be initialized with setDefinition() prior to use");
}
}
@@ -1999,20 +2064,20 @@
List aliases = metadata.getAliasesInOrder();
Iterator eachAlias = aliases.iterator();
- String lastAlias = (String)eachAlias.next();
+ String lastAlias = (String) eachAlias.next();
if (aliases.size() < 2) {
- throw new IllegalStateException("Must have at least two tables to perform a join");
+ throw new IllegalStateException(
+ "Must have at least two tables to perform a join");
}
-
//
//We must list tables in implicit joins first. So this
//loop sorts the implicitly defined joins and the unspecified joins.
//
while (eachAlias.hasNext()) {
- String oneAlias = (String)eachAlias.next();
+ String oneAlias = (String) eachAlias.next();
JoinedDataObjectMetaData.Relation oneRelation =
- metadata.getRelation(lastAlias,oneAlias);
+ metadata.getRelation(lastAlias, oneAlias);
if (oneRelation == null) {
//ok, we have an issue because we've found no relation to
@@ -2020,9 +2085,9 @@
//find the unspecified join. Throw an execption otherwise.
Map m = metadata.getAllRelations();
- for (Iterator j = m.values().iterator(); j.hasNext();) {
+ for (Iterator j = m.values().iterator(); j.hasNext(); ) {
JoinedDataObjectMetaData.Relation testRelation =
- (JoinedDataObjectMetaData.Relation)j.next();
+ (JoinedDataObjectMetaData.Relation) j.next();
if (testRelation != null) {
if (oneAlias.equals(testRelation.getForeignAlias())) {
@@ -2033,19 +2098,23 @@
}
if (oneRelation == null) {
- throw new DataException("Unable to find any way to relate alias: "
- + oneAlias + " to the rest of the join.");
+ throw new DataException(
+ "Unable to find any way to relate alias: "
+ + oneAlias + " to the rest of the join.");
}
- if (oneRelation.getJoinType() != JoinedDataObject.UNSPECIFIED_JOIN) {
- throw new DataException("Alias " + oneAlias + " currently has to be "+
- "joined to the rest of the query through an unspecified"+
- " join type rather than an ANSI join");
+ if (oneRelation.getJoinType()
+ != JoinedDataObject.UNSPECIFIED_JOIN) {
+ throw new DataException("Alias " + oneAlias
+ + " currently has to be " +
+ "joined to the rest of the query through an unspecified" +
+ " join type rather than an ANSI join");
}
}
- if (oneRelation.getJoinType() == JoinedDataObject.UNSPECIFIED_JOIN) {
+ if (oneRelation.getJoinType()
+ == JoinedDataObject.UNSPECIFIED_JOIN) {
implicitRelations.add(oneRelation);
} else {
definedSet.add(oneRelation.getLocalAlias());
@@ -2063,20 +2132,22 @@
//We must list tables in implicit joins first. So we add all tables
//listed without a specified join type first.
//
- for (Iterator i = implicitRelations.iterator(); i.hasNext();) {
+ for (Iterator i = implicitRelations.iterator(); i.hasNext(); ) {
if (needComma) {
fsb.append(", ");
}
-
- JoinedDataObjectMetaData.Relation oneRelation = (JoinedDataObjectMetaData.Relation)i.next();
+ JoinedDataObjectMetaData.Relation oneRelation = (
+ JoinedDataObjectMetaData.Relation) i.next();
String leftAlias = oneRelation.getLocalAlias();
String rightAlias = oneRelation.getForeignAlias();
- if ( ! definedSet.contains(leftAlias)) {
+ if (!definedSet.contains(leftAlias)) {
definedSet.add(leftAlias);
- JDBCDataObject oneObj = (JDBCDataObject)this.myDataObjects.get(leftAlias);
- fsb.append(oneObj.getJDBCMetaData().getTargetSQLTable(oneObj.getDataContext()));
+ JDBCDataObject oneObj = (JDBCDataObject)this.myDataObjects.
+ get(leftAlias);
+ fsb.append(oneObj.getJDBCMetaData().getTargetSQLTable(
+ oneObj.getDataContext()));
needComma = true;
if (!definedSet.contains(rightAlias)) {
@@ -2084,9 +2155,10 @@
}
}
- if (! definedSet.contains(rightAlias)) {
+ if (!definedSet.contains(rightAlias)) {
definedSet.add(rightAlias);
- JDBCDataObject oneObj = (JDBCDataObject)this.myDataObjects.get(rightAlias);
+ JDBCDataObject oneObj = (JDBCDataObject)this.myDataObjects.
+ get(rightAlias);
fsb.append(oneObj.getJDBCMetaData().getTargetTable());
needComma = true;
}
@@ -2097,31 +2169,37 @@
//Now we add all explicitly defined joins to the select list.
//
boolean firstJoin = true;
- for (Iterator i = explicitRelations.iterator(); i.hasNext();) {
+ for (Iterator i = explicitRelations.iterator(); i.hasNext(); ) {
if (needComma) {
fsb.append(", ");
}
needComma = false;
- JoinedDataObjectMetaData.Relation relation =(JoinedDataObjectMetaData.Relation)i.next();
+ JoinedDataObjectMetaData.Relation relation = (
+ JoinedDataObjectMetaData.Relation) i.next();
if (firstJoin) {
- JDBCDataObject oneObj = (JDBCDataObject)this.myDataObjects.get(relation.getLocalAlias());
- fsb.append(oneObj.getJDBCMetaData().getTargetSQLTable(oneObj.getDataContext()));
+ JDBCDataObject oneObj = (JDBCDataObject)this.myDataObjects.
+ get(relation.getLocalAlias());
+ fsb.append(oneObj.getJDBCMetaData().getTargetSQLTable(
+ oneObj.getDataContext()));
firstJoin = false;
}
- fsb.append(this.buildJoin(relation.getLocalAlias(), relation.getLocalField(),
- relation.getForeignAlias(),relation.getForeignField(), relation.getJoinType()));
+ fsb.append(this.buildJoin(relation.getLocalAlias()
+ , relation.getLocalField(),
+ relation.getForeignAlias()
+ , relation.getForeignField()
+ , relation.getJoinType()));
}
return fsb.toString();
} catch (DBException dbe) {
- log.error("Error building 'FROM' clause",dbe);
- throw new DataException("Error building 'FROM' clause",dbe);
+ log.error("Error building 'FROM' clause", dbe);
+ throw new DataException("Error building 'FROM' clause", dbe);
} catch (Exception ex) {
- log.error("Error building 'FROM' clause",ex);
- throw new DataException("Error building 'FROM' clause",ex);
+ log.error("Error building 'FROM' clause", ex);
+ throw new DataException("Error building 'FROM' clause", ex);
} finally {
fsb.release();
}
@@ -2141,27 +2219,29 @@
boolean needComma = false;
FastStringBuffer fsb = FastStringBuffer.getInstance();
try {
- for (Iterator i = this.getMetaData().getFieldListArray().iterator(); i.hasNext();) {
+ for (Iterator i = this.getMetaData().getFieldListArray().iterator();
+ i.hasNext(); ) {
if (needComma) {
fsb.append(", ");
}
- String fullFieldName = (String)i.next();
- String location[] = this.getJoinMetaData().getObjectAndField(fullFieldName);
- JDBCDataObject obj = (JDBCDataObject)this.myDataObjects.get(location[0]);
+ String fullFieldName = (String) i.next();
+ String location[] = this.getJoinMetaData().getObjectAndField(
+ fullFieldName);
+ JDBCDataObject obj = (JDBCDataObject)this.myDataObjects.get(
+ location[0]);
DataFieldMetaData metadata = obj.getFieldMetaData(location[1]);
if (metadata.isLongObjectType() || metadata.isVirtual()) {
continue;
}
-
- fsb.append(obj.getJDBCMetaData().getTargetSQLTable(obj.getDataContext()));
+ fsb.append(obj.getJDBCMetaData().getTargetSQLTable(obj.
+ getDataContext()));
fsb.append(".");
fsb.append(location[1]);
needComma = true;
}
-
return fsb.toString();
} finally {
fsb.release();
@@ -2184,30 +2264,36 @@
FastStringBuffer sqlCommand = FastStringBuffer.getInstance();
try {
DataFieldMetaData oneField = null;
- JoinedDataObjectMetaData metadata = this.getJoinMetaData();
- for (Iterator i = this.getMetaData().getFieldListArray().iterator(); i.hasNext();) {
+ JoinedDataObjectMetaData metadata = this.getJoinMetaData();
+ for (Iterator i = this.getMetaData().getFieldListArray().iterator();
+ i.hasNext(); ) {
String oneFieldName = (String) i.next();
oneField = this.getFieldMetaData(oneFieldName);
/* We skip any key fields in the update part (not allowed to */
/* update them). Also skip any virtual fields */
if ((!oneField.isKey()) && (!oneField.isVirtual()) &&
- (!oneField.isAutoIncremented()) && (!oneField.isBinaryObjectType())) {
-
+ (!oneField.isAutoIncremented())
+ && (!oneField.isBinaryObjectType())) {
try {
- this.checkField(oneFieldName, this.getDataField(oneFieldName).asString());
- }
- catch (DBException ex) {
+ this.checkField(oneFieldName
+ , this.getDataField(oneFieldName).
+ asString());
+ } catch (DBException ex) {
log.error("Error validating field " + oneFieldName, ex);
- throw new DataException("Error validating field " + oneFieldName, ex);
+ throw new DataException("Error validating field "
+ + oneFieldName, ex);
}
if (needComma) {
sqlCommand.append(", ");
}
String location[] = metadata.getObjectAndField(oneFieldName);
- sqlCommand.append( ((JDBCDataObject)this.myDataObjects.get(location[0])).getJDBCMetaData().getTargetSQLTable(((JDBCDataObject)this.myDataObjects.get(location[0])).getDataContext()));
+ sqlCommand.append(((JDBCDataObject)this.myDataObjects.get(
+ location[0])).getJDBCMetaData().getTargetSQLTable(((
+ JDBCDataObject)this.myDataObjects.get(location[0])).
+ getDataContext()));
sqlCommand.append(".");
sqlCommand.append(oneField.getName());
sqlCommand.append(" = ? ");
@@ -2217,7 +2303,7 @@
return sqlCommand.toString();
} catch (Throwable t) {
log.error("Error building update field string", t);
- throw new DataException("Error building update field string",t);
+ throw new DataException("Error building update field string", t);
} finally {
sqlCommand.release();
}
@@ -2238,26 +2324,28 @@
return "";
}
- StringTokenizer stok = new StringTokenizer(sortKeys,"|");
+ StringTokenizer stok = new StringTokenizer(sortKeys, "|");
if (!stok.hasMoreTokens()) {
return "";
}
-
FastStringBuffer fsb = FastStringBuffer.getInstance();
try {
fsb.append(" ORDER BY ");
boolean needComma = false;
while (stok.hasMoreTokens()) {
String fieldName = stok.nextToken();
- String location[] = this.getJoinMetaData().getObjectAndField(fieldName);
- JDBCDataObject obj = (JDBCDataObject)this.myDataObjects.get(location[0]);
+ String location[] = this.getJoinMetaData().getObjectAndField(
+ fieldName);
+ JDBCDataObject obj = (JDBCDataObject)this.myDataObjects.get(
+ location[0]);
if (needComma) {
fsb.append(", ");
}
- fsb.append(obj.getJDBCMetaData().getTargetSQLTable(obj.getDataContext()));
+ fsb.append(obj.getJDBCMetaData().getTargetSQLTable(obj.
+ getDataContext()));
fsb.append(".");
fsb.append(location[1]);
needComma = true;
@@ -2283,8 +2371,9 @@
* Modify by Yves Henri AMAIZO <amy_amaizo at compuserve.com>
* @since $DatabaseSchema $Date$
*/
- protected String buildWhereClauseBuffer(boolean useAllFields, FastStringBuffer myStatement)
- throws DBException {
+ protected String buildWhereClauseBuffer(boolean useAllFields
+ , FastStringBuffer myStatement) throws
+ DBException {
/* list of field names (with table names prefixed) */
List fields = new ArrayList();
@@ -2296,41 +2385,55 @@
if (useAllFields) {
// oneObj = (JDBCDataObject) eachObj.next();
- for (Iterator j = this.getJoinMetaData().getAliasesInOrder().iterator(); j.hasNext();) {
- String oneAlias = (String)j.next();
+ for (Iterator j = this.getJoinMetaData().getAliasesInOrder().
+ iterator(); j.hasNext(); ) {
+ String oneAlias = (String) j.next();
oneObj = (JDBCDataObject)this.myDataObjects.get(oneAlias);
- byTableName.put(oneObj.getJDBCMetaData().getTargetSQLTable(oneObj.getDataContext()), oneObj);
+ byTableName.put(oneObj.getJDBCMetaData().getTargetSQLTable(
+ oneObj.getDataContext()), oneObj);
- for (Iterator i = oneObj.getMetaData().getFieldListArray().iterator(); i.hasNext();) {
+ for (Iterator i = oneObj.getMetaData().getFieldListArray().
+ iterator(); i.hasNext(); ) {
fieldName = (String) i.next();
- DataFieldMetaData fieldMetaData = oneObj.getFieldMetaData(fieldName);
- if (!fieldMetaData.isVirtual() && !fieldMetaData.isLongObjectType()) {
- fields.add(oneObj.getJDBCMetaData().getTargetSQLTable(oneObj.getDataContext()) + "." +
- fieldName);
+ DataFieldMetaData fieldMetaData = oneObj.getFieldMetaData(
+ fieldName);
+ if (!fieldMetaData.isVirtual()
+ && !fieldMetaData.isLongObjectType()) {
+ fields.add(oneObj.getJDBCMetaData().getTargetSQLTable(
+ oneObj.getDataContext()) + "." +
+ fieldName);
}
- } /* for each field */
+ }
+ /* for each field */
}
} else { /* for each db object */
for (Iterator eachAlias = metadata.getAliasesInOrder().iterator();
- eachAlias.hasNext();) {
- String oneAlias = (String)eachAlias.next();
+ eachAlias.hasNext(); ) {
+ String oneAlias = (String) eachAlias.next();
oneObj = (JDBCDataObject)this.myDataObjects.get(oneAlias);
- byTableName.put(oneObj.getJDBCMetaData().getTargetSQLTable(oneObj.getDataContext()), oneObj);
+ byTableName.put(oneObj.getJDBCMetaData().getTargetSQLTable(
+ oneObj.getDataContext()), oneObj);
- for (Iterator i = oneObj.getMetaData().getKeyFieldListArray().iterator();
- i.hasNext();) {
+ for (Iterator i = oneObj.getMetaData().getKeyFieldListArray().
+ iterator();
+ i.hasNext(); ) {
fieldName = (String) i.next();
- DataFieldMetaData fieldMetaData = oneObj.getFieldMetaData(fieldName);
- if (!fieldMetaData.isVirtual() && !fieldMetaData.isBinaryObjectType()) {
- fields.add(oneObj.getJDBCMetaData().getTargetSQLTable(oneObj.getDataContext()) + "." +
- fieldName);
+ DataFieldMetaData fieldMetaData = oneObj.getFieldMetaData(
+ fieldName);
+ if (!fieldMetaData.isVirtual()
+ && !fieldMetaData.isBinaryObjectType()) {
+ fields.add(oneObj.getJDBCMetaData().getTargetSQLTable(
+ oneObj.getDataContext()) + "." +
+ fieldName);
}
- } /* for each field */
+ }
+ /* for each field */
- } /* for each db object */
+ }
+ /* for each db object */
}
@@ -2353,7 +2456,7 @@
FieldRangeParser parser = FieldRangeParser.getInstance();
for (Iterator fieldsToUse = fields.iterator();
- fieldsToUse.hasNext();) {
+ fieldsToUse.hasNext(); ) {
oneFullName = (String) fieldsToUse.next();
StringTokenizer stk = new StringTokenizer(oneFullName, ".");
@@ -2373,7 +2476,8 @@
rangeString = parser.denotesRange(oneFieldValue);
if (rangeString != null && rangeString.length() > 0) {
- if (!parser.isValidRange(oneDataField.getFieldMetaData(),oneFieldValue)) {
+ if (!parser.isValidRange(oneDataField.getFieldMetaData()
+ , oneFieldValue)) {
throw new DataException("Invalid range: " + rangeString);
}
}
@@ -2381,7 +2485,8 @@
oneFieldValue.trim().equalsIgnoreCase("is not null")) {
;
} else {
- oneFieldValue = oneObj.quoteIfNeeded(oneFieldName, rangeString);
+ oneFieldValue = oneObj.quoteIfNeeded(oneFieldName
+ , rangeString);
}
}
@@ -2392,31 +2497,39 @@
if (!skipField) {
// check to see if the field value is valid (protects agains sql injection)
try {
- String unalteredFieldValue = oneObj.getDataField(oneFieldName).asString();
+ String unalteredFieldValue = oneObj.getDataField(
+ oneFieldName).asString();
if (rangeString != null) {
- boolean valid = parser.isValidRange(oneObj.getFieldMetaData(oneFieldName), unalteredFieldValue);
+ boolean valid = parser.isValidRange(oneObj.
+ getFieldMetaData(oneFieldName), unalteredFieldValue);
if (!valid) {
- throw new DataException("Invalid field range value: " + unalteredFieldValue);
+ throw new DataException(
+ "Invalid field range value: "
+ + unalteredFieldValue);
}
- }
- else if (sJdbcUtil.containsWildCards(oneObj, oneFieldValue)) {
- Object origValue = oneObj.getDataField(oneFieldName).getValue();
+ } else if (sJdbcUtil.containsWildCards(oneObj
+ , oneFieldValue)) {
+ Object origValue = oneObj.getDataField(oneFieldName).
+ getValue();
String[] wildcards = null;
- wildcards = (String []) oneObj.getConnectionPool().getWildCardsList().toArray(new String[0]);
+ wildcards = (String[]) oneObj.getConnectionPool().
+ getWildCardsList().toArray(new String[0]);
Filter filter = new Filter(wildcards, wildcards);
- String valueWithoutWildCards = filter.stripFilter(unalteredFieldValue);
+ String valueWithoutWildCards = filter.stripFilter(
+ unalteredFieldValue);
// if the value without wildcards is empty, then we know the field is valid
if (!valueWithoutWildCards.equals("")) {
- oneObj.getDataField(oneFieldName).setValue(valueWithoutWildCards);
+ oneObj.getDataField(oneFieldName).setValue(
+ valueWithoutWildCards);
oneObj.getDataField(oneFieldName).checkValue();
- oneObj.getDataField(oneFieldName).setValue(origValue);
+ oneObj.getDataField(oneFieldName).setValue(
+ origValue);
}
- }
- else
+ } else {
oneObj.getDataField(oneFieldName).checkValue();
- }
- catch (DBException ex) {
+ }
+ } catch (DBException ex) {
if (ex instanceof DataException) {
throw ((DataException) ex);
} else {
@@ -2431,48 +2544,58 @@
if (addAnd) {
myStatement.append(" AND ");
}
- if (sJdbcUtil.containsWildCards(oneObj,oneFieldValue)) {
+ if (sJdbcUtil.containsWildCards(oneObj, oneFieldValue)) {
if (caseSensitiveQuery) {
- myStatement.append(objMetadata.getTargetSQLTable(oneObj.getDataContext()) + "." +
- oneFieldName);
+ myStatement.append(objMetadata.getTargetSQLTable(oneObj.
+ getDataContext()) + "." +
+ oneFieldName);
myStatement.append(" LIKE ");
myStatement.append(oneFieldValue);
} else {
myStatement.append("UPPER(");
- myStatement.append(objMetadata.getTargetSQLTable(oneObj.getDataContext()) + "." +
- oneFieldName);
+ myStatement.append(objMetadata.getTargetSQLTable(oneObj.
+ getDataContext()) + "." +
+ oneFieldName);
myStatement.append(") LIKE ");
myStatement.append(oneFieldValue.toUpperCase());
}
} else if (rangeString != null) {
- myStatement.append(objMetadata.getTargetSQLTable(oneObj.getDataContext()) + "." +
- oneFieldName);
+ myStatement.append(objMetadata.getTargetSQLTable(oneObj.
+ getDataContext()) + "." +
+ oneFieldName);
myStatement.append(" " + rangeString + " ");
myStatement.append(oneFieldValue);
} else {
if ((oneFieldValue.trim().equalsIgnoreCase("is null")) ||
(oneFieldValue.trim().equalsIgnoreCase("is not null"))) {
- myStatement.append(objMetadata.getTargetSQLTable(oneObj.getDataContext()) + "." +
- oneFieldName);
+ myStatement.append(objMetadata.getTargetSQLTable(oneObj.
+ getDataContext()) + "." +
+ oneFieldName);
myStatement.append(" = ");
myStatement.append(oneFieldValue);
} else {
if (caseSensitiveQuery) {
- myStatement.append(objMetadata.getTargetSQLTable(oneObj.getDataContext()) + "." +
- oneFieldName);
+ myStatement.append(objMetadata.getTargetSQLTable(
+ oneObj.getDataContext()) + "." +
+ oneFieldName);
myStatement.append(" = ");
myStatement.append(oneFieldValue);
} else {
- DataFieldMetaData dfmd = oneDataField.getFieldMetaData();
+ DataFieldMetaData dfmd = oneDataField.
+ getFieldMetaData();
if (dfmd.isQuotedTextType()) {
myStatement.append("UPPER(");
- myStatement.append(objMetadata.getTargetSQLTable(oneObj.getDataContext()) + "." +
- oneFieldName);
+ myStatement.append(objMetadata.
+ getTargetSQLTable(oneObj.getDataContext())
+ + "." +
+ oneFieldName);
myStatement.append(") = ");
myStatement.append(oneFieldValue.toUpperCase());
} else {
- myStatement.append(objMetadata.getTargetSQLTable(oneObj.getDataContext()) + "." +
- oneFieldName);
+ myStatement.append(objMetadata.
+ getTargetSQLTable(oneObj.getDataContext())
+ + "." +
+ oneFieldName);
myStatement.append(" = ");
myStatement.append(oneFieldValue);
}
@@ -2501,7 +2624,8 @@
//
FastStringBuffer fieldDefinitions = FastStringBuffer.getInstance();
try {
- for (Iterator e = metadata.getSQLRelationList().iterator(); e.hasNext();) {
+ for (Iterator e = metadata.getSQLRelationList().iterator();
+ e.hasNext(); ) {
oneRelation = (String) e.next();
if (needAnd) {
@@ -2540,10 +2664,10 @@
* Replaces alias names in the customWhereClause with their correct
* table names
* @param myStatement the preallocated buffer to append to
- * @return the formatted customWhereClause
+ * @throws DBException
*/
- private void formatCustomWhereClause(FastStringBuffer myStatement)
- throws DBException {
+ private void formatCustomWhereClause(FastStringBuffer myStatement) throws
+ DBException {
String customWhere = " " + this.customWhereClause;
@@ -2552,25 +2676,32 @@
} else {
myStatement.append(" WHERE ");
}
- for (Iterator eachAlias = this.getJoinMetaData().getAliasesInOrder().iterator();
- eachAlias.hasNext();) {
- String oneAlias = (String)eachAlias.next();
- JDBCDataObject oneObj = (JDBCDataObject)this.myDataObjects.get(oneAlias);
+ for (Iterator eachAlias = this.getJoinMetaData().getAliasesInOrder().
+ iterator();
+ eachAlias.hasNext(); ) {
+ String oneAlias = (String) eachAlias.next();
+ JDBCDataObject oneObj = (JDBCDataObject)this.myDataObjects.get(
+ oneAlias);
// replace the alias names in the custom where clause with the
// table names. Using the following method ensures that if any
// alias is a substring of another, we don't hit problems
customWhere =
StringUtil.replaceAll(customWhere, " " + oneAlias + ".",
- " " + oneObj.getJDBCMetaData().getTargetTable() + ".");
- if (customWhere.indexOf("("+ oneAlias + ".") != -1) {
+ " "
+ + oneObj.getJDBCMetaData().getTargetTable()
+ + ".");
+ if (customWhere.indexOf("(" + oneAlias + ".") != -1) {
customWhere =
StringUtil.replaceAll(customWhere, "(" + oneAlias + ".",
- "(" + oneObj.getJDBCMetaData().getTargetTable() + ".");
+ "("
+ + oneObj.getJDBCMetaData().getTargetTable()
+ + ".");
}
}
this.setCustomWhereClause(null, false);
myStatement.append(customWhere.trim());
}
+
/**
* Retrieves a nested dataobject based upon the public field name that
* the DataObject publishes. For example, in JoinedDataObjects, the field
@@ -2596,8 +2727,9 @@
*/
public DataObject[] getAllNested() {
DataObject[] returnValue = new DataObject[this.myDataObjects.size()];
- return (DataObject[]) this.myDataObjects.values().toArray(returnValue);
- } /* buildWhereClause(boolean) */
+ return (DataObject[])this.myDataObjects.values().toArray(returnValue);
+ }
+ /* buildWhereClause(boolean) */
/**
@@ -2627,6 +2759,7 @@
public String getField(String fieldName) throws DBException {
return this.getDataField(fieldName).asString();
}
+
/**
* Set a specific DB connection for use with this JoinedDataObject. If you do not set
* a connection, the db object will request it's own connection from the
@@ -2637,10 +2770,11 @@
* @param newConnection The new DBConnection object to be used by this DB Object
* @throws DBException
*/
- public synchronized void setConnection(DBConnection newConnection)
- throws DBException {
+ public synchronized void setConnection(DBConnection newConnection) throws
+ DBException {
setConnection(newConnection, newConnection.getDataContext());
- } /* setConnection(DBConnection) */
+ }
+ /* setConnection(DBConnection) */
/**
* <p>
@@ -2661,40 +2795,54 @@
* @throws DBException
*/
public synchronized void setConnection(DBConnection newConnection,
- String setupTablesContext) throws DBException {
+ String setupTablesContext) throws
+ DBException {
localConnection = newConnection;
this.setDataContext(setupTablesContext);
}
- /**
- * Set a regular expression "mask" for this base data object that specifies it's
- * valid values. The mask should already be compiled by the regular
- * expression compiler
- * @param newMask The compiled regular expression mask
- *
- */
- public void setGlobalMask(Pattern newMask) {
- this.setGlobalMask(newMask);
- }
-
- /**
- * Get the compiled regular expression for this base data object.
- * @return the precompiled regular expression mask
- */
- public Pattern getGlobalMask() {
- return this.getGlobalMask();
- }
+ /**
+ * Set a regular expression "mask" for this base data object that specifies it's
+ * valid values. The mask should already be compiled by the regular
+ * expression compiler
+ * @param newMask The compiled regular expression mask
+ *
+ */
+ public void setGlobalMask(Pattern newMask) {
+ this.setGlobalMask(newMask);
+ }
+ /**
+ * Get the compiled regular expression for this base data object.
+ * @return the precompiled regular expression mask
+ */
+ public Pattern getGlobalMask() {
+ return this.getGlobalMask();
+ }
- /**
- * Return boolean if the data object has a mask set
- *
- * @return True if the data object mask is set, else false if it is not
- */
- public boolean isGlobalMasked() {
- return this.isGlobalMasked();
- } /* isMasked() */
+ /**
+ * Return boolean if the data object has a mask set
+ *
+ * @return True if the data object mask is set, else false if it is not
+ */
+ public boolean isGlobalMasked() {
+ return this.isGlobalMasked();
+ }
+ /* isGlobalMasked() */
+
+ /**
+ * {@inheritDoc}
+ * @throws DataException upon setField error.
+ */
+ public void setFieldsWithDefaults() throws DataException {
+ for (Iterator j = this.getJoinMetaData().getAliasesInOrder().
+ iterator(); j.hasNext(); ) {
+ String oneAlias = (String) j.next();
+ JDBCDataObject oneObj = (JDBCDataObject)this.myDataObjects.get(oneAlias);
+ oneObj.setFieldsWithDefaults();
+ }
+ }
}
Index: DBObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java,v
retrieving revision 1.224
retrieving revision 1.225
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java -u -r1.224 -r1.225
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/dbobj/DBObject.java
@@ -84,14 +84,11 @@
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
-
import org.apache.log4j.Logger;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.PatternMatcher;
import org.apache.oro.text.regex.Perl5Matcher;
-
import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-
import com.jcorporate.expresso.core.cache.CacheException;
import com.jcorporate.expresso.core.cache.CacheManager;
import com.jcorporate.expresso.core.cache.CacheSystem;
@@ -119,6 +116,7 @@
import com.jcorporate.expresso.core.misc.DateTime;
import com.jcorporate.expresso.core.misc.StringUtil;
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 com.jcorporate.expresso.services.dbobj.ChangeLog;
@@ -130,7 +128,6 @@
* <p>DBObjects are the core of Expresso's object-relational mapping. They are object-oriented
* wrappers for some sort of data. They are generally expected to be used in a single thread, like
* in processing a web query.</p>
- * <p/>
* <p>When making your own application, you derive your classes from DBObject or
* SecuredDBObject.</p>
*
@@ -423,6 +420,12 @@
public DBObject()
throws DBException {
initialize();
+ try {
+ this.setDataContext(RequestRegistry.getDataContext());
+ } catch (Exception ex) {
+ log.warn("No data context set for this thread. You may"+
+ " need to install a servlet filter to set the data context");
+ }
} /* DBObject() */
/**
@@ -444,7 +447,6 @@
/**
- * <p/>
* Constructor that sets a connection as the object is create