Package de.mhus.lib.parser

Examples of de.mhus.lib.parser.CompiledString


 
  public void  testSimple() throws ParseException {
    String sql = "SELECT * FROM hamster where aaa = 'alpha' AND bbb='beta'";
    SqlCompiler compiler = new SqlCompiler();
    CompiledString compiled = compiler.compileString(sql);
    StringBuffer sb = new StringBuffer();
    compiled.dump(sb);
    System.out.println(sb.toString());
   
    HashMap<String, Object> attributes = new HashMap<String, Object>();
    sb = new StringBuffer();
    compiled.execute(sb, attributes);
    String res = sb.toString();
    System.out.println(res);
   
    assertEquals( sql, res);
   
View Full Code Here


  }
 
  public void testQuotes() throws ParseException {
    String sql = "SELECT 'aloa' FROM hamster where aaa = 'alpha' AND bbb='beta' ccc='wow''aha'";
    SqlCompiler compiler = new SqlCompiler();
    CompiledString compiled = compiler.compileString(sql);
    StringBuffer sb = new StringBuffer();
    compiled.dump(sb);
    System.out.println(sb.toString());
   
    HashMap<String, Object> attributes = new HashMap<String, Object>();
    sb = new StringBuffer();
    compiled.execute(sb, attributes);
    String res = sb.toString();
    System.out.println(res);
   
    assertEquals( sql, res);
  }
View Full Code Here

  }
 
  public void testAttribute() throws ParseException {
    String sql = "SELECT $raw$ FROM $val$ where aaa = '$val$'";
    SqlCompiler compiler = new SqlCompiler();
    CompiledString compiled = compiler.compileString(sql);
    StringBuffer sb = new StringBuffer();
    compiled.dump(sb);
    System.out.println(sb.toString());
   
    HashMap<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("val", "wow");
    attributes.put("raw", new Raw("wow"));
    sb = new StringBuffer();
    compiled.execute(sb, attributes);
    String res = sb.toString();
    System.out.println(res);
   
    sql = "SELECT wow FROM 'wow' where aaa = '$val$'"; // expected
   
View Full Code Here

  }
 
  public void testMath() throws ParseException {
    String sql = "SELECT * FROM aaa WHERE a+b=c-7*3/2 AND z != -13";
    SqlCompiler compiler = new SqlCompiler();
    CompiledString compiled = compiler.compileString(sql);
    StringBuffer sb = new StringBuffer();
    compiled.dump(sb);
    System.out.println(sb.toString());
   
    HashMap<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("val", "wow");
    attributes.put("raw", new Raw("wow"));
    sb = new StringBuffer();
    compiled.execute(sb, attributes);
    String res = sb.toString();
    System.out.println(res);
       
    assertEquals( sql, res);
  }
View Full Code Here

  }
 
  public void testFunction() throws ParseException {
    String sql = "SELECT * FROM aaa WHERE round(a) = round(b) AND date(a,b) = diff(date(a),'1928-03-21')";
    SqlCompiler compiler = new SqlCompiler();
    CompiledString compiled = compiler.compileString(sql);
    StringBuffer sb = new StringBuffer();
    compiled.dump(sb);
    System.out.println(sb.toString());
   
    HashMap<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("val", "wow");
    attributes.put("raw", new Raw("wow"));
    sb = new StringBuffer();
    compiled.execute(sb, attributes);
    String res = sb.toString();
    System.out.println(res);
       
    assertEquals( sql, res);
  }
View Full Code Here

    } catch (IOException e) {
      throw new ParseException(e);
    }
    root.parse(pr);
   
    return new CompiledString(new StringPart[] {root});
  }
View Full Code Here

      if (!rootElement.getNodeName().equals("common"))
        throw new ParseException("xml is not in common language, need to start with the tag <common>",in);
     
     
     
      return new CompiledString(new StringPart[] {});
    } catch (Exception e) {
      throw new ParseException(in,e);
    }
  }
View Full Code Here

    synchronized (this) {
      if (compiler == null) {
        compiler = new ConfigStringCompiler();
        compiledCache = new HashMap<String, CompiledString>();
      }
      CompiledString cached = compiledCache.get(key);
      if (cached == null) {
        cached = compiler.compileString(value);
        compiledCache.put(key, cached);
      }
      return cached.execute(level == 0 ?null : new ConfigMap(level));
    }
  }
View Full Code Here

TOP

Related Classes of de.mhus.lib.parser.CompiledString

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.