mapTbl, null, mapTbl.getOwnerMapping(), null, null);
if (valCmd != null)
{
if (valIsUnbound)
{
DatastoreClass valTbl = storeMgr.getDatastoreClass(valCmd.getFullClassName(), clr);
SQLTable valSqlTbl = stmt.innerJoin(joinSqlTbl, mapTbl.getValueMapping(),
valTbl, valAlias, valTbl.getIdMapping(), null, null);
// Bind the variable in the QueryGenerator
valExpr = exprFactory.newExpression(stmt, valSqlTbl, valSqlTbl.getTable().getIdMapping());
stmt.getQueryGenerator().bindVariable(varName, valCmd, valExpr.getSQLTable(),
valExpr.getJavaTypeMapping());
}
else
{
// Add restrict to value
SQLExpression valIdExpr = exprFactory.newExpression(stmt, joinSqlTbl, mapTbl.getValueMapping());
stmt.whereAnd(valIdExpr.eq(valExpr), true);
}
}
else
{
if (valIsUnbound)
{
// Bind the variable in the QueryGenerator
valExpr = exprFactory.newExpression(stmt, joinSqlTbl, mapTbl.getValueMapping());
stmt.getQueryGenerator().bindVariable(varName, valCmd, valExpr.getSQLTable(),
valExpr.getJavaTypeMapping());
}
else
{
// Add restrict to value
SQLExpression valIdExpr = exprFactory.newExpression(stmt, joinSqlTbl, mapTbl.getValueMapping());
stmt.whereAnd(valIdExpr.eq(valExpr), true);
}
}
}
else if (mmd.getMap().getMapType() == MapType.MAP_TYPE_KEY_IN_VALUE)
{
// Map formed in value table - add join to value table
DatastoreClass valTbl = storeMgr.getDatastoreClass(valCmd.getFullClassName(), clr);
JavaTypeMapping ownerMapping = null;
if (mmd.getMappedBy() != null)
{
ownerMapping = valTbl.getMemberMapping(valCmd.getMetaDataForMember(mmd.getMappedBy()));
}
else
{
ownerMapping = valTbl.getExternalMapping(mmd, MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
}
SQLTable valSqlTbl = stmt.innerJoin(mapExpr.getSQLTable(), mapExpr.getSQLTable().getTable().getIdMapping(),
valTbl, valAlias, ownerMapping, null, null);
if (valIsUnbound)
{
// Bind the variable in the QueryGenerator
valExpr = exprFactory.newExpression(stmt, valSqlTbl, valTbl.getIdMapping());
stmt.getQueryGenerator().bindVariable(varName, valCmd, valExpr.getSQLTable(),
valExpr.getJavaTypeMapping());
}
else
{
// Add restrict to value
SQLExpression valIdExpr = exprFactory.newExpression(stmt, valSqlTbl, valTbl.getIdMapping());
stmt.whereAnd(valIdExpr.eq(valExpr), true);
}
}
else if (mmd.getMap().getMapType() == MapType.MAP_TYPE_VALUE_IN_KEY)
{
// Map formed in key table - add join to key table then to value table
AbstractClassMetaData keyCmd = mmd.getMap().getKeyClassMetaData(clr, mmgr);
DatastoreClass keyTbl = storeMgr.getDatastoreClass(keyCmd.getFullClassName(), clr);
AbstractMemberMetaData keyValMmd =
keyCmd.getMetaDataForMember(mmd.getValueMetaData().getMappedBy());
JavaTypeMapping ownerMapping = null;
if (mmd.getMappedBy() != null)
{
ownerMapping = keyTbl.getMemberMapping(keyCmd.getMetaDataForMember(mmd.getMappedBy()));
}
else
{
ownerMapping = keyTbl.getExternalMapping(mmd, MappingConsumer.MAPPING_TYPE_EXTERNAL_FK);
}
SQLTable keySqlTbl = stmt.innerJoin(mapExpr.getSQLTable(), mapExpr.getSQLTable().getTable().getIdMapping(),
keyTbl, null, ownerMapping, null, null);
if (valCmd != null)
{
DatastoreClass valTbl = storeMgr.getDatastoreClass(valCmd.getFullClassName(), clr);
SQLTable valSqlTbl = stmt.innerJoin(keySqlTbl, keyTbl.getMemberMapping(keyValMmd),
valTbl, valAlias, valTbl.getIdMapping(), null, null);
if (valIsUnbound)
{
// Bind the variable in the QueryGenerator
valExpr = exprFactory.newExpression(stmt, valSqlTbl, valTbl.getIdMapping());
stmt.getQueryGenerator().bindVariable(varName, valCmd, valExpr.getSQLTable(),
valExpr.getJavaTypeMapping());
}
else
{
// Add restrict to value
SQLExpression valIdExpr = exprFactory.newExpression(stmt, valSqlTbl, valTbl.getIdMapping());
stmt.whereAnd(valIdExpr.eq(valExpr), true);
}
}
else
{