#2318 - Refactor internals - final classes in type packages

This commit is contained in:
rbygrave committed 2021-08-17 19:46:08 +12:00
1 parent 55587b12aa
commit 826e8518ea
19 files changed
+56 -75

No files matched your search

@@ -7,7 +7,7 @@ import javax.persistence.AttributeConverter;
/**
* Adapter from ScalarTypeConverter to AttributeConverter.
*/
class AttributeConverterAdapter<B,S> implements ScalarTypeConverter<B, S> {
final class AttributeConverterAdapter<B,S> implements ScalarTypeConverter<B, S> {
private final AttributeConverter<B,S> converter;
private final B nullValue;
@@ -26,15 +26,10 @@ public class DataBind implements DataBinder {
private static final Logger log = LoggerFactory.getLogger(DataBind.class);
private final DataTimeZone dataTimeZone;
private final PreparedStatement pstmt;
private final Connection connection;
private final StringBuilder bindLog = new StringBuilder();
private List<InputStream> inputStreams;
protected int pos;
private String json;
@@ -45,35 +40,35 @@ public class DataBind implements DataBinder {
}
@Override
public void pushJson(String json) {
public final void pushJson(String json) {
assert this.json == null; // we can only push one value
this.json = json;
}
@Override
public String popJson() {
public final String popJson() {
String ret = json;
json = null;
return ret;
}
@Override
public StringBuilder append(Object entry) {
public final StringBuilder append(Object entry) {
return bindLog.append(entry);
}
@Override
public StringBuilder log() {
public final StringBuilder log() {
return bindLog;
}
@Override
public void close() throws SQLException {
public final void close() throws SQLException {
pstmt.close();
}
@Override
public int currentPos() {
public final int currentPos() {
return pos;
}
@@ -83,7 +78,7 @@ public class DataBind implements DataBinder {
}
@Override
public void setObject(Object value, int sqlType) throws SQLException {
public final void setObject(Object value, int sqlType) throws SQLException {
pstmt.setObject(++pos, value, sqlType);
}
@@ -93,17 +88,17 @@ public class DataBind implements DataBinder {
}
@Override
public int nextPos() {
public final int nextPos() {
return ++pos;
}
@Override
public void decrementPos() {
public final void decrementPos() {
--pos;
}
@Override
public int executeUpdate() throws SQLException {
public final int executeUpdate() throws SQLException {
try {
return pstmt.executeUpdate();
} finally {
@@ -125,7 +120,7 @@ public class DataBind implements DataBinder {
}
@Override
public PreparedStatement getPstmt() {
public final PreparedStatement getPstmt() {
return pstmt;
}
@@ -135,37 +130,37 @@ public class DataBind implements DataBinder {
}
@Override
public void setInt(int i) throws SQLException {
public final void setInt(int i) throws SQLException {
pstmt.setInt(++pos, i);
}
@Override
public void setLong(long i) throws SQLException {
public final void setLong(long i) throws SQLException {
pstmt.setLong(++pos, i);
}
@Override
public void setShort(short i) throws SQLException {
public final void setShort(short i) throws SQLException {
pstmt.setShort(++pos, i);
}
@Override
public void setFloat(float i) throws SQLException {
public final void setFloat(float i) throws SQLException {
pstmt.setFloat(++pos, i);
}
@Override
public void setDouble(double i) throws SQLException {
public final void setDouble(double i) throws SQLException {
pstmt.setDouble(++pos, i);
}
@Override
public void setBigDecimal(BigDecimal v) throws SQLException {
public final void setBigDecimal(BigDecimal v) throws SQLException {
pstmt.setBigDecimal(++pos, v);
}
@Override
public void setDate(java.sql.Date v) throws SQLException {
public final void setDate(java.sql.Date v) throws SQLException {
Calendar timeZone = dataTimeZone.getDateTimeZone();
if (timeZone != null) {
pstmt.setDate(++pos, v, timeZone);
@@ -175,7 +170,7 @@ public class DataBind implements DataBinder {
}
@Override
public void setTimestamp(Timestamp v) throws SQLException {
public final void setTimestamp(Timestamp v) throws SQLException {
Calendar timeZone = dataTimeZone.getTimeZone();
if (timeZone != null) {
pstmt.setTimestamp(++pos, v, timeZone);
@@ -185,7 +180,7 @@ public class DataBind implements DataBinder {
}
@Override
public void setTime(Time v) throws SQLException {
public final void setTime(Time v) throws SQLException {
Calendar timeZone = dataTimeZone.getTimeZone();
if (timeZone != null) {
pstmt.setTime(++pos, v, timeZone);
@@ -7,7 +7,7 @@ import io.ebeaninternal.server.type.bindcapture.BindCaptureStatement;
/**
* Special DataBind used to capture bind values for obtaining explain plans.
*/
public class DataBindCapture extends DataBind {
public final class DataBindCapture extends DataBind {
private final BindCaptureStatement captureStatement;
@@ -4,7 +4,7 @@ import io.ebean.config.EncryptKey;
import io.ebean.config.EncryptKeyManager;
import io.ebean.config.Encryptor;
public class DataEncryptSupport {
public final class DataEncryptSupport {
private final EncryptKeyManager encryptKeyManager;
private final Encryptor encryptor;
@@ -38,10 +38,8 @@ public final class DecimalUtils {
}
public static Duration toDuration(BigDecimal value) {
long seconds = value.longValue();
int nanoseconds = extractNanosecondDecimal(value, seconds);
return Duration.ofSeconds(seconds, nanoseconds);
}
@@ -50,10 +48,8 @@ public final class DecimalUtils {
}
public static Timestamp toTimestamp(BigDecimal value) {
long seconds = value.longValue();
int nanoseconds = extractNanosecondDecimal(value, seconds);
Timestamp ts = new Timestamp(seconds * 1000);
ts.setNanos(nanoseconds);
return ts;
@@ -66,7 +62,6 @@ public final class DecimalUtils {
}
public static Instant toInstant(BigDecimal value) {
long seconds = value.longValue();
int nanoseconds = extractNanosecondDecimal(value, seconds);
return Instant.ofEpochSecond(seconds, nanoseconds);
@@ -14,7 +14,7 @@ import java.util.Date;
* Helper to create some default ScalarType objects for Booleans,
* java.util.Date, java.util.Calendar etc.
*/
public class DefaultTypeFactory {
public final class DefaultTypeFactory {
private final DatabaseConfig config;
@@ -22,7 +22,7 @@ public class DefaultTypeFactory {
this.config = config;
}
protected ScalarTypeBool createBoolean(String trueValue, String falseValue) {
ScalarTypeBool createBoolean(String trueValue, String falseValue) {
try {
// first try Integer based boolean
Integer intTrue = BasicTypeConverter.toInteger(trueValue);
@@ -10,7 +10,7 @@ import java.sql.Types;
/**
* Used to map enum values to database integer values.
*/
public class EnumToDbIntegerMap extends EnumToDbValueMap<Integer> {
public final class EnumToDbIntegerMap extends EnumToDbValueMap<Integer> {
@Override
public int getDbType() {
@@ -9,7 +9,7 @@ import java.sql.Types;
/**
* Used to map Enum values to database string/varchar values.
*/
public class EnumToDbStringMap extends EnumToDbValueMap<String> {
public final class EnumToDbStringMap extends EnumToDbValueMap<String> {
@Override
public int getDbType() {
@@ -22,13 +22,9 @@ public abstract class EnumToDbValueMap<T> {
}
final LinkedHashMap<Object, T> keyMap;
final LinkedHashMap<T, Object> valueMap;
final HashMap<Object, Object> nameMap;
final boolean allowNulls;
final boolean isIntegerType;
/**
@@ -9,7 +9,7 @@ import java.util.Set;
/**
* Initialise the Jackson ObjectMapper.
*/
class InitObjectMapper {
final class InitObjectMapper {
/**
* Create and return the default ObjectMapper.
@@ -4,7 +4,7 @@ import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
class IsoJsonDateTimeParser {
final class IsoJsonDateTimeParser {
private static final DateTimeFormatter ISO_MILLIS = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.type;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
class JacksonTypeHelper {
final class JacksonTypeHelper {
private final AnnotatedField field;
private final ObjectMapper objectMapper;
@@ -4,7 +4,7 @@ import io.ebean.config.ScalarTypeConverter;
import java.sql.Timestamp;
public class LongToTimestampConverter implements ScalarTypeConverter<Long, Timestamp> {
public final class LongToTimestampConverter implements ScalarTypeConverter<Long, Timestamp> {
@Override
public Long getNullValue() {
@@ -13,15 +13,12 @@ public class LongToTimestampConverter implements ScalarTypeConverter<Long, Times
@Override
public Timestamp unwrapValue(Long beanType) {
return new Timestamp(beanType);
}
@Override
public Long wrapValue(Timestamp scalarType) {
return scalarType.getTime();
}
}
@@ -4,7 +4,7 @@ import org.postgresql.util.PGobject;
import java.sql.SQLException;
public class PostgresHelper {
public final class PostgresHelper {
/**
* The Postgres JSON DB type.
@@ -26,7 +26,6 @@ public class PostgresHelper {
* Construct and return Postgres specific PG object.
*/
public static Object asObject(String pgType, String rawJson) throws SQLException {
PGobject pgo = new PGobject();
pgo.setType(pgType);
pgo.setValue(rawJson);
@@ -7,7 +7,7 @@ import java.sql.ResultSet;
/**
* A DataReader with indexed positions for the properties to read specifically for RawSql use.
*/
public class RsetDataReaderIndexed extends RsetDataReader {
public final class RsetDataReaderIndexed extends RsetDataReader {
private final int[] rsetIndexPositions;
@@ -6,12 +6,12 @@ import java.io.IOException;
/**
* Utility methods for ScalarTypes.
*/
public class ScalarHelp {
final class ScalarHelp {
/**
* Write the string content as UTF with the proceeding boolean true indicating the non-null.
*/
public static void writeUTF(DataOutput dataOutput, String content) throws IOException {
static void writeUTF(DataOutput dataOutput, String content) throws IOException {
dataOutput.writeBoolean(true);
dataOutput.writeUTF(content);
}
@@ -9,7 +9,7 @@ import java.util.List;
/**
* Holds bind values that can be used to obtain an explain plan.
*/
public class BindCapture {
public final class BindCapture {
private final List<BindCaptureEntry> entries = new ArrayList<>();
@@ -12,7 +12,7 @@ import java.util.Calendar;
/**
* Special PreparedStatement used to capture bind values used to obtain explain plans.
*/
public class BindCaptureStatement extends BindCaptureStatementBase implements PreparedStatement {
public final class BindCaptureStatement extends BindCaptureStatementBase implements PreparedStatement {
private final BindCapture capture = new BindCapture();
@@ -13,9 +13,9 @@ import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Calendar;
class BindCaptureTypes {
final class BindCaptureTypes {
static class Null implements BindCaptureEntry {
static final class Null implements BindCaptureEntry {
private final int parameterIndex;
private final int sqlType;
@@ -36,7 +36,7 @@ class BindCaptureTypes {
}
}
static class Boolean implements BindCaptureEntry {
static final class Boolean implements BindCaptureEntry {
private final int parameterIndex;
private final boolean x;
@@ -57,7 +57,7 @@ class BindCaptureTypes {
}
}
static class Byte implements BindCaptureEntry {
static final class Byte implements BindCaptureEntry {
private final int parameterIndex;
private final byte x;
@@ -78,7 +78,7 @@ class BindCaptureTypes {
}
}
static class Bytes implements BindCaptureEntry {
static final class Bytes implements BindCaptureEntry {
private final int parameterIndex;
private final byte[] x;
@@ -99,7 +99,7 @@ class BindCaptureTypes {
}
}
static class TShort implements BindCaptureEntry {
static final class TShort implements BindCaptureEntry {
private final int parameterIndex;
private final short value;
@@ -120,7 +120,7 @@ class BindCaptureTypes {
}
}
static class TInt implements BindCaptureEntry {
static final class TInt implements BindCaptureEntry {
private final int parameterIndex;
private final int value;
@@ -141,7 +141,7 @@ class BindCaptureTypes {
}
}
static class TLong implements BindCaptureEntry {
static final class TLong implements BindCaptureEntry {
private final int parameterIndex;
private final long value;
@@ -162,7 +162,7 @@ class BindCaptureTypes {
}
}
static class TFloat implements BindCaptureEntry {
static final class TFloat implements BindCaptureEntry {
private final int parameterIndex;
private final float value;
@@ -183,7 +183,7 @@ class BindCaptureTypes {
}
}
static class TDouble implements BindCaptureEntry {
static final class TDouble implements BindCaptureEntry {
private final int parameterIndex;
private final double value;
@@ -204,7 +204,7 @@ class BindCaptureTypes {
}
}
static class TBigDecimal implements BindCaptureEntry {
static final class TBigDecimal implements BindCaptureEntry {
private final int parameterIndex;
private final BigDecimal value;
@@ -226,7 +226,7 @@ class BindCaptureTypes {
}
static class TString implements BindCaptureEntry {
static final class TString implements BindCaptureEntry {
private final int parameterIndex;
private final String value;
@@ -247,7 +247,7 @@ class BindCaptureTypes {
}
}
static class TDate implements BindCaptureEntry {
static final class TDate implements BindCaptureEntry {
private final int parameterIndex;
private final Date value;
@@ -268,7 +268,7 @@ class BindCaptureTypes {
}
}
static class TTime implements BindCaptureEntry {
static final class TTime implements BindCaptureEntry {
private final int parameterIndex;
private final Time value;
@@ -289,7 +289,7 @@ class BindCaptureTypes {
}
}
static class TTimestamp implements BindCaptureEntry {
static final class TTimestamp implements BindCaptureEntry {
private final int parameterIndex;
private final Timestamp value;
@@ -316,7 +316,7 @@ class BindCaptureTypes {
}
}
static class TObject implements BindCaptureEntry {
static final class TObject implements BindCaptureEntry {
private final int parameterIndex;
private final Object value;
@@ -337,13 +337,12 @@ class BindCaptureTypes {
}
}
static class TArray implements BindCaptureEntry {
static final class TArray implements BindCaptureEntry {
private final int parameterIndex;
private final String arrayType;
private final Object[] elements;
TArray(int parameterIndex, String arrayType, Object[] elements) {
this.parameterIndex = parameterIndex;
this.arrayType = arrayType;
@@ -362,7 +361,7 @@ class BindCaptureTypes {
}
}
static class CharacterStream implements BindCaptureEntry {
static final class CharacterStream implements BindCaptureEntry {
private static final String dummy = "hi";
@@ -383,7 +382,7 @@ class BindCaptureTypes {
}
}
static class BinaryStream implements BindCaptureEntry {
static final class BinaryStream implements BindCaptureEntry {
private static final byte[] dummy = "hi".getBytes(Charset.defaultCharset());