protected void setRelatedMocks(Object mockObj, boolean ignoreNulls,
IClassDbMetadata classMetadata) {
for (Map.Entry<Method, ColumnRelationshipMetadata> relationColumn :
classMetadata.getColumnsByRelationship().entrySet()) {
ColumnRelationshipMetadata columnMetadata = relationColumn.getValue();
Relationship relationship = columnMetadata.getRelationship();
Class<?> relatedType;
IClassDbMetadata relatedClassMetadata;
Object relatedMockObj;
switch (relationship) {
case ONE_TO_ONE:
/*
* Get the type and create a mock object from it.
*/
relatedType = columnMetadata.getType();
relatedClassMetadata =
getAnnotationManager().getClassMetadata(relatedType);
relatedMockObj = mock(relatedType, ignoreNulls,
relationship);
//add table
getQuery().addTable(relatedClassMetadata.getPrimaryTable());
//match identity columns
addMatchedCriteriaSetter(
relatedClassMetadata.getIdentityColumn(),
classMetadata.getIdentityColumn(), ignoreNulls);
//add child mock
if(columnMetadata.hasSetter()) {
try {
columnMetadata.getSetterMethod().invoke(mockObj, relatedMockObj);
getController().clearLastInvocation();
} catch (IllegalArgumentException exp) {
LOG.error(exp.getMessage());
LOG.debug("Details :", exp);
}
catch (IllegalAccessException exp) {}
catch (InvocationTargetException exp) {}
}
else {
LOG.error("Could not find setter for relationship");
}
break;
case ONE_TO_MANY:
// /*
// * Get the type and create a mock object from it.
// */
relatedType = columnMetadata.getReturnTypeInfo()
.getGenericArgumentType();
relatedClassMetadata =
getAnnotationManager().getClassMetadata(relatedType);
// relatedMockObj = mock(relatedType, ignoreNulls,
// relationship);
//add table
getQuery().addTable(relatedClassMetadata.getPrimaryTable());
//match identity columns
addMatchedCriteriaSetter(
relatedClassMetadata.getColumns().get(columnMetadata.getMappedBy()),
classMetadata.getIdentityColumn(),
ignoreNulls);
// //add child mock
// if(columnMetadata.hasSetter()) {