/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package reportgen.cores.ejb;
import java.util.Collection;
import org.jdom.Element;
import reportgen.prototype.QCoreInlineSQL;
import reportgen.prototype.utils.RowCount;
import reportgen.utils.ReportException;
import reportgen.prototype.context.Context;
import reportgen.prototype.entity.QSQLBuilder;
import reportgen.prototype.stream.SQLStream;
/**
* @author axe
*/
class CoreInlineSQL extends CoreInline implements QCoreInlineSQL {
public CoreInlineSQL(Element element, Context context) throws ReportException {
super(element, context);
}
public CoreInlineSQL(String title, Context context) {
super(title, context);
}
@Override
public RowCount getRowCount() {
return null;
}
@Override
public void setRowCount(RowCount rowCount) {
//do nothing
}
@Override
protected Context getCoreContext() {
return getSQLContext();
}
@Override
public Class getCls() throws ReportException {
return Collection.class;
}
@Override
public void appendToQuery(SQLStream sql) throws ReportException {
QSQLBuilder builder = root.getSQLBuilder(getLoadable());
if(getResult().isEmpty()) {
throw new ReportException("Не выбрано ни одного объекта или свойства объекта");
}
String entities = builder.getSQLEntities();
String links = builder.getSQLEntityLinks();
sql.append("(SELECT ");
sql.append(isDistinct() ? "DISTINCT ":"");
getResult().appendToQuery(sql, null);
sql.append(" FROM " + entities);
sql.append(links.length() > 0 ? " WHERE "+links:"");
if(!getConditions().isEmptyOnMissingVariables()) {
sql.append(links.length() > 0 ? " AND ":" WHERE ");
getConditions().appendToQuery(sql, null);
}
sql.append(")");
}
}