protected Object[][] getColumnValues(Configuration tableConf,
CacheHelper queryData,
Map objectModel) throws ConfigurationException, ServiceException {
Object[][] columnValues = new Object[ queryData.columns.length ][];
for ( int i = 0; i < queryData.columns.length; i++ ){
columnValues[i] = this.getColumnValue( tableConf, queryData.columns[i], objectModel );
}
return columnValues;
}
Fetch all values for all columns that are needed to do the
database operation. |
protected CacheHelper getQuery(Configuration table,
Map modeTypes,
Map defaultModeNames) throws ConfigurationException, ServiceException {
LookUpKey lookUpKey = new LookUpKey( table, modeTypes );
CacheHelper queryData = null;
synchronized( this.cachedQueryData ) {
queryData = (CacheHelper) this.cachedQueryData.get( lookUpKey );
if (queryData == null) {
Configuration[] keys = table.getChild("keys").getChildren("key");
Configuration[] values = table.getChild("values").getChildren("value");
queryData = new CacheHelper( keys.length, keys.length + values.length );
fillModes( keys, true, defaultModeNames, modeTypes, queryData );
fillModes( values, false, defaultModeNames, modeTypes, queryData );
StringBuffer queryBuffer = new StringBuffer("UPDATE ");
queryBuffer.append(table.getAttribute("name"));
if (values.length > 0){
queryBuffer.append(" SET ");
int cols = 0;
for (int i = 0; i < queryData.columns.length; i++) {
if ( !queryData.columns[i].isKey ) {
if ( cols > 0 ) {
queryBuffer.append(", ");
}
cols++;
queryBuffer
.append( queryData.columns[i].columnConf.getAttribute( "name" ) )
.append( "= ?" );
}
}
}
queryBuffer.append(" WHERE ");
for (int i = 0; i < queryData.columns.length; i++) {
if ( queryData.columns[i].isKey ) {
if ( i > 0 ) {
queryBuffer.append(" AND ");
}
queryBuffer
.append( queryData.columns[i].columnConf.getAttribute( "name" ) )
.append( "= ?" );
}
}
queryData.queryString = queryBuffer.toString();
this.cachedQueryData.put( lookUpKey, queryData );
}
}
return queryData;
}
Get the String representation of the PreparedStatement. This is
mapped to the Configuration object itself, so if it doesn't exist,
it will be created. |
protected int processRow(Map objectModel,
Connection conn,
PreparedStatement statement,
String outputMode,
Configuration table,
CacheHelper queryData,
Object[][] columnValues,
int rowIndex,
Map results) throws Exception, SQLException, ConfigurationException {
int currentIndex = 1;
// ordering is different for UPDATE than for INSERT: values, keys
for (int i = 0; i < queryData.columns.length; i++) {
Column col = queryData.columns[i];
if ( !col.isKey ) {
this.setColumn( objectModel, outputMode, results, table, col.columnConf, rowIndex,
columnValues[ i ][ ( col.isSet ? rowIndex : 0 ) ], statement, currentIndex );
currentIndex++;
}
}
for (int i = 0; i < queryData.columns.length; i++) {
Column col = queryData.columns[i];
if ( col.isKey ) {
this.setColumn( objectModel, outputMode, results, table, col.columnConf, rowIndex,
columnValues[ i ][ ( col.isSet ? rowIndex : 0 ) ], statement, currentIndex );
currentIndex++;
}
}
int rowCount = statement.executeUpdate();
return rowCount;
}
set all necessary ?s and execute the query |