use of org.datanucleus.store.query.compiler.Symbol in project datanucleus-rdbms by datanucleus.
the class QueryToSQLMapper method processUnboundExpression.
protected SQLExpression processUnboundExpression(UnboundExpression expr) {
String varName = expr.getVariableName();
Symbol varSym = compilation.getSymbolTable().getSymbol(varName);
SQLExpression sqlExpr = bindVariable(expr, varSym.getValueType());
if (sqlExpr != null) {
stack.push(sqlExpr);
return sqlExpr;
}
throw new NucleusUserException("Variable '" + varName + "' is unbound and cannot be determined (is it a misspelled field name? or is not intended to be a variable?)");
}
use of org.datanucleus.store.query.compiler.Symbol in project datanucleus-rdbms by datanucleus.
the class QueryToSQLMapper method compile.
/**
* Method to update the supplied SQLStatement with the components of the specified query.
* During the compilation process this updates the SQLStatement "compileComponent" to the
* component of the query being compiled.
*/
public void compile() {
if (NucleusLogger.QUERY.isDebugEnabled() && parentMapper == null) {
// Give debug output of compilation
StringBuilder str = new StringBuilder("JoinType : navigation(default=");
str.append(defaultJoinType != null ? defaultJoinType : "(using nullability)");
str.append(", filter=");
str.append(defaultJoinTypeFilter != null ? defaultJoinTypeFilter : "(using nullability)");
str.append(")");
if (extensionsByName != null) {
Iterator<Map.Entry<String, Object>> extensionsIter = extensionsByName.entrySet().iterator();
while (extensionsIter.hasNext()) {
Map.Entry<String, Object> entry = extensionsIter.next();
String key = entry.getKey();
if (key.startsWith("datanucleus.query.jdoql.") && key.endsWith(".join")) {
// Alias join definition
String alias = key.substring("datanucleus.query.jdoql.".length(), key.lastIndexOf(".join"));
str.append(", ").append(alias).append("=").append(entry.getValue());
}
}
}
NucleusLogger.QUERY.debug("Compile of " + compilation.getQueryLanguage() + " into SQL - " + str);
}
compileFrom();
compileFilter();
if (stmt instanceof UpdateStatement) {
compileUpdate((UpdateStatement) stmt);
} else if (stmt instanceof SelectStatement) {
SelectStatement selectStmt = (SelectStatement) stmt;
// the datastore doesn't allow select of some field types when used with DISTINCT
if (compilation.getResultDistinct()) {
selectStmt.setDistinct(true);
} else if (!options.contains(OPTION_EXPLICIT_JOINS) && compilation.getExprResult() == null) {
// Joins are made implicitly and no result so set distinct based on whether joining to other table groups
if (selectStmt.getNumberOfTableGroups() > 1) {
// Queries against an extent always consider only distinct candidate instances, regardless of whether distinct is specified (JDO spec)
if (!options.contains(OPTION_NON_DISTINCT_IMPLICIT_JOINS)) {
// If user can guarantee distinct w/ query no reason to take performance hit of distinct clause
selectStmt.setDistinct(true);
}
}
}
compileResult(selectStmt);
compileGrouping(selectStmt);
compileHaving(selectStmt);
compileOrdering(selectStmt);
}
// Check for variables that haven't been bound to the query (declared but not used)
for (String symbol : compilation.getSymbolTable().getSymbolNames()) {
Symbol sym = compilation.getSymbolTable().getSymbol(symbol);
if (sym.getType() == Symbol.VARIABLE) {
if (compilation.getCompilationForSubquery(sym.getQualifiedName()) == null && !hasSQLTableMappingForAlias(sym.getQualifiedName())) {
// Variable not a subquery, nor had its table allocated
throw new QueryCompilerSyntaxException("Query has variable \"" + sym.getQualifiedName() + "\" which is not bound to the query");
}
}
}
}
Aggregations