com.shapestone.session.adapters.DynamoSessionTableManager Maven / Gradle / Ivy
The newest version!
package com.shapestone.session.adapters;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.DeleteTableRequest;
import com.amazonaws.services.dynamodbv2.model.ScanRequest;
import com.shapestone.dynamo.HashKey;
import com.shapestone.dynamo.util.DynamoTableManager;
import com.shapestone.result.Result;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.shapestone.session.adapters.DynamoSessionRepository.getSessionTablePrimaryKey;
import static com.shapestone.session.adapters.DynamoSessionRepository.getSessionsTableIndex;
import static com.shapestone.session.adapters.DynamoSessionRepository.getSessionsTableName;
/**
* Name: Michael Williams
* Date: 12/13/16.
*/
public class DynamoSessionTableManager {
private DynamoTableManager dynamoTableManager;
public DynamoSessionTableManager(DynamoTableManager dynamoTableManager) {
this.dynamoTableManager = dynamoTableManager;
}
public List> createTables() throws InterruptedException {
return this.dynamoTableManager.createTables(
this.dynamoTableManager.buildCreateTableRequest(getSessionsTableName(), getSessionsTableIndex())
);
}
public List> deleteTables() throws InterruptedException {
return this.dynamoTableManager.deleteTables(
this.dynamoTableManager.buildDeleteTableRequest(getSessionsTableName())
);
}
public void deleteAllRecords() {
final Map stringHashKeyMap = new HashMap<>();
stringHashKeyMap.put(getSessionsTableName(), getSessionTablePrimaryKey().getHashKey());
stringHashKeyMap.forEach((tableName, hashKey) -> {
final ScanRequest scanRequest = dynamoTableManager.buildScanRequest(tableName);
dynamoTableManager.deleteAllRecords(scanRequest, hashKey);
});
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy