public StringTemplate3StatementLocator build() { return new StringTemplate3StatementLocator(basePath, superGroupPath, errorListener, allowImplicitTemplateGroupEnabled, treatLiteralsAsTemplatesEnabled, shouldCacheEnabled); } }
private StringTemplate3StatementLocator(String templateGroupFilePathOnClasspath, String superTemplateGroupFilePathOnClasspath, StringTemplateErrorListener errorListener, boolean allowImplicitTemplateGroup, boolean treatLiteralsAsTemplates, boolean shouldCache) { this.treatLiteralsAsTemplates = treatLiteralsAsTemplates; final StringTemplateGroup superGroup; final StringBuilder sb = new StringBuilder(templateGroupFilePathOnClasspath); if (superTemplateGroupFilePathOnClasspath != null) { sb.append(SUPER_SEPARATOR).append(superTemplateGroupFilePathOnClasspath); superGroup = createGroup(superTemplateGroupFilePathOnClasspath, errorListener, shouldCache ? superTemplateGroupFilePathOnClasspath : null, allowImplicitTemplateGroup, getClass(), null); } else { superGroup = null; } this.group = createGroup(templateGroupFilePathOnClasspath, errorListener, shouldCache ? sb.toString() : null, allowImplicitTemplateGroup, getClass(), superGroup); }
/** * Use {@link StringTemplate3StatementLocator#builder()} and {@link StringTemplate3StatementLocator.Builder}. */ @Deprecated public StringTemplate3StatementLocator(Class baseClass) { this(mungify(baseClass), null, null, false, false, false); }
@Test public void testLocatorWithAttributes() throws Exception final StringTemplate3StatementLocator locator = StringTemplate3StatementLocator.builder(Kombucha.class) .withSuperGroup(SuperDrink.class) .withErrorListener(StringTemplateGroup.DEFAULT_ERROR_LISTENER) final String getFromHistoryTableName = locator.locate("getFromHistoryTableName", ctx); Assert.assertEquals("select tea\n" + ", mushroom\n" + Assert.assertTrue(StringTemplate3StatementLocator.templateCached(Kombucha.class, SuperDrink.class)); final String getFromHistoryTableNameAgain = locator.locate("getFromHistoryTableName", ctx); Assert.assertEquals("select tea\n" + ", mushroom\n" +
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); } }; }
@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) final String getFromHistoryTableName = locator.locate("getFromHistoryTableName", ctx); Assert.assertEquals("select tea\n" + ", mushroom\n" + Assert.assertTrue(StringTemplate3StatementLocator.templateCached(Kombucha.class, SuperDrink.class)); final String getFromHistoryTableNameAgain = locator.locate("getFromHistoryTableName", ctx); Assert.assertEquals("select tea\n" + ", mushroom\n" +
@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); } }; }
@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); }
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 StringTemplate3StatementLocator build() { return new StringTemplate3StatementLocator(basePath, superGroupPath, errorListener, allowImplicitTemplateGroupEnabled, treatLiteralsAsTemplatesEnabled, shouldCacheEnabled); } }
/** * Use {@link StringTemplate3StatementLocator#builder()} and {@link StringTemplate3StatementLocator.Builder}. */ @Deprecated public StringTemplate3StatementLocator(Class baseClass) { this(mungify(baseClass), null, null, false, false, false); }
sb.append(SUPER_SEPARATOR).append(superTemplateGroupFilePathOnClasspath); superGroup = createGroup(superTemplateGroupFilePathOnClasspath, errorListener, shouldCache ? superTemplateGroupFilePathOnClasspath : null, this.group = createGroup(templateGroupFilePathOnClasspath, errorListener, shouldCache ? sb.toString() : null,
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); } }; }
public SqlStatementCustomizer createForType(final Annotation annotation, final Class sqlObjectType) { new StringTemplate3StatementLocator(QueueSqlDao.class, true, true); l = new StringTemplate3StatementLocator(sqlObjectType, true, true); } else { l = new StringTemplate3StatementLocator(a.value(), true, true);
/** * Use {@link StringTemplate3StatementLocator#builder()} and {@link StringTemplate3StatementLocator.Builder}. */ @Deprecated public StringTemplate3StatementLocator(Class baseClass, boolean allowImplicitTemplateGroup, boolean treatLiteralsAsTemplates) { this(mungify(baseClass), null, null, allowImplicitTemplateGroup, treatLiteralsAsTemplates, false); }
@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); } }; }
@Override public Void withHandle(final Handle handle) throws Exception { // MySQL needs special setup to make it stream the results. See: // http://javaquirks.blogspot.com/2007/12/mysql-streaming-result-set.html // http://stackoverflow.com/questions/2447324/streaming-large-result-sets-with-mysql final Query<Map<String, Object>> query = handle.createQuery("getStreamingAggregationCandidates") .setFetchSize(Integer.MIN_VALUE) .bind("aggregationLevel", aggregationLevel) .bind("tenantRecordId", createCallContext().getTenantRecordId()); query.setStatementLocator(new StringTemplate3StatementLocator(TimelineAggregatorSqlDao.class)); ResultIterator<TimelineChunk> iterator = null; try { iterator = query .map(timelineChunkMapper) .iterator(); while (iterator.hasNext()) { aggregationConsumer.processTimelineChunk(iterator.next()); } } catch (Exception e) { log.error(String.format("Exception during aggregation of level %d", aggregationLevel), e); } finally { if (iterator != null) { iterator.close(); } } return null; }
/** * Use {@link StringTemplate3StatementLocator#builder()} and {@link StringTemplate3StatementLocator.Builder}. */ @Deprecated public StringTemplate3StatementLocator(Class baseClass, boolean allowImplicitTemplateGroup, boolean treatLiteralsAsTemplates) { this(mungify(baseClass), null, null, allowImplicitTemplateGroup, treatLiteralsAsTemplates, false); }
@Override public Void withHandle(final Handle handle) throws Exception { handle.setStatementLocator(new StringTemplate3StatementLocator(TimelineSqlDao.class));