Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Hale <[email protected]>
  • Loading branch information
nebhale committed Jan 31, 2019
1 parent 1e8442a commit 7db028e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,25 @@

public final class MockColumnMetadata implements ColumnMetadata {

public static final String EMPTY_NAME = "empty-name";

public static final Nullability EMPTY_NULLABILITY = Nullability.UNKNOWN;
private final Class<?> javaType;

private final String name;

private final Integer precision;

private final Integer scale;
private final Object nativeTypeMetadata;

private final Nullability nullability;

private final Class<?> type;
private final Integer precision;

private final Object nativeMetadata;
private final Integer scale;

private MockColumnMetadata(String name, @Nullable Integer precision, @Nullable Integer scale, Nullability nullability, @Nullable Class<?> type, @Nullable Object nativeMetadata) {
private MockColumnMetadata(@Nullable Class<?> javaType, String name, @Nullable Object nativeTypeMetadata, Nullability nullability, @Nullable Integer precision, @Nullable Integer scale) {
this.javaType = javaType;
this.name = Assert.requireNonNull(name, "name must not be null");
this.nativeTypeMetadata = nativeTypeMetadata;
this.nullability = Assert.requireNonNull(nullability, "nullability must not be null");
this.precision = precision;
this.scale = scale;
this.nullability = Assert.requireNonNull(nullability, "nullability must not be null");
this.type = type;
this.nativeMetadata = nativeMetadata;
}

public static Builder builder() {
Expand All @@ -52,24 +48,24 @@ public static Builder builder() {

public static MockColumnMetadata empty() {
return builder()
.name(EMPTY_NAME)
.nullability(EMPTY_NULLABILITY)
.name("test-name")
.nullability(Nullability.UNKNOWN)
.build();
}

@Override
public String getName() {
return this.name;
public Class<?> getJavaType() {
return this.javaType;
}

@Override
public Integer getPrecision() {
return this.precision;
public String getName() {
return this.name;
}

@Override
public Integer getScale() {
return this.scale;
public Object getNativeTypeMetadata() {
return this.nativeTypeMetadata;
}

@Override
Expand All @@ -78,60 +74,60 @@ public Nullability getNullability() {
}

@Override
public Class<?> getJavaType() {
return this.type;
public Integer getPrecision() {
return this.precision;
}

@Override
public Object getNativeTypeMetadata() {
return this.nativeMetadata;
public Integer getScale() {
return this.scale;
}

@Override
public String toString() {
return "MockColumnMetadata{" +
"name='" + this.name + '\'' +
"javaType=" + this.javaType +
", name='" + this.name + '\'' +
", nativeTypeMetadata=" + this.nativeTypeMetadata +
", nullability=" + this.nullability +
", precision=" + this.precision +
", scale=" + this.scale +
", nullability=" + this.nullability +
", type=" + this.type +
", nativeMetadata=" + this.nativeMetadata +
'}';
}

public static final class Builder {

private String name;
private Class<?> javaType;

private Integer precision;
private String name;

private Integer scale;
private Object nativeTypeMetadata;

private Nullability nullability;
private Nullability nullability = Nullability.UNKNOWN;

private Class<?> type;
private Integer precision;

private Object nativeMetadata;
private Integer scale;

private Builder() {
}

public MockColumnMetadata build() {
return new MockColumnMetadata(this.name, this.precision, this.scale, this.nullability, this.type, this.nativeMetadata);
return new MockColumnMetadata(this.javaType, this.name, this.nativeTypeMetadata, this.nullability, this.precision, this.scale);
}

public Builder name(String name) {
this.name = Assert.requireNonNull(name, "name must not be null");
public Builder javaType(Class<?> type) {
this.javaType = Assert.requireNonNull(type, "javaType must not be null");
return this;
}

public Builder precision(Integer precision) {
this.precision = Assert.requireNonNull(precision, "precision must not be null");
public Builder name(String name) {
this.name = Assert.requireNonNull(name, "name must not be null");
return this;
}

public Builder scale(Integer precision) {
this.scale = Assert.requireNonNull(precision, "scale must not be null");
public Builder nativeTypeMetadata(Object nativeTypeMetadata) {
this.nativeTypeMetadata = Assert.requireNonNull(nativeTypeMetadata, "nativeTypeMetadata must not be null");
return this;
}

Expand All @@ -140,27 +136,15 @@ public Builder nullability(Nullability nullability) {
return this;
}

public Builder type(Class<?> type) {
this.type = Assert.requireNonNull(type, "type must not be null");
public Builder precision(Integer precision) {
this.precision = Assert.requireNonNull(precision, "precision must not be null");
return this;
}

public Builder nativeMetadata(Object nativeMetadata) {
this.nativeMetadata = Assert.requireNonNull(nativeMetadata, "nativeMetadata must not be null");
public Builder scale(Integer precision) {
this.scale = Assert.requireNonNull(precision, "scale must not be null");
return this;
}

@Override
public String toString() {
return "Builder{" +
"name='" + this.name + '\'' +
", precision=" + this.precision +
", scale=" + this.scale +
", nullability=" + this.nullability +
", type=" + this.type +
", nativeMetadata=" + this.nativeMetadata +
'}';
}
}

}
72 changes: 36 additions & 36 deletions r2dbc-spi/src/main/java/io/r2dbc/spi/ColumnMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,38 @@
public interface ColumnMetadata {

/**
* Returns the name of the column.
*
* @return the name of the column
*/
String getName();

/**
* Returns the precision of the column.
* <p>
* For numeric data, this is the maximum precision.
* For character data, this is the length in characters.
* For datetime data types, this is the length in bytes required to represent the value (assuming the
* maximum allowed precision of the fractional seconds component).
* For binary data, this is the length in bytes.
* Returns {@code null} for data types where the column size is not applicable or if the precision cannot be provided.
* Returns the primary Java {@link Class type}. This type can be considered the native representation that is used to exchange values with the least loss in precision.
* <p>
* <strong>Implementation notes</strong>
* Implementation of this method is optional. The default implementation returns {@code null}.
* Drivers should implement this method. The method should return the actual type and refrain from returning {@code Object.class}. The default implementation returns {@code null}.
* Drivers may need to inspect the value and perform parts of decoding to determine the native Java type. This method
* should be expected to run in non-constant time.
*
* @return the precision of the column or {@code null} if the precision is not available.
* @return the primary Java {@link Class type} or {@code null} if the type is not available.
* @see Row#get(Object, Class)
*/
@Nullable
default Integer getPrecision() {
default Class<?> getJavaType() {
return null;
}

/**
* Returns the scale of the column.
* <p>
* This is the number of digits to right of the decimal point.
* Returns {@code null} for data types where the scale is not applicable or if the precision cannot be provided.
* Returns the name of the column.
*
* @return the name of the column
*/
String getName();

/**
* Returns the native type descriptor that potentially exposes more metadata.
* <p>
* <strong>Implementation notes</strong>
* Implementation of this method is optional. The default implementation returns {@code null}.
* Drivers should implement this method if they can expose a driver-specific type metadata object exposing additional information. The default implementation returns {@code null}.
*
* @return the scale of the column or {@code null} if the scale is not available.
* @return the native type descriptor that potentially exposes more metadata or {@code null} if no native type descriptor is available.
*/
@Nullable
default Integer getScale() {
default Object getNativeTypeMetadata() {
return null;
}

Expand All @@ -79,31 +72,38 @@ default Nullability getNullability() {
}

/**
* Returns the primary Java {@link Class type}. This type can be considered the native representation that is used to exchange values with the least loss in precision.
* Returns the precision of the column.
* <p>
* For numeric data, this is the maximum precision.
* For character data, this is the length in characters.
* For datetime data types, this is the length in bytes required to represent the value (assuming the
* maximum allowed precision of the fractional seconds component).
* For binary data, this is the length in bytes.
* Returns {@code null} for data types where the column size is not applicable or if the precision cannot be provided.
* <p>
* <strong>Implementation notes</strong>
* Drivers should implement this method. The method should return the actual type and refrain from returning {@code Object.class}. The default implementation returns {@code null}.
* Drivers may need to inspect the value and perform parts of decoding to determine the native Java type. This method
* should be expected to run in non-constant time.
* Implementation of this method is optional. The default implementation returns {@code null}.
*
* @return the primary Java {@link Class type} or {@code null} if the type is not available.
* @see Row#get(Object, Class)
* @return the precision of the column or {@code null} if the precision is not available.
*/
@Nullable
default Class<?> getJavaType() {
default Integer getPrecision() {
return null;
}

/**
* Returns the native type descriptor that potentially exposes more metadata.
* Returns the scale of the column.
* <p>
* This is the number of digits to right of the decimal point.
* Returns {@code null} for data types where the scale is not applicable or if the precision cannot be provided.
* <p>
* <strong>Implementation notes</strong>
* Drivers should implement this method if they can expose a driver-specific type metadata object exposing additional information. The default implementation returns {@code null}.
* Implementation of this method is optional. The default implementation returns {@code null}.
*
* @return the native type descriptor that potentially exposes more metadata or {@code null} if no native type descriptor is available.
* @return the scale of the column or {@code null} if the scale is not available.
*/
@Nullable
default Object getNativeTypeMetadata() {
default Integer getScale() {
return null;
}

Expand Down

0 comments on commit 7db028e

Please sign in to comment.