* @param query Type: BusinessQuery
*/
public void update(@Input BusinessQuery query) {
SqlQuery sQLquery = query.getSqlQuery(this.getDB());
Array_Of_TextData<TextData> queries = null;
IBusinessMgr mgr = null;
int mgrIndex = 0;
if (this.getReadOnly()) {
throw new Error(Error.BM_CANT_UPDATE, "UpdateQuery", this).getException();
}
//
// Build the SQL query that needs to be executed. query describes what needs
// to be done in terms of the BusinessClass. BuildQuery returns an SQLquery
// which describes what needs to be done in terms of SQL.
//
// ---------------------------------
// Parameters for call to BuildQuery
// ---------------------------------
ParameterHolder_SqlQuery qq_query = new ParameterHolder_SqlQuery(sQLquery);
query.buildQuery(qq_query);
sQLquery = (SqlQuery)qq_query.getObject();
//
// Delete operations get processed on dependent entities first so we do not
// run afoul of any referential integrity constraints in the database.
//
if (sQLquery.getOperation() == BusinessQuery.OP_DELETE) {
Array_Of_BusinessQuery<BusinessQuery> qq_localVector = query.getForeignClasses();
if (qq_localVector != null) {
for (BusinessQuery f : qq_localVector) {
mgrIndex = query.getForeignAttrMgr(f.getParentAttr());
if (mgrIndex > 0) {
mgr = this.getForeignMgrs().get(mgrIndex-1);
if (!(mgr.getReadOnly())) {
mgr.update(f);
}
}
}
}
}
//
// Get the SQL text of the queries to be executed. There can be more than
// one because a BusinessClass can be comprised of more than one databaes
// table and only one table can be updated by a single query (which is
// different than select where lots of tables can be selected from).
//
queries = sQLquery.getText();
switch (sQLquery.getOperation()) {
case BusinessQuery.OP_INSERT: {
for (int i1 = 1; i1 <= queries.size(); i1++) {
this.SQLinsert(sQLquery, queries.get(i1-1), sQLquery.getData().get(i1-1));
}
break;
}
case BusinessQuery.OP_UPDATE: {
for (int i1 = 1; i1 <= queries.size(); i1++) {
this.SQLupdate(sQLquery, queries.get(i1-1), sQLquery.getData().get(i1-1));
}
break;
}
case BusinessQuery.OP_DELETE: {
for (int i1 = queries.size(); i1 >= 1; i1--) {
this.SQLdelete(sQLquery, queries.get(i1-1), sQLquery.getData().get(i1-1));
}
break;
}
}
// And now we need to run any dependent queries, unless of course this
// was a delete we already took care of those.
//
if (sQLquery.getOperation() != BusinessQuery.OP_DELETE) {
Array_Of_BusinessQuery<BusinessQuery> qq_localVector = query.getForeignClasses();
if (qq_localVector != null) {
for (BusinessQuery f : qq_localVector) {
mgrIndex = query.getForeignAttrMgr(f.getParentAttr());
if (mgrIndex > 0) {
mgr = this.getForeignMgrs().get(mgrIndex-1);
if (!(mgr.getReadOnly())) {
mgr.update(f);
}
}
}
}
}