// jpa/1201: postgres 8.0.x/8.2.x compatibility
if (getMetaData() instanceof PostgresMetaData) {
item = _fromList.get(0);
EntityType type = item.getEntityType();
String targetId = type.getId().generateSelect(item.getName());
cb.append(" FROM ");
String tableName = item.getTable().getName();
cb.append(tableName);
cb.append(' ');
cb.append(item.getName());
isFirst = false;
cb.append(" where ");
cb.append(targetId);
cb.append(" = ");
cb.append(type.getId().generateSelect(item.getTable().getName()));
}
// jpa/1231, jpa/1202 vs jpa/1201 and jpa/1203
if (_fromList.size() > 1
&& ! getMetaData().supportsUpdateTableList()) {
// Postgres: jpa/1201 and Oracle: jpa/1203
item = _fromList.get(1);
EntityType type = item.getEntityType();
String relatedId = type.getId().generateSelect(item.getName());
if (isFirst) {
isFirst = false;
cb.append(" where ");
}
else
cb.append(" and ");
cb.append("exists (select ");
cb.append(relatedId);
cb.append(" from ");
generateFromList(cb, true);
// jpa/1231
isFirst = true;
}
for (int i = 0; i < _fromList.size(); i++) {
item = _fromList.get(i);
AmberExpr expr = item.getJoinExpr();
if (expr != null && ! item.isOuterJoin()) {
// jpa/1231
if (isFirst) {
isFirst = false;
cb.append(" where ");
}
else
cb.append(" and ");
expr.generateJoin(cb);
}
EntityType entityType = item.getEntityType();
// jpa/0l44
if (entityType != null) {
AmberColumn discriminator = entityType.getDiscriminator();
// jpa/0l43
if (entityType instanceof SubEntityType &&
discriminator != null) {
// jpa/0l12, jpa/0l4b
if (item.getTable() == discriminator.getTable()) {
if (isFirst) {
isFirst = false;
cb.append(" where ");
}
else
cb.append(" and ");
cb.append("(" + item.getName() + "." + discriminator.getName() + " = ");
cb.append("'" + entityType.getDiscriminatorValue() + "')");
}
}
}
}