return jm;
}
protected JavaMethod getPMClassUpdateMethod(TypeSG pController, JavaSource pSource, CustomTableData pData)
throws SAXException {
JavaMethod jm = pSource.newJavaMethod("update", JavaQNameImpl.VOID, JavaSource.PUBLIC);
Parameter pElement = jm.addParam(Element.class, "pElement");
jm.addThrows(PMException.class);
Table table = pData.getTable();
String q = table.getSchema().getSQLFactory().newSQLGenerator().getQuery(table.getUpdateStatement());
LocalJavaField query = jm.newJavaField(String.class);
query.setFinal(true);
query.addLine(JavaSource.getQuoted(q));
JavaQName qName = pController.getComplexTypeSG().getClassContext().getXMLInterfaceName();
LocalJavaField elem = jm.newJavaField(qName);
elem.addLine("(", qName, ") ", pElement);
LocalJavaField connection = jm.newJavaField(Connection.class);
connection.addLine("null");
jm.addTry();
jm.addLine(connection, " = getConnection();");
LocalJavaField stmt = jm.newJavaField(PreparedStatement.class);
stmt.addLine(connection, ".prepareStatement(", query, ")");
jm.addTry();
List nonKeyColumns = new ArrayList();
for (Iterator iter = table.getColumns(); iter.hasNext(); ) {
Column col = (Column) iter.next();
if (!col.isPrimaryKeyPart()) {
nonKeyColumns.add(col);
}
}
int i = 0;
i = getPreparedStatementParameters(jm, stmt, elem, nonKeyColumns.iterator(), i);
getPreparedStatementParameters(jm, stmt, elem, table.getPrimaryKey().getColumns(), i);
jm.addLine(stmt, ".executeUpdate();");
getFinally(jm, stmt, null, null);
getFinally(jm, connection, new Object[]{JavaSource.getQuoted("Failed to execute query "),
" + ", query}, null);
return jm;