Skip to content

Commit 99ade34

Browse files
committed
Implement CassandraDatabaseMetaData.getAttributes()
Also replace all Findbugs NonNull/Nullable annotations with standard Java equivalent, and preform some code cleanup.
1 parent 236928e commit 99ade34

32 files changed

+360
-140
lines changed

Diff for: src/main/java/com/ing/data/cassandra/jdbc/AbstractResultSet.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
import com.datastax.oss.driver.api.core.type.DataType;
1919
import com.ing.data.cassandra.jdbc.types.DataTypeEnum;
20-
import edu.umd.cs.findbugs.annotations.NonNull;
2120
import org.apache.commons.lang3.StringUtils;
2221

22+
import javax.annotation.Nonnull;
2323
import java.io.InputStream;
2424
import java.io.Reader;
2525
import java.math.BigDecimal;
@@ -56,7 +56,7 @@ abstract class AbstractResultSet implements Wrapper {
5656
* @param type The data type to check.
5757
* @return {@code true} if the column CQL data type is the given one, {@code false} otherwise.
5858
*/
59-
boolean isCqlType(final int columnIndex, @NonNull final DataTypeEnum type) {
59+
boolean isCqlType(final int columnIndex, @Nonnull final DataTypeEnum type) {
6060
final String columnType = StringUtils.substringBefore(DataTypeEnum.cqlName(getCqlDataType(columnIndex)), "<");
6161
return type.cqlType.equalsIgnoreCase(columnType);
6262
}
@@ -68,7 +68,7 @@ boolean isCqlType(final int columnIndex, @NonNull final DataTypeEnum type) {
6868
* @param type The data type to check.
6969
* @return {@code true} if the column CQL data type is the given one, {@code false} otherwise.
7070
*/
71-
boolean isCqlType(final String columnLabel, @NonNull final DataTypeEnum type) {
71+
boolean isCqlType(final String columnLabel, @Nonnull final DataTypeEnum type) {
7272
final String columnType = StringUtils.substringBefore(DataTypeEnum.cqlName(getCqlDataType(columnLabel)), "<");
7373
return type.cqlType.equalsIgnoreCase(columnType);
7474
}

Diff for: src/main/java/com/ing/data/cassandra/jdbc/CassandraConnection.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.HashMap;
5252
import java.util.List;
5353
import java.util.Map;
54+
import java.util.Objects;
5455
import java.util.Properties;
5556
import java.util.ServiceLoader;
5657
import java.util.Set;
@@ -160,18 +161,13 @@ public CassandraConnection(final SessionHolder sessionHolder) throws SQLExceptio
160161
this.cSession = sessionHolder.session;
161162
this.metadata = this.cSession.getMetadata();
162163

163-
// TODO check if this code should be definitely removed.
164-
// final List<SessionHolder> l = new ArrayList<>();
165-
// l.stream().map(s -> s.session).collect(Collectors.toList());
166-
167164
LOG.info("Connected to cluster: {}, with session: {}",
168-
StringUtils.defaultString(getCatalog(), "<not available>"), this.cSession.getName());
165+
Objects.toString(getCatalog(), "<not available>"), this.cSession.getName());
169166
this.metadata.getNodes().forEach(
170167
(uuid, node) -> LOG.info("Datacenter: {}; Host: {}; Rack: {}", node.getDatacenter(),
171168
node.getEndPoint().resolve(), node.getRack())
172169
);
173170

174-
// TODO this is shared among all Connections, what if they belong to different clusters?
175171
this.metadata.getNodes().entrySet().stream().findFirst().ifPresent(entry -> {
176172
final Version cassandraVersion = entry.getValue().getCassandraVersion();
177173
if (cassandraVersion != null) {

Diff for: src/main/java/com/ing/data/cassandra/jdbc/CassandraDatabaseMetaData.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ public boolean generatedKeyAlwaysReturned() {
123123
@Override
124124
public ResultSet getAttributes(final String catalog, final String schemaPattern, final String typeNamePattern,
125125
final String attributeNamePattern) throws SQLException {
126-
// TODO: method to implement into TypeMetadataResultSetBuilder
127126
checkStatementClosed();
127+
// Only null or the current catalog (i.e. cluster) name are supported.
128+
if (catalog == null || catalog.equals(this.connection.getCatalog())) {
129+
return new TypeMetadataResultSetBuilder(this.statement).buildAttributes(schemaPattern, typeNamePattern,
130+
attributeNamePattern);
131+
}
128132
return CassandraResultSet.EMPTY_RESULT_SET;
129133
}
130134

Diff for: src/main/java/com/ing/data/cassandra/jdbc/CassandraResultSetJsonSupport.java

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
* <tr><td>uuid </td><td>string </td><td>{@link UUID} </td></tr>
7070
* <tr><td>varchar </td><td>string </td><td>{@link String} </td></tr>
7171
* <tr><td>varint </td><td>integer </td><td>{@link Number} </td></tr>
72+
* <tr><td>vector </td><td>list </td><td>{@link List} </td></tr>
7273
* </table>
7374
* See: <a href="https://cassandra.apache.org/doc/latest/cassandra/cql/json.html">
7475
* CQL reference for JSON support</a>.

Diff for: src/main/java/com/ing/data/cassandra/jdbc/CassandraStatement.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import com.datastax.oss.driver.internal.core.cql.MultiPageResultSet;
2525
import com.datastax.oss.driver.internal.core.cql.SinglePageResultSet;
2626
import com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures;
27-
import edu.umd.cs.findbugs.annotations.NonNull;
2827
import org.apache.commons.lang3.StringUtils;
2928
import org.slf4j.Logger;
3029
import org.slf4j.LoggerFactory;
3130

31+
import javax.annotation.Nonnull;
3232
import java.sql.CallableStatement;
3333
import java.sql.Connection;
3434
import java.sql.PreparedStatement;
@@ -282,7 +282,7 @@ public void close() {
282282
}
283283

284284
@Override
285-
public int compareTo(@NonNull final Object target) {
285+
public int compareTo(@Nonnull final Object target) {
286286
if (this.equals(target)) {
287287
return 0;
288288
}

Diff for: src/main/java/com/ing/data/cassandra/jdbc/codec/AbstractCodec.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
package com.ing.data.cassandra.jdbc.codec;
1717

1818
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
19-
import edu.umd.cs.findbugs.annotations.NonNull;
2019
import org.apache.commons.lang3.StringUtils;
2120

21+
import javax.annotation.Nonnull;
22+
2223
import static com.ing.data.cassandra.jdbc.utils.DriverUtil.NULL_KEYWORD;
2324

2425
/**
@@ -51,15 +52,15 @@ public JavaTypeT parse(final String value) {
5152
* @param value The value to parse.
5253
* @return The parsed value.
5354
*/
54-
abstract JavaTypeT parseNonNull(@NonNull String value);
55+
abstract JavaTypeT parseNonNull(@Nonnull String value);
5556

5657
/**
5758
* Formats the given value as a valid CQL literal according to the CQL type handled by this codec.
5859
*
5960
* @param value The value to format.
6061
* @return The formatted value or {@code NULL} CQL keyword if the value to format is {@code null}.
6162
*/
62-
@NonNull
63+
@Nonnull
6364
public String format(final JavaTypeT value) {
6465
if (value == null) {
6566
return NULL_KEYWORD;
@@ -73,5 +74,5 @@ public String format(final JavaTypeT value) {
7374
* @param value The value to format.
7475
* @return The formatted value.
7576
*/
76-
abstract String formatNonNull(@NonNull JavaTypeT value);
77+
abstract String formatNonNull(@Nonnull JavaTypeT value);
7778
}

Diff for: src/main/java/com/ing/data/cassandra/jdbc/codec/BigintToBigDecimalCodec.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import com.datastax.oss.driver.api.core.type.DataTypes;
2121
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
2222
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
23-
import edu.umd.cs.findbugs.annotations.NonNull;
2423
import com.ing.data.cassandra.jdbc.utils.ByteBufferUtil;
2524

25+
import javax.annotation.Nonnull;
2626
import java.math.BigDecimal;
2727
import java.nio.ByteBuffer;
2828

@@ -37,28 +37,28 @@ public class BigintToBigDecimalCodec extends AbstractCodec<BigDecimal> implement
3737
public BigintToBigDecimalCodec() {
3838
}
3939

40-
@NonNull
40+
@Nonnull
4141
@Override
4242
public GenericType<BigDecimal> getJavaType() {
4343
return GenericType.BIG_DECIMAL;
4444
}
4545

46-
@NonNull
46+
@Nonnull
4747
@Override
4848
public DataType getCqlType() {
4949
return DataTypes.BIGINT;
5050
}
5151

5252
@Override
53-
public ByteBuffer encode(final BigDecimal value, @NonNull final ProtocolVersion protocolVersion) {
53+
public ByteBuffer encode(final BigDecimal value, @Nonnull final ProtocolVersion protocolVersion) {
5454
if (value == null) {
5555
return null;
5656
}
5757
return ByteBufferUtil.bytes(value.longValue());
5858
}
5959

6060
@Override
61-
public BigDecimal decode(final ByteBuffer bytes, @NonNull final ProtocolVersion protocolVersion) {
61+
public BigDecimal decode(final ByteBuffer bytes, @Nonnull final ProtocolVersion protocolVersion) {
6262
if (bytes == null) {
6363
return null;
6464
}
@@ -68,12 +68,12 @@ public BigDecimal decode(final ByteBuffer bytes, @NonNull final ProtocolVersion
6868
}
6969

7070
@Override
71-
BigDecimal parseNonNull(@NonNull final String value) {
71+
BigDecimal parseNonNull(@Nonnull final String value) {
7272
return BigDecimal.valueOf(Long.parseLong(value));
7373
}
7474

7575
@Override
76-
String formatNonNull(@NonNull final BigDecimal value) {
76+
String formatNonNull(@Nonnull final BigDecimal value) {
7777
return String.valueOf(value);
7878
}
7979

Diff for: src/main/java/com/ing/data/cassandra/jdbc/codec/DecimalToDoubleCodec.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import com.datastax.oss.driver.api.core.type.DataTypes;
2121
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
2222
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
23-
import edu.umd.cs.findbugs.annotations.NonNull;
2423
import com.ing.data.cassandra.jdbc.utils.ByteBufferUtil;
2524

25+
import javax.annotation.Nonnull;
2626
import java.nio.ByteBuffer;
2727

2828
/**
@@ -36,28 +36,28 @@ public class DecimalToDoubleCodec extends AbstractCodec<Double> implements TypeC
3636
public DecimalToDoubleCodec() {
3737
}
3838

39-
@NonNull
39+
@Nonnull
4040
@Override
4141
public GenericType<Double> getJavaType() {
4242
return GenericType.DOUBLE;
4343
}
4444

45-
@NonNull
45+
@Nonnull
4646
@Override
4747
public DataType getCqlType() {
4848
return DataTypes.DECIMAL;
4949
}
5050

5151
@Override
52-
public ByteBuffer encode(final Double value, @NonNull final ProtocolVersion protocolVersion) {
52+
public ByteBuffer encode(final Double value, @Nonnull final ProtocolVersion protocolVersion) {
5353
if (value == null) {
5454
return null;
5555
}
5656
return ByteBufferUtil.bytes(value);
5757
}
5858

5959
@Override
60-
public Double decode(final ByteBuffer bytes, @NonNull final ProtocolVersion protocolVersion) {
60+
public Double decode(final ByteBuffer bytes, @Nonnull final ProtocolVersion protocolVersion) {
6161
if (bytes == null) {
6262
return null;
6363
}
@@ -66,12 +66,12 @@ public Double decode(final ByteBuffer bytes, @NonNull final ProtocolVersion prot
6666
}
6767

6868
@Override
69-
Double parseNonNull(@NonNull final String value) {
69+
Double parseNonNull(@Nonnull final String value) {
7070
return Double.valueOf(value);
7171
}
7272

7373
@Override
74-
String formatNonNull(@NonNull final Double value) {
74+
String formatNonNull(@Nonnull final Double value) {
7575
return String.valueOf(value);
7676
}
7777

Diff for: src/main/java/com/ing/data/cassandra/jdbc/codec/FloatToDoubleCodec.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import com.datastax.oss.driver.api.core.type.DataTypes;
2121
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
2222
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
23-
import edu.umd.cs.findbugs.annotations.NonNull;
2423
import com.ing.data.cassandra.jdbc.utils.ByteBufferUtil;
2524

25+
import javax.annotation.Nonnull;
2626
import java.nio.ByteBuffer;
2727

2828
/**
@@ -36,28 +36,28 @@ public class FloatToDoubleCodec extends AbstractCodec<Double> implements TypeCod
3636
public FloatToDoubleCodec() {
3737
}
3838

39-
@NonNull
39+
@Nonnull
4040
@Override
4141
public GenericType<Double> getJavaType() {
4242
return GenericType.DOUBLE;
4343
}
4444

45-
@NonNull
45+
@Nonnull
4646
@Override
4747
public DataType getCqlType() {
4848
return DataTypes.FLOAT;
4949
}
5050

5151
@Override
52-
public ByteBuffer encode(final Double value, @NonNull final ProtocolVersion protocolVersion) {
52+
public ByteBuffer encode(final Double value, @Nonnull final ProtocolVersion protocolVersion) {
5353
if (value == null) {
5454
return null;
5555
}
5656
return ByteBufferUtil.bytes(value.floatValue());
5757
}
5858

5959
@Override
60-
public Double decode(final ByteBuffer bytes, @NonNull final ProtocolVersion protocolVersion) {
60+
public Double decode(final ByteBuffer bytes, @Nonnull final ProtocolVersion protocolVersion) {
6161
if (bytes == null) {
6262
return null;
6363
}
@@ -67,12 +67,12 @@ public Double decode(final ByteBuffer bytes, @NonNull final ProtocolVersion prot
6767
}
6868

6969
@Override
70-
Double parseNonNull(@NonNull final String value) {
70+
Double parseNonNull(@Nonnull final String value) {
7171
return Double.valueOf(value);
7272
}
7373

7474
@Override
75-
String formatNonNull(@NonNull final Double value) {
75+
String formatNonNull(@Nonnull final Double value) {
7676
return String.valueOf(value);
7777
}
7878

Diff for: src/main/java/com/ing/data/cassandra/jdbc/codec/IntToLongCodec.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import com.datastax.oss.driver.api.core.type.DataTypes;
2121
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
2222
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
23-
import edu.umd.cs.findbugs.annotations.NonNull;
2423
import com.ing.data.cassandra.jdbc.utils.ByteBufferUtil;
2524

25+
import javax.annotation.Nonnull;
2626
import java.nio.ByteBuffer;
2727

2828
/**
@@ -36,28 +36,28 @@ public class IntToLongCodec extends AbstractCodec<Long> implements TypeCodec<Lon
3636
public IntToLongCodec() {
3737
}
3838

39-
@NonNull
39+
@Nonnull
4040
@Override
4141
public GenericType<Long> getJavaType() {
4242
return GenericType.LONG;
4343
}
4444

45-
@NonNull
45+
@Nonnull
4646
@Override
4747
public DataType getCqlType() {
4848
return DataTypes.INT;
4949
}
5050

5151
@Override
52-
public ByteBuffer encode(final Long value, @NonNull final ProtocolVersion protocolVersion) {
52+
public ByteBuffer encode(final Long value, @Nonnull final ProtocolVersion protocolVersion) {
5353
if (value == null) {
5454
return null;
5555
}
5656
return ByteBufferUtil.bytes(value.intValue());
5757
}
5858

5959
@Override
60-
public Long decode(final ByteBuffer bytes, @NonNull final ProtocolVersion protocolVersion) {
60+
public Long decode(final ByteBuffer bytes, @Nonnull final ProtocolVersion protocolVersion) {
6161
if (bytes == null) {
6262
return null;
6363
}
@@ -66,12 +66,12 @@ public Long decode(final ByteBuffer bytes, @NonNull final ProtocolVersion protoc
6666
}
6767

6868
@Override
69-
Long parseNonNull(@NonNull final String value) {
69+
Long parseNonNull(@Nonnull final String value) {
7070
return Long.valueOf(value);
7171
}
7272

7373
@Override
74-
String formatNonNull(@NonNull final Long value) {
74+
String formatNonNull(@Nonnull final Long value) {
7575
return String.valueOf(value);
7676
}
7777
}

0 commit comments

Comments
 (0)