balld 01/05/22 20:51:47
Modified: src/org/apache/cocoon/acting AbstractDatabaseAction.java
DatabaseAddAction.java
Log:
couple of bug fixes and feature enhancements. not sure about the rowIndex
stuff though...
Revision Changes Path
1.6 +43 -31
xml-cocoon2/src/org/apache/cocoon/acting/AbstractDatabaseAction.java
Index: AbstractDatabaseAction.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/AbstractDatabaseAction.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractDatabaseAction.java 2001/05/22 14:30:39 1.5
+++ AbstractDatabaseAction.java 2001/05/23 03:51:41 1.6
@@ -171,7 +171,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Donald Ball</a>
- * @version CVS $Revision: 1.5 $ $Date: 2001/05/22 14:30:39 $
+ * @version CVS $Revision: 1.6 $ $Date: 2001/05/23 03:51:41 $
*/
public abstract class AbstractDatabaseAction extends
AbstractComplementaryConfigurableAction implements Configurable, Disposable {
protected Map files = new HashMap();
@@ -180,8 +180,8 @@
static {
/** Initialize the map of type names to jdbc column types.
- Note that INTEGER and BLOB column types map to more than one
- type name. **/
+ Note that INTEGER, BLOB, and VARCHAR column types map to more
than
+ one type name. **/
Map constants = new HashMap();
constants.put("ascii", new Integer(Types.CLOB));
constants.put("big-decimal", new Integer(Types.BIGINT));
@@ -205,6 +205,8 @@
constants.put("image-width",new Integer(Types.INTEGER));
constants.put("image-height",new Integer(Types.INTEGER));
constants.put("image-size",new Integer(Types.INTEGER));
+ constants.put("row-index",new Integer(Types.INTEGER));
+ constants.put("image-mime-type",new Integer(Types.VARCHAR));
typeConstants = Collections.unmodifiableMap(constants);
}
@@ -359,6 +361,21 @@
* @param value the value of the column
*/
protected void setColumn(PreparedStatement statement, int position,
Request request, Configuration entry, String param, Object value) throws
Exception {
+ setColumn(statement,position,request,entry,param,value,0);
+ }
+
+ /**
+ * Set the Statement column so that the results are mapped correctly.
+ *
+ * @param statement the prepared statement
+ * @param position the position of the column
+ * @param request the request
+ * @param entry the configuration object
+ * @param param the name of the request parameter
+ * @param value the value of the column
+ * @param rowIndex the index of the current row for manyrows inserts
+ */
+ protected void setColumn(PreparedStatement statement, int position,
Request request, Configuration entry, String param, Object value, int rowIndex)
throws Exception {
getLogger().debug("Setting column "+position+" named "+param+" with
value "+value);
if (value instanceof String) {
value = ((String) value).trim();
@@ -368,32 +385,9 @@
if (typeObject == null) {
throw new SQLException("Can't set column because the type
"+typeName+" is unrecognized");
}
- /*
- if (value == null || "".equals(value)) {
- switch (typeObject.intValue()) {
- case Types.DISTINCT:
- statement.setNull(position, Types.BINARY);
- return;
- case Types.ARRAY:
- case Types.BIT:
- case Types.CHAR:
- if (value == null) {
- statement.setNull(position, Types.INTEGER);
- }
- break;
- case Types.CLOB:
- case Types.VARCHAR:
- case Types.OTHER:
- break;
- default:
- statement.setNull(position, typeObject.intValue());
- return;
- }
- }
- */
if (value == null) {
/** If the value is null, set the column value null and return
**/
- if (typeName.equals("image-width") ||
typeName.equals("image-height") || typeName.equals("image-size")) {
+ if (typeName.equals("image-width") ||
typeName.equals("image-height") || typeName.equals("image-size") ||
typeName.equals("row-index") || typeName.equals("image-mime-type")) {
/** these column types are automatically generated so it's ok
**/
} else {
statement.setNull(position, typeObject.intValue());
@@ -409,7 +403,7 @@
a string type, we can continue **/
break;
case Types.INTEGER:
- if (typeName.equals("image-width") ||
typeName.equals("image-height") || typeName.equals("image-size")) {
+ if (typeName.equals("image-width") ||
typeName.equals("image-height") || typeName.equals("image-size") ||
typeName.equals("row-index")) {
/** again, these types are okay to be absent **/
break;
}
@@ -466,9 +460,6 @@
statement.setByte(position, b.byteValue());
break;
- case Types.VARCHAR:
- statement.setString(position, (String) value);
- break;
case Types.DATE:
Date d = null;
@@ -549,6 +540,22 @@
case Types.OTHER:
statement.setTimestamp(position, new Timestamp((new
java.util.Date()).getTime()));
break;
+ case Types.VARCHAR:
+ if ("string".equals(typeName)) {
+ statement.setString(position, (String) value);
+ break;
+ } else if ("image-mime-type".equals(typeName)) {
+ String imageAttr = param.substring(0, (param.length() -
"-mime-type".length()));
+ file = (File) request.get(imageAttr);
+ synchronized (this.files) {
+ Parameters parameters = (Parameters)
this.files.get(file);
+ statement.setString(position,
parameters.getParameter("image-mime-type",""));
+ /** Store the image mime type in the request
attributes.
+ Why do we do this? **/
+
setRequestAttribute(request,param,parameters.getParameter("image-mime-type",""));
+ }
+ break;
+ }
case Types.BLOB:
if (value instanceof File) {
file = (File)value;
@@ -566,8 +573,10 @@
Parameters parameters = new Parameters();
parameters.setParameter("image-size",
Long.toString(file.length()));
int [] dimensions =
ImageDirectoryGenerator.getSize(file);
+ String type = ImageDirectoryGenerator.getFileType(file);
parameters.setParameter("image-width",
Integer.toString(dimensions[0]));
parameters.setParameter("image-height",
Integer.toString(dimensions[1]));
+ parameters.setParameter("image-mime-type",type);
synchronized (this.files) {
this.files.put(file, parameters);
}
@@ -616,6 +625,9 @@
statement.setInt(position,
parameters.getParameterAsInteger("image-size", -1));
setRequestAttribute(request,param,parameters.getParameter("image-size",""));
}
+ break;
+ } else if ("row-index".equals(typeName)) {
+ statement.setInt(position,rowIndex);
break;
}
default:
1.5 +28 -13
xml-cocoon2/src/org/apache/cocoon/acting/DatabaseAddAction.java
Index: DatabaseAddAction.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/DatabaseAddAction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DatabaseAddAction.java 2001/05/22 14:30:45 1.4
+++ DatabaseAddAction.java 2001/05/23 03:51:43 1.5
@@ -18,6 +18,8 @@
import java.util.Map;
import java.util.Enumeration;
import java.util.Collections;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.configuration.Configurable;
@@ -41,7 +43,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Donald Ball</a>
- * @version CVS $Revision: 1.4 $ $Date: 2001/05/22 14:30:45 $
+ * @version CVS $Revision: 1.5 $ $Date: 2001/05/23 03:51:43 $
*/
public class DatabaseAddAction extends AbstractDatabaseAction {
protected static final Map addStatements = new HashMap();
@@ -133,25 +135,38 @@
* to be inserting n rows, where 0 <= n
*/
String prefix = wildcardParam.substring(0,wildcardIndex);
- String suffix = wildcardParam.substring(wildcardIndex+1);
+ String suffix;
+ if (wildcardParam.length() >= wildcardIndex+1) {
+ suffix = wildcardParam.substring(wildcardIndex+1);
+ } else {
+ suffix = "";
+ }
Enumeration names = request.getParameterNames();
+ SortedSet matchset = new TreeSet();
while (names.hasMoreElements()) {
String name = (String)names.nextElement();
if (name.startsWith(prefix) && name.endsWith(suffix)) {
String wildcard = name.substring(prefix.length());
wildcard =
wildcard.substring(0,wildcard.length()-suffix.length());
- currentIndex = 1;
- for (int j=0; j<keys.length; j++) {
- String myparam =
getActualParam(keys[j].getAttribute("param"),wildcard);
- currentIndex +=
setKey(table,keys[j],conn,statement,currentIndex,request,myparam,results);
- }
- for (int j=0; j<values.length; j++) {
- String myparam =
getActualParam(values[j].getAttribute("param"),wildcard);
-
this.setColumn(statement,currentIndex,request,values[j],myparam,request.getParameter(myparam));
- currentIndex++;
- }
- statement.execute();
+ matchset.add(wildcard);
+ }
+ }
+ Iterator iterator = matchset.iterator();
+ int rowIndex = 1;
+ while (iterator.hasNext()) {
+ String wildcard = (String)iterator.next();
+ currentIndex = 1;
+ for (int j=0; j<keys.length; j++) {
+ String myparam =
getActualParam(keys[j].getAttribute("param"),wildcard);
+ currentIndex +=
setKey(table,keys[j],conn,statement,currentIndex,request,myparam,results);
+ }
+ for (int j=0; j<values.length; j++) {
+ String myparam =
getActualParam(values[j].getAttribute("param"),wildcard);
+
this.setColumn(statement,currentIndex,request,values[j],myparam,request.getParameter(myparam),rowIndex);
+ currentIndex++;
}
+ statement.execute();
+ rowIndex++;
}
} else {
/**
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]