JavaMethod jm = pSource.newJavaMethod("select", JavaQNameImpl.VOID, JavaSource.PUBLIC);
Parameter pObserver = jm.addParam(Observer.class, "pObserver");
Parameter pQuery = jm.addParam(String.class, "pQuery");
Parameter pParams = jm.addParam(PMParams.class, "pParams");
jm.addThrows(PMException.class);
Table table = pData.getTable();
JavaQName qName = pController.getComplexTypeSG().getClassContext().getXMLInterfaceName();
StringBuffer sb = new StringBuffer();
for (Iterator iter = table.getColumns(); iter.hasNext(); ) {
Column col = (Column) iter.next();
if (sb.length() > 0) sb.append(", ");
sb.append(col.getName().getName());
}
LocalJavaField query = jm.newJavaField(String.class);
jm.addIf(pParams, " != null && pParams.isDistinct()");
jm.addLine(query, " = ", JavaSource.getQuoted("SELECT DISTINCT"), ";");
jm.addElse();
jm.addLine(query, " = ", JavaSource.getQuoted("SELECT"), ";");
jm.addEndIf();
jm.addLine(query, " += ", JavaSource.getQuoted(" " + sb + " FROM " + table.getQName()), ";");
jm.addIf(pQuery, " != null");
jm.addLine(query, " += ", JavaSource.getQuoted(" WHERE "), " + ", pQuery, ";");
jm.addEndIf();
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();
LocalJavaField rs = jm.newJavaField(ResultSet.class);
rs.addLine(stmt, ".executeQuery();");
jm.addTry();
jm.addWhile(rs, ".next()");
LocalJavaField elem = jm.newJavaField(qName);
elem.addLine("(", qName, ") create()");
getResultSet(jm, rs, elem, table.getColumns(), 0);
jm.addLine(pObserver, ".notify(", elem, ");");
jm.addEndWhile();
getFinally(jm, rs, null, null);
getFinally(jm, stmt, null, null);