Search in sources :

Example 1 with ParseException

use of org.apache.cayenne.template.parser.ParseException in project cayenne by apache.

the class CayenneSQLTemplateProcessor method process.

protected SQLStatement process(String template, Context context) {
    Node node = templateCache.get(template);
    if (node == null) {
        SQLTemplateParser parser = parserPool.get();
        try {
            parser.ReInit(new ByteArrayInputStream(template.getBytes()));
            node = parser.template();
        } catch (ParseException | TokenMgrError ex) {
            throw new CayenneRuntimeException("Error parsing template '%s' : %s", template, ex.getMessage());
        } finally {
            parserPool.put(parser);
        }
        // can ignore case when someone resolved this template concurrently, it has no side effects
        templateCache.put(template, node);
    }
    node.evaluate(context);
    return new SQLStatement(context.buildTemplate(), context.getColumnDescriptors(), context.getParameterBindings());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Node(org.apache.cayenne.template.parser.Node) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) SQLTemplateParser(org.apache.cayenne.template.parser.SQLTemplateParser) TokenMgrError(org.apache.cayenne.template.parser.TokenMgrError) ParseException(org.apache.cayenne.template.parser.ParseException) SQLStatement(org.apache.cayenne.access.jdbc.SQLStatement)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 SQLStatement (org.apache.cayenne.access.jdbc.SQLStatement)1 Node (org.apache.cayenne.template.parser.Node)1 ParseException (org.apache.cayenne.template.parser.ParseException)1 SQLTemplateParser (org.apache.cayenne.template.parser.SQLTemplateParser)1 TokenMgrError (org.apache.cayenne.template.parser.TokenMgrError)1