Unlike AbstractScope, this implementation lazy initialises its #data() map in order to avoid allocation in very short lived Scope implementations, such as e.g. CacheContext, ConverterContext, GeneratorContext. @author Lukas Eder
| 58 | * @author Lukas Eder |
| 59 | */ |
| 60 | abstract class AbstractLazyScope implements Scope { |
| 61 | |
| 62 | final Configuration configuration; |
| 63 | final Instant creationTime; |
| 64 | private Map<Object, Object> data; |
| 65 | |
| 66 | AbstractLazyScope(Configuration configuration) { |
| 67 | this(configuration, null, null); |
| 68 | } |
| 69 | |
| 70 | AbstractLazyScope(Configuration configuration, Map<Object, Object> data) { |
| 71 | this(configuration, data, null); |
| 72 | } |
| 73 | |
| 74 | AbstractLazyScope(Configuration configuration, Map<Object, Object> data, Instant creationTime) { |
| 75 | |
| 76 | // The Configuration can be null when unattached objects are |
| 77 | // executed or when unattached Records are stored... |
| 78 | if (configuration == null) |
| 79 | configuration = new DefaultConfiguration(); |
| 80 | |
| 81 | this.configuration = configuration; |
| 82 | this.data = data; |
| 83 | this.creationTime = creationTime != null ? creationTime : configuration.clock().instant(); |
| 84 | } |
| 85 | |
| 86 | // ------------------------------------------------------------------------ |
| 87 | // XXX Scope API |
| 88 | // ------------------------------------------------------------------------ |
| 89 | |
| 90 | @Override |
| 91 | public final Instant creationTime() { |
| 92 | return creationTime; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public final Configuration configuration() { |
| 97 | return configuration; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public final DSLContext dsl() { |
| 102 | return configuration.dsl(); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public final Settings settings() { |
| 107 | return configuration.settings(); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public final SQLDialect dialect() { |
| 112 | return configuration.dialect(); |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public final SQLDialect family() { |
| 117 | return configuration.family(); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…