private OrderExpression createJoinOrderExpression(PrimaryExpression expression) { PrimaryExpression primaryOrderExpr = new PrimaryExpression(expression.getTuples()); return new OrderExpression(primaryOrderExpr); }
/** * Convenience method that takes a PrimaryExpression and returns the path to apply to the * query in terms of a "descend" argument. * @param expr The PrimaryExpression * @return The path */ private String getPathForPrimaryExpression(PrimaryExpression expr) { // Find the path to apply. This currently only caters for direct fields, and fields of the candidate // TODO Cater for other candidate aliases from JPQL "FROM" clause String firstTuple = expr.getTuples().iterator().next(); String exprPath = expr.getId(); if (firstTuple.equals(candidateAlias)) { exprPath = exprPath.substring(candidateAlias.length()+1); } return exprPath; }
@Override protected Object processPrimaryExpression(PrimaryExpression expr) { Expression left = expr.getLeft(); if (left == null) { List<String> tuples = expr.getTuples(); PrimaryDetails primDetails = getFamilyColumnNameForPrimary(tuples); if (primDetails == null) { if (compileComponent == CompilationComponent.FILTER) { filterComplete = false; } NucleusLogger.QUERY.debug(">> Primary " + expr + " is not stored in this document, so unexecutable in datastore"); } else { HBaseFieldExpression fieldExpr = new HBaseFieldExpression(primDetails.type, primDetails.family, primDetails.column, primDetails.mmd, primDetails.mapping); stack.push(fieldExpr); return fieldExpr; } } // TODO Auto-generated method stub return super.processPrimaryExpression(expr); }
private String getAlias(Expression expr, Set<String> mappingAliases) { if (expr instanceof PrimaryExpression) { List<String> tuples = ((PrimaryExpression) expr).getTuples(); return tuples.size() > 1 ? tuples.get(0) : null; } else if (expr instanceof InvokeExpression) { return getAliasIfMapExpression((InvokeExpression) expr, mappingAliases); } return null; }
if (expr.getLeft() != null) if (expr.getLeft() instanceof DyadicExpression && expr.getLeft().getOperator() == Expression.OP_CAST) if (expr.getLeft().getLeft() instanceof PrimaryExpression) exprCastName = "CAST_" + ((PrimaryExpression)expr.getLeft().getLeft()).getId(); else if (expr.getLeft().getLeft() instanceof VariableExpression) exprCastName = "CAST_" + ((VariableExpression)expr.getLeft().getLeft()).getId(); else if (expr.getLeft().getLeft() instanceof InvokeExpression) exprCastName = "CAST_" + expr.getLeft().getLeft(); throw new NucleusException("Don't currently support cast of " + expr.getLeft().getLeft()); expr.getLeft().getLeft().evaluate(this); sqlExpr = stack.pop(); JavaTypeMapping mapping = sqlExpr.getJavaTypeMapping(); Literal castLitExpr = (Literal)expr.getLeft().getRight(); Class castType = resolveClass((String)castLitExpr.getLiteral()); AbstractClassMetaData castCmd = ec.getMetaDataManager().getMetaDataForClass(castType, clr); expr.getLeft().evaluate(this); sqlExpr = stack.pop();
/** * Method to process the supplied primary expression. * @param expr The expression * @return The result */ protected Object processPrimaryExpression(PrimaryExpression expr) { Object value = (parameters != null ? parameters.get(expr.getId()) : null); if (value != null) { // Parameter/Variable stack.push(value); return value; } // Just push the PrimaryExpression on to the stack and handle it elsewhere since we likely need the whole list of tuples to specify the Where stack.push(expr); return expr; }
String joinAlias = indexExpr.getId(); String collExprName = joinAlias; if (explicitJoinPrimaryByAlias != null) tuples.add(token); PrimaryExpression collPrimExpr = new PrimaryExpression(tuples); processPrimaryExpression(collPrimExpr); SQLExpression collSqlExpr = stack.pop();
if (forceJoin == null && primExpr.getParent() != null) if (primExpr.getParent().getOperator() == Expression.OP_IS || primExpr.getParent().getOperator() == Expression.OP_ISNOT) List<String> tuples = primExpr.getTuples(); if (primExpr.getParent() != null && primExpr.getParent().getOperator() == Expression.OP_CAST) Operator op = (primExpr.getParent() != null ? primExpr.getParent().getOperator() : null); if (!iter.hasNext() && (op == Expression.OP_EQ || op == Expression.OP_GT || op == Expression.OP_LT || op == Expression.OP_GTEQ || op == Expression.OP_LTEQ || op == Expression.OP_NOTEQ))
private void getFieldNameList(SObject[] sObjects, boolean createFieldNameExpressions, List<String> fieldNameList, List<Expression> fieldNameExprs) { Iterator<XmlObject> fieldIter = sObjects[0].getChildren(); /** * Skip the first two items. First item is "type" and second is "id". * If we have selected id then it will show up again in the list. */ for (int i = 0; fieldIter.hasNext(); i++) { XmlObject xo = fieldIter.next(); String name = xo.getName().getLocalPart(); if (i < 2) continue; fieldNameList.add(name); if (createFieldNameExpressions) { fieldNameExprs.add(new PrimaryExpression(Arrays.asList(name))); } } }
@Override protected Object processPrimaryExpression(PrimaryExpression expr) Expression left = expr.getLeft(); if (left == null)
private String getAlias(Expression expr, Set<String> mappingAliases) { if (expr instanceof PrimaryExpression) { List<String> tuples = ((PrimaryExpression) expr).getTuples(); return tuples.size() > 1 ? tuples.get(0) : null; } else if (expr instanceof InvokeExpression) { return getAliasIfMapExpression((InvokeExpression) expr, mappingAliases); } return null; }
/** * @param qd The QueryData * @param orderExpr The OrderExpression * @return The name of the sort property that was added to the primary datastore query. */ String getSortProperty(QueryData qd, OrderExpression orderExpr) { PrimaryExpression left = (PrimaryExpression) orderExpr.getLeft(); AbstractClassMetaData acmd = qd.acmd; List<String> tuples = getTuples(left, qd.compilation.getCandidateAlias()); if (isJoin(left.getLeft(), tuples)) { // Change the class meta data to the meta-data for the joined class acmd = getJoinClassMetaData(left.getLeft(), tuples, qd); } AbstractMemberMetaData ammd = getMemberMetaDataForTuples(acmd, tuples); if (ammd == null) { throw noMetaDataException(left.getId(), acmd.getFullClassName()); } if (MetaDataUtils.isParentPKField(ammd)) { throw new UnsupportedDatastoreFeatureException("Cannot sort by parent."); } else { String sortProp; if (ammd.isPrimaryKey()) { sortProp = Entity.KEY_RESERVED_PROPERTY; } else { sortProp = determinePropertyName(ammd); } return sortProp; } }
/** * Method to return the path as something suitable for use as JPQL single-string. * @return The JPQL form */ public String toString() { return ((PrimaryExpression)getQueryExpression()).getId(); } }
private void getFieldNameList(SObject[] sObjects, boolean createFieldNameExpressions, List<String> fieldNameList, List<Expression> fieldNameExprs) { Iterator<XmlObject> fieldIter = sObjects[0].getChildren(); /** * Skip the first two items. First item is "type" and second is "id". * If we have selected id then it will show up again in the list. */ for (int i = 0; fieldIter.hasNext(); i++) { XmlObject xo = fieldIter.next(); String name = xo.getName().getLocalPart(); if (i < 2) continue; fieldNameList.add(name); if (createFieldNameExpressions) { fieldNameExprs.add(new PrimaryExpression(Arrays.asList(name))); } } }
/** * Given a list of expressions in a.b.c format return a list of expressions that are only field names, 'c' in this example. * @param exprs - expressions to convert * @return - returns an array of expressions that only contain the field name */ private Expression[] toShortNameExpressions(Expression[] exprs) { if (exprs == null || exprs.length == 0) return exprs; Expression[] shortNameExpr = new Expression[exprs.length]; for (int i = 0; i < exprs.length; i++) { if (exprs[i] instanceof PrimaryExpression) { List<String> t = ((PrimaryExpression) exprs[i]).getTuples(); shortNameExpr[i] = new PrimaryExpression(Arrays.asList(t.get(t.size() - 1))); } else { shortNameExpr[i] = exprs[i]; } } return shortNameExpr; }
/** * Fetches the tuples of the provided expression, stripping off the first * tuple if there are multiple tuples, the table name is aliased, and the * first tuple matches the alias. */ private List<String> getTuples(PrimaryExpression expr, String alias) { List<String> tuples = Utils.newArrayList(); tuples.addAll(expr.getTuples()); return getTuples(tuples, alias); }
/** * Convenience method that takes a PrimaryExpression and returns the path to apply to the * query in terms of a "descend" argument. * @param expr The PrimaryExpression * @return The path */ private String getPathForPrimaryExpression(PrimaryExpression expr) { // Find the path to apply. This currently only caters for direct fields, and fields of the candidate // TODO Cater for other candidate aliases from JPQL "FROM" clause String firstTuple = (String)expr.getTuples().iterator().next(); String exprPath = expr.getId(); if (firstTuple.equals(candidateAlias)) { exprPath = exprPath.substring(candidateAlias.length()+1); } return exprPath; }
/** * Method to process the supplied primary expression. * @param expr The expression * @return The result */ protected Object processPrimaryExpression(PrimaryExpression expr) { Object value = (parameters != null ? parameters.get(expr.getId()) : null); if (value != null) { stack.push(value); return value; } String exprPath = getPathForPrimaryExpression(expr); Query q = query.descend(exprPath); if (NucleusLogger.QUERY.isDebugEnabled()) { NucleusLogger.QUERY.debug(LOCALISER_DB4O.msg("DB4O.SODA.Query", "query.descend(\"" + exprPath + "\")")); } stack.push(q); return q; }