use of org.apache.cayenne.template.parser.SQLTemplateParser 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());
}
use of org.apache.cayenne.template.parser.SQLTemplateParser in project cayenne by apache.
the class TemplateParserPoolTest method createNewParser.
@Test
public void createNewParser() throws Exception {
SQLTemplateParser parser = parserPool.createNewParser();
assertNotNull(parser);
}
use of org.apache.cayenne.template.parser.SQLTemplateParser in project cayenne by apache.
the class TemplateParserPoolTest method put.
@Test
public void put() throws Exception {
SQLTemplateParser parser = new SQLTemplateParser(new ByteArrayInputStream("".getBytes()));
parserPool.put(parser);
for (int i = 0; i < TemplateParserPool.INITIAL_POOL_SIZE; i++) {
SQLTemplateParser parser1 = parserPool.get();
assertNotNull(parser1);
assertNotSame(parser, parser1);
}
SQLTemplateParser parser1 = parserPool.get();
assertSame(parser, parser1);
}
use of org.apache.cayenne.template.parser.SQLTemplateParser in project cayenne by apache.
the class TemplateParserPoolTest method get.
@Test
public void get() throws Exception {
for (int i = 0; i < TemplateParserPool.MAX_POOL_SIZE + 10; i++) {
SQLTemplateParser parser = parserPool.get();
assertNotNull(parser);
}
}
Aggregations