|
15 | 15 | */
|
16 | 16 | package org.springframework.data.relational.core.sql;
|
17 | 17 |
|
| 18 | +import java.util.Collections; |
| 19 | +import java.util.Iterator; |
18 | 20 | import java.util.function.UnaryOperator;
|
19 | 21 |
|
| 22 | +import org.springframework.data.util.Streamable; |
| 23 | + |
20 | 24 | /**
|
21 | 25 | * Represents a named object that exists in the database like a table name or a column name. SQL identifiers are created
|
22 | 26 | * from a {@link String name} with specifying whether the name should be quoted or unquoted.
|
|
28 | 32 | * <p>
|
29 | 33 | * {@link SqlIdentifier} objects are immutable. Calling transformational methods such as
|
30 | 34 | * {@link #transform(UnaryOperator)} creates a new instance.
|
| 35 | + * <p> |
| 36 | + * {@link SqlIdentifier} are composable so an identifier may consist of a single identifier part or can be composed from |
| 37 | + * multiple parts. Composed identifier can be traversed with {@link #stream()} or {@link #iterator()}. The iteration |
| 38 | + * order depends on the actual composition ordering. |
31 | 39 | *
|
32 | 40 | * @author Jens Schauder
|
33 | 41 | * @author Mark Paluch
|
34 | 42 | * @since 2.0
|
35 | 43 | */
|
36 |
| -public interface SqlIdentifier { |
| 44 | +public interface SqlIdentifier extends Streamable<SqlIdentifier> { |
37 | 45 |
|
38 | 46 | /**
|
39 | 47 | * Null-object.
|
40 | 48 | */
|
41 | 49 | SqlIdentifier EMPTY = new SqlIdentifier() {
|
42 | 50 |
|
| 51 | + @Override |
| 52 | + public Iterator<SqlIdentifier> iterator() { |
| 53 | + return Collections.emptyIterator(); |
| 54 | + } |
| 55 | + |
43 | 56 | @Override
|
44 | 57 | public SqlIdentifier transform(UnaryOperator<String> transformationFunction) {
|
45 | 58 | return this;
|
@@ -99,16 +112,6 @@ default String getReference() {
|
99 | 112 | */
|
100 | 113 | SqlIdentifier transform(UnaryOperator<String> transformationFunction);
|
101 | 114 |
|
102 |
| - /** |
103 |
| - * Returns the last part of an identifier. For a fully qualified column name {@literal schema.table.column} it will |
104 |
| - * just return the column part. If the identifier consists of only a single part, that part is returned. |
105 |
| - * |
106 |
| - * @return Guaranteed to be not {@literal null}. |
107 |
| - */ |
108 |
| - default SqlIdentifier getSimpleIdentifier() { |
109 |
| - return this; |
110 |
| - } |
111 |
| - |
112 | 115 | /**
|
113 | 116 | * Create a new quoted identifier given {@code name}.
|
114 | 117 | *
|
|
0 commit comments