Package org.skife.jdbi.v2

Examples of org.skife.jdbi.v2.Script


   
    this.modifiedQuery = q.toString();
   
    Boolean result = null;
    if (rewritten) {
      Script script = engine.createScript(this.modifiedQuery);
      try {
        result = (Boolean) script.execute(ctx);
      } catch (Exception e) {
        log.error("Error evaluating script: " + this.modifiedQuery + " against event" + eventFields.toString(), e);
      }
    } else {
      Expression expr = engine.createExpression(this.modifiedQuery);
View Full Code Here


            throw new NullPointerException("script and context must be non-null");
        }
        // This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - Script Execution)
        context.setAttribute(CONTEXT_KEY, context, ScriptContext.ENGINE_SCOPE);
        try {
            Script jexlScript = jexlEngine.createScript(script);
            JexlContext ctxt = new JexlContextWrapper(context);
            return jexlScript.execute(ctxt);
        } catch (Exception e) {
            throw new ScriptException(e.toString());
        }
    }
View Full Code Here

        // This is mandated by JSR-223
        if (script == null) {
            throw new NullPointerException("script must be non-null");
        }
        try {
            Script jexlScript = jexlEngine.createScript(script);
            return new JexlCompiledScript(jexlScript);
        } catch (Exception e) {
            throw new ScriptException(e.toString());
        }
    }
View Full Code Here

        if (ctx instanceof JexlContext) {
            jexlCtx = (JexlContext) ctx;
        } else {
            throw new SCXMLExpressionException(ERR_CTX_TYPE);
        }
        Script jexlScript = null;
        try {
            final JexlContext effective = getEffectiveContext(jexlCtx);
            effective.setEvaluatingLocation(true);
            jexlScript = getJexlEngine().createScript(script);
            return jexlScript.execute(effective);
        } catch (Exception e) {
            String exMessage = e.getMessage() != null ? e.getMessage() : e.getClass().getCanonicalName();
            throw new SCXMLExpressionException("evalScript('" + script + "'): " + exMessage, e);
        }
    }
View Full Code Here

  public boolean filterMatchesEntry(String filter, FeedEntry entry) throws FeedEntryFilterException {
    if (StringUtils.isBlank(filter)) {
      return true;
    }

    Script script = null;
    try {
      script = ENGINE.createScript(filter);
    } catch (JexlException e) {
      throw new FeedEntryFilterException("Exception while parsing expression " + filter, e);
    }

    JexlContext context = new MapContext();
    context.set("title", Jsoup.parse(entry.getContent().getTitle()).text().toLowerCase());
    context.set("author", entry.getContent().getAuthor().toLowerCase());
    context.set("content", Jsoup.parse(entry.getContent().getContent()).text().toLowerCase());
    context.set("url", entry.getUrl().toLowerCase());

    Callable<Object> callable = script.callable(context);
    Future<Object> future = executor.submit(callable);
    Object result = null;
    try {
      result = future.get(500, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
View Full Code Here

    /**
     * See org.springframework.beans.factory.FactoryBean#getObject
     */
    public Object getObject() throws Exception
    {
        final DBI dbi = new DBI(new SpringDataSourceConnectionFactory(dataSource));
        if (statementLocator != null) {
            dbi.setStatementLocator(statementLocator);
        }

        for (Map.Entry<String, Object> entry : globalDefines.entrySet()) {
            dbi.define(entry.getKey(), entry.getValue());
        }

        return dbi;
    }
View Full Code Here

        return new StringTemplateStatementLocator(loader);
    }

    public void testSimpleTemplate() throws Exception
    {
        final Handle h = openHandle();
        final int count = h.insert("tests:insert_one");
        assertEquals(1, count);
    }
View Full Code Here

        assertEquals(1, count);
    }

    public void testParameterizedInsert() throws Exception
    {
        final Handle h = openHandle();
        final int count = h.createStatement("tests:parameterized_insert")
                .define("table", "something")
                .define("column_one", "id")
                .define("column_two", "name")
                .bind("column_one", 7)
                .bind("column_two", "Rebecca")
                .execute();
        assertEquals(1, count);

        final String name = h.createQuery("select name from something where id = 7")
                .map(StringMapper.FIRST)
                .first();
        assertEquals(name, "Rebecca");
    }
View Full Code Here

        assertEquals(name, "Rebecca");
    }

    public void testExtraDefinesDontBreakThings() throws Exception
    {
        final Handle h = openHandle();
        final int count = h.createStatement("tests:insert_one")
                .define("name", "Nicole")
                .execute();
        assertEquals(1, count);
    }
View Full Code Here

*/
public class TestQueryObjectGenerator extends DBITestCase
{
    public void testApiWhichTakesConnection() throws Exception
    {
        Handle h = openHandle();
        MyQueries qo = QueryObjectFactory.createQueryObject(MyQueries.class, h.getConnection());
        assertNotNull(qo);
    }
View Full Code Here

TOP

Related Classes of org.skife.jdbi.v2.Script

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.