public SqlStatementCustomizer createForType(Annotation annotation, Class sqlObjectType) { final ExternalizedSqlViaStringTemplate3 a = (ExternalizedSqlViaStringTemplate3) annotation; final StringTemplate3StatementLocator.Builder builder; if (DEFAULT_VALUE.equals(a.value())) { builder = StringTemplate3StatementLocator.builder(sqlObjectType); } else { builder = StringTemplate3StatementLocator.builder(a.value()); } final StatementLocator l = builder.shouldCache().build(); return new SqlStatementCustomizer() { public void apply(SQLStatement q) { q.setStatementLocator(l); } }; }
@Override public SqlStatementCustomizer createForType(Annotation annotation, Class sqlObjectType) { final ExternalizedSqlViaStringTemplate3 a = (ExternalizedSqlViaStringTemplate3) annotation; final StringTemplate3StatementLocator.Builder builder; if (DEFAULT_VALUE.equals(a.value())) { builder = StringTemplate3StatementLocator.builder(sqlObjectType); } else { builder = StringTemplate3StatementLocator.builder(a.value()); } final StatementLocator l = builder.shouldCache().build(); return new SqlStatementCustomizer() { @Override public void apply(SQLStatement q) { q.setStatementLocator(l); } }; }
private static StatementLocator getLocator(final String locatorPath) { if (enableGroupTemplateCaching && locatorCache.containsKey(locatorPath)) { return locatorCache.get(locatorPath); } final StringTemplate3StatementLocator.Builder builder = StringTemplate3StatementLocator.builder(locatorPath) .shouldCache() .withSuperGroup(EntitySqlDao.class) .allowImplicitTemplateGroup() .treatLiteralsAsTemplates(); final StatementLocator locator = builder.build(); if (enableGroupTemplateCaching) { locatorCache.put(locatorPath, locator); } return locator; }
public SqlStatementCustomizer createForType(Annotation annotation, Class sqlObjectType) { final UseStringTemplate3StatementLocator a = (UseStringTemplate3StatementLocator) annotation; final StringTemplate3StatementLocator.Builder builder; if (DEFAULT_VALUE.equals(a.value())) { builder = StringTemplate3StatementLocator.builder(sqlObjectType); } else { builder = StringTemplate3StatementLocator.builder(a.value()); } final StatementLocator l = builder.allowImplicitTemplateGroup().treatLiteralsAsTemplates().shouldCache().build(); return new SqlStatementCustomizer() { public void apply(SQLStatement q) { q.setStatementLocator(l); } }; }
@Override public SqlStatementCustomizer createForType(Annotation annotation, Class sqlObjectType) { final UseStringTemplate3StatementLocator a = (UseStringTemplate3StatementLocator) annotation; final StringTemplate3StatementLocator.Builder builder; if (DEFAULT_VALUE.equals(a.value())) { builder = StringTemplate3StatementLocator.builder(sqlObjectType); } else { builder = StringTemplate3StatementLocator.builder(a.value()); } StringTemplateErrorListener errorListener = StringTemplateGroup.DEFAULT_ERROR_LISTENER; if (!StringTemplateErrorListener.class.equals(a.errorListener())) { try { errorListener = (StringTemplateErrorListener) a.errorListener().newInstance(); } catch(Exception e) { throw new IllegalStateException("Error initializing StringTemplateErrorListener", e); } } final StatementLocator l = builder.allowImplicitTemplateGroup().treatLiteralsAsTemplates().shouldCache().withErrorListener(errorListener).build(); return new SqlStatementCustomizer() { @Override public void apply(SQLStatement q) { q.setStatementLocator(l); } }; }
@Test public void testSuperTemplate() throws Exception { final StringTemplate3StatementLocator locator = StringTemplate3StatementLocator.builder(Kombucha.class) .withSuperGroup(SuperDrink.class) .withErrorListener(StringTemplateGroup.DEFAULT_ERROR_LISTENER) .allowImplicitTemplateGroup() .treatLiteralsAsTemplates() .shouldCache() .build(); // Test statement locator from child template group and verify templates table_name got correctly evaluated final StatementContext ctx = new TestingStatementContext(new HashMap<String, Object>()); final String getIngredients = locator.locate("getIngredients", ctx); Assert.assertEquals("select tea\n" + ", mushroom\n" + ", sugar from kombucha;", getIngredients); // Test statement locator from base template group final String awesomeness = locator.locate("awesomeness", ctx); Assert.assertEquals("awesomeness;", awesomeness); }
@Test public void testSuperTemplate() throws Exception { final StringTemplate3StatementLocator locator = StringTemplate3StatementLocator.builder(Kombucha.class) .withSuperGroup(SuperDrink.class) .withErrorListener(StringTemplateGroup.DEFAULT_ERROR_LISTENER) .allowImplicitTemplateGroup() .treatLiteralsAsTemplates() .shouldCache() .build(); // Test statement locator from child template group and verify templates table_name got correctly evaluated final StatementContext ctx = new TestingStatementContext(new HashMap<String, Object>()); final String getIngredients = locator.locate("getIngredients", ctx); Assert.assertEquals("select tea\n" + ", mushroom\n" + ", sugar from kombucha;", getIngredients); // Test statement locator from base template group final String awesomeness = locator.locate("awesomeness", ctx); Assert.assertEquals("awesomeness;", awesomeness); }
@Test public void testLocatorWithAttributes() throws Exception final StringTemplate3StatementLocator locator = StringTemplate3StatementLocator.builder(Kombucha.class) .withSuperGroup(SuperDrink.class) .withErrorListener(StringTemplateGroup.DEFAULT_ERROR_LISTENER)
@Test public void testLocatorWithAttributes() throws Exception final StringTemplate3StatementLocator locator = StringTemplate3StatementLocator.builder(Kombucha.class) .withSuperGroup(SuperDrink.class) .withErrorListener(StringTemplateGroup.DEFAULT_ERROR_LISTENER)