DynamoDbMapper.batch загружает данные в таблицу, когда количество элементов = 1 для более чем одного элемента, он не загружается в таблицу и также не генерируется исключение.
Фрагмент кода:
object AnytimePayEmployeeJobData {
final val EMPLOYEE_TABLE_NAME = "TestAnytimepayEmployeeJobData"
final val EMPLOYEE_ID_HASH_ATTRIBUTE = "employeeId"
final val EMPLOYEE_JOB_DATA_LIST_ATTRIBUTE = "employeeJobDataList"
final val LAST_UPDATE_TIME_ATTRIBUTE = "lastUpdatedTime"
}
@DynamoDBTable(tableName = AnytimePayEmployeeJobData.EMPLOYEE_TABLE_NAME)
class AnytimePayEmployeeJobData {
import AnytimePayEmployeeJobData._
@BeanProperty
@DynamoDBHashKey(attributeName = EMPLOYEE_ID_HASH_ATTRIBUTE)
var employeeId: String = _
@BeanProperty
@DynamoDBAttribute(attributeName = EMPLOYEE_JOB_DATA_LIST_ATTRIBUTE)
var employeeJobDataList: List[EmployeeJobData] = _
@BeanProperty
@DynamoDBAttribute(attributeName = LAST_UPDATE_TIME_ATTRIBUTE)
var lastUpdatedTime: Long = _
}
Клиент DynamoDb Mapper:
object DynamoDBResource extends Logger {
@throws(classOf[AmazonDynamoDBException])
def getDynamoDBMapper(region: String): DynamoDBMapper = {
try {
val dynamoDBClient = getDDBClient(region)
Option(
new DynamoDBMapper(dynamoDBClient,
new DynamoDBMapperConfig(SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES)))
.getOrElse(throw new AmazonDynamoDBException(
"Could not create DynamoDBMapper object."))
} catch {
case e: Throwable => {
log.error("Unable to create DynamoDB Mapper to the region " + region)
log.error(e.toString)
throw e
}}}
def getDDBClient(region: String): AmazonDynamoDB =
AmazonDynamoDBClientBuilder
.standard()
.withRegion(region)
.build()
} код функции для сохранения данных:
def batchSaveInDDB[T](employeeJobDataList: ArrayList[T]): List[FailedBatch] =
AWSSession.dynamoDBMapper.batchSave(employeeJobDataList)