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 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> |
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)
When the new instance of a class annotated with
@Dao is created an automatic check for
schema validation is performed. |
public static final String SCHEMA_VALIDATION_ENABLED_SETTING
protected final CqlSession session
protected CqlIdentifier defaultKeyspaceId
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))
.public MapperBuilder<MapperT> withSchemaValidationEnabled(boolean enableSchemaValidation)
@Dao
is created an automatic check for
schema validation is performed. It verifies if all @Dao
entity fields are present in
CQL table. If not the exception is thrown. This check has startup overhead so once your app is
stable you may want to disable it. The schema Validation check is enabled by default.@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–2020. All rights reserved.