예제 #1
0
  @Test
  public void testExecuteOnDBConnection() throws IOException {
    Query<Organisation> query = new Query<Organisation>(Organisation.class);
    query.clear();
    query.add(Organisation.FLD_NAME1, "=", "orgname2");

    // create a new DBConnection
    DBConnection connection = new DBConnection();
    connection.setDBConnectString("jdbc:h2:mem:test_query_mem");
    connection.setDBUser("sa");
    connection.setDBPassword("");
    assertTrue(connection.connect());
    initElexisDatabase(connection);

    List<Organisation> result = query.execute(connection);
    assertEquals(0, result.size());

    DBConnection initialConnection = PersistentObject.getDefaultConnection();

    // change default connection of PersistenObject and create an Organization
    PersistentObject.connect(connection);
    new Organisation("orgname2", "orgzusatz1");

    result = query.execute(connection);
    assertEquals(1, result.size());

    // cleanup new connection and reset to initial connection
    PersistentObject.disconnect();
    PersistentObject.connect(initialConnection);
  }
예제 #2
0
 /**
  * Execute a script that is part of the call
  *
  * @param call e.g. scriptname(a="foo",b="bar")
  * @param objects some Objects to cinvert in the script
  * @return the result of the interpreter
  * @throws ElexisException if no such scruiopt was found or an error occurred
  */
 public static Object executeScript(String call, PersistentObject... objects)
     throws ElexisException {
   call = call.trim();
   String name = call;
   String params = null;
   int x = name.indexOf('(');
   if (x != -1) {
     name = call.substring(0, x);
     params = call.substring(x + 1, call.length() - 1);
   }
   Query<Script> qbe = new Query<Script>(Script.class);
   qbe.add("ID", Query.EQUALS, PREFIX + name);
   List<Script> found = qbe.execute();
   if (found.size() == 0) {
     throw new ElexisException(
         Script.class,
         "A Script with this name was not found " + name,
         ElexisException.EE_NOT_FOUND);
   }
   Script script = found.get(0);
   try {
     return script.execute(params, objects);
   } catch (Exception e) {
     ExHandler.handle(e);
     throw new ElexisException(
         Script.class,
         "Error while executing " + name + ": " + e.getMessage(),
         ElexisException.EE_UNEXPECTED_RESPONSE);
   }
 }
예제 #3
0
 @Test
 public void testExecute() {
   Query<Organisation> query = new Query<Organisation>(Organisation.class);
   query.clear();
   query.add(Organisation.FLD_NAME1, "=", "orgname");
   List<Organisation> result = query.execute();
   assertEquals(1, result.size());
 }
예제 #4
0
 public static List<Script> getScripts() {
   Query<Script> qbe = new Query<Script>(Script.class);
   qbe.add("ID", "LIKE", PREFIX + "%");
   return qbe.execute();
 }