You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2005/01/08 21:18:14 UTC
svn commit: r124674 - /cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAddAction.java
Author: antonio
Date: Sat Jan 8 12:18:13 2005
New Revision: 124674
URL: http://svn.apache.org/viewcvs?view=rev&rev=124674
Log:
Fix posible null pointers
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAddAction.java
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAddAction.java
Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAddAction.java?view=diff&rev=124674&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAddAction.java&r1=124673&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAddAction.java&r2=124674
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAddAction.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoon/acting/modular/DatabaseAddAction.java Sat Jan 8 12:18:13 2005
@@ -35,7 +35,7 @@
* {@link DatabaseAction} for details.
*
* @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id: DatabaseAddAction.java,v 1.5 2004/03/05 13:01:52 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class DatabaseAddAction extends DatabaseAction {
@@ -87,76 +87,78 @@
* @param results sitemap result object
* @return the number of columns by which to increment the currentIndex
*/
- protected int setKeyAuto ( Configuration table, Column column, int currentIndex, int rowIndex,
- Connection conn, PreparedStatement statement, Map objectModel, String outputMode, Map results )
+ protected int setKeyAuto(Configuration table, Column column, int currentIndex, int rowIndex,
+ Connection conn, PreparedStatement statement, Map objectModel, String outputMode, Map results)
throws ConfigurationException, SQLException, Exception {
int columnCount = 0;
ServiceSelector autoincrSelector = null;
AutoIncrementModule autoincr = null;
try {
- autoincrSelector = (ServiceSelector) this.manager.lookup(DATABASE_MODULE_SELECTOR);
+ autoincrSelector = (ServiceSelector)this.manager.lookup(DATABASE_MODULE_SELECTOR);
if (column.mode != null && autoincrSelector != null && autoincrSelector.isSelectable(column.mode)){
- autoincr = (AutoIncrementModule) autoincrSelector.select(column.mode);
+ autoincr = (AutoIncrementModule)autoincrSelector.select(column.mode);
}
-
- if ( autoincr.includeInQuery() ) {
- if ( autoincr.includeAsValue() ) {
- Object value = autoincr.getPreValue( table, column.columnConf, column.modeConf, conn, objectModel );
- this.setColumn(objectModel, outputMode, results, table, column.columnConf, rowIndex, value, statement, currentIndex);
- columnCount = 1;
+ if (autoincr != null) {
+ if (autoincr.includeInQuery()) {
+ if (autoincr.includeAsValue()) {
+ Object value = autoincr.getPreValue(table, column.columnConf, column.modeConf, conn, objectModel);
+ this.setColumn(objectModel, outputMode, results, table, column.columnConf, rowIndex, value, statement, currentIndex);
+ columnCount = 1;
+ }
+ } else {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Automatically setting key");
+ }
}
- } else {
- if (getLogger().isDebugEnabled())
- getLogger().debug( "Automatically setting key" );
+ } else if (getLogger().isWarnEnabled()) {
+ getLogger().warn("Could not select autoincrement module" + outputMode + ". Defaulting to automatically setting key.");
}
-
} finally {
if (autoincrSelector != null) {
- if (autoincr != null)
+ if (autoincr != null) {
autoincrSelector.release(autoincr);
+ }
this.manager.release(autoincrSelector);
}
}
-
return columnCount;
}
-
-
/**
* Put key values into request attributes. Checks whether the
* value needs to be retrieved from the database module first.
*
*/
- protected void storeKeyValue( Configuration tableConf, Column key, int rowIndex, Connection conn,
- Statement statement, Map objectModel, String outputMode, Map results )
+ protected void storeKeyValue(Configuration tableConf, Column key, int rowIndex, Connection conn,
+ Statement statement, Map objectModel, String outputMode, Map results)
throws SQLException, ConfigurationException, ServiceException {
- ServiceSelector autoincrSelector = null;
+ ServiceSelector autoincrSelector = null;
AutoIncrementModule autoincr = null;
try {
- autoincrSelector=(ServiceSelector) this.manager.lookup(DATABASE_MODULE_SELECTOR);
+ autoincrSelector = (ServiceSelector)this.manager.lookup(DATABASE_MODULE_SELECTOR);
if (key.mode != null && autoincrSelector != null && autoincrSelector.isSelectable(key.mode)){
- autoincr = (AutoIncrementModule) autoincrSelector.select(key.mode);
+ autoincr = (AutoIncrementModule)autoincrSelector.select(key.mode);
}
-
- if (!autoincr.includeAsValue()) {
- Object value = autoincr.getPostValue( tableConf, key.columnConf, key.modeConf, conn, statement, objectModel );
- this.setOutput(objectModel, outputMode, results, tableConf, key.columnConf, rowIndex, value);
+ if (autoincr != null) {
+ if (!autoincr.includeAsValue()) {
+ Object value = autoincr.getPostValue(tableConf, key.columnConf, key.modeConf, conn, statement, objectModel);
+ this.setOutput(objectModel, outputMode, results, tableConf, key.columnConf, rowIndex, value);
+ }
+ } else {
+ throw new ConfigurationException("Could not obtain key value");
}
-
} finally {
if (autoincrSelector != null) {
- if (autoincr != null)
+ if (autoincr != null) {
autoincrSelector.release(autoincr);
+ }
this.manager.release(autoincrSelector);
}
}
-
}
-
/**
* determine which mode to use as default mode
* here: INSERT
@@ -260,7 +262,6 @@
}
throw new ConfigurationException("Could not find mode description "+queryData.columns[i].mode+" for column "+i);
}
-
} finally {
if (autoincrSelector != null) {
if (autoincr != null)
@@ -268,14 +269,12 @@
this.manager.release(autoincrSelector);
}
}
-
} else {
actualColumns++;
queryBuffer.append( queryData.columns[i].columnConf.getAttribute( "name" ) );
valueBuffer.append( "?" );
}
}
-
valueBuffer.append(")");
queryBuffer.append(valueBuffer);
@@ -284,9 +283,6 @@
this.cachedQueryData.put( lookUpKey, queryData );
}
}
-
return queryData;
}
-
-
}