Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 10 additions & 25 deletions api/src/main/java/jakarta/data/expression/NavigableExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,23 @@
import jakarta.data.metamodel.NumericAttribute;
import jakarta.data.metamodel.TemporalAttribute;
import jakarta.data.metamodel.TextAttribute;
import jakarta.data.spi.expression.path.BooleanPath;
import jakarta.data.spi.expression.path.ComparablePath;
import jakarta.data.spi.expression.path.NavigablePath;
import jakarta.data.spi.expression.path.NumericPath;
import jakarta.data.spi.expression.path.TemporalPath;
import jakarta.data.spi.expression.path.TextPath;

public interface NavigableExpression<T, U> {

default <V> NavigableExpression<T, V> navigate(NavigableAttribute<U, V> attribute) {
return NavigablePath.of(this, attribute);
}
<V> NavigableExpression<T, V> navigate(NavigableAttribute<U, V> attribute);

default TextExpression<T> navigate(TextAttribute<U> attribute) {
return TextPath.of(this, attribute);
}
TextAttribute<T> navigate(TextAttribute<U> attribute);

default <C extends Comparable<C>> ComparableExpression<T, C> navigate(ComparableAttribute<U, C> attribute) {
return ComparablePath.of(this, attribute);
}
<C extends Comparable<C>> ComparableAttribute<T, C> navigate(
ComparableAttribute<U, C> attribute);

default BooleanExpression<T> navigate(BooleanAttribute<U> attribute) {
return BooleanPath.of(this, attribute);
}
BooleanAttribute<T> navigate(BooleanAttribute<U> attribute);

default <N extends Number & Comparable<N>> NumericExpression<T, N> navigate(NumericAttribute<U, N> attribute) {
return NumericPath.of(this, attribute);
}
<N extends Number & Comparable<N>> NumericAttribute<T, N> navigate(
NumericAttribute<U, N> attribute);

default <V extends Temporal & Comparable<? extends Temporal>> TemporalExpression<T, V> navigate(
TemporalAttribute<U, V> attribute) {
return TemporalPath.of(this, attribute);
}
<V extends Temporal & Comparable<? extends Temporal>>
TemporalAttribute<T, V> navigate(
TemporalAttribute<U, V> attribute);

}
45 changes: 44 additions & 1 deletion api/src/main/java/jakarta/data/metamodel/NavigableAttribute.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2025,2026 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,8 +17,16 @@
*/
package jakarta.data.metamodel;

import java.time.temporal.Temporal;

import jakarta.data.expression.NavigableExpression;
import jakarta.data.messages.Messages;
import jakarta.data.spi.expression.path.BooleanPath;
import jakarta.data.spi.expression.path.ComparablePath;
import jakarta.data.spi.expression.path.NavigablePath;
import jakarta.data.spi.expression.path.NumericPath;
import jakarta.data.spi.expression.path.TemporalPath;
import jakarta.data.spi.expression.path.TextPath;

/**
* <p>Represents an entity attribute that is an embeddable or association to
Expand All @@ -33,6 +41,41 @@
public interface NavigableAttribute<T, U>
extends Attribute<T>, NavigableExpression<T, U> {

@Override
default BooleanAttribute<T> navigate(BooleanAttribute<U> attribute) {
return BooleanPath.of(this, attribute);
}

@Override
default <C extends Comparable<C>> ComparableAttribute<T, C> navigate(
ComparableAttribute<U, C> attribute) {
return ComparablePath.of(this, attribute);
}

@Override
default <V> NavigableExpression<T, V> navigate(
NavigableAttribute<U, V> attribute) {
return NavigablePath.of(this, attribute);
}

@Override
default <N extends Number & Comparable<N>> NumericAttribute<T, N> navigate(
NumericAttribute<U, N> attribute) {
return NumericPath.of(this, attribute);
}

@Override
default <V extends Temporal & Comparable<? extends Temporal>>
TemporalAttribute<T, V> navigate(
TemporalAttribute<U, V> attribute) {
return TemporalPath.of(this, attribute);
}

@Override
default TextAttribute<T> navigate(TextAttribute<U> attribute) {
return TextPath.of(this, attribute);
}

@Override
Class<U> type();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
*/
package jakarta.data.spi.expression.path;

import jakarta.data.expression.BooleanExpression;
import jakarta.data.expression.NavigableExpression;
import jakarta.data.metamodel.BooleanAttribute;
import jakarta.data.metamodel.NavigableAttribute;

public interface BooleanPath<T, U>
extends Path<T, U>,
BooleanExpression<T> {
BooleanAttribute<T> {

static <T, U> BooleanPath<T, U> of(NavigableExpression<T, U> expression,
static <T, U> BooleanPath<T, U> of(NavigableAttribute<T, U> expression,
BooleanAttribute<U> attribute) {

return new BooleanPathRecord<>(expression, attribute);
String name = expression.name() + '.' + attribute.name();
return new BooleanPathRecord<>(name, expression, attribute);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
*/
package jakarta.data.spi.expression.path;

import jakarta.data.expression.NavigableExpression;
import jakarta.data.messages.Messages;
import jakarta.data.metamodel.BooleanAttribute;
import jakarta.data.metamodel.NavigableAttribute;

record BooleanPathRecord<T, U>(NavigableExpression<T, U> expression,
record BooleanPathRecord<T, U>(String name,
NavigableAttribute<T, U> expression,
BooleanAttribute<U> attribute)
implements BooleanPath<T, U> {

Expand All @@ -30,13 +31,19 @@ record BooleanPathRecord<T, U>(NavigableExpression<T, U> expression,
Messages.requireNonNull(attribute, "attribute");
}

@Override
public Class<T> declaringType() {
return expression.declaringType();
}

@Override
public String toString() {
String expr = expression.toString();
String attrName = attribute.name();
StringBuilder path =
new StringBuilder(expr.length() + 1 + attrName.length());
path.append(expr).append('.').append(attrName);
return path.toString();
return expression + "." + attribute.name();
}

@Override
public Class<Boolean> type() {
return attribute.type();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2025,2026 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,14 +17,15 @@
*/
package jakarta.data.spi.expression.path;

import jakarta.data.expression.ComparableExpression;
import jakarta.data.expression.NavigableExpression;
import jakarta.data.metamodel.ComparableAttribute;
import jakarta.data.metamodel.NavigableAttribute;

public interface ComparablePath<T, U, C extends Comparable<?>>
extends Path<T, U>, ComparableExpression<T, C> {
static <T, U, C extends Comparable<C>> ComparablePath<T, U, C>
of(NavigableExpression<T, U> expression, ComparableAttribute<U, C> attribute) {
return new ComparablePathRecord<>(expression, attribute);
extends Path<T, U>, ComparableAttribute<T, C> {
static <T, U, C extends Comparable<C>> ComparablePath<T, U, C> of(
NavigableAttribute<T, U> expression,
ComparableAttribute<U, C> attribute) {
String name = expression.name() + '.' + attribute.name();
return new ComparablePathRecord<>(name, expression, attribute);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2025,2026 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,13 +17,14 @@
*/
package jakarta.data.spi.expression.path;

import jakarta.data.expression.NavigableExpression;
import jakarta.data.messages.Messages;
import jakarta.data.metamodel.ComparableAttribute;
import jakarta.data.metamodel.NavigableAttribute;

record ComparablePathRecord<T, U, C extends Comparable<?>>
(NavigableExpression<T, U> expression,
ComparableAttribute<U, C> attribute)
record ComparablePathRecord<T, U, C extends Comparable<?>>(
String name,
NavigableAttribute<T, U> expression,
ComparableAttribute<U, C> attribute)
implements ComparablePath<T, U, C> {

ComparablePathRecord {
Expand All @@ -32,7 +33,12 @@ record ComparablePathRecord<T, U, C extends Comparable<?>>
}

@Override
public Class<? extends C> type() {
public Class<T> declaringType() {
return expression.declaringType();
}

@Override
public Class<C> type() {
return attribute.type();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2025,2026 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,8 +22,10 @@

public interface NavigablePath<T, U, V>
extends Path<T, U>, NavigableExpression<T, V> {
static <T, U, V> NavigablePath<T, U, V> of(NavigableExpression<T, U> expression,
NavigableAttribute<U, V> attribute) {
return new NavigablePathRecord<>(expression, attribute);
static <T, U, V> NavigablePath<T, U, V> of(
NavigableAttribute<T, U> expression,
NavigableAttribute<U, V> attribute) {
String name = expression.name() + '.' + attribute.name();
return new NavigablePathRecord<>(name, expression, attribute);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2025,2026 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,10 +21,11 @@
import jakarta.data.messages.Messages;
import jakarta.data.metamodel.NavigableAttribute;

record NavigablePathRecord<T, U, V>
(NavigableExpression<T, U> expression,
NavigableAttribute<U, V> attribute)
implements NavigablePath<T, U, V> {
record NavigablePathRecord<T, U, V>(
String name,
NavigableExpression<T, U> expression,
NavigableAttribute<U, V> attribute)
implements NavigableAttribute<T, V>, NavigablePath<T, U, V> {

NavigablePathRecord {
Messages.requireNonNull(expression, "expression");
Expand All @@ -35,4 +36,9 @@ record NavigablePathRecord<T, U, V>
public String toString() {
return expression + "." + attribute.name();
}

@Override
public Class<V> type() {
return attribute.type();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2025,2026 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,14 +17,15 @@
*/
package jakarta.data.spi.expression.path;

import jakarta.data.expression.NavigableExpression;
import jakarta.data.expression.NumericExpression;
import jakarta.data.metamodel.NavigableAttribute;
import jakarta.data.metamodel.NumericAttribute;

public interface NumericPath<T, U, N extends Number & Comparable<N>>
extends Path<T, U>, NumericExpression<T, N> {
static <T, U, N extends Number & Comparable<N>> NumericPath<T, U, N>
of(NavigableExpression<T, U> expression, NumericAttribute<U, N> attribute) {
return new NumericPathRecord<>(expression, attribute);
extends Path<T, U>, NumericAttribute<T, N> {
static <T, U, N extends Number & Comparable<N>> NumericPath<T, U, N> of(
NavigableAttribute<T, U> expression,
NumericAttribute<U, N> attribute) {
String name = expression.name() + '.' + attribute.name();
return new NumericPathRecord<>(name, expression, attribute);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2025,2026 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,12 +17,14 @@
*/
package jakarta.data.spi.expression.path;

import jakarta.data.expression.NavigableExpression;
import jakarta.data.messages.Messages;
import jakarta.data.metamodel.NavigableAttribute;
import jakarta.data.metamodel.NumericAttribute;

record NumericPathRecord<T, U, N extends Number & Comparable<N>>
(NavigableExpression<T, U> expression, NumericAttribute<U, N> attribute)
record NumericPathRecord<T, U, N extends Number & Comparable<N>>(
String name,
NavigableAttribute<T, U> expression,
NumericAttribute<U, N> attribute)
implements NumericPath<T, U, N> {

NumericPathRecord {
Expand All @@ -31,7 +33,12 @@ record NumericPathRecord<T, U, N extends Number & Comparable<N>>
}

@Override
public Class<? extends N> type() {
public Class<T> declaringType() {
return expression.declaringType();
}

@Override
public Class<N> type() {
return attribute.type();
}

Expand Down
Loading