public abstract class MapperBuilder<MapperT> extends Object
Mapper
-annotated interface wrapping a CqlSession
.
The mapper generates an implementation of this class for every such interface. It is either
named <InterfaceName>Builder
, or what you provided in Mapper.builderName()
.
Modifier and Type | Field and Description |
---|---|
protected Map<Object,Object> |
customState |
protected DriverExecutionProfile |
defaultExecutionProfile |
protected String |
defaultExecutionProfileName |
protected CqlIdentifier |
defaultKeyspaceId |
static String |
SCHEMA_VALIDATION_ENABLED_SETTING |
protected CqlSession |
session |
Modifier | Constructor and Description |
---|---|
protected |
MapperBuilder(CqlSession session) |
Modifier and Type | Method and Description |
---|---|
abstract MapperT |
build() |
MapperBuilder<MapperT> |
withCustomState(Object key,
Object value)
Stores custom state that will be propagated to
MapperContext.getCustomState() . |
MapperBuilder<MapperT> |
withDefaultExecutionProfile(DriverExecutionProfile executionProfile)
Specifies a default execution profile name that will be used for all DAOs built with this
mapper (unless they specify their own execution profile).
|
MapperBuilder<MapperT> |
withDefaultExecutionProfileName(String executionProfileName)
Specifies a default execution profile name that will be used for all DAOs built with this
mapper (unless they specify their own execution profile).
|
MapperBuilder<MapperT> |
withDefaultKeyspace(CqlIdentifier keyspaceId)
Specifies a default keyspace that will be used for all DAOs built with this mapper (unless they
specify their own keyspace).
|
MapperBuilder<MapperT> |
withDefaultKeyspace(String keyspaceName)
Shortcut for
withDefaultKeyspace(CqlIdentifier.fromCql(keyspaceName)) . |
MapperBuilder<MapperT> |
withSchemaValidationEnabled(boolean enableSchemaValidation)
Whether to validate mapped entities against the database schema.
|
public static final String SCHEMA_VALIDATION_ENABLED_SETTING
protected final CqlSession session
protected CqlIdentifier defaultKeyspaceId
protected String defaultExecutionProfileName
protected DriverExecutionProfile defaultExecutionProfile
protected MapperBuilder(CqlSession session)
@NonNull public MapperBuilder<MapperT> withDefaultKeyspace(@Nullable CqlIdentifier keyspaceId)
In other words, given the following definitions:
@Mapper public interface InventoryMapper { @DaoFactory ProductDao productDao(); @DaoFactory ProductDao productDao(@DaoKeyspace CqlIdentifier keyspace); } InventoryMapper mapper1 = new InventoryMapperBuilder(session) .withDefaultKeyspace(CqlIdentifier.fromCql("ks1")) .build(); InventoryMapper mapper2 = new InventoryMapperBuilder(session) .withDefaultKeyspace(CqlIdentifier.fromCql("ks2")) .build();Then:
mapper1.productDao()
will use keyspace ks1
;
mapper2.productDao()
will use keyspace ks2
;
mapper1.productDao(CqlIdentifier.fromCql("ks3"))
will use keyspace ks3
.
DaoFactory
@NonNull public MapperBuilder<MapperT> withDefaultKeyspace(@Nullable String keyspaceName)
withDefaultKeyspace(CqlIdentifier.fromCql(keyspaceName))
.@NonNull public MapperBuilder<MapperT> withDefaultExecutionProfileName(@Nullable String executionProfileName)
This works the same way as the default keyspace.
Note that if you had already set a profile with #withDefaultExecutionProfile, this method erases it.
DaoFactory
@NonNull public MapperBuilder<MapperT> withDefaultExecutionProfile(@Nullable DriverExecutionProfile executionProfile)
This works the same way as the default keyspace.
Note that if you had already set a profile name with #withDefaultExecutionProfileName, this method erases it.
DaoFactory
public MapperBuilder<MapperT> withSchemaValidationEnabled(boolean enableSchemaValidation)
If this is enabled, then every time a new DAO gets created, for each entity referenced in the DAO, the mapper will check that there is a corresponding table or UDT.
NamingStrategy
).
CodecRegistry
used by the session.
IllegalArgumentException
is thrown.
Schema validation is enabled by default; it adds a small startup overhead, so once your application is stable you may want to disable it.
SchemaHint
@NonNull public MapperBuilder<MapperT> withCustomState(@Nullable Object key, @Nullable Object value)
MapperContext.getCustomState()
.
This is intended mainly for QueryProvider
methods: since provider classes are
instantiated directly by the generated mapper code, they have no way to access non-static state
from the rest of your application. This method allows you to pass that state while building the
mapper, and access it later at runtime.
Note that this state will be accessed concurrently, it should be thread-safe.
public abstract MapperT build()
Copyright © 2017–2023. All rights reserved.