|
15 | 15 | */
|
16 | 16 | package org.springframework.data.jdbc.core.dialect;
|
17 | 17 |
|
18 |
| -import java.sql.JDBCType; |
| 18 | +import java.sql.SQLType; |
19 | 19 |
|
20 | 20 | import org.springframework.data.relational.core.dialect.ArrayColumns;
|
21 | 21 |
|
22 | 22 | /**
|
23 |
| - * {@link org.springframework.data.relational.core.dialect.ArrayColumns} that offer JDBC specific functionality. |
24 |
| - * |
| 23 | + * {@link org.springframework.data.relational.core.dialect.ArrayColumns} that offer JDBC-specific functionality. |
| 24 | + * |
25 | 25 | * @author Jens Schauder
|
26 | 26 | * @since 2.3
|
27 | 27 | */
|
28 | 28 | public interface JdbcArrayColumns extends ArrayColumns {
|
29 | 29 |
|
30 |
| - JdbcArrayColumns UNSUPPORTED = new JdbcArrayColumns() { |
| 30 | + /* |
| 31 | + * (non-Javadoc) |
| 32 | + * @see org.springframework.data.relational.core.dialect.ArrayColumns#getArrayType(java.lang.Class) |
| 33 | + */ |
| 34 | + @Override |
| 35 | + default Class<?> getArrayType(Class<?> userType) { |
| 36 | + |
| 37 | + Class<?> componentType = userType; |
| 38 | + while (componentType.isArray()) { |
| 39 | + componentType = componentType.getComponentType(); |
| 40 | + } |
| 41 | + |
| 42 | + return componentType; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * The appropriate SQL type as a String which should be used to represent the given {@link SQLType} in an |
| 47 | + * {@link java.sql.Array}. Defaults to the name of the argument. |
| 48 | + * |
| 49 | + * @param jdbcType the {@link SQLType} value representing the type that should be stored in the |
| 50 | + * {@link java.sql.Array}. Must not be {@literal null}. |
| 51 | + * @return the appropriate SQL type as a String which should be used to represent the given {@link SQLType} in an |
| 52 | + * {@link java.sql.Array}. Guaranteed to be not {@literal null}. |
| 53 | + */ |
| 54 | + default String getArrayTypeName(SQLType jdbcType) { |
| 55 | + return jdbcType.getName(); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Default {@link ArrayColumns} implementation for dialects that do not support array-typed columns. |
| 60 | + */ |
| 61 | + enum Unsupported implements JdbcArrayColumns { |
| 62 | + |
| 63 | + INSTANCE; |
| 64 | + |
| 65 | + /* |
| 66 | + * (non-Javadoc) |
| 67 | + * @see org.springframework.data.relational.core.dialect.ArrayColumns#isSupported() |
| 68 | + */ |
31 | 69 | @Override
|
32 | 70 | public boolean isSupported() {
|
33 | 71 | return false;
|
34 | 72 | }
|
35 | 73 |
|
| 74 | + /* |
| 75 | + * (non-Javadoc) |
| 76 | + * @see org.springframework.data.relational.core.dialect.ArrayColumns#JdbcArrayColumns(JDBCType) |
| 77 | + */ |
36 | 78 | @Override
|
37 |
| - public Class<?> getArrayType(Class<?> userType) { |
| 79 | + public String getArrayTypeName(SQLType jdbcType) { |
38 | 80 | throw new UnsupportedOperationException("Array types not supported");
|
39 | 81 | }
|
40 | 82 |
|
41 |
| - @Override |
42 |
| - public String getSqlTypeRepresentation(JDBCType jdbcType) { |
43 |
| - throw new UnsupportedOperationException("Array types not supported"); |
44 |
| - } |
45 |
| - }; |
| 83 | + } |
46 | 84 |
|
47 | 85 | /**
|
48 |
| - * The appropriate SQL type as a String which should be used to represent the given {@link JDBCType} in an |
49 |
| - * {@link java.sql.Array}. Defaults to the name of the argument. |
50 |
| - * |
51 |
| - * @param jdbcType the {@link JDBCType} value representing the type that should be stored in the |
52 |
| - * {@link java.sql.Array}. Must not be {@literal null}. |
53 |
| - * @return the appropriate SQL type as a String which should be used to represent the given {@link JDBCType} in an |
54 |
| - * {@link java.sql.Array}. Guaranteed to be not {@literal null}. |
| 86 | + * Default {@link ArrayColumns} implementation for dialects that do not support array-typed columns. |
55 | 87 | */
|
56 |
| - default String getSqlTypeRepresentation(JDBCType jdbcType) { |
57 |
| - return jdbcType.getName(); |
| 88 | + enum DefaultSupport implements JdbcArrayColumns { |
| 89 | + |
| 90 | + INSTANCE; |
| 91 | + |
| 92 | + /* |
| 93 | + * (non-Javadoc) |
| 94 | + * @see org.springframework.data.relational.core.dialect.ArrayColumns#isSupported() |
| 95 | + */ |
| 96 | + @Override |
| 97 | + public boolean isSupported() { |
| 98 | + return true; |
| 99 | + } |
| 100 | + |
| 101 | + /* |
| 102 | + * (non-Javadoc) |
| 103 | + * @see org.springframework.data.relational.core.dialect.ArrayColumns#JdbcArrayColumns(JDBCType) |
| 104 | + */ |
| 105 | + @Override |
| 106 | + public String getArrayTypeName(SQLType jdbcType) { |
| 107 | + return jdbcType.getName(); |
| 108 | + } |
| 109 | + |
58 | 110 | }
|
59 | 111 |
|
60 | 112 | }
|
0 commit comments