Package ch.epfl.labos.iu.orm.query2

Examples of ch.epfl.labos.iu.orm.query2.ParameterLocation$LambdaCapturedArg


               where.add(")");
               lambdaContext.joins.addWhere(where);
            }
            lambdaContext.joins.addCachedJoin(link.fromEntity, link.name, fromKey, from);
         }
         EntityManagerBackdoor em = lambdaContext.joins.getEntityManager();
         SQLColumnValues joinedEntity = new SQLColumnValues<T>(em.getReaderForEntity(link.toEntity));
         String []columnNames = em.getEntityColumnNames(link.toEntity);
         for (int n = 0; n < columnNames.length; n++)
         {
            SQLFragment fragment = new SQLFragment();
            fragment.add(from);
            fragment.add("." + columnNames[n]);
View Full Code Here


   {
      MethodSignature sig = val.getSignature();
      if (entityInfo.allEntityMethods.containsKey(sig))
      {
         String entityName = entityInfo.allEntityMethods.get(sig);
         EntityManagerBackdoor em = getAndCheckEntityManager(val.base);
         if (em == null)
            throw new TypedValueVisitorException("Accessing an unknown entity manager");
         return new SQLQuery.SelectFromWhere<T>(
               em.getReaderForEntity(entityName),
               em.getEntityColumnNames(entityName),
               em.getTableForEntity(entityName));
      }
      else
         return super.virtualMethodCallValue(val, in);
   }
View Full Code Here

               // TODO: Careful here. ParameterLocation is relative to the base
               // lambda, but if we arrive here from inside a nested query, "this"
               // might refer to a lambda nested inside the base lambda. (Of course,
               // nested queries with parameters aren't currently supported, so it
               // doesn't matter.)
               ParameterLocation paramLoc = ParameterLocation.createJava8LambdaArgAccess(val.getIndex(), lambdaIndex);
               SQLColumnValues toReturn = new SQLColumnValues(allowedQueryParameterTypes.get(t));
               assert(toReturn.getNumColumns() == 1);
               toReturn.columns[0].add(new SQLSubstitution.ExternalParameterLink(paramLoc));
               return toReturn;
            } catch (Exception e)
View Full Code Here

            // TODO: Careful here. ParameterLocation is relative to the base
            // lambda, but if we arrive here from inside a nested query, "this"
            // might refer to a lambda nested inside the base lambda. (Of course,
            // nested queries with parameters aren't currently supported, so it
            // doesn't matter.)
            ParameterLocation paramLoc = ParameterLocation.createThisFieldAccess(val.name, lambdaIndex);
//            Object param = paramLoc.getParameter(lambda);
            SQLColumnValues toReturn = new SQLColumnValues(allowedQueryParameterTypes.get(t));
            assert(toReturn.getNumColumns() == 1);
            toReturn.columns[0].add(new SQLSubstitution.ExternalParameterLink(paramLoc));
            return toReturn;
View Full Code Here

                  new ParamHandler<Object>(lambdaThisIndex, test, emSource),
                  SelectFromWhereExtensionJoin.fromSfw(sfw, (EntityManagerBackdoor)emSource),
                  this);

         try {
            SQLFragment newWhere = new SQLFragment();
            if (analysis.paths.size() > 1)
            {
               for (PathAnalysis path: analysis.paths)
               {
                  TypedValue pathReturn = path.getSimplifiedIsTrueReturnValue();
                  if (pathReturn instanceof ConstantValue.IntegerConstant
                        && ((ConstantValue.IntegerConstant)pathReturn).val == 0)
                     continue;
                  SQLFragment pathWhere = new SQLFragment();
                  if (pathReturn instanceof ConstantValue.IntegerConstant
                        && ((ConstantValue.IntegerConstant)pathReturn).val != 0)
                  {
                     // do nothing
                  }
                  else
                  {
                     SQLColumnValues colVals = gen.generateFor(pathReturn);
                     assert(colVals.getNumColumns() == 1);
                     pathWhere.add("(");
                     pathWhere.add(colVals.columns[0]);
                     pathWhere.add(")");
                  }
                  for (TypedValue condition: path.getSimplifiedConditions())
                  {
                     if (condition instanceof ConstantValue.IntegerConstant
                           && ((ConstantValue.IntegerConstant)condition).val != 0)
                        continue;
                     if (condition instanceof ConstantValue.IntegerConstant
                           && ((ConstantValue.IntegerConstant)condition).val == 0)
                     {
                        if (!pathWhere.isEmpty())
                           pathWhere.add(" AND ");
                        pathWhere.add("(1<>1)");
                     }
                     else
                     {
                        SQLColumnValues condColVals = gen.generateFor(condition);
                        assert(condColVals.getNumColumns() == 1);
                        if (!pathWhere.isEmpty())
                           pathWhere.add(" AND ");
                        pathWhere.add("(");
                        pathWhere.add(condColVals.columns[0]);
                        pathWhere.add(")");
                     }
                  }
                  if (!pathWhere.isEmpty())
                  {
                     if (!newWhere.isEmpty())
                        newWhere.add(" OR ");
                     newWhere.add("(");
                     newWhere.add(pathWhere);
                     newWhere.add(")");
                  }
               }
            }
            else
            {
               PathAnalysis path = analysis.paths.get(0);
               SQLColumnValues colVals = gen.generateFor(path.getSimplifiedReturnValue());
               assert(colVals.reader.getNumColumns() == 1);
               if (!newWhere.isEmpty())
                  newWhere.add(" OR ");
               newWhere.add("(");
               newWhere.add(colVals.columns[0]);
               newWhere.add(")");
            }
           
            if (!sfw.where.isEmpty())
            {
               SQLFragment sql = new SQLFragment("(");
               sql.add(sfw.where);
               sql.add(") AND (");
               sql.add(newWhere);
               sql.add(")");
               sfw.where = sql;
            }
            else
               sfw.where = newWhere;
            return sfw;
View Full Code Here

      SQLFragment [] wheres = new SQLFragment[analysis.paths.size()];
      SQLColumnValues[] selects = new SQLColumnValues[analysis.paths.size()];
      for (int n = 0; n < analysis.paths.size(); n++)
      {
         PathAnalysis path = analysis.paths.get(n);
         wheres[n] = new SQLFragment();
         selects[n] = gen.generateFor(path.getSimplifiedReturnValue());
         for (TypedValue condition: path.getSimplifiedConditions())
         {
            if (condition instanceof ConstantValue.IntegerConstant
                  && ((ConstantValue.IntegerConstant)condition).val != 0)
               continue;
            if (condition instanceof ConstantValue.IntegerConstant
                  && ((ConstantValue.IntegerConstant)condition).val == 0)
            {
               if (!wheres[n].isEmpty())
                  wheres[n].add(" AND ");
               wheres[n].add("(1<>1)");
            }
            else
            {
               SQLColumnValues condColVals = gen.generateFor(condition);
               assert(condColVals.getNumColumns() == 1);
               if (!wheres[n].isEmpty())
                  wheres[n].add(" AND ");
               wheres[n].add("(");
               wheres[n].add(condColVals.columns[0]);
               wheres[n].add(")");
            }
         }
      }
     
      // TODO: Check that return type and number of columns is the same
      // for all paths
      SQLReader reader = selects[0].reader;
      if (wheres.length > 1)
      {
         for (int n = 0; n < selects[0].columns.length; n++)
         {
            SQLFragment col = new SQLFragment();
            boolean isAllSame = true;
            for (SQLColumnValues pathSql: selects)
            {
               if (!pathSql.columns[n].equals(selects[0].columns[n]))
                  isAllSame = false;
            }
            if (!isAllSame)
            {
               col.add("CASE");
               for (int i = 0; i < selects.length - 1; i++)
               {
                  col.add(" WHEN ");
                  if (wheres[i].isEmpty())
                     col.add("(1=1)");
                  else
                     col.add(wheres[i]);
                  col.add(" THEN ");
                  col.add(selects[i].columns[n]);
               }
               col.add(" ELSE ");
               col.add(selects[selects.length-1].columns[n]);
               col.add(" END");
            }
            else
               col = selects[0].columns[n];
            columns.add(col);
         }
View Full Code Here

                     this);
            List<SQLFragment> columns = new ArrayList<SQLFragment>();
            sfw.reader = generateSelect(analysis, gen, columns);
            assert(desiredSQLReader.isInstance(sfw.reader));
            assert(columns.size() == 1);
            SQLFragment summedColumn = new SQLFragment();
            summedColumn.add(aggregateOperator + "(");
            summedColumn.add(columns.get(0));
            summedColumn.add(")");
            sfw.columns = new ArrayList<SQLFragment>();
            sfw.columns.add(summedColumn);
            return (SQLQuery<U>)sfw;
         }
         else if (query instanceof SQLQuery.InternalGroup)
         {
            final SQLQuery.InternalGroup<T> ig = (SQLQuery.InternalGroup<T>)query;
            SymbExToSQLGenerator gen =
               new SQLGeneratorWithParams<Object, T>(entityInfo,
                     SelectFromWhereExtensionArg.fromReaderColumns(ig.reader, ig.columns, java8LambdaParams, -1),
                     null,//new ParamHandler<Object>(transformClass, emSource),
                     null,//SelectFromWhereExtensionJoin.fromSfw(sfw),
                     this);
            List<SQLFragment> columns = new ArrayList<SQLFragment>();
            ig.reader = generateSelect(analysis, gen, columns);
            assert(desiredSQLReader.isInstance(ig.reader));
            assert(columns.size() == 1);
            SQLFragment summedColumn = new SQLFragment();
            summedColumn.add(aggregateOperator + "(");
            summedColumn.add(columns.get(0));
            summedColumn.add(")");
            ig.columns = new ArrayList<SQLFragment>();
            ig.columns.add(summedColumn);
            return (SQLQuery<U>)ig;
         }
      } catch(TypedValueVisitorException e)
View Full Code Here

   }

   @Override public SQLColumnValues integerConstantValue(ConstantValue.IntegerConstant val, T in) throws TypedValueVisitorException
   {
      SQLColumnValues sql = new SQLColumnValues(new SQLReader.IntegerSQLReader());
      sql.columns[0] = new SQLFragment(Integer.toString(val.val));
      return sql;
   }
View Full Code Here

   }

   @Override public SQLColumnValues stringConstantValue(ConstantValue.StringConstant val, T in) throws TypedValueVisitorException
   {
      SQLColumnValues sql = new SQLColumnValues(new SQLReader.StringSQLReader());
      sql.columns[0] = new SQLFragment("'"+ val.val.replaceAll("'", "''") +"'");
      return sql;
   }
View Full Code Here

         // optimization step, maybe?
         if (val.left instanceof ConstantValue.IntegerConstant
               && ((ConstantValue.IntegerConstant)val.left).val == 0)
         {
            left = new SQLColumnValues(new SQLReader.BooleanSQLReader());
            left.columns[0] = new SQLFragment("FALSE");
         }
         if (val.right instanceof ConstantValue.IntegerConstant
               && ((ConstantValue.IntegerConstant)val.right).val == 0)
         {
            right = new SQLColumnValues(new SQLReader.BooleanSQLReader());
            right.columns[0] = new SQLFragment("FALSE");
         }
      }
      sql.add("(").add(left).add(")");
      sql.add(" " + val.sqlOpString() + " ");
      sql.add("(").add(right).add(")");
View Full Code Here

TOP

Related Classes of ch.epfl.labos.iu.orm.query2.ParameterLocation$LambdaCapturedArg

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.