Skip to content

Adopt dataType for Literals and preparedValues #3395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 4.2.4-release
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
package com.apple.foundationdb.relational.api;

import com.apple.foundationdb.relational.api.exceptions.ErrorCode;
import com.apple.foundationdb.relational.api.metadata.DataType;

import javax.annotation.Nonnull;
import java.sql.SQLException;
import java.sql.Wrapper;

Expand Down Expand Up @@ -59,4 +61,13 @@ default StructMetaData getElementStructMetaData() throws SQLException {
* @throws SQLException if the type of the column is not an array, or if something else goes wrong.
*/
ArrayMetaData getElementArrayMetaData() throws SQLException;

/**
* Get the {@link DataType} object equivalent of this metadata.
*
* @return the datatype object.
* @throws SQLException if something goes wrong.
*/
@Nonnull
DataType.ArrayType asRelationalType() throws SQLException;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import javax.annotation.Nonnull;
import java.sql.SQLException;
import java.util.UUID;

/**
* Builder for {@link RelationalArray}.
Expand All @@ -42,7 +43,11 @@ public interface RelationalArrayBuilder {

RelationalArrayBuilder addString(@Nonnull String value) throws SQLException;

RelationalArrayBuilder addLong(@Nonnull long value) throws SQLException;
RelationalArrayBuilder addLong(long value) throws SQLException;

RelationalArrayBuilder addUuid(@Nonnull UUID value) throws SQLException;

RelationalArrayBuilder addObject(@Nonnull Object value) throws SQLException;

RelationalArrayBuilder addStruct(RelationalStruct struct) throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
package com.apple.foundationdb.relational.api;

import com.apple.foundationdb.annotation.API;

import com.apple.foundationdb.relational.api.exceptions.ErrorCode;
import com.apple.foundationdb.relational.api.exceptions.RelationalException;

import com.apple.foundationdb.relational.api.metadata.DataType;
import com.google.common.base.Suppliers;

import javax.annotation.Nonnull;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Objects;
import java.util.function.Supplier;

Expand All @@ -39,41 +38,42 @@
@API(API.Status.EXPERIMENTAL)
public final class RelationalArrayMetaData implements ArrayMetaData {

private final FieldDescription element;
private final DataType.ArrayType type;

private final Supplier<Integer> hashCodeSupplier;

private RelationalArrayMetaData(@Nonnull FieldDescription element) {
this.element = element;
private RelationalArrayMetaData(@Nonnull DataType.ArrayType type) {
this.type = type;
this.hashCodeSupplier = Suppliers.memoize(this::calculateHashCode);
}

public static RelationalArrayMetaData ofPrimitive(int sqlType, int nullable) {
return new RelationalArrayMetaData(FieldDescription.primitive("VALUE", sqlType, nullable));
}

public static RelationalArrayMetaData ofStruct(@Nonnull StructMetaData metaData, int nullable) {
return new RelationalArrayMetaData(FieldDescription.struct("VALUE", nullable, metaData));
@Nonnull
public static RelationalArrayMetaData of(@Nonnull DataType.ArrayType type) {
return new RelationalArrayMetaData(type);
}

@Override
public int isElementNullable() throws SQLException {
return element.isNullable();
public int isElementNullable() {
if (type.getElementType().isNullable()) {
return DatabaseMetaData.columnNullable;
} else {
return DatabaseMetaData.columnNoNulls;
}
}

@Override
public String getElementName() throws SQLException {
return element.getName();
return "VALUE";
}

@Override
public int getElementType() throws SQLException {
return element.getSqlTypeCode();
return type.getElementType().getJdbcSqlCode();
}

@Override
public String getElementTypeName() throws SQLException {
return SqlTypeNamesSupport.getSqlTypeName(element.getSqlTypeCode());
public String getElementTypeName() {
return SqlTypeNamesSupport.getSqlTypeName(type.getElementType().getJdbcSqlCode());
}

/**
Expand All @@ -86,10 +86,10 @@ public String getElementTypeName() throws SQLException {
*/
@Override
public StructMetaData getElementStructMetaData() throws SQLException {
if (element.getSqlTypeCode() != Types.STRUCT) {
if (type.getElementType().getCode() != DataType.Code.STRUCT) {
throw new RelationalException("Element is not of STRUCT type", ErrorCode.CANNOT_CONVERT_TYPE).toSqlException();
}
return element.getFieldMetaData();
return RelationalStructMetaData.of((DataType.StructType) type.getElementType());
}

/**
Expand All @@ -102,15 +102,21 @@ public StructMetaData getElementStructMetaData() throws SQLException {
*/
@Override
public ArrayMetaData getElementArrayMetaData() throws SQLException {
if (element.getSqlTypeCode() != Types.ARRAY) {
if (type.getElementType().getCode() != DataType.Code.ARRAY) {
throw new RelationalException("Element is not of ARRAY type", ErrorCode.CANNOT_CONVERT_TYPE).toSqlException();
}
return element.getArrayMetaData();
return RelationalArrayMetaData.of((DataType.ArrayType) type.getElementType());
}

@Nonnull
@Override
public DataType.ArrayType asRelationalType() throws SQLException {
return type;
}

@Nonnull
public FieldDescription getElementField() {
return element;
public DataType getElementDataType() {
return type.getElementType();
}

@Override
Expand All @@ -132,7 +138,7 @@ public boolean equals(Object other) {
if (otherMetadata == this) {
return true;
}
return element.equals(otherMetadata.element);
return type.equals(otherMetadata.type);
}

@Override
Expand All @@ -141,7 +147,7 @@ public int hashCode() {
}

private int calculateHashCode() {
return Objects.hash(element);
return Objects.hash(type);
}

}
Loading
Loading