public si31mtEmpViewImpl()
{
}
protected void executeQueryForCollection(Object qcObj, Object[] params,
int noUserParams)
{
/*-------------------------------------------
If BC4J version is 9.0.5 or later, use the mechanism provided by
the framework.
-------------------------------------------*/
if (Version.major >= 9 && Version.revision >= 5)
{
if (Diagnostic.isOn())
{
Diagnostic.println("## 9.0.5 or later -- call super.executeQueryForCollection()");
}
/*-------------------------------------------
In 9.0.5 or later, you use RowQualifier to filter new rows
inserted through assoc-consistency.
-------------------------------------------*/
if (getRowQualifier() == null)
{
setRowQualifier(new RowQualifier("EmpDeptNum = 10"));
}
super.executeQueryForCollection(qcObj, params, noUserParams);
return;
}
isInExecuteQuery = true;
super.executeQueryForCollection(qcObj, params, noUserParams);
if (isAssociationConsistent())
{
/*-------------------------------------------
If assoc-consistent, then we need to find new entity rows,
create new view rows from them, and insert them.
-------------------------------------------*/
QueryCollection qc = (QueryCollection) qcObj;
int siz = qc.size();
/*-------------------------------------------
siz == 0 is a double check to make sure that super.executeQueryCollection()
didn't insert any rows in the QueryCollection.
-------------------------------------------*/
if (siz == 0)
{
if (Diagnostic.isOn())
{
Diagnostic.println("## Checking entity cache for new rows");
}
/* Get all entity rows from the entity cache. */
EntityDefImpl eDef = getEntityDef(0);
Iterator allERows = eDef.getAllEntityInstancesIterator(getDBTransaction());
while (allERows.hasNext())
{
EntityImpl eRow = (EntityImpl) allERows.next();
Integer deptNum = (Integer) eRow.getAttribute("EmpDeptNum");
/*-------------------------------------------
Look for new rows. Check to see if the EmpDeptNum attr
is 10.
-------------------------------------------*/
if ((eRow.getPostState() == EntityImpl.STATUS_NEW ||
eRow.getPostState() == EntityImpl.STATUS_INITIALIZED) &&
deptNum != null && deptNum.intValue() == 10)
{
/*-------------------------------------------
Create a new view row and set its entity row with
the one that we've just found.
-------------------------------------------*/
si31mtEmpViewRowImpl newRow = (si31mtEmpViewRowImpl) createRow();
/*-------------------------------------------
testSetEntity is a method on si31mtEmpViewRowImpl
to make setEntity(int, Entity) public.
-------------------------------------------*/
newRow.testSetEntity(0, eRow);
/* Find a good RowSet and insert it. */
RowSet[] rowSets = getRowSets();
for (int j = 0; j < rowSets.length; j++)
{
if (rowSets[j] instanceof ViewObjectImpl)
{
rowSets[j] = getDefaultRowSet();
}
if (((ViewRowSetImpl) rowSets[j]).getQueryCollection() == qc)
{
rowSets[j].insertRow(newRow);
break;
}
}
}
} /* end: while (allERows.hasNext()) */
} /* end: if (siz == 0) */
} /* end: if (isAssociationConsistent()) */
}
protected void notifyRowInserted(ViewRowSetImpl vrs, Row viewRow, int rowIndex)
{
/*-------------------------------------------
Skip rowInserted notification if the row was being
inserted by executeQueryForCollection.
-------------------------------------------*/
if (isInExecuteQuery == false)
{
super.notifyRowInserted(vrs, viewRow, rowIndex);
}
}
/*-------------------------------------------
We also need to handle sourceChanged. Logic is added to
handle only entity rows whose EmpDeptNum is 10.
-------------------------------------------*/
public void sourceChanged(EntityEvent event)
{
/*-------------------------------------------
In 9.0.5, the RowQualifier already does the work.
So, just call super and short-circuit.
-------------------------------------------*/
if (Version.major >= 9 && Version.revision >= 5)
{
if (Diagnostic.isOn())
{
Diagnostic.println("## 9.0.5 or later -- call super.sourceChanged()");
}
super.sourceChanged(event);
return;
}
EntityImpl eRow = event.getEntity();
int eventType = event.getEventType();
byte eRowPostState = eRow.getPostState();
if (eventType == EntityEvent.ATTRIBUTE_CHANGE)
{
Integer deptNum = (Integer) eRow.getAttribute("EmpDeptNum");
/* If we have a new row and if its EmpDeptNum is not 10, skip it. */
if ((eRowPostState == EntityImpl.STATUS_NEW ||
eRowPostState == EntityImpl.STATUS_INITIALIZED) &&
(deptNum == null || deptNum.intValue() != 10))
{
return;
}
}
super.sourceChanged(event);
}
}
===== si31mtEmpViewImpl.java END =====