#2318 - Refactor internals - final classes in type packages

This commit is contained in:
rbygrave
2021-08-17 20:09:27 +12:00
parent 183416a640
commit dde9b507ce
77 changed files with 113 additions and 161 deletions
@@ -19,7 +19,7 @@ import static java.util.Collections.EMPTY_LIST;
* H2 database support for DB ARRAY.
*/
@SuppressWarnings("rawtypes")
class ScalarTypeArrayListH2 extends ScalarTypeArrayList {
final class ScalarTypeArrayListH2 extends ScalarTypeArrayList {
static PlatformArrayTypeFactory factory() {
return new ScalarTypeArrayListH2.Factory();
@@ -19,7 +19,7 @@ import static java.util.Collections.EMPTY_SET;
* H2 database support for DB ARRAY.
*/
@SuppressWarnings("rawtypes")
class ScalarTypeArraySetH2 extends ScalarTypeArraySet {
final class ScalarTypeArraySetH2 extends ScalarTypeArraySet {
static PlatformArrayTypeFactory factory() {
return new ScalarTypeArraySetH2.Factory();
@@ -21,9 +21,9 @@ import java.sql.Types;
* This may or may not be a native jdbc type depending on the database and jdbc driver.
* </p>
*/
public class ScalarTypeBoolean {
public final class ScalarTypeBoolean {
public static class Native extends BooleanBase {
public static final class Native extends BooleanBase {
/**
* Native Boolean database type.
@@ -75,7 +75,7 @@ public class ScalarTypeBoolean {
* type.boolean.dbtype="bit" in the ebean configuration
* </p>
*/
static class BitBoolean extends BooleanBase {
static final class BitBoolean extends BooleanBase {
/**
* Native Boolean database type.
@@ -124,7 +124,7 @@ public class ScalarTypeBoolean {
/**
* Converted to/from an Integer in the Database.
*/
static class IntBoolean extends BooleanBase {
static final class IntBoolean extends BooleanBase {
private final Integer trueValue;
private final Integer falseValue;
@@ -211,7 +211,7 @@ public class ScalarTypeBoolean {
/**
* Converted to/from an Integer in the Database.
*/
static class StringBoolean extends BooleanBase {
static final class StringBoolean extends BooleanBase {
private final String trueValue;
private final String falseValue;
@@ -18,7 +18,7 @@ import java.sql.Types;
/**
* ScalarType for Byte.
*/
public class ScalarTypeByte extends ScalarTypeBase<Byte> {
public final class ScalarTypeByte extends ScalarTypeBase<Byte> {
public ScalarTypeByte() {
super(Byte.class, true, Types.TINYINT);
@@ -8,7 +8,7 @@ import java.sql.Types;
/**
* ScalarType for Types.BINARY to byte[].
*/
public class ScalarTypeBytesBinary extends ScalarTypeBytesBase {
public final class ScalarTypeBytesBinary extends ScalarTypeBytesBase {
public ScalarTypeBytesBinary() {
super(true, Types.BINARY);
@@ -8,7 +8,7 @@ import java.sql.Types;
/**
* ScalarType for BLOB.
*/
public class ScalarTypeBytesBlob extends ScalarTypeBytesBase {
public final class ScalarTypeBytesBlob extends ScalarTypeBytesBase {
public ScalarTypeBytesBlob() {
super(true, Types.BLOB);
@@ -16,10 +16,9 @@ import java.sql.SQLException;
/**
* Encrypted ScalarType that wraps a byte[] types.
*/
public class ScalarTypeBytesEncrypted implements ScalarType<byte[]> {
public final class ScalarTypeBytesEncrypted implements ScalarType<byte[]> {
private final ScalarTypeBytesBase baseType;
private final DataEncryptSupport dataEncryptSupport;
public ScalarTypeBytesEncrypted(ScalarTypeBytesBase baseType, DataEncryptSupport dataEncryptSupport) {
@@ -8,7 +8,7 @@ import java.sql.Types;
/**
* ScalarType for Longvarbinary.
*/
public class ScalarTypeBytesLongVarbinary extends ScalarTypeBytesBase {
public final class ScalarTypeBytesLongVarbinary extends ScalarTypeBytesBase {
public ScalarTypeBytesLongVarbinary() {
super(true, Types.LONGVARBINARY);
@@ -8,7 +8,7 @@ import java.sql.Types;
/**
* ScalarType for Types.VARBINARY to byte[].
*/
public class ScalarTypeBytesVarbinary extends ScalarTypeBytesBase {
public final class ScalarTypeBytesVarbinary extends ScalarTypeBytesBase {
public ScalarTypeBytesVarbinary() {
super(true, Types.VARBINARY);
@@ -16,7 +16,7 @@ import static io.ebeaninternal.server.type.IsoJsonDateTimeParser.formatIso;
/**
* ScalarType for java.util.Calendar.
*/
public class ScalarTypeCalendar extends ScalarTypeBaseDateTime<Calendar> {
public final class ScalarTypeCalendar extends ScalarTypeBaseDateTime<Calendar> {
public ScalarTypeCalendar(JsonConfig.DateTime mode, int jdbcType) {
super(mode, Calendar.class, false, jdbcType);
@@ -10,7 +10,7 @@ import java.sql.Types;
/**
* ScalarType for char.
*/
public class ScalarTypeChar extends ScalarTypeBaseVarchar<Character> {
public final class ScalarTypeChar extends ScalarTypeBaseVarchar<Character> {
public ScalarTypeChar() {
super(char.class, false, Types.VARCHAR);
@@ -13,7 +13,7 @@ import java.sql.Types;
/**
* ScalarType for char[].
*/
public class ScalarTypeCharArray extends ScalarTypeBaseVarchar<char[]> {
public final class ScalarTypeCharArray extends ScalarTypeBaseVarchar<char[]> {
public ScalarTypeCharArray() {
super(char[].class, false, Types.VARCHAR);
@@ -42,7 +42,7 @@ public abstract class ScalarTypeCidr extends ScalarTypeBaseVarchar<Cidr> {
/**
* Cidr to Varchar.
*/
public static class Varchar extends ScalarTypeCidr {
public static final class Varchar extends ScalarTypeCidr {
@Override
public void bind(DataBinder binder, Cidr value) throws SQLException {
@@ -57,7 +57,7 @@ public abstract class ScalarTypeCidr extends ScalarTypeBaseVarchar<Cidr> {
/**
* Cidr to Postgres CIDR.
*/
public static class Postgres extends ScalarTypeCidr {
public static final class Postgres extends ScalarTypeCidr {
@Override
public void bind(DataBinder binder, Cidr value) throws SQLException {
@@ -4,12 +4,9 @@ import javax.persistence.PersistenceException;
/**
* ScalarType for Class that persists it to VARCHAR column.
*
* @author emcgreal
* @author rbygrave
*/
@SuppressWarnings({"rawtypes"})
public class ScalarTypeClass extends ScalarTypeBaseVarchar<Class> {
public final class ScalarTypeClass extends ScalarTypeBaseVarchar<Class> {
public ScalarTypeClass() {
super(Class.class);
@@ -5,7 +5,7 @@ import java.util.Currency;
/**
* ScalarType for java.util.Currency which converts to and from a VARCHAR database column.
*/
public class ScalarTypeCurrency extends ScalarTypeBaseVarchar<Currency> {
public final class ScalarTypeCurrency extends ScalarTypeBaseVarchar<Currency> {
public ScalarTypeCurrency() {
super(Currency.class);
@@ -12,7 +12,7 @@ import java.sql.Types;
/**
* ScalarType for java.sql.Date.
*/
public class ScalarTypeDate extends ScalarTypeBaseDate<java.sql.Date> {
public final class ScalarTypeDate extends ScalarTypeBaseDate<java.sql.Date> {
public ScalarTypeDate(JsonConfig.Date mode) {
super(mode, Date.class, true, Types.DATE);
@@ -11,7 +11,7 @@ import java.time.DayOfWeek;
/**
* ScalarType mapping for Month enum.
*/
public class ScalarTypeDayOfWeek extends ScalarTypeEnumWithMapping {
public final class ScalarTypeDayOfWeek extends ScalarTypeEnumWithMapping {
static final EnumToDbIntegerMap beanDbMap = new EnumToDbIntegerMap();
@@ -16,7 +16,7 @@ import java.sql.Types;
/**
* ScalarType for Double and double.
*/
public class ScalarTypeDouble extends ScalarTypeBase<Double> {
public final class ScalarTypeDouble extends ScalarTypeBase<Double> {
public ScalarTypeDouble() {
super(Double.class, true, Types.DOUBLE);
@@ -15,7 +15,7 @@ import java.time.Duration;
* Stored in the DB as DECIMAL value.
* </p>
*/
public class ScalarTypeDurationWithNanos extends ScalarTypeDuration {
public final class ScalarTypeDurationWithNanos extends ScalarTypeDuration {
public ScalarTypeDurationWithNanos() {
super(Types.DECIMAL);
@@ -12,12 +12,10 @@ import java.io.DataOutput;
import java.io.IOException;
import java.sql.SQLException;
public class ScalarTypeEncryptedWrapper<T> implements ScalarType<T>, LocalEncryptedType {
public final class ScalarTypeEncryptedWrapper<T> implements ScalarType<T>, LocalEncryptedType {
private final ScalarType<T> wrapped;
private final DataEncryptSupport dataEncryptSupport;
private final ScalarTypeBytesBase byteArrayType;
public ScalarTypeEncryptedWrapper(ScalarType<T> wrapped, ScalarTypeBytesBase byteArrayType, DataEncryptSupport dataEncryptSupport) {
@@ -28,10 +28,10 @@ import java.util.Set;
* Ebean specific @EnumMapping.
* </p>
*/
public class ScalarTypeEnumStandard {
public final class ScalarTypeEnumStandard {
@SuppressWarnings({"rawtypes", "unchecked"})
public static class StringEnum extends EnumBase implements ScalarTypeEnum {
public static final class StringEnum extends EnumBase implements ScalarTypeEnum {
private final int length;
@@ -63,15 +63,12 @@ public class ScalarTypeEnumStandard {
}
private int maxValueLength(Class<?> enumType) {
int maxLen = 0;
Object[] ea = enumType.getEnumConstants();
for (Object anEa : ea) {
Enum<?> e = (Enum<?>) anEa;
maxLen = Math.max(maxLen, e.name().length());
}
return maxLen;
}
@@ -120,7 +117,7 @@ public class ScalarTypeEnumStandard {
}
@SuppressWarnings({"rawtypes", "unchecked"})
public static class OrdinalEnum extends EnumBase implements ScalarTypeEnum {
public static final class OrdinalEnum extends EnumBase implements ScalarTypeEnum {
private final Object[] enumArray;
@@ -17,9 +17,7 @@ import java.util.Set;
public class ScalarTypeEnumWithMapping extends ScalarTypeEnumStandard.EnumBase implements ScalarType, ScalarTypeEnum {
private final EnumToDbValueMap beanDbMap;
private final int length;
private final boolean withConstraint;
/**
@@ -25,16 +25,13 @@ import java.sql.Types;
/**
* ScalarType for streaming between a File and the database.
*/
public class ScalarTypeFile extends ScalarTypeBase<File> {
public final class ScalarTypeFile extends ScalarTypeBase<File> {
private static final Logger logger = LoggerFactory.getLogger(ScalarTypeFile.class);
private final String prefix;
private final String suffix;
private final File directory;
private final int bufferSize;
/**
@@ -16,7 +16,7 @@ import java.sql.Types;
/**
* ScalarType for Float and float.
*/
public class ScalarTypeFloat extends ScalarTypeBase<Float> {
public final class ScalarTypeFloat extends ScalarTypeBase<Float> {
public ScalarTypeFloat() {
super(Float.class, true, Types.REAL);
@@ -42,7 +42,7 @@ public abstract class ScalarTypeInet extends ScalarTypeBaseVarchar<Inet> {
/**
* Inet to Varchar.
*/
public static class Varchar extends ScalarTypeInet {
public static final class Varchar extends ScalarTypeInet {
Varchar() {
super(Types.VARCHAR);
@@ -61,7 +61,7 @@ public abstract class ScalarTypeInet extends ScalarTypeBaseVarchar<Inet> {
/**
* Inet to Postgres INET.
*/
public static class Postgres extends ScalarTypeInet {
public static final class Postgres extends ScalarTypeInet {
Postgres() {
super(ExtraDbTypes.INET);
@@ -7,7 +7,7 @@ import java.net.InetAddress;
/**
* ScalarType for java.net.URI which converts to and from a VARCHAR database column.
*/
public class ScalarTypeInetAddress extends ScalarTypeBaseVarchar<InetAddress> {
public final class ScalarTypeInetAddress extends ScalarTypeBaseVarchar<InetAddress> {
public ScalarTypeInetAddress() {
super(InetAddress.class);
@@ -11,7 +11,7 @@ import java.sql.Types;
/**
* ScalarType for InetAddress to Postgres INET.
*/
public class ScalarTypeInetAddressPostgres extends ScalarTypeBaseVarchar<InetAddress> {
public final class ScalarTypeInetAddressPostgres extends ScalarTypeBaseVarchar<InetAddress> {
public ScalarTypeInetAddressPostgres() {
super(InetAddress.class, false, ExtraDbTypes.INET);
@@ -9,7 +9,7 @@ import java.time.Instant;
/**
* ScalarType for java.sql.Timestamp.
*/
public class ScalarTypeInstant extends ScalarTypeBaseDateTime<Instant> {
public final class ScalarTypeInstant extends ScalarTypeBaseDateTime<Instant> {
public ScalarTypeInstant(JsonConfig.DateTime mode) {
super(mode, Instant.class, false, Types.TIMESTAMP);
@@ -17,7 +17,7 @@ import java.sql.Types;
/**
* ScalarType for Integer and int.
*/
public class ScalarTypeInteger extends ScalarTypeBase<Integer> {
public final class ScalarTypeInteger extends ScalarTypeBase<Integer> {
public static ScalarTypeInteger INSTANCE = new ScalarTypeInteger();
@@ -11,7 +11,7 @@ import java.sql.Types;
* ScalarType for Joda DateMidnight. This maps to a JDBC Date.
*/
@SuppressWarnings("deprecation")
public class ScalarTypeJodaDateMidnight extends ScalarTypeBaseDate<org.joda.time.DateMidnight> {
public final class ScalarTypeJodaDateMidnight extends ScalarTypeBaseDate<org.joda.time.DateMidnight> {
/**
* Instantiates a new scalar type joda date midnight.
@@ -11,7 +11,7 @@ import java.time.Instant;
/**
* ScalarType for Joda DateTime. This maps to a JDBC Timestamp.
*/
public class ScalarTypeJodaDateTime extends ScalarTypeBaseDateTime<DateTime> {
public final class ScalarTypeJodaDateTime extends ScalarTypeBaseDateTime<DateTime> {
public ScalarTypeJodaDateTime(JsonConfig.DateTime mode) {
super(mode, DateTime.class, false, Types.TIMESTAMP);
@@ -11,7 +11,7 @@ import java.sql.Types;
/**
* ScalarType for Joda LocalDate. This maps to a JDBC Date.
*/
public class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate<LocalDate> {
public final class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate<LocalDate> {
public ScalarTypeJodaLocalDate(JsonConfig.Date mode) {
super(mode, LocalDate.class, false, Types.DATE);
@@ -11,7 +11,7 @@ import java.time.Instant;
/**
* ScalarType for Joda LocalDateTime. This maps to a JDBC Timestamp.
*/
public class ScalarTypeJodaLocalDateTime extends ScalarTypeBaseDateTime<LocalDateTime> {
public final class ScalarTypeJodaLocalDateTime extends ScalarTypeBaseDateTime<LocalDateTime> {
public ScalarTypeJodaLocalDateTime(JsonConfig.DateTime mode) {
super(mode, LocalDateTime.class, false, Types.TIMESTAMP);
@@ -13,7 +13,7 @@ import java.sql.Types;
/**
* ScalarType for Joda LocalTime. This maps to a JDBC Time.
*/
public class ScalarTypeJodaLocalTimeUTC extends ScalarTypeJodaLocalTime {
public final class ScalarTypeJodaLocalTimeUTC extends ScalarTypeJodaLocalTime {
public ScalarTypeJodaLocalTimeUTC() {
super();
@@ -5,7 +5,7 @@ import org.joda.time.Period;
/**
* ScalarType for Joda Period stored as DB VARCHAR
*/
public class ScalarTypeJodaPeriod extends ScalarTypeBaseVarchar<Period> {
public final class ScalarTypeJodaPeriod extends ScalarTypeBaseVarchar<Period> {
public ScalarTypeJodaPeriod() {
super(Period.class);
@@ -19,7 +19,7 @@ import java.util.List;
/**
* Types for mapping List in JSON format to DB types VARCHAR, JSON and JSONB.
*/
class ScalarTypeJsonList {
final class ScalarTypeJsonList {
/**
* Return the appropriate ScalarType based requested dbType and if Postgres.
@@ -27,7 +27,7 @@ public abstract class ScalarTypeJsonNode extends ScalarTypeBase<JsonNode> {
/**
* Clob storage based implementation.
*/
public static class Clob extends ScalarTypeJsonNode {
public static final class Clob extends ScalarTypeJsonNode {
public Clob(ObjectMapper objectMapper) {
super(objectMapper, Types.CLOB);
@@ -46,7 +46,7 @@ public abstract class ScalarTypeJsonNode extends ScalarTypeBase<JsonNode> {
/**
* Varchar storage based implementation.
*/
public static class Varchar extends ScalarTypeJsonNode {
public static final class Varchar extends ScalarTypeJsonNode {
public Varchar(ObjectMapper objectMapper) {
super(objectMapper, Types.VARCHAR);
@@ -31,7 +31,7 @@ public abstract class ScalarTypeJsonNodePostgres extends ScalarTypeJsonNode {
/**
* ScalarType mapping JsonNode to Postgres JSON database type.
*/
public static class JSON extends ScalarTypeJsonNodePostgres {
public static final class JSON extends ScalarTypeJsonNodePostgres {
public JSON(ObjectMapper objectMapper) {
super(objectMapper, DbPlatformType.JSON, PostgresHelper.JSON_TYPE);
@@ -41,7 +41,7 @@ public abstract class ScalarTypeJsonNodePostgres extends ScalarTypeJsonNode {
/**
* ScalarType mapping JsonNode to Postgres JSONB database type.
*/
public static class JSONB extends ScalarTypeJsonNodePostgres {
public static final class JSONB extends ScalarTypeJsonNodePostgres {
public JSONB(ObjectMapper objectMapper) {
super(objectMapper, DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE);
@@ -25,7 +25,7 @@ import java.sql.Types;
/**
* Supports @DbJson properties using Jackson ObjectMapper.
*/
class ScalarTypeJsonObjectMapper {
final class ScalarTypeJsonObjectMapper {
/**
* Create and return the appropriate ScalarType.
@@ -13,7 +13,7 @@ import java.time.ZonedDateTime;
/**
* ScalarType for java.time.LocalDate. This maps to a JDBC Date.
*/
public class ScalarTypeLocalDate extends ScalarTypeBaseDate<LocalDate> {
public final class ScalarTypeLocalDate extends ScalarTypeBaseDate<LocalDate> {
public ScalarTypeLocalDate(JsonConfig.Date mode) {
super(mode, LocalDate.class, false, Types.DATE);
@@ -14,7 +14,7 @@ import java.time.ZoneId;
/**
* ScalarType for java.sql.Timestamp.
*/
public class ScalarTypeLocalDateTime extends ScalarTypeBaseDateTime<LocalDateTime> {
public final class ScalarTypeLocalDateTime extends ScalarTypeBaseDateTime<LocalDateTime> {
public ScalarTypeLocalDateTime(JsonConfig.DateTime mode) {
super(mode, LocalDateTime.class, false, Types.TIMESTAMP);
@@ -11,7 +11,7 @@ import java.time.LocalTime;
/**
* ScalarType for java.time.LocalTime stored with Nanos as DB BIGINT type.
*/
public class ScalarTypeLocalTimeWithNanos extends ScalarTypeLocalTime {
public final class ScalarTypeLocalTimeWithNanos extends ScalarTypeLocalTime {
public ScalarTypeLocalTimeWithNanos() {
super(Types.BIGINT);
@@ -5,7 +5,7 @@ import java.util.Locale;
/**
* ScalarType for java.util.Currency which converts to and from a VARCHAR database column.
*/
public class ScalarTypeLocale extends ScalarTypeBaseVarchar<Locale> {
public final class ScalarTypeLocale extends ScalarTypeBaseVarchar<Locale> {
public ScalarTypeLocale() {
super(Locale.class);
@@ -16,7 +16,7 @@ import java.sql.Types;
/**
* ScalarType for Long and long.
*/
public class ScalarTypeLong extends ScalarTypeBase<Long> {
public final class ScalarTypeLong extends ScalarTypeBase<Long> {
public ScalarTypeLong() {
super(Long.class, true, Types.BIGINT);
@@ -5,7 +5,7 @@ import java.sql.Types;
/**
* ScalarType for String.
*/
public class ScalarTypeLongVarchar extends ScalarTypeClob {
public final class ScalarTypeLongVarchar extends ScalarTypeClob {
public ScalarTypeLongVarchar() {
super(true, Types.LONGVARCHAR);
@@ -17,7 +17,7 @@ import java.sql.Types;
/**
* ScalarType for java.math.BigInteger.
*/
public class ScalarTypeMathBigInteger extends ScalarTypeBase<BigInteger> {
public final class ScalarTypeMathBigInteger extends ScalarTypeBase<BigInteger> {
public ScalarTypeMathBigInteger() {
super(BigInteger.class, false, Types.BIGINT);
@@ -11,7 +11,7 @@ import java.time.Month;
/**
* ScalarType mapping for Month enum.
*/
public class ScalarTypeMonth extends ScalarTypeEnumWithMapping {
public final class ScalarTypeMonth extends ScalarTypeEnumWithMapping {
static final EnumToDbIntegerMap beanDbMap = new EnumToDbIntegerMap();
@@ -21,24 +21,14 @@ import java.time.MonthDay;
* Note that the year used should be a leap year.
* </p>
*/
public class ScalarTypeMonthDay extends ScalarTypeBase<MonthDay> {
protected final int year;
/**
* Construct with a year of 2000 (which is a leap year).
*/
public ScalarTypeMonthDay() {
this(2000); // Year 2000 is a leap year
}
final class ScalarTypeMonthDay extends ScalarTypeBase<MonthDay> {
/**
* Construct with a base year. The year should be a leap year to
* allow the 29th Feb value.
*/
public ScalarTypeMonthDay(int year) {
ScalarTypeMonthDay() {
super(MonthDay.class, false, Types.DATE);
this.year = year;
}
private MonthDay convertFromDate(Date ts) {
@@ -13,11 +13,11 @@ import static io.ebeaninternal.server.type.IsoJsonDateTimeParser.formatIso;
/**
* ScalarType for java.sql.Timestamp.
*/
public class ScalarTypeOffsetDateTime extends ScalarTypeBaseDateTime<OffsetDateTime> {
final class ScalarTypeOffsetDateTime extends ScalarTypeBaseDateTime<OffsetDateTime> {
private final ZoneId zoneId;
public ScalarTypeOffsetDateTime(JsonConfig.DateTime mode, ZoneId zoneId) {
ScalarTypeOffsetDateTime(JsonConfig.DateTime mode, ZoneId zoneId) {
super(mode, OffsetDateTime.class, false, Types.TIMESTAMP);
this.zoneId = zoneId;
}
@@ -5,9 +5,9 @@ import java.time.OffsetTime;
/**
* ScalarType for java.time.OffsetTime stored as DB VARCHAR
*/
public class ScalarTypeOffsetTime extends ScalarTypeBaseVarchar<OffsetTime> {
final class ScalarTypeOffsetTime extends ScalarTypeBaseVarchar<OffsetTime> {
public ScalarTypeOffsetTime() {
ScalarTypeOffsetTime() {
super(OffsetTime.class);
}
@@ -8,9 +8,9 @@ import java.nio.file.Paths;
/**
* ScalarType for java.nio.file.Path which converts to and from a VARCHAR database column.
*/
public class ScalarTypePath extends ScalarTypeBaseVarchar<Path> {
final class ScalarTypePath extends ScalarTypeBaseVarchar<Path> {
public ScalarTypePath() {
ScalarTypePath() {
super(Path.class);
}
@@ -5,9 +5,9 @@ import java.time.Period;
/**
* ScalarType for Joda Period stored as DB VARCHAR
*/
public class ScalarTypePeriod extends ScalarTypeBaseVarchar<Period> {
final class ScalarTypePeriod extends ScalarTypeBaseVarchar<Period> {
public ScalarTypePeriod() {
ScalarTypePeriod() {
super(Period.class);
}
@@ -20,9 +20,9 @@ import java.util.Map;
* Postgres Hstore type which maps Map<String,String> to a single 'HStore column' in the DB.
*/
@SuppressWarnings("rawtypes")
public class ScalarTypePostgresHstore extends ScalarTypeBase<Map> {
final class ScalarTypePostgresHstore extends ScalarTypeBase<Map> {
public ScalarTypePostgresHstore() {
ScalarTypePostgresHstore() {
super(Map.class, false, DbPlatformType.HSTORE);
}
@@ -17,9 +17,9 @@ import java.sql.Types;
/**
* ScalarType for Short and short.
*/
public class ScalarTypeShort extends ScalarTypeBase<Short> {
final class ScalarTypeShort extends ScalarTypeBase<Short> {
public ScalarTypeShort() {
ScalarTypeShort() {
super(Short.class, true, Types.SMALLINT);
}
@@ -5,7 +5,7 @@ import java.sql.Types;
/**
* ScalarType for String.
*/
public class ScalarTypeString extends ScalarTypeStringBase {
public final class ScalarTypeString extends ScalarTypeStringBase {
public static final ScalarTypeString INSTANCE = new ScalarTypeString();
@@ -16,7 +16,7 @@ import java.sql.Types;
/**
* Base ScalarType for String type using Varchar, Clob and LongVarchar.
*/
public abstract class ScalarTypeStringBase extends ScalarTypeBase<String> {
abstract class ScalarTypeStringBase extends ScalarTypeBase<String> {
ScalarTypeStringBase(boolean jdbcNative, int jdbcType) {
super(String.class, jdbcNative, jdbcType);
@@ -17,9 +17,9 @@ import java.sql.Types;
/**
* ScalarType for java.sql.Time.
*/
public class ScalarTypeTime extends ScalarTypeBase<Time> {
final class ScalarTypeTime extends ScalarTypeBase<Time> {
public ScalarTypeTime() {
ScalarTypeTime() {
super(Time.class, true, Types.TIME);
}
@@ -5,9 +5,9 @@ import java.util.TimeZone;
/**
* ScalarType for java.util.TimeZone which converts to and from a VARCHAR database column.
*/
public class ScalarTypeTimeZone extends ScalarTypeBaseVarchar<TimeZone> {
final class ScalarTypeTimeZone extends ScalarTypeBaseVarchar<TimeZone> {
public ScalarTypeTimeZone() {
ScalarTypeTimeZone() {
super(TimeZone.class);
}
@@ -15,9 +15,9 @@ import static io.ebeaninternal.server.type.IsoJsonDateTimeParser.formatIso;
/**
* ScalarType for java.sql.Timestamp.
*/
public class ScalarTypeTimestamp extends ScalarTypeBaseDateTime<Timestamp> {
final class ScalarTypeTimestamp extends ScalarTypeBaseDateTime<Timestamp> {
public ScalarTypeTimestamp(JsonConfig.DateTime mode) {
ScalarTypeTimestamp(JsonConfig.DateTime mode) {
super(mode, Timestamp.class, true, Types.TIMESTAMP);
}
@@ -8,9 +8,9 @@ import java.net.URISyntaxException;
/**
* ScalarType for java.net.URI which converts to and from a VARCHAR database column.
*/
public class ScalarTypeURI extends ScalarTypeBaseVarchar<URI> {
final class ScalarTypeURI extends ScalarTypeBaseVarchar<URI> {
public ScalarTypeURI() {
ScalarTypeURI() {
super(URI.class);
}
@@ -8,9 +8,9 @@ import java.net.URL;
/**
* ScalarType for java.net.URL which converts to and from a VARCHAR database column.
*/
public class ScalarTypeURL extends ScalarTypeBaseVarchar<URL> {
final class ScalarTypeURL extends ScalarTypeBaseVarchar<URL> {
public ScalarTypeURL() {
ScalarTypeURL() {
super(URL.class);
}
@@ -14,9 +14,9 @@ import java.util.UUID;
/**
* Base UUID type for string formatting, json handling etc.
*/
public abstract class ScalarTypeUUIDBase extends ScalarTypeBase<UUID> implements ScalarTypeLogicalType {
abstract class ScalarTypeUUIDBase extends ScalarTypeBase<UUID> implements ScalarTypeLogicalType {
public ScalarTypeUUIDBase(boolean jdbcNative, int jdbcType) {
ScalarTypeUUIDBase(boolean jdbcNative, int jdbcType) {
super(UUID.class, jdbcNative, jdbcType);
}
@@ -8,11 +8,11 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.UUID;
public class ScalarTypeUUIDBinary extends ScalarTypeUUIDBase {
public final class ScalarTypeUUIDBinary extends ScalarTypeUUIDBase {
private final boolean optimized;
protected ScalarTypeUUIDBinary(boolean optimized) {
ScalarTypeUUIDBinary(boolean optimized) {
super(false, Types.BINARY);
this.optimized = optimized;
}
@@ -10,9 +10,9 @@ import java.util.UUID;
/**
* Postgres Hstore type which maps Map<String,String> to a single 'HStore column' in the DB.
*/
public class ScalarTypeUUIDNative extends ScalarTypeUUIDBase {
final class ScalarTypeUUIDNative extends ScalarTypeUUIDBase {
public ScalarTypeUUIDNative() {
ScalarTypeUUIDNative() {
super(false, DbPlatformType.UUID);
}
@@ -10,9 +10,9 @@ import java.util.UUID;
/**
* ScalarType for java.util.UUID which converts to and from a VARCHAR database column.
*/
public class ScalarTypeUUIDVarchar extends ScalarTypeUUIDBase {
final class ScalarTypeUUIDVarchar extends ScalarTypeUUIDBase {
protected ScalarTypeUUIDVarchar() {
ScalarTypeUUIDVarchar() {
super(false, Types.VARCHAR);
}
@@ -16,11 +16,11 @@ import static io.ebeaninternal.server.type.IsoJsonDateTimeParser.formatIso;
/**
* ScalarType for java.util.Date.
*/
public class ScalarTypeUtilDate {
final class ScalarTypeUtilDate {
public static class TimestampType extends ScalarTypeBaseDateTime<java.util.Date> {
static final class TimestampType extends ScalarTypeBaseDateTime<java.util.Date> {
public TimestampType(JsonConfig.DateTime mode) {
TimestampType(JsonConfig.DateTime mode) {
super(mode, java.util.Date.class, false, Types.TIMESTAMP);
}
@@ -89,9 +89,9 @@ public class ScalarTypeUtilDate {
}
}
public static class DateType extends ScalarTypeBaseDate<java.util.Date> {
static final class DateType extends ScalarTypeBaseDate<java.util.Date> {
public DateType(JsonConfig.Date mode) {
DateType(JsonConfig.Date mode) {
super(mode, Date.class, false, Types.DATE);
}
@@ -26,11 +26,8 @@ import java.sql.SQLException;
public class ScalarTypeWrapper<B, S> implements ScalarType<B> {
private final ScalarType<S> scalarType;
private final ScalarTypeConverter<B, S> converter;
private final Class<B> wrapperType;
private final B nullValue;
public ScalarTypeWrapper(Class<B> wrapperType, ScalarType<S> scalarType, ScalarTypeConverter<B, S> converter) {
@@ -18,9 +18,9 @@ import java.time.Year;
/**
* ScalarType for java.time.Year
*/
public class ScalarTypeYear extends ScalarTypeBase<Year> {
final class ScalarTypeYear extends ScalarTypeBase<Year> {
public ScalarTypeYear() {
ScalarTypeYear() {
super(Year.class, false, Types.INTEGER);
}
@@ -14,21 +14,22 @@ import java.time.ZonedDateTime;
/**
* ScalarType for java.time.LocalDate. This maps to a JDBC Date.
*/
public class ScalarTypeYearMonthDate extends ScalarTypeBaseDate<YearMonth> {
final class ScalarTypeYearMonthDate extends ScalarTypeBaseDate<YearMonth> {
public ScalarTypeYearMonthDate(JsonConfig.Date mode) {
ScalarTypeYearMonthDate(JsonConfig.Date mode) {
super(mode, YearMonth.class, false, Types.DATE);
}
@Override
protected String toIsoFormat(YearMonth value) {
return value.atDay(1).toString();
}
protected LocalDate toLocalDate(YearMonth yearMonth) {
LocalDate toLocalDate(YearMonth yearMonth) {
return yearMonth.atDay(1);
}
protected YearMonth fromLocalDate(LocalDate localDate) {
YearMonth fromLocalDate(LocalDate localDate) {
return YearMonth.of(localDate.getYear(), localDate.getMonth());
}
@@ -5,9 +5,9 @@ import java.time.ZoneId;
/**
* ScalarType for java.time.OffsetTime stored as DB VARCHAR
*/
public class ScalarTypeZoneId extends ScalarTypeBaseVarchar<ZoneId> {
final class ScalarTypeZoneId extends ScalarTypeBaseVarchar<ZoneId> {
public ScalarTypeZoneId() {
ScalarTypeZoneId() {
super(ZoneId.class);
}
@@ -5,9 +5,9 @@ import java.time.ZoneOffset;
/**
* ScalarType for java.time.OffsetTime stored as DB VARCHAR
*/
public class ScalarTypeZoneOffset extends ScalarTypeBaseVarchar<ZoneOffset> {
final class ScalarTypeZoneOffset extends ScalarTypeBaseVarchar<ZoneOffset> {
public ScalarTypeZoneOffset() {
ScalarTypeZoneOffset() {
super(ZoneOffset.class);
}
@@ -11,11 +11,11 @@ import java.time.ZonedDateTime;
/**
* ScalarType for ZonedDateTime.
*/
public class ScalarTypeZonedDateTime extends ScalarTypeBaseDateTime<ZonedDateTime> {
final class ScalarTypeZonedDateTime extends ScalarTypeBaseDateTime<ZonedDateTime> {
private final ZoneId zoneId;
public ScalarTypeZonedDateTime(JsonConfig.DateTime mode, ZoneId zoneId) {
ScalarTypeZonedDateTime(JsonConfig.DateTime mode, ZoneId zoneId) {
super(mode, ZonedDateTime.class, false, Types.TIMESTAMP);
this.zoneId = zoneId;
}
@@ -11,7 +11,7 @@ import java.nio.charset.StandardCharsets;
/**
* Simple AES based encryption and decryption.
*/
public class SimpleAesEncryptor implements Encryptor {
public final class SimpleAesEncryptor implements Encryptor {
private static final String AES_CIPHER = "AES/CBC/PKCS5Padding";
@@ -21,7 +21,6 @@ public class SimpleAesEncryptor implements Encryptor {
}
private String paddKey(EncryptKey encryptKey) {
String key = encryptKey.getStringValue();
int addChars = 16 - key.length();
if (addChars < 0) {
@@ -38,25 +37,18 @@ public class SimpleAesEncryptor implements Encryptor {
@Override
public byte[] decrypt(byte[] data, EncryptKey encryptKey) {
if (data == null) {
return null;
}
String key = paddKey(encryptKey);
try {
byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
IvParameterSpec iv = getIvParameterSpec(key);
SecretKeySpec sks = new SecretKeySpec(keyBytes, "AES");
Cipher c = Cipher.getInstance(AES_CIPHER);
c.init(Cipher.DECRYPT_MODE, sks, iv);
return c.doFinal(data);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -64,24 +56,17 @@ public class SimpleAesEncryptor implements Encryptor {
@Override
public byte[] encrypt(byte[] data, EncryptKey encryptKey) {
if (data == null) {
return null;
}
String key = paddKey(encryptKey);
try {
byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
IvParameterSpec iv = getIvParameterSpec(key);
SecretKeySpec sks = new SecretKeySpec(keyBytes, "AES");
Cipher c = Cipher.getInstance(AES_CIPHER);
c.init(Cipher.ENCRYPT_MODE, sks, iv);
return c.doFinal(data);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -92,14 +77,12 @@ public class SimpleAesEncryptor implements Encryptor {
if (data == null) {
return null;
}
byte[] bytes = decrypt(data, key);
return new String(bytes, StandardCharsets.UTF_8);
}
@Override
public byte[] encryptString(String valueFormatValue, EncryptKey key) {
if (valueFormatValue == null) {
return null;
}
@@ -5,7 +5,7 @@ import io.ebean.ModifyAwareType;
import io.ebean.annotation.MutationDetection;
import io.ebean.config.dbplatform.DbPlatformType;
class TypeJsonManager {
final class TypeJsonManager {
private final boolean postgres;
private final ObjectMapper objectMapper;
@@ -4,7 +4,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
public class TypeReflectHelper {
public final class TypeReflectHelper {
public static Class<?>[] getParams(Class<?> cls, Class<?> matchRawType) {
return TypeResolver.resolveRawArgs(matchRawType, cls);
@@ -46,7 +46,6 @@ public class TypeReflectHelper {
}
private static Class<?> getClass(Type type) {
while (true) {
if (type instanceof ParameterizedType) {
type = ((ParameterizedType) type).getRawType();
@@ -15,7 +15,7 @@ import java.util.Map;
*
* It is a cut down version removing the lambda support and related sun.misc.Unsafe use etc.
*/
class TypeResolver {
final class TypeResolver {
/** An unknown type. */
private static final class Unknown {
@@ -137,9 +137,7 @@ class TypeResolver {
}
private static Map<TypeVariable<?>, Type> getTypeVariableMap(final Class<?> targetType) {
Map<TypeVariable<?>, Type> map = new HashMap<>();
// Populate interfaces
populateSuperTypeArgs(targetType.getGenericInterfaces(), map);
@@ -173,7 +171,6 @@ class TypeResolver {
* Populates the {@code map} with with variable/argument pairs for the given {@code types}.
*/
private static void populateSuperTypeArgs(final Type[] types, final Map<TypeVariable<?>, Type> map) {
for (Type type : types) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
@@ -195,7 +192,6 @@ class TypeResolver {
if (type.getRawType() instanceof Class) {
TypeVariable<?>[] typeVariables = ((Class<?>) type.getRawType()).getTypeParameters();
Type[] typeArguments = type.getActualTypeArguments();
if (type.getOwnerType() != null) {
Type owner = type.getOwnerType();
if (owner instanceof ParameterizedType) {
@@ -4,7 +4,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
class UtilDateParser {
final class UtilDateParser {
private static final SimpleDateFormat dateTimeProto = new SimpleDateFormat("yyyy-MM-dd");