ta.getType(),
targetReferFld,
pkFld,
many.key());
}
ManyMany mm = field.getAnnotation(ManyMany.class);
if (null != mm) {
// Read relation
Statement stat = null;
ResultSet rs = null;
ResultSetMetaData rsmd = null;
boolean fromName = false;
boolean toName = false;
try {
stat = conn.createStatement();
Segment tableName = new CharSegment(mm.relation());
rs = stat.executeQuery(db.getResultSetMetaSql(TableName.render(tableName)));
rsmd = rs.getMetaData();
fromName = !Daos.isIntLikeColumn(rsmd, mm.from());
toName = !Daos.isIntLikeColumn(rsmd, mm.to());
}
catch (Exception e) {
if (log.isWarnEnabled())
log.warnf("Fail to get table '%s', '%s' and '%s' "
+ "will be taken as @Id ", mm.relation(), mm.from(), mm.to());
}
finally {
Daos.safeClose(stat, rs);
}
Mirror<?> ta = Mirror.me(mm.target());
Field selfPk = mirror.getField(fromName ? Name.class : Id.class);
Field targetPk = ta.getField(toName ? Name.class : Id.class);
return Link.getLinkForManyMany( mirror,
field,
ta.getType(),
selfPk,
targetPk,
mm.key(),
mm.relation(),
mm.from(),
mm.to());
// return Link.getLinkForManyMany(mirror, field, mm.target(),
// mm.key(), mm.from(), mm
// .to(), mm.relation(), fromName, toName);
}
}