protected void test() { for (int i = 0; i <= 1; i++) { getSession().getPlatform().setShouldBindAllParameters(i != 0); for (int j = 0; j <= 2; j++) { query = new ReadAllQuery(Employee.class); ExpressionBuilder builder = new ExpressionBuilder(); Vector vExp = new Vector(2); vExp.add(builder.getParameter("p1")); query.addArgument("p1"); vExp.add(builder.getParameter("p2")); query.addArgument("p2"); Expression exp = builder.get("id").in(vExp); query.setSelectionCriteria(exp); switch (j) { case 0: // nothing to do - just test the default: // query.bindAllParameters == Undefined break; case 1: // query.bindAllParameters == False query.setShouldBindAllParameters(false); break; case 2: // query.bindAllParameters == True query.setShouldBindAllParameters(true); break; } // clear the writer's buffer ((StringWriter) getSession().getLog()).getBuffer().setLength(0); try { getSession().executeQuery(query, v); } catch (DatabaseException e) { throw new TestProblemException("executeQuery threw DatabaseException"); } if (shouldBind() != wasBound()) { return; } } } }
public void setup() { // JGL: If the arguments are already set by the test, don't // set them again if (!hasArguments()) { setArgumentsForTestUsing(getSomeEmployees()); } ReadAllQuery raq = new ReadAllQuery(); raq.setReferenceClass(Employee.class); raq.setSelectionCriteria(getOriginalObjectExpression()); // Add all the arguments to the query Enumeration enumtr = getExpressionParameters().elements(); while (enumtr.hasMoreElements()) { raq.addArgument((String) enumtr.nextElement()); } // Save the retrieved employees for the verify setOriginalOject(getSession().executeQuery(raq, getArguments())); // Finish the setup super.setup(); }
public void setup() { // Get the baseline employees for the verify Employee emp = (Employee) getSomeEmployees().firstElement(); String parameterName = "firstName"; ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.get("firstName").equal(builder.getParameter(parameterName)); ReadAllQuery raq = new ReadAllQuery(); raq.setReferenceClass(Employee.class); raq.setSelectionCriteria(whereClause); raq.addArgument(parameterName); Vector parameters = new Vector(); parameters.add(emp.getFirstName()); Vector employees = (Vector) getSession().executeQuery(raq, parameters); emp = (Employee) employees.firstElement(); // Set up the EJBQL using the retrieved employees String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE "; ejbqlString = ejbqlString + "?1 = emp.firstName "; setEjbqlString(ejbqlString); setOriginalOject(employees); setArguments(parameters); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); setArgumentNames(myArgumentNames); // Finish the setup super.setup(); }