mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2318 - Refactor internals - final classes in id and generated property packages
This commit is contained in:
+2
-5
@@ -13,14 +13,13 @@ import java.sql.Types;
|
||||
* Aka, Integer, Long, Short etc.
|
||||
* </p>
|
||||
*/
|
||||
class CounterFactory {
|
||||
final class CounterFactory {
|
||||
|
||||
private final GeneratedCounterInteger integerCounter = new GeneratedCounterInteger();
|
||||
|
||||
private final GeneratedCounterLong longCounter = new GeneratedCounterLong();
|
||||
|
||||
public void setCounter(DeployBeanProperty property) {
|
||||
|
||||
void setCounter(DeployBeanProperty property) {
|
||||
property.setGeneratedProperty(createCounter(property));
|
||||
}
|
||||
|
||||
@@ -28,7 +27,6 @@ class CounterFactory {
|
||||
* Create the GeneratedProperty based on the property type.
|
||||
*/
|
||||
private GeneratedProperty createCounter(DeployBeanProperty property) {
|
||||
|
||||
Class<?> propType = property.getPropertyType();
|
||||
if (propType.equals(Integer.class) || propType.equals(int.class)) {
|
||||
return integerCounter;
|
||||
@@ -36,7 +34,6 @@ class CounterFactory {
|
||||
if (propType.equals(Long.class) || propType.equals(long.class)) {
|
||||
return longCounter;
|
||||
}
|
||||
|
||||
int type = getType(propType);
|
||||
return new GeneratedCounter(type);
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
/**
|
||||
* A general number counter for various number types.
|
||||
*/
|
||||
public class GeneratedCounter implements GeneratedProperty {
|
||||
final class GeneratedCounter implements GeneratedProperty {
|
||||
|
||||
private final int numberType;
|
||||
|
||||
|
||||
+1
-5
@@ -6,11 +6,7 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
/**
|
||||
* Used to create a counter version column for Integer.
|
||||
*/
|
||||
public class GeneratedCounterInteger implements GeneratedProperty {
|
||||
|
||||
public GeneratedCounterInteger() {
|
||||
|
||||
}
|
||||
final class GeneratedCounterInteger implements GeneratedProperty {
|
||||
|
||||
/**
|
||||
* Always returns a 1.
|
||||
|
||||
+1
-5
@@ -6,11 +6,7 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
/**
|
||||
* Used to create a counter version column for Long.
|
||||
*/
|
||||
public class GeneratedCounterLong implements GeneratedProperty {
|
||||
|
||||
public GeneratedCounterLong() {
|
||||
|
||||
}
|
||||
final class GeneratedCounterLong implements GeneratedProperty {
|
||||
|
||||
/**
|
||||
* Always returns a 1.
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import java.util.Date;
|
||||
/**
|
||||
* Used to generate a (java.util.Date) timestamp when a bean is inserted.
|
||||
*/
|
||||
public class GeneratedInsertDate implements GeneratedProperty, GeneratedWhenCreated {
|
||||
final class GeneratedInsertDate implements GeneratedProperty, GeneratedWhenCreated {
|
||||
|
||||
/**
|
||||
* Return the current time as a Timestamp.
|
||||
|
||||
+6
-6
@@ -6,9 +6,9 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
/**
|
||||
* Support java.time types as GeneratedProperty.
|
||||
*/
|
||||
public class GeneratedInsertJavaTime {
|
||||
final class GeneratedInsertJavaTime {
|
||||
|
||||
public static abstract class Base implements GeneratedProperty, GeneratedWhenCreated {
|
||||
static abstract class Base implements GeneratedProperty, GeneratedWhenCreated {
|
||||
|
||||
@Override
|
||||
public boolean includeInUpdate() {
|
||||
@@ -39,7 +39,7 @@ public class GeneratedInsertJavaTime {
|
||||
/**
|
||||
* Instant support.
|
||||
*/
|
||||
public static class InstantDT extends Base {
|
||||
static final class InstantDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
@@ -50,7 +50,7 @@ public class GeneratedInsertJavaTime {
|
||||
/**
|
||||
* LocalDateTime support.
|
||||
*/
|
||||
public static class LocalDT extends Base {
|
||||
static final class LocalDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
@@ -61,7 +61,7 @@ public class GeneratedInsertJavaTime {
|
||||
/**
|
||||
* OffsetDateTime support.
|
||||
*/
|
||||
public static class OffsetDT extends Base {
|
||||
static final class OffsetDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
@@ -73,7 +73,7 @@ public class GeneratedInsertJavaTime {
|
||||
/**
|
||||
* ZonedDateTime support.
|
||||
*/
|
||||
public static class ZonedDT extends Base {
|
||||
static final class ZonedDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
|
||||
+4
-4
@@ -8,9 +8,9 @@ import org.joda.time.LocalDateTime;
|
||||
/**
|
||||
* Support joda time types as GeneratedProperty.
|
||||
*/
|
||||
public class GeneratedInsertJodaTime {
|
||||
final class GeneratedInsertJodaTime {
|
||||
|
||||
public static abstract class Base implements GeneratedProperty, GeneratedWhenCreated {
|
||||
static abstract class Base implements GeneratedProperty, GeneratedWhenCreated {
|
||||
|
||||
@Override
|
||||
public boolean includeInUpdate() {
|
||||
@@ -41,7 +41,7 @@ public class GeneratedInsertJodaTime {
|
||||
/**
|
||||
* LocalDateTime support.
|
||||
*/
|
||||
public static class LocalDT extends Base {
|
||||
static final class LocalDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
@@ -52,7 +52,7 @@ public class GeneratedInsertJodaTime {
|
||||
/**
|
||||
* DateTime support.
|
||||
*/
|
||||
public static class DateTimeDT extends Base {
|
||||
static final class DateTimeDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
/**
|
||||
* Used to generate a (Long) timestamp when a bean is inserted.
|
||||
*/
|
||||
public class GeneratedInsertLong implements GeneratedProperty {
|
||||
final class GeneratedInsertLong implements GeneratedProperty {
|
||||
|
||||
/**
|
||||
* Return the current time as a Timestamp.
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import java.sql.Timestamp;
|
||||
/**
|
||||
* Used to generate a timestamp when a bean is inserted.
|
||||
*/
|
||||
public class GeneratedInsertTimestamp implements GeneratedProperty, GeneratedWhenCreated {
|
||||
final class GeneratedInsertTimestamp implements GeneratedProperty, GeneratedWhenCreated {
|
||||
|
||||
/**
|
||||
* Return the current time as a Timestamp.
|
||||
|
||||
+1
-9
@@ -17,24 +17,16 @@ import java.util.Map;
|
||||
/**
|
||||
* Default implementation of GeneratedPropertyFactory.
|
||||
*/
|
||||
public class GeneratedPropertyFactory {
|
||||
public final class GeneratedPropertyFactory {
|
||||
|
||||
private final CounterFactory counterFactory = new CounterFactory();
|
||||
|
||||
private final InsertTimestampFactory insertFactory;
|
||||
|
||||
private final UpdateTimestampFactory updateFactory;
|
||||
|
||||
private final HashSet<String> numberTypes = new HashSet<>();
|
||||
|
||||
private final UuidGeneratedProperty generatedUuid = new UuidGeneratedProperty();
|
||||
|
||||
private final GeneratedWhoModified generatedWhoModified;
|
||||
|
||||
private final GeneratedWhoCreated generatedWhoCreated;
|
||||
|
||||
private final ClassLoadConfig classLoadConfig;
|
||||
|
||||
private final Map<String, PlatformIdGenerator> idGeneratorMap = new HashMap<>();
|
||||
|
||||
public GeneratedPropertyFactory(boolean offlineMode, DatabaseConfig config, List<IdGenerator> idGenerators) {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.util.Date;
|
||||
* Generate a (java.util.Date) Timestamp whenever the bean is inserted or
|
||||
* updated.
|
||||
*/
|
||||
public class GeneratedUpdateDate implements GeneratedProperty {
|
||||
final class GeneratedUpdateDate implements GeneratedProperty {
|
||||
|
||||
/**
|
||||
* Return now as a Timestamp.
|
||||
|
||||
+6
-6
@@ -6,9 +6,9 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
/**
|
||||
* Support java.time DateTime types as GeneratedProperty.
|
||||
*/
|
||||
public class GeneratedUpdateJavaTime {
|
||||
final class GeneratedUpdateJavaTime {
|
||||
|
||||
public static abstract class Base implements GeneratedProperty, GeneratedWhenModified {
|
||||
static abstract class Base implements GeneratedProperty, GeneratedWhenModified {
|
||||
|
||||
@Override
|
||||
public boolean includeInUpdate() {
|
||||
@@ -34,7 +34,7 @@ public class GeneratedUpdateJavaTime {
|
||||
/**
|
||||
* Instant support.
|
||||
*/
|
||||
public static class InstantDT extends Base {
|
||||
static final class InstantDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
@@ -50,7 +50,7 @@ public class GeneratedUpdateJavaTime {
|
||||
/**
|
||||
* LocalDateTime support.
|
||||
*/
|
||||
public static class LocalDT extends Base {
|
||||
static final class LocalDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
@@ -66,7 +66,7 @@ public class GeneratedUpdateJavaTime {
|
||||
/**
|
||||
* OffsetDateTime support.
|
||||
*/
|
||||
public static class OffsetDT extends Base {
|
||||
static final class OffsetDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
@@ -82,7 +82,7 @@ public class GeneratedUpdateJavaTime {
|
||||
/**
|
||||
* ZonedDateTime support.
|
||||
*/
|
||||
public static class ZonedDT extends Base {
|
||||
static final class ZonedDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
|
||||
+4
-4
@@ -8,9 +8,9 @@ import org.joda.time.LocalDateTime;
|
||||
/**
|
||||
* Support java.time DateTime types as GeneratedProperty.
|
||||
*/
|
||||
public class GeneratedUpdateJodaTime {
|
||||
final class GeneratedUpdateJodaTime {
|
||||
|
||||
public static abstract class Base implements GeneratedProperty, GeneratedWhenModified {
|
||||
static abstract class Base implements GeneratedProperty, GeneratedWhenModified {
|
||||
|
||||
@Override
|
||||
public boolean includeInUpdate() {
|
||||
@@ -36,7 +36,7 @@ public class GeneratedUpdateJodaTime {
|
||||
/**
|
||||
* LocalDateTime support.
|
||||
*/
|
||||
public static class LocalDT extends Base {
|
||||
static final class LocalDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
@@ -52,7 +52,7 @@ public class GeneratedUpdateJodaTime {
|
||||
/**
|
||||
* OffsetDateTime support.
|
||||
*/
|
||||
public static class DateTimeDT extends Base {
|
||||
static final class DateTimeDT extends Base {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
/**
|
||||
* Generate a (Long) Timestamp whenever the bean is inserted or updated.
|
||||
*/
|
||||
public class GeneratedUpdateLong implements GeneratedProperty {
|
||||
final class GeneratedUpdateLong implements GeneratedProperty {
|
||||
|
||||
/**
|
||||
* Return now as a Timestamp.
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import java.sql.Timestamp;
|
||||
/**
|
||||
* Generate a Timestamp whenever the bean is inserted or updated.
|
||||
*/
|
||||
public class GeneratedUpdateTimestamp implements GeneratedProperty, GeneratedWhenModified {
|
||||
final class GeneratedUpdateTimestamp implements GeneratedProperty, GeneratedWhenModified {
|
||||
|
||||
/**
|
||||
* Return now as a Timestamp.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
/**
|
||||
* Used to populate @WhoCreated bean properties.
|
||||
*/
|
||||
public class GeneratedWhoCreated implements GeneratedProperty {
|
||||
final class GeneratedWhoCreated implements GeneratedProperty {
|
||||
|
||||
private final CurrentUserProvider currentUserProvider;
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
/**
|
||||
* Used to populate @WhoModified bean properties.
|
||||
*/
|
||||
public class GeneratedWhoModified implements GeneratedProperty {
|
||||
final class GeneratedWhoModified implements GeneratedProperty {
|
||||
|
||||
private final CurrentUserProvider currentUserProvider;
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Helper for creating Insert timestamp GeneratedProperty objects.
|
||||
*/
|
||||
class InsertTimestampFactory {
|
||||
final class InsertTimestampFactory {
|
||||
|
||||
private final Map<Class<?>, GeneratedProperty> map = new HashMap<>();
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.time.ZonedDateTime;
|
||||
/**
|
||||
* Helper methods for Java time conversion.
|
||||
*/
|
||||
class JavaTimeUtils {
|
||||
final class JavaTimeUtils {
|
||||
|
||||
/**
|
||||
* Return the system millis time as a LocalDateTime.
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Helper for creating Update timestamp GeneratedProperty objects.
|
||||
*/
|
||||
class UpdateTimestampFactory {
|
||||
final class UpdateTimestampFactory {
|
||||
|
||||
private final Map<Class<?>, GeneratedProperty> map = new HashMap<>();
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UuidGeneratedProperty implements GeneratedProperty {
|
||||
final class UuidGeneratedProperty implements GeneratedProperty {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
|
||||
@@ -7,12 +7,11 @@ import io.ebeaninternal.server.persist.platform.MultiValueBind;
|
||||
/**
|
||||
* Creates the appropriate IdConvertSet depending on the type of Id property(s).
|
||||
*/
|
||||
public class IdBinderFactory {
|
||||
public final class IdBinderFactory {
|
||||
|
||||
private static final IdBinderEmpty EMPTY = new IdBinderEmpty();
|
||||
|
||||
private final boolean idInExpandedForm;
|
||||
|
||||
private final MultiValueBind multiValueBind;
|
||||
|
||||
public IdBinderFactory(boolean idInExpandedForm, MultiValueBind multiValueBind) {
|
||||
|
||||
@@ -26,13 +26,9 @@ import java.util.List;
|
||||
public final class IdBinderSimple implements IdBinder {
|
||||
|
||||
private final BeanProperty idProperty;
|
||||
|
||||
private final String bindIdSql;
|
||||
|
||||
private final Class<?> expectedType;
|
||||
|
||||
private final MultiValueBind multiValueBind;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final ScalarType scalarType;
|
||||
|
||||
|
||||
@@ -18,12 +18,10 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Imported Embedded id.
|
||||
*/
|
||||
public class ImportedIdEmbedded implements ImportedId {
|
||||
public final class ImportedIdEmbedded implements ImportedId {
|
||||
|
||||
private final BeanPropertyAssoc<?> owner;
|
||||
|
||||
private final BeanPropertyAssocOne<?> foreignAssocOne;
|
||||
|
||||
private final ImportedIdSimple[] imported;
|
||||
|
||||
public ImportedIdEmbedded(BeanPropertyAssoc<?> owner, BeanPropertyAssocOne<?> foreignAssocOne, ImportedIdSimple[] imported) {
|
||||
|
||||
@@ -36,23 +36,11 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
|
||||
private static final EntryComparator COMPARATOR = new EntryComparator();
|
||||
|
||||
final BeanPropertyAssoc<?> owner;
|
||||
|
||||
final String localDbColumn;
|
||||
|
||||
private final String localSqlFormula;
|
||||
|
||||
final BeanProperty foreignProperty;
|
||||
|
||||
private final int position;
|
||||
|
||||
/**
|
||||
* If true include in insert.
|
||||
*/
|
||||
private final boolean insertable;
|
||||
|
||||
/**
|
||||
* If true include in update.
|
||||
*/
|
||||
private final boolean updateable;
|
||||
|
||||
public ImportedIdSimple(BeanPropertyAssoc<?> owner, String localDbColumn, String localSqlFormula, BeanProperty foreignProperty, int position,
|
||||
|
||||
Reference in New Issue
Block a user