Skip to content

Commit

Permalink
Merge pull request #895 from njr-11/829-dynamic-query-restrictions
Browse files Browse the repository at this point in the history
dynamic query restrictions
  • Loading branch information
otaviojava authored Dec 4, 2024
2 parents 1bb60bb + 1e70a1a commit a4cd44d
Show file tree
Hide file tree
Showing 19 changed files with 1,541 additions and 1 deletion.
26 changes: 26 additions & 0 deletions api/src/main/java/jakarta/data/BasicRestriction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2024 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package jakarta.data;

public interface BasicRestriction<T> extends Restriction<T> {
Operator comparison();

String field();

Object value();
}
39 changes: 39 additions & 0 deletions api/src/main/java/jakarta/data/BasicRestrictionRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package jakarta.data;

// Internal implementation class.
// The proper way for users to obtain instances is via
// the static metamodel or Restrict.* methods

import java.util.Objects;

record BasicRestrictionRecord<T>(
String field,
boolean isNegated,
Operator comparison,
Object value) implements BasicRestriction<T> {

BasicRestrictionRecord {
Objects.requireNonNull(field, "Field must not be null");
}

BasicRestrictionRecord(String field, Operator comparison, Object value) {
this(field, false, comparison, value);
}
}
31 changes: 31 additions & 0 deletions api/src/main/java/jakarta/data/CompositeRestriction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package jakarta.data;

import java.util.List;

public interface CompositeRestriction<T> extends Restriction<T> {
List<Restriction<T>> restrictions();

Type type();

enum Type {
ALL,
ANY
}
}
41 changes: 41 additions & 0 deletions api/src/main/java/jakarta/data/CompositeRestrictionRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package jakarta.data;

import java.util.List;

// Internal implementation class.
// The proper way for users to obtain instances is via
// the Restrict.any(...) or Restrict.all(...) methods

record CompositeRestrictionRecord<T>(
Type type,
List<Restriction<T>> restrictions,
boolean isNegated) implements CompositeRestriction<T> {

CompositeRestrictionRecord {
if (restrictions == null || restrictions.isEmpty()) {
throw new IllegalArgumentException(
"Cannot create a composite restriction without any restrictions to combine.");
}
}

CompositeRestrictionRecord(Type type, List<Restriction<T>> restrictions) {
this(type, restrictions, false);
}
}
28 changes: 28 additions & 0 deletions api/src/main/java/jakarta/data/Operator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package jakarta.data;

public enum Operator {
EQUAL,
GREATER_THAN,
GREATER_THAN_EQUAL,
IN,
LESS_THAN,
LESS_THAN_EQUAL,
LIKE
}
Loading

0 comments on commit a4cd44d

Please sign in to comment.