haul 2002/08/11 13:07:45
Modified: src/java/org/apache/cocoon/components/language/markup/xsp
Tag: cocoon_2_0_3_branch XSPRequestHelper.java
EsqlQuery.java
Log:
<action dev="CH" type="fix">
Request logicsheet: Fix session tags.
</action>
<action dev="CH" type="update">
ESQL: Allow arbitrary types for prepared and callable statements via
dynamically loading classes like the SQLTransformer does. Is-null now uses
dynamic colum specification. Fixed skip-row feature, which was off by one.
Added tag to get connection meta data.
</action>
Revision Changes Path
No revision
No revision
1.11.2.1 +37 -2
xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPRequestHelper.java
Index: XSPRequestHelper.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPRequestHelper.java,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -r1.11 -r1.11.2.1
--- XSPRequestHelper.java 27 Feb 2002 05:33:50 -0000 1.11
+++ XSPRequestHelper.java 11 Aug 2002 20:07:45 -0000 1.11.2.1
@@ -64,7 +64,6 @@
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
-import java.util.List;
/**
* The <code>Request</code> object helper
@@ -528,5 +527,41 @@
uribuf.append(request.getRequestURI());
return uribuf.toString();
+ }
+
+ /**
+ * Return the given session attribute value or a user-provided default if
+ * none was specified.
+ *
+ * @param objectModel The Map objectModel
+ * @param name The attribute name
+ * @param defaultValue Value to substitute in absence of a attribute value
+ */
+ public static Object getSessionAttribute(Map objectModel, String name,
+ Object defaultValue ) {
+
+ Session session = ObjectModelHelper.getRequest(objectModel).getSession();
+ Object obj = session.getAttribute(name);
+ return (obj != null ? obj : defaultValue );
+ }
+
+ /**
+ * Output the given session attribute value or a user-provided default if
+ * none was specified.
+ *
+ * @param objectModel The Map objectModel
+ * @param contentHandler The SAX content handler
+ * @param name The attribute name
+ * @param defaultValue Value to substitute in absence of an attribute value
+ * @exception SAXException If a SAX error occurs
+ */
+ public static void getSessionAttribute(Map objectModel, ContentHandler
contentHandler,
+ String name, Object defaultValue)
+ throws SAXException {
+ AttributesImpl attr = new AttributesImpl();
+ XSPObjectHelper.addAttribute(attr, "name", name);
+
+ XSPObjectHelper.elementData(URI, PREFIX, contentHandler, "parameter",
+ getSessionAttribute(objectModel, name, defaultValue).toString(), attr);
}
}
1.11.2.8 +58 -10
xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java
Index: EsqlQuery.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java,v
retrieving revision 1.11.2.7
retrieving revision 1.11.2.8
diff -u -r1.11.2.7 -r1.11.2.8
--- EsqlQuery.java 25 Jul 2002 19:51:36 -0000 1.11.2.7
+++ EsqlQuery.java 11 Aug 2002 20:07:45 -0000 1.11.2.8
@@ -58,7 +58,7 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
-
+import java.lang.reflect.Field;
/**
* This helper class takes care of contstructing queries
* and cursor positioning (paging) for all different kinds
@@ -183,12 +183,33 @@
public PreparedStatement prepareStatement() throws SQLException {
switch(limitMethod) {
- case EsqlConnection.LIMIT_METHOD_JDBC:
- preparedStatement = connection.prepareStatement( getQueryString(),
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ case EsqlConnection.LIMIT_METHOD_POSTGRESQL:
+ case EsqlConnection.LIMIT_METHOD_MYSQL:
+ preparedStatement = connection.prepareStatement(getQueryString() );
break;
- default:
- preparedStatement = connection.prepareStatement( getQueryString() );
- };
+ case EsqlConnection.LIMIT_METHOD_JDBC:
+ // Produce scrollable ResultSet and skip rows with
ResultSet.absolute(skipRows).
+ // With SQL Server, statement.getResultSet() throws
+ // java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error
setting up static cursor cache.
+ // Same error with TYPE_SCROLL_SENSITIVE.
+ preparedStatement = connection.prepareStatement( getQueryString(),
+
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ if (maxRows > -1) {
+ // if all JDBC driver's honoured this the code to quit after maxRows
could be removed
+ preparedStatement.setMaxRows(skipRows + maxRows +1); // need this to
determine if there's more
+ }
+ break;
+ case EsqlConnection.LIMIT_METHOD_NOLIMIT:
+ default:
+ // maxRows can be set without the limit method being set - it defaults to
LIMIT_METHOD_NOLIMIT
+ // which is not such a good name as its really another way of limiting
using JDBC.
+ // Produce non-scrollable ResultSet and skip rows with multiple
ResultSet.next().
+ preparedStatement = connection.prepareStatement(getQueryString() );
+ if (maxRows > -1) {
+ preparedStatement.setMaxRows(skipRows + maxRows +1); // need this to
determine if there's more
+ }
+ break;
+ }
statement = preparedStatement;
return(preparedStatement);
}
@@ -196,11 +217,22 @@
public CallableStatement prepareCall() throws SQLException {
switch(limitMethod) {
- case EsqlConnection.LIMIT_METHOD_JDBC:
+ case EsqlConnection.LIMIT_METHOD_POSTGRESQL:
+ case EsqlConnection.LIMIT_METHOD_MYSQL:
+ preparedStatement = connection.prepareCall( getQueryString() );
+ break;
+ case EsqlConnection.LIMIT_METHOD_JDBC:
preparedStatement = connection.prepareCall( getQueryString(),
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ if (maxRows > -1) {
+ preparedStatement.setMaxRows(skipRows + maxRows +1); // need this to
determine if there's more
+ }
break;
- default:
+ case EsqlConnection.LIMIT_METHOD_NOLIMIT:
+ default:
preparedStatement = connection.prepareCall( getQueryString() );
+ if (maxRows > -1) {
+ preparedStatement.setMaxRows(skipRows + maxRows +1); // need this to
determine if there's more
+ }
};
statement = preparedStatement;
return((CallableStatement)preparedStatement);
@@ -338,7 +370,7 @@
public boolean execute( int resultSetFromObject ) throws SQLException {
hasResultSet = this.execute(false);
- resultSet = (ResultSet) ((CallableStatement) preparedStatement).getObject(1);
+ resultSet = (ResultSet) ((CallableStatement)
preparedStatement).getObject(resultSetFromObject);
resultSetValid = true;
return hasResultSet;
}
@@ -428,4 +460,20 @@
};
}
}
+
+ /**
+ * Get the integer value for a JDBC type.
+ */
+ public static int getType(String typeName)
+ throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
{
+
+ int index = typeName.lastIndexOf(".");
+ String className = typeName.substring(0, index);
+ String fieldName = typeName.substring(index + 1);
+ Class clss = Class.forName( className );
+ Field fld = clss.getField( fieldName );
+ return fld.getInt( fieldName );
+ }
+
+
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]