public Object visit(ASTMemberOf node, Object data)
{
Node member = node.jjtGetChild(0);
ASTPath colPath = (ASTPath) node.jjtGetChild(1);
JDBCAbstractEntityBridge colEntity = (JDBCAbstractEntityBridge) colPath.getEntity();
StringBuffer sql = (StringBuffer) data;
if(node.not)
{
sql.append(SQLUtil.NOT);
}
sql.append(SQLUtil.EXISTS).append('(').append(SQLUtil.SELECT);
if(member instanceof ASTParameter)
{
ASTParameter toParam = (ASTParameter) member;
verifyParameterEntityType(toParam.number, colEntity);
inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, colEntity));
String parentAlias = aliasManager.getAlias(colPath.getPath(0));
String localParentAlias = aliasManager.getAlias(colPath.getPath(0) + "_local");
JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge) colPath.getEntity(0);
SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), localParentAlias, sql);
sql.append(SQLUtil.FROM)
.append(parentEntity.getQualifiedTableName()).append(' ').append(localParentAlias);
innerJoinPath(colPath, sql);
sql.append(SQLUtil.WHERE);
JDBCAbstractEntityBridge col0 = (JDBCAbstractEntityBridge)colPath.getEntity(0);
SQLUtil.getSelfCompareWhereClause(col0.getPrimaryKeyFields(), parentAlias, localParentAlias, sql);
sql.append(SQLUtil.AND);
String localColAlias = aliasManager.getAlias(colPath.getPath() + "_local");
SQLUtil.getWhereClause(colEntity.getPrimaryKeyFields(), localColAlias, sql);
}
else
{
ASTPath memberPath = (ASTPath) member;
JDBCAbstractEntityBridge memberEntity = (JDBCAbstractEntityBridge) memberPath.getEntity();
if(!memberEntity.equals(colEntity))
{
throw new IllegalStateException("Member must be if the same type as the collection, got: member="
+
memberEntity.getEntityName()
+ ", collection=" + colEntity.getEntityName());
}
String memberAlias = aliasManager.getAlias(memberPath.getPath());
if(memberPath.size() > 1)
{
String parentAlias = aliasManager.getAlias(memberPath.getPath(0) + "_local");
JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge) memberPath.getEntity(0);
SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), parentAlias, sql);
sql.append(SQLUtil.FROM)
.append(parentEntity.getQualifiedTableName()).append(' ').append(parentAlias);
innerJoinPath(memberPath, sql);
innerJoinPath(colPath, sql);
}
else if(colPath.size() > 1)
{
String parentAlias = aliasManager.getAlias(colPath.getPath(0) + "_local");
JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge) colPath.getEntity(0);
SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), parentAlias, sql);
sql.append(SQLUtil.FROM)
.append(parentEntity.getQualifiedTableName()).append(' ').append(parentAlias);
innerJoinPath(colPath, sql);
}
else
{
throw new IllegalStateException(
"There should be collection valued path expression, not identification variable.");
}
sql.append(SQLUtil.WHERE);
JDBCAbstractEntityBridge member0 = (JDBCAbstractEntityBridge)memberPath.getEntity(0);
String colAliasLocal = aliasManager.getAlias(colPath.getPath() + "_local");
if(memberPath.size() > 1)
{
String memberAliasLocal = aliasManager.getAlias(memberPath.getPath() + "_local");
SQLUtil.getSelfCompareWhereClause(colEntity.getPrimaryKeyFields(),
memberAliasLocal,
colAliasLocal,
sql);
sql.append(SQLUtil.AND);
String member0Alias = aliasManager.getAlias(memberPath.getPath(0));
String member0AliasLocal = aliasManager.getAlias(memberPath.getPath(0) + "_local");
SQLUtil.getSelfCompareWhereClause(member0.getPrimaryKeyFields(),
member0Alias,
member0AliasLocal,
sql);
}
else
{
SQLUtil.getSelfCompareWhereClause(member0.getPrimaryKeyFields(), memberAlias, colAliasLocal, sql);
sql.append(SQLUtil.AND);
String col0Alias = aliasManager.getAlias(colPath.getPath(0));
String col0AliasLocal = aliasManager.getAlias(colPath.getPath(0) + "_local");