Package org.xorm.tests

Source Code of org.xorm.tests.TestCodeQuery$Query4

package org.xorm.tests;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.xorm.query.CodeQuery;
import org.xorm.tests.model.*;
import java.util.Collection;

public class TestCodeQuery extends XORMTestCase {
    public static void main(String[] argv) throws Exception {
  TestCodeQuery tcq = new TestCodeQuery();
  tcq.setUp();
  tcq.testQueries();
  tcq.tearDown();
    }

    public void testQueries() {
  PersistenceManager mgr = factory.getPersistenceManager();
  Query q;

  Class[] queries = new Class[] {
      Query0.class,
      Query1.class,
      Query2.class,
      Query3.class,
      Query4.class
  };

  Object[] params = new Object[] {
      new Object[] { "Foo" },
      new Object[] { new Integer(11), new Float(22.2) },
      new Object[] { new Double(33.33d), "Bar" },
      new Object[] { },
      new Object[] { }
  };

  // Execute each query
  for (int i = 0; i < queries.length; i++) {
      q = CodeQuery.parseCodeQuery(mgr, queries[i]);
      System.out.println(q);
      // Force the query to execute
      ((Collection) q.executeWithArray((Object[]) params[i]))
    .iterator().hasNext();
  }

  q = mgr.newQuery(TestInterface.class, "collection.contains(employee) && employee.firstName != \"Bob\"");
  q.declareVariables("Employee employee");
  System.out.println(q);
  ((Collection) q.execute())
      .iterator().hasNext();
 
    }

    abstract static class Query0 implements TestInterface {
  public boolean evaluate(String s) {
      return getString().equals(s);
  }
    }

    abstract static class Query1 implements TestInterface {
  public boolean evaluate(int ii, float ff) {
      return (getInt() == ii) && (getFloat() == ff);
  }
    }
   
    abstract static class Query2 implements TestInterface {
  public boolean evaluate(double dd, String ss) {
      return getString().equals(ss) || (getDouble() > dd);
  }
    }

    abstract static class Query3 implements TestInterface {
  public transient Employee employee;
  public boolean evaluate() {
      return getCollection().contains(employee) &
    !employee.getFirstName().equals("Bob");
  }
    }

    abstract static class Query4 implements TestInterface {
  public transient Employee employee;
  public boolean evaluate() {
      return getCollection().contains(employee) &
    !employee.getFirstName().equals("Bob") &&
    employee.getLastName().startsWith("Sm") && getBoolean();
  }
    }
   
}
TOP

Related Classes of org.xorm.tests.TestCodeQuery$Query4

TOP
Copyright © 2018 www.massapi.com. 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.