1 16 17 package org.apache.cocoon.acting.modular; 18 19 import java.sql.Connection ; 20 import java.sql.PreparedStatement ; 21 import java.sql.SQLException ; 22 import java.util.Map ; 23 24 import org.apache.avalon.framework.configuration.Configuration; 25 import org.apache.avalon.framework.configuration.ConfigurationException; 26 import org.apache.avalon.framework.service.ServiceException; 27 28 35 public class DatabaseDeleteAction extends DatabaseAction { 36 37 42 protected String selectMode ( boolean isAutoIncrement, Map modes ) { 43 44 return (String ) modes.get( MODE_OTHERS ); 45 } 46 47 48 52 protected boolean honourAutoIncrement() { return false; } 53 54 55 59 protected Object [][] getColumnValues( Configuration tableConf, CacheHelper queryData, Map objectModel ) 60 throws ConfigurationException, ServiceException { 61 62 Object [][] columnValues = new Object [ queryData.columns.length ][]; 63 for ( int i = 0; i < queryData.columns.length; i++ ){ 64 if ( queryData.columns[i].isKey ) { 65 columnValues[i] = this.getColumnValue( tableConf, queryData.columns[i], objectModel ); 66 } else { 67 } 69 } 70 return columnValues; 71 } 72 73 74 75 83 protected CacheHelper getQuery( Configuration table, Map modeTypes, Map defaultModeNames ) 84 throws ConfigurationException, ServiceException { 85 86 LookUpKey lookUpKey = new LookUpKey( table, modeTypes ); 87 CacheHelper queryData = null; 88 synchronized( this.cachedQueryData ) { 89 queryData = (CacheHelper) this.cachedQueryData.get( lookUpKey ); 90 if (queryData == null) { 91 Configuration[] keys = table.getChild("keys").getChildren("key"); 92 93 queryData = new CacheHelper( keys.length, keys.length ); 94 fillModes( keys, true, defaultModeNames, modeTypes, queryData ); 95 96 StringBuffer queryBuffer = new StringBuffer ("DELETE FROM "); 97 queryBuffer.append(table.getAttribute("name")).append(" WHERE "); 98 for (int i = 0; i < queryData.columns.length; i++) { 99 if ( i > 0 ) { 100 queryBuffer.append(" AND "); 101 } 102 queryBuffer 103 .append( queryData.columns[i].columnConf.getAttribute( "name" ) ) 104 .append( "= ?" ); 105 } 106 107 queryData.queryString = queryBuffer.toString(); 108 109 this.cachedQueryData.put( lookUpKey, queryData ); 110 } 111 } 112 113 return queryData; 114 } 115 116 117 118 121 protected int processRow ( Map objectModel, Connection conn, PreparedStatement statement, String outputMode, 122 Configuration table, CacheHelper queryData, Object [][] columnValues, 123 int rowIndex, Map results ) 124 throws SQLException , ConfigurationException, Exception { 125 126 int currentIndex = 1; 127 128 for (int i = 0; i < queryData.columns.length; i++) { 130 Column col = queryData.columns[i]; 131 if ( col.isKey ) { 132 this.setColumn( objectModel, outputMode, results, table, col.columnConf, rowIndex, 133 columnValues[ i ][ ( col.isSet ? rowIndex : 0 ) ], 134 statement, currentIndex ); 135 currentIndex++; 136 } 137 } 138 int rowCount = statement.executeUpdate(); 139 return rowCount; 140 } 141 142 } 143 | Popular Tags |