@Override public MacroConfiguration getDefaultMacroConfiguration() { return delegate.getDefaultMacroConfiguration(); }
@Override public MacroConfiguration getDefaultMacroConfiguration() { return delegate.getDefaultMacroConfiguration(); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof ExpressionFactory) { ExpressionFactory that = (ExpressionFactory) o; ExpressionFactory thatExpressionFactory = that.unwrap(expressionFactory.getClass()); if (thatExpressionFactory == null || !expressionFactory.equals(thatExpressionFactory)) { return false; } return getDefaultMacroConfiguration() != null ? getDefaultMacroConfiguration().equals(that.getDefaultMacroConfiguration()) : that.getDefaultMacroConfiguration() == null; } return false; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof ExpressionFactory) { ExpressionFactory that = (ExpressionFactory) o; ExpressionFactory thatExpressionFactory = that.unwrap(expressionFactory.getClass()); if (thatExpressionFactory == null || !expressionFactory.equals(thatExpressionFactory)) { return false; } return getDefaultMacroConfiguration() != null ? getDefaultMacroConfiguration().equals(that.getDefaultMacroConfiguration()) : that.getDefaultMacroConfiguration() == null; } return false; }
private void applyMapping(StringBuilder sb, String prefixParts, String mapping, String skippedAlias) { if (mapping.isEmpty()) { if (prefixParts != null && !prefixParts.isEmpty()) { sb.append(AbstractAttribute.stripThisFromMapping(prefixParts)); } return; } if (prefixParts != null && !prefixParts.isEmpty()) { Expression expr = ef.createSimpleExpression(mapping, false); EmbeddingViewJpqlMacro embeddingViewJpqlMacro = (EmbeddingViewJpqlMacro) ef.getDefaultMacroConfiguration().get("EMBEDDING_VIEW").getState()[0]; SimpleQueryGenerator generator = new PrefixingQueryGenerator(Collections.singletonList(prefixParts), embeddingViewJpqlMacro.getEmbeddingViewPath(), CorrelatedSubqueryEmbeddingViewJpqlMacro.CORRELATION_EMBEDDING_VIEW_ALIAS, skippedAlias); generator.setQueryBuffer(sb); expr.accept(generator); } else { sb.append(mapping); } }
public AbstractCorrelationJoinTupleElementMapper(ExpressionFactory ef, String joinBase, String correlationBasis, String correlationResult, String alias, String attributePath, String embeddingViewPath, String[] fetches) { this.correlationBasis = correlationBasis.intern(); this.alias = alias; this.embeddingViewPath = embeddingViewPath; this.fetches = fetches; this.joinBase = joinBase.intern(); // TODO: incorporate subtype index! this.correlationAlias = CorrelationProviderHelper.getDefaultCorrelationAlias(attributePath); if (correlationResult.isEmpty()) { this.correlationResult = correlationAlias; } else { StringBuilder sb = new StringBuilder(correlationAlias.length() + correlationResult.length() + 1); EmbeddingViewJpqlMacro embeddingViewJpqlMacro = (EmbeddingViewJpqlMacro) ef.getDefaultMacroConfiguration().get("EMBEDDING_VIEW").getState()[0]; String oldEmbeddingViewPath = embeddingViewJpqlMacro.getEmbeddingViewPath(); embeddingViewJpqlMacro.setEmbeddingViewPath(embeddingViewPath); Expression expr = ef.createSimpleExpression(correlationResult, false); embeddingViewJpqlMacro.setEmbeddingViewPath(oldEmbeddingViewPath); SimpleQueryGenerator generator = new PrefixingQueryGenerator(Collections.singletonList(correlationAlias), joinBase, null, null); generator.setQueryBuffer(sb); expr.accept(generator); this.correlationResult = sb.toString().intern(); } }
@Override public ExpressionFactory createMacroAwareExpressionFactory(String viewRoot) { MacroConfiguration originalMacroConfiguration = expressionFactory.getDefaultMacroConfiguration(); ExpressionFactory cachingExpressionFactory = expressionFactory.unwrap(AbstractCachingExpressionFactory.class); Map<String, MacroFunction> macros = new HashMap<>(); macros.put("view_root", new JpqlMacroAdapter(new DefaultViewRootJpqlMacro(viewRoot), cachingExpressionFactory)); macros.put("embedding_view", new JpqlMacroAdapter(new MutableEmbeddingViewJpqlMacro(), cachingExpressionFactory)); MacroConfiguration macroConfiguration = originalMacroConfiguration.with(macros); return new MacroConfigurationExpressionFactory(cachingExpressionFactory, macroConfiguration); }
private ExpressionFactory createTypeValidationExpressionFactory() { MacroConfiguration originalMacroConfiguration = expressionFactory.getDefaultMacroConfiguration(); ExpressionFactory cachingExpressionFactory = expressionFactory.unwrap(AbstractCachingExpressionFactory.class); Map<String, MacroFunction> macros = new HashMap<>(); macros.put("view_root", new JpqlMacroAdapter(new TypeValidationViewRootJpqlMacro(), cachingExpressionFactory)); macros.put("embedding_view", new JpqlMacroAdapter(new TypeValidationEmbeddingViewJpqlMacro(), cachingExpressionFactory)); MacroConfiguration macroConfiguration = originalMacroConfiguration.with(macros); return new MacroConfigurationExpressionFactory(cachingExpressionFactory, macroConfiguration); }
public ObjectBuilder<?> createObjectBuilder(ManagedViewTypeImplementor<?> viewType, MappingConstructorImpl<?> mappingConstructor, String viewName, Class<?> rootType, String entityViewRoot, String embeddingViewPath, FullQueryBuilder<?, ?> criteriaBuilder, EntityViewConfiguration configuration, int offset, int suffix) { ExpressionFactory ef = criteriaBuilder.getService(ExpressionFactory.class); if (!viewType.getEntityClass().isAssignableFrom(rootType)) { if (rootType.isAssignableFrom(viewType.getEntityClass())) { entityViewRoot = "TREAT(" + entityViewRoot + " AS " + metamodel.getEntityMetamodel().getEntity(viewType.getJavaType()).getName() + ")"; } else { throw new IllegalArgumentException("The given view type with the entity type '" + viewType.getEntityClass().getName() + "' can not be applied to the query builder with result type '" + rootType.getName() + "'"); } } MacroConfiguration originalMacroConfiguration = ef.getDefaultMacroConfiguration(); ExpressionFactory cachingExpressionFactory = ef.unwrap(AbstractCachingExpressionFactory.class); JpqlMacro viewRootJpqlMacro = new DefaultViewRootJpqlMacro(entityViewRoot); EmbeddingViewJpqlMacro embeddingViewJpqlMacro = configuration.getEmbeddingViewJpqlMacro(); Map<String, MacroFunction> macros = new HashMap<>(); macros.put("view_root", new JpqlMacroAdapter(viewRootJpqlMacro, cachingExpressionFactory)); macros.put("embedding_view", new JpqlMacroAdapter(embeddingViewJpqlMacro, cachingExpressionFactory)); MacroConfiguration macroConfiguration = originalMacroConfiguration.with(macros); ef = new MacroConfigurationExpressionFactory(cachingExpressionFactory, macroConfiguration); criteriaBuilder.registerMacro("view_root", viewRootJpqlMacro); return getTemplate(ef, viewType, mappingConstructor, viewName, entityViewRoot, embeddingViewPath, embeddingViewJpqlMacro, offset) .createObjectBuilder(criteriaBuilder, configuration.getOptionalParameters(), configuration, suffix); }
EmbeddingViewJpqlMacro embeddingViewJpqlMacro = (EmbeddingViewJpqlMacro) macroAwareExpressionFactory.getDefaultMacroConfiguration().get("EMBEDDING_VIEW").getState()[0]; getTemplate(macroAwareExpressionFactory, view, null, null, null, embeddingViewJpqlMacro);
@Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { String alias = correlationBuilder.getCorrelationAlias(); // Exercise the parser first to resolve the view root ExpressionFactory expressionFactory = correlationBuilder.getService(ExpressionFactory.class); String expressionString = AbstractAttribute.replaceThisFromMapping(this.correlationExpression, alias); Expression expression = expressionFactory.createBooleanExpression(expressionString, false); // Find out the view root alias MacroFunction viewRootFunction = expressionFactory.getDefaultMacroConfiguration().get("VIEW_ROOT"); ViewRootJpqlMacro viewRootMacro = (ViewRootJpqlMacro) viewRootFunction.getState()[0]; // Prefix all paths except view root alias based ones and substitute the key alias with the correlation expression String aliasToSkip; if (viewRootMacro.getViewRoot() == null) { EmbeddingViewJpqlMacro embeddingViewJpqlMacro = (EmbeddingViewJpqlMacro) expressionFactory.getDefaultMacroConfiguration().get("EMBEDDING_VIEW").getState()[0]; aliasToSkip = embeddingViewJpqlMacro.getEmbeddingViewPath(); } else { aliasToSkip = viewRootMacro.getViewRoot(); } PrefixingAndAliasReplacementQueryGenerator generator = new PrefixingAndAliasReplacementQueryGenerator(alias, correlationExpression, correlationKeyAlias, aliasToSkip, true); StringBuilder buffer = new StringBuilder(approximateExpressionSize); generator.setQueryBuffer(buffer); expression.accept(generator); correlationBuilder.correlate(correlated) .setOnExpression(buffer.toString()); } }