You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ha...@apache.org on 2002/11/06 19:18:30 UTC
cvs commit: xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/acting/modular DatabaseAction.java
haul 2002/11/06 10:18:30
Modified: src/webapp/samples/mod-db sitemap.xmap
src/documentation/xdocs/userdocs/xsp esql.xml
src/documentation/xdocs/userdocs/actions
database-actions.xml
src/blocks/databases/java/org/apache/cocoon/util
JDBCTypeConversions.java
src/blocks/databases/java/org/apache/cocoon/components/modules/database
PgsqlAutoIncrementModule.java
src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp
EsqlHelper.java
src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/java
esql.xsl
src/blocks/databases/java/org/apache/cocoon/acting/modular
DatabaseAction.java
Log:
* Additional documentation
- column types in database actions
- dynamic queries in esql
* Improved BLOB & CLOB support for database actions
* Fixed mod-db sample problem
Revision Changes Path
1.6 +1 -8 xml-cocoon2/src/webapp/samples/mod-db/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/webapp/samples/mod-db/sitemap.xmap,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- sitemap.xmap 20 Oct 2002 12:25:45 -0000 1.5
+++ sitemap.xmap 6 Nov 2002 18:18:29 -0000 1.6
@@ -16,14 +16,7 @@
<map:serializers default="html"/>
- <map:matchers default="wildcard">
- <map:matcher logger="sitemap.matcher.modular.non-cached" name="uri" src="org.apache.cocoon.matching.modular.WildcardMatcher">
- <input-module name="URI"/>
- </map:matcher>
- <map:matcher logger="sitemap.matcher.modular.cached" name="cached-uri" src="org.apache.cocoon.matching.modular.CachingWildcardMatcher">
- <input-module name="URI"/>
- </map:matcher>
- </map:matchers>
+ <map:matchers default="wildcard"/>
<map:selectors default="browser"/>
1.9 +50 -2 xml-cocoon2/src/documentation/xdocs/userdocs/xsp/esql.xml
Index: esql.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/documentation/xdocs/userdocs/xsp/esql.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- esql.xml 9 Aug 2002 08:22:45 -0000 1.8
+++ esql.xml 6 Nov 2002 18:18:29 -0000 1.9
@@ -123,7 +123,51 @@
</esql:connection>]]>
</source>
- <s2 title="Refering to results">
+ <s2 title="Dynamic Queries">
+ <p>When a query contains dynamic parts, e.g. a value that is to be matched,
+ esql offers two different possibilities to achieve that. First, as the
+ query is really a string, it can be constructed like any other string by
+ concattenation.
+ </p>
+
+ <source><![CDATA[
+ <xsp:logic>
+ String orderBy = null;
+ switch(type) {
+ case 1: orderBy = "order by name"; break;
+ case 2: orderBy = "order by salary"; break;
+ default: orderBy = "";
+ }
+ </xsp:logic>
+
+ <!-- ... -->
+
+ <esql:query>SELECT name, salary FROM employee <xsp:expr>orderBy</xsp:expr></esql:query>
+]]>
+</source>
+
+ <p>Note, however, that here any string will be part of the actual
+ statement. In this example it does no harm as the value for the
+ <code>orderBy</code> variable is completely under the control of
+ your code. Any malicious attacker could not inject his or her own
+ code. Thus this technique should not be used when values returned
+ from the client have to be used.
+ </p>
+ <p>The second variant is to use a PreparedStatement for dynamic
+ parameters. Since the driver is supposed to keep parameters
+ distinct from the statement, no code can be injected this way. In
+ addition, your DBMS puts more effort into optimizing the
+ statement. PreparedStatements are created whenever a
+ <code><esql:parameter/></code> tag appears in a query.
+ </p>
+ <source><![CDATA[
+ <esql:query>SELECT name, salary FROM employee
+ WHERE name=<esql:parameter><xsp:expr>name</xsp:expr></esql:parameter></esql:query>
+]]>
+ </source>
+ </s2>
+
+ <s2 title="Refering to Results">
<p>A select query usually returns one ResultSet. This case is handled by
the <code>esql:results</code> tag and its content. However, many special
@@ -237,7 +281,11 @@
tags. It follows the nesting ideology of <code><xsp:logic> ...
<xsp:content></></></code>You can nest
<code><esql:group></code> and <code><esql:member></code>
- indefinately.</p>
+ indefinately. <code>group-on</code> can be an attribute of
+ <code>group</code> or a text node. The value of the text node has
+ precedence over the attribute. The value can be the column name or the
+ column number.
+ </p>
<source><![CDATA[
<esql:execute-query>
1.2 +5 -0 xml-cocoon2/src/documentation/xdocs/userdocs/actions/database-actions.xml
Index: database-actions.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/documentation/xdocs/userdocs/actions/database-actions.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- database-actions.xml 28 Apr 2002 18:14:45 -0000 1.1
+++ database-actions.xml 6 Nov 2002 18:18:29 -0000 1.2
@@ -29,6 +29,11 @@
modules. Even for auto increment columns specific modules exist that
cover a wide range of database management systems.
</p>
+ <p>
+ For an overview of column types supported by the modular database
+ actions, see javadocs for JDBCTypeConversions. The types supported by
+ the original actions are documented in AbstractDatabaseAction.
+ </p>
</s1>
<s1 title="Original Database Actions">
1.4 +306 -202 xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/util/JDBCTypeConversions.java
Index: JDBCTypeConversions.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/util/JDBCTypeConversions.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JDBCTypeConversions.java 28 Oct 2002 15:02:08 -0000 1.3
+++ JDBCTypeConversions.java 6 Nov 2002 18:18:30 -0000 1.4
@@ -60,6 +60,7 @@
import java.sql.Array;
import java.sql.Types;
import java.sql.Clob;
+import java.sql.Blob;
import java.sql.Struct;
import java.math.BigDecimal;
import java.util.Map;
@@ -75,6 +76,35 @@
* them to JDBC statements. Largely copied from
* org.apache.cocoon.acting.AbstractDatabaseAction.
*
+ * <p>The following table lists all available column type names
+ * together with the JDBC methods used to get or set a column with
+ * that type. In some cases the returned type differs from the type
+ * returned by the getXXX method. To set a column, a number of
+ * conversions are automatically used. For details, please see the
+ * actual code.</p>
+ *
+ * <p><table border="1">
+ * <tr><th>type </th><th>getXXX </th><th>returns </th><th>setXXX </th></tr>
+ * <tr><td>clob </td><td>Clob </td><td>String </td><td>Clob </td></tr>
+ * <tr><td>ascii </td><td>Clob </td><td>String </td><td>asciStream </td></tr>
+ * <tr><td>big-decimal</td><td>BigDecimal </td><td> </td><td>BigDecimal </td></tr>
+ * <tr><td>binary </td><td> </td><td> </td><td>BinaryStream </td></tr>
+ * <tr><td>blob </td><td> </td><td> </td><td>Blob </td></tr>
+ * <tr><td>boolean </td><td>Bit </td><td>Integer </td><td>Boolean </td></tr>
+ * <tr><td>byte </td><td>Byte </td><td>Byte </td><td>Byte </td></tr>
+ * <tr><td>string </td><td>String </td><td> </td><td>String </td></tr>
+ * <tr><td>date </td><td>Date </td><td> </td><td>Date </td></tr>
+ * <tr><td>double </td><td>Double </td><td>Double </td><td>Double </td></tr>
+ * <tr><td>float </td><td>Float </td><td>Float </td><td>Float </td></tr>
+ * <tr><td>int </td><td>Int </td><td>Integer </td><td>Int </td></tr>
+ * <tr><td>long </td><td>Long </td><td>Long </td><td>Long </td></tr>
+ * <tr><td>short </td><td>Short </td><td> </td><td>Short </td></tr>
+ * <tr><td>time </td><td>Time </td><td> </td><td>Time </td></tr>
+ * <tr><td>time-stamp </td><td>Timestamp </td><td> </td><td>Timestamp </td></tr>
+ * <tr><td>array </td><td>Array </td><td> </td><td>Array </td></tr>
+ * <tr><td>row </td><td>Object </td><td>Struct </td><td>Object </td></tr>
+ * <tr><td>object </td><td>Object </td><td> </td><td>Object </td></tr>
+ * </table></p>
*/
public class JDBCTypeConversions {
public static final Map typeConstants;
@@ -84,9 +114,11 @@
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("clob", new Integer(Types.CLOB));
+ constants.put("ascii", new Integer(Types.CHAR));
constants.put("big-decimal", new Integer(Types.BIGINT));
- constants.put("binary", new Integer(Types.BLOB));
+ constants.put("binary", new Integer(Types.VARBINARY));
+ constants.put("blob", new Integer(Types.BLOB));
constants.put("boolean", new Integer(Types.BIT));
constants.put("byte", new Integer(Types.TINYINT));
constants.put("string", new Integer(Types.VARCHAR));
@@ -155,6 +187,7 @@
switch (type.intValue()) {
case Types.CLOB:
+ case Types.CHAR:
Clob dbClob = set.getClob(dbcol);
int length = (int) dbClob.length();
InputStream asciiStream = new BufferedInputStream(dbClob.getAsciiStream());
@@ -203,9 +236,6 @@
case Types.BIT:
value = new Integer(set.getInt(dbcol));
break;
- case Types.CHAR:
- value = new Integer(set.getInt(dbcol));
- break;
case Types.STRUCT:
value = (Struct) set.getObject(dbcol);
break;
@@ -244,211 +274,285 @@
}
if ("".equals(value)) {
switch (typeObject.intValue()) {
- case Types.CHAR:
- case Types.CLOB:
- case Types.VARCHAR:
- /** If the value is an empty string and the column is
- a string type, we can continue **/
- break;
- default:
- /** If the value is an empty string and the column
- is something else, we treat it as a null value **/
- statement.setNull(position, typeObject.intValue());
- return;
+ case Types.CHAR:
+ case Types.CLOB:
+ case Types.VARCHAR:
+ /** If the value is an empty string and the column is
+ a string type, we can continue **/
+ break;
+ default:
+ /** If the value is an empty string and the column
+ is something else, we treat it as a null value **/
+ statement.setNull(position, typeObject.intValue());
+ return;
}
}
File file = null;
+ int length = -1;
+ InputStream asciiStream = null;
+ //System.out.println("========================================================================");
+ //System.out.println("JDBCTypeConversions: setting type "+typeObject.intValue());
switch (typeObject.intValue()) {
- case Types.CLOB:
- int length = -1;
- InputStream asciiStream = null;
-
- if (value instanceof File) {
- File asciiFile = (File) value;
- asciiStream = new BufferedInputStream(new FileInputStream(asciiFile));
- length = (int) asciiFile.length();
- } else if (value instanceof JDBCxlobHelper) {
- asciiStream = ((JDBCxlobHelper) value).inputStream;
- length = ((JDBCxlobHelper) value).length;
- } else if (value instanceof Source) {
- asciiStream = ((Source) value).getInputStream();
- length = (int)((Source) value).getContentLength();
- } else {
- String asciiText = (String) value;
- asciiStream = new BufferedInputStream(new ByteArrayInputStream(asciiText.getBytes()));
- length = asciiText.length();
- }
-
- statement.setAsciiStream(position, asciiStream, length);
- break;
- case Types.BIGINT:
- BigDecimal bd = null;
-
- if (value instanceof BigDecimal) {
- bd = (BigDecimal) value;
- } else if (value instanceof Number) {
- bd = BigDecimal.valueOf(((Number)value).longValue());
- } else {
- bd = new BigDecimal((String) value);
- }
-
- statement.setBigDecimal(position, bd);
- break;
- case Types.TINYINT:
- Byte b = null;
-
- if (value instanceof Byte) {
- b = (Byte) value;
- } else if (value instanceof Number) {
- b = new Byte(((Number) value).byteValue());
- } else {
- b = new Byte((String) value);
- }
-
- statement.setByte(position, b.byteValue());
- break;
- case Types.DATE:
- Date d = null;
-
- if (value instanceof Date) {
- d = (Date) value;
- } else if (value instanceof java.util.Date) {
- d = new Date(((java.util.Date) value).getTime());
- } else if (value instanceof Calendar) {
- d = new Date(((Calendar) value).getTime().getTime());
- }
-
- statement.setDate(position, d);
- break;
- case Types.DOUBLE:
- double db;
-
- if (value instanceof Number) {
- db = (((Number) value).doubleValue());
- } else {
- db = Double.parseDouble(String.valueOf(value));
- }
- statement.setDouble(position, db);
- break;
- case Types.FLOAT:
- float f;
-
- if (value instanceof Number) {
- f = (((Number) value).floatValue());
- } else {
- f = Float.parseFloat(String.valueOf(value));
- }
- statement.setFloat(position, f);
- break;
- case Types.NUMERIC:
- long l;
-
- if (value instanceof Number) {
- l = (((Number) value).longValue());
- } else {
- l = Long.parseLong(String.valueOf(value));
- }
-
- statement.setLong(position, l);
- break;
- case Types.SMALLINT:
- Short s = null;
-
- if (value instanceof Short) {
- s = (Short) value;
- } else if (value instanceof Number) {
- s = new Short(((Number) value).shortValue());
- } else {
- s = new Short((String) value);
- }
-
- statement.setShort(position, s.shortValue());
- break;
- case Types.TIME:
- Time t = null;
-
- if (value instanceof Time) {
- t = (Time) value;
- } else if (value instanceof java.util.Date){
- t = new Time(((java.util.Date) value).getTime());
- } else {
- t = Time.valueOf(value.toString());
- }
-
- statement.setTime(position, t);
- break;
- case Types.TIMESTAMP:
- Timestamp ts = null;
-
- if (value instanceof Time) {
- ts = (Timestamp) value;
- } else if (value instanceof java.util.Date) {
- ts = new Timestamp(((java.util.Date) value).getTime());
- } else {
- ts = Timestamp.valueOf(value.toString());
- }
-
- statement.setTimestamp(position, ts);
- break;
- case Types.ARRAY:
- statement.setArray(position, (Array) value); // no way to convert string to array
- break;
- case Types.STRUCT:
- case Types.OTHER:
- statement.setObject(position, value);
- break;
- case Types.LONGVARBINARY:
- statement.setTimestamp(position, new Timestamp((new java.util.Date()).getTime()));
- case Types.VARCHAR:
- statement.setString(position, (String) value);
- break;
- case Types.BLOB:
- if (value instanceof JDBCxlobHelper) {
- statement.setBinaryStream(position, ((JDBCxlobHelper)value).inputStream, ((JDBCxlobHelper)value).length);
- } else if (value instanceof Source){
- statement.setBinaryStream(position, ((Source)value).getInputStream(), (int)((Source)value).getContentLength());
- } else {
- if (value instanceof File) {
- file = (File)value;
- } else if (value instanceof String) {
- file = new File((String)value);
- } else {
- throw new SQLException("Invalid type for blob: "+value.getClass().getName());
- }
- //InputStream input = new BufferedInputStream(new FileInputStream(file));
- FileInputStream input = new FileInputStream(file);
- statement.setBinaryStream(position, input, (int)file.length());
- }
- break;
- case Types.INTEGER:
- Integer i = null;
- if (value instanceof Integer) {
- i = (Integer) value;
- } else if (value instanceof java.lang.Number) {
- i = new Integer(((java.lang.Number) value).intValue());
- } else {
- i = new Integer(value.toString());
- }
- statement.setInt(position, i.intValue());
- break;
- case Types.BIT:
- Boolean bo = null;
- if (value instanceof Boolean) {
- bo = (Boolean) value;
- } else if (value instanceof java.lang.Number) {
- bo = new Boolean(((java.lang.Number) value).intValue()==1);
+ case Types.CLOB:
+ //System.out.println("CLOB");
+ Clob clob = null;
+ if (value instanceof Clob) {
+ clob = (Clob) value;
+ } else if (value instanceof File) {
+ File asciiFile = (File) value;
+ asciiStream = new BufferedInputStream(new FileInputStream(asciiFile));
+ length = (int) asciiFile.length();
+ clob = new ClobHelper(asciiStream, length);
+ } else if (value instanceof JDBCxlobHelper) {
+ asciiStream = ((JDBCxlobHelper) value).inputStream;
+ length = ((JDBCxlobHelper) value).length;
+ clob = new ClobHelper(asciiStream, length);
+ } else if (value instanceof Source) {
+ asciiStream = ((Source) value).getInputStream();
+ length = (int)((Source) value).getContentLength();
+ clob = new ClobHelper(asciiStream, length);
+ } else {
+ String asciiText = (String) value;
+ asciiStream = new ByteArrayInputStream(asciiText.getBytes());
+ length = asciiText.length();
+ clob = new ClobHelper(asciiStream, length);
+ }
+
+ statement.setClob(position, clob);
+ break;
+ case Types.CHAR:
+ // simple large object, e.g. Informix's TEXT
+ //System.out.println("CHAR");
+
+ if (value instanceof File) {
+ File asciiFile = (File) value;
+ asciiStream = new BufferedInputStream(new FileInputStream(asciiFile));
+ length = (int) asciiFile.length();
+ } else if (value instanceof JDBCxlobHelper) {
+ asciiStream = ((JDBCxlobHelper) value).inputStream;
+ length = ((JDBCxlobHelper) value).length;
+ } else if (value instanceof Source) {
+ asciiStream = ((Source) value).getInputStream();
+ length = (int)((Source) value).getContentLength();
+ } else {
+ String asciiText = (String) value;
+ asciiStream = new BufferedInputStream(new ByteArrayInputStream(asciiText.getBytes()));
+ length = asciiText.length();
+ }
+
+ statement.setAsciiStream(position, asciiStream, length);
+ break;
+ case Types.BIGINT:
+ //System.out.println("BIGINT");
+ BigDecimal bd = null;
+
+ if (value instanceof BigDecimal) {
+ bd = (BigDecimal) value;
+ } else if (value instanceof Number) {
+ bd = BigDecimal.valueOf(((Number)value).longValue());
+ } else {
+ bd = new BigDecimal((String) value);
+ }
+
+ statement.setBigDecimal(position, bd);
+ break;
+ case Types.TINYINT:
+ //System.out.println("TINYINT");
+ Byte b = null;
+
+ if (value instanceof Byte) {
+ b = (Byte) value;
+ } else if (value instanceof Number) {
+ b = new Byte(((Number) value).byteValue());
+ } else {
+ b = new Byte((String) value);
+ }
+
+ statement.setByte(position, b.byteValue());
+ break;
+ case Types.DATE:
+ //System.out.println("DATE");
+ Date d = null;
+
+ if (value instanceof Date) {
+ d = (Date) value;
+ } else if (value instanceof java.util.Date) {
+ d = new Date(((java.util.Date) value).getTime());
+ } else if (value instanceof Calendar) {
+ d = new Date(((Calendar) value).getTime().getTime());
+ }
+
+ statement.setDate(position, d);
+ break;
+ case Types.DOUBLE:
+ //System.out.println("DOUBLE");
+ double db;
+
+ if (value instanceof Number) {
+ db = (((Number) value).doubleValue());
+ } else {
+ db = Double.parseDouble(String.valueOf(value));
+ }
+ statement.setDouble(position, db);
+ break;
+ case Types.FLOAT:
+ //System.out.println("FLOAT");
+ float f;
+
+ if (value instanceof Number) {
+ f = (((Number) value).floatValue());
+ } else {
+ f = Float.parseFloat(String.valueOf(value));
+ }
+ statement.setFloat(position, f);
+ break;
+ case Types.NUMERIC:
+ //System.out.println("NUMERIC");
+ long l;
+
+ if (value instanceof Number) {
+ l = (((Number) value).longValue());
+ } else {
+ l = Long.parseLong(String.valueOf(value));
+ }
+
+ statement.setLong(position, l);
+ break;
+ case Types.SMALLINT:
+ //System.out.println("SMALLINT");
+ Short s = null;
+
+ if (value instanceof Short) {
+ s = (Short) value;
+ } else if (value instanceof Number) {
+ s = new Short(((Number) value).shortValue());
+ } else {
+ s = new Short((String) value);
+ }
+
+ statement.setShort(position, s.shortValue());
+ break;
+ case Types.TIME:
+ //System.out.println("TIME");
+ Time t = null;
+
+ if (value instanceof Time) {
+ t = (Time) value;
+ } else if (value instanceof java.util.Date){
+ t = new Time(((java.util.Date) value).getTime());
+ } else {
+ t = Time.valueOf(value.toString());
+ }
+
+ statement.setTime(position, t);
+ break;
+ case Types.TIMESTAMP:
+ //System.out.println("TIMESTAMP");
+ Timestamp ts = null;
+
+ if (value instanceof Time) {
+ ts = (Timestamp) value;
+ } else if (value instanceof java.util.Date) {
+ ts = new Timestamp(((java.util.Date) value).getTime());
+ } else {
+ ts = Timestamp.valueOf(value.toString());
+ }
+
+ statement.setTimestamp(position, ts);
+ break;
+ case Types.ARRAY:
+ //System.out.println("ARRAY");
+ statement.setArray(position, (Array) value); // no way to convert string to array
+ break;
+ case Types.STRUCT:
+ //System.out.println("STRUCT");
+ case Types.OTHER:
+ //System.out.println("OTHER");
+ statement.setObject(position, value);
+ break;
+ case Types.LONGVARBINARY:
+ //System.out.println("LONGVARBINARY");
+ statement.setTimestamp(position, new Timestamp((new java.util.Date()).getTime()));
+ break;
+ case Types.VARCHAR:
+ //System.out.println("VARCHAR");
+ statement.setString(position, (String) value);
+ break;
+ case Types.BLOB:
+ //System.out.println("BLOB");
+ if (value instanceof JDBCxlobHelper) {
+ statement.setBinaryStream(position, ((JDBCxlobHelper)value).inputStream, ((JDBCxlobHelper)value).length);
+ } else if (value instanceof Source){
+ statement.setBinaryStream(position, ((Source)value).getInputStream(), (int)((Source)value).getContentLength());
+ } else {
+ Blob blob = null;
+ if (value instanceof Blob) {
+ blob = (Blob) value;
+ } else if( value instanceof File) {
+ file = (File)value;
+ blob = new BlobHelper(new FileInputStream(file), (int) file.length());
+ } else if (value instanceof String) {
+ file = new File((String)value);
+ blob = new BlobHelper(new FileInputStream(file), (int) file.length());
} else {
- bo = new Boolean(value.toString());
+ throw new SQLException("Invalid type for blob: "+value.getClass().getName());
}
- statement.setBoolean(position, bo.booleanValue());
- break;
-
- default:
- throw new SQLException("Impossible exception - invalid type ");
+ //InputStream input = new BufferedInputStream(new FileInputStream(file));
+ statement.setBlob(position, blob);
+ }
+ break;
+ case Types.VARBINARY:
+ //System.out.println("VARBINARY");
+ if (value instanceof JDBCxlobHelper) {
+ statement.setBinaryStream(position, ((JDBCxlobHelper)value).inputStream, ((JDBCxlobHelper)value).length);
+ } else if (value instanceof Source){
+ statement.setBinaryStream(position, ((Source)value).getInputStream(), (int)((Source)value).getContentLength());
+ } else {
+ if (value instanceof File) {
+ file = (File)value;
+ } else if (value instanceof String) {
+ file = new File((String)value);
+ } else {
+ throw new SQLException("Invalid type for blob: "+value.getClass().getName());
+ }
+ //InputStream input = new BufferedInputStream(new FileInputStream(file));
+ FileInputStream input = new FileInputStream(file);
+ statement.setBinaryStream(position, input, (int)file.length());
+ }
+ break;
+ case Types.INTEGER:
+ //System.out.println("INTEGER");
+ Integer i = null;
+ if (value instanceof Integer) {
+ i = (Integer) value;
+ } else if (value instanceof java.lang.Number) {
+ i = new Integer(((java.lang.Number) value).intValue());
+ } else {
+ i = new Integer(value.toString());
+ }
+ statement.setInt(position, i.intValue());
+ break;
+ case Types.BIT:
+ //System.out.println("BIT");
+ Boolean bo = null;
+ if (value instanceof Boolean) {
+ bo = (Boolean) value;
+ } else if (value instanceof java.lang.Number) {
+ bo = new Boolean(((java.lang.Number) value).intValue()==1);
+ } else {
+ bo = new Boolean(value.toString());
+ }
+ statement.setBoolean(position, bo.booleanValue());
+ break;
+
+ default:
+ //System.out.println("default");
+ throw new SQLException("Impossible exception - invalid type ");
}
+ //System.out.println("========================================================================");
}
-
-
+
+
}
1.2 +18 -7 xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/modules/database/PgsqlAutoIncrementModule.java
Index: PgsqlAutoIncrementModule.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/modules/database/PgsqlAutoIncrementModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PgsqlAutoIncrementModule.java 18 Oct 2002 14:04:26 -0000 1.1
+++ PgsqlAutoIncrementModule.java 6 Nov 2002 18:18:30 -0000 1.2
@@ -65,7 +65,11 @@
/**
* Abstraction layer to encapsulate different DBMS behaviour for autoincrement columns.
*
- * Here: {@link <a href="http://www.postgres.org">PostgreSQL</a>} SERIAL columns
+ * Here: {@link <a href="http://www.postgres.org">PostgreSQL</a>}
+ * sequences. The default sequence name is constructed from the table
+ * name, a "_", the column name, and the suffix "_seq". To use a
+ * different sequence name, set an attribute "sequence" for the
+ * modeConf e.g. <mode name="auto" type="auto" sequence="my_sequence"/>.
*
* @author <a href="mailto:pmhahn@titan.lahn.de">Philipp Hahn</a>
* @version CVS $Id$
@@ -84,12 +88,19 @@
ResultSet resultSet = callStmt.executeQuery();
*/
- StringBuffer queryBuffer = new StringBuffer("SELECT currval('");
- queryBuffer.append(tableConf.getAttribute("name",""));
- queryBuffer.append('_');
- queryBuffer.append(columnConf.getAttribute("name"));
- queryBuffer.append("_seq')");
+ String sequence = modeConf.getAttribute("sequence",null);
+ StringBuffer queryBuffer = new StringBuffer("SELECT currval('");
+ if (sequence != null) {
+ queryBuffer.append(sequence);
+ } else {
+ queryBuffer.append(tableConf.getAttribute("name",""));
+ queryBuffer.append('_');
+ queryBuffer.append(columnConf.getAttribute("name"));
+ queryBuffer.append("_seq");
+ };
+ queryBuffer.append("')");
+
PreparedStatement pstmt = conn.prepareStatement(queryBuffer.toString());
ResultSet resultSet = pstmt.executeQuery();
while ( resultSet.next() ) {
1.2 +0 -0 xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/EsqlHelper.java
Index: EsqlHelper.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/EsqlHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
1.2 +0 -0 xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl
Index: esql.xsl
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
1.2 +6 -2 xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAction.java
Index: DatabaseAction.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DatabaseAction.java 18 Oct 2002 14:04:27 -0000 1.1
+++ DatabaseAction.java 6 Nov 2002 18:18:30 -0000 1.2
@@ -125,7 +125,10 @@
*
* <p>The number of affected rows is returned to the sitemap with the
* "row-count" parameter if at least one row was affected.</p>
-
+ *
+ * <p>All known column types can be found in
+ * {@link org.apache.cocoon.util.JDBCTypeConversions JDBCTypeConversions}.</p>
+ *
* <table>
* <tr><td colspan="2">Configuration options (setup):</td></tr>
* <tr><td>input </td><td>default mode name for reading values</td></tr>
@@ -145,6 +148,7 @@
* @see org.apache.cocoon.components.modules.input
* @see org.apache.cocoon.components.modules.output
* @see org.apache.cocoon.components.modules.database
+ * @see org.apache.cocoon.util.JDBCTypeConversions
*/
public abstract class DatabaseAction extends AbstractComplementaryConfigurableAction implements Configurable, Disposable {
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org