use of com.datastax.driver.core.BatchStatement in project aroma-data-operations by RedRoma.
the class CassandraApplicationRepository method createStatementToSave.
private Statement createStatementToSave(Application app) {
BatchStatement batch = new BatchStatement();
// UUIDs
UUID appId = UUID.fromString(app.applicationId);
UUID iconId = null;
UUID orgId = null;
// Enums
String tier = null;
String programmingLanguage = null;
if (app.tier != null) {
tier = app.tier.toString();
}
if (app.programmingLanguage != null) {
programmingLanguage = app.programmingLanguage.toString();
}
if (app.isSetApplicationIconMediaId()) {
iconId = UUID.fromString(app.applicationIconMediaId);
}
if (app.isSetOrganizationId()) {
orgId = UUID.fromString(app.organizationId);
}
Set<UUID> owners = Sets.nullToEmpty(app.owners).stream().map(UUID::fromString).collect(Collectors.toSet());
Statement insertIntoMainTable = QueryBuilder.insertInto(TABLE_NAME).value(APP_ID, appId).value(APP_NAME, app.name).value(APP_DESCRIPTION, app.applicationDescription).value(ICON_MEDIA_ID, iconId).value(ORG_ID, orgId).value(OWNERS, owners).value(PROGRAMMING_LANGUAGE, programmingLanguage).value(TIME_PROVISIONED, app.timeOfProvisioning).value(TIME_OF_TOKEN_EXPIRATION, app.timeOfTokenExpiration).value(TIER, tier);
batch.add(insertIntoMainTable);
// Save into the "Recents Table"
Long timeToLive = DEFAULT_RECENT_DURATION.getSeconds();
Statement insertIntoRecentlyCreated = QueryBuilder.insertInto(TABLE_NAME_RECENTLY_CREATED).value(APP_ID, appId).value(APP_NAME, app.name).value(APP_DESCRIPTION, app.applicationDescription).value(ICON_MEDIA_ID, iconId).value(ORG_ID, orgId).value(OWNERS, owners).value(PROGRAMMING_LANGUAGE, programmingLanguage).value(TIME_PROVISIONED, app.timeOfProvisioning).value(TIME_OF_TOKEN_EXPIRATION, app.timeOfTokenExpiration).value(TIER, tier).using(ttl(timeToLive.intValue()));
batch.add(insertIntoRecentlyCreated);
return batch;
}
use of com.datastax.driver.core.BatchStatement in project aroma-data-operations by RedRoma.
the class CassandraFollowerRepository method createStatementToSaveFollowing.
private Statement createStatementToSaveFollowing(User user, Application app) {
UUID userId = UUID.fromString(user.userId);
UUID appId = UUID.fromString(app.applicationId);
BatchStatement batch = new BatchStatement();
Statement insertIntoAppFollowersTable = QueryBuilder.insertInto(Follow.TABLE_NAME_APP_FOLLOWERS).value(APP_ID, appId).value(USER_ID, userId).value(APP_NAME, app.name).value(USER_FIRST_NAME, user.firstName).value(TIME_OF_FOLLOW, Instant.now().toEpochMilli());
batch.add(insertIntoAppFollowersTable);
Statement insertIntoUserFollowingsTable = QueryBuilder.insertInto(Follow.TABLE_NAME_USER_FOLLOWING).value(APP_ID, appId).value(USER_ID, userId).value(APP_NAME, app.name).value(USER_FIRST_NAME, user.firstName).value(TIME_OF_FOLLOW, Instant.now().toEpochMilli());
batch.add(insertIntoUserFollowingsTable);
return batch;
}
use of com.datastax.driver.core.BatchStatement in project aroma-data-operations by RedRoma.
the class CassandraFollowerRepository method createDeleteStatementFor.
private Statement createDeleteStatementFor(String userId, String applicationId) {
UUID appUuid = UUID.fromString(applicationId);
UUID userUuid = UUID.fromString(userId);
BatchStatement batch = new BatchStatement();
Statement deleteFromAppFollowersTable = QueryBuilder.delete().all().from(Follow.TABLE_NAME_APP_FOLLOWERS).where(eq(APP_ID, appUuid)).and(eq(USER_ID, userUuid));
batch.add(deleteFromAppFollowersTable);
Statement deleteFromUserFollowingsTable = QueryBuilder.delete().all().from(Follow.TABLE_NAME_USER_FOLLOWING).where(eq(APP_ID, appUuid)).and(eq(USER_ID, userUuid));
batch.add(deleteFromUserFollowingsTable);
return batch;
}
use of com.datastax.driver.core.BatchStatement in project aroma-data-operations by RedRoma.
the class CassandraTokenRepository method createStatementToDeleteToken.
private Statement createStatementToDeleteToken(String tokenId) throws TException {
UUID tokenUuid = UUID.fromString(tokenId);
// Need to get Token first
AuthenticationToken token = this.getToken(tokenId);
UUID ownerUuid = UUID.fromString(token.ownerId);
BatchStatement batch = new BatchStatement();
Statement deleteFromMainTable = QueryBuilder.delete().all().from(Tokens.TABLE_NAME).where(eq(TOKEN_ID, tokenUuid));
batch.add(deleteFromMainTable);
Statement deleteFromOwnersTable = QueryBuilder.delete().all().from(Tokens.TABLE_NAME_BY_OWNER).where(eq(OWNER_ID, ownerUuid));
batch.add(deleteFromOwnersTable);
return batch;
}
use of com.datastax.driver.core.BatchStatement in project aroma-data-operations by RedRoma.
the class CassandraTokenRepository method createStatementToInsert.
private Statement createStatementToInsert(AuthenticationToken token) throws InvalidArgumentException {
// UUIDs
UUID tokenId = UUID.fromString(token.tokenId);
UUID ownerId = UUID.fromString(token.ownerId);
UUID orgId = null;
// Enums
String tokenType = null;
if (token.tokenType != null) {
tokenType = token.tokenType.toString();
}
long timeToLive = TimeFunctions.toSeconds(DEFAULT_TOKEN_LIFETIME);
if (!isNullOrEmpty(token.organizationId)) {
checkThat(token.organizationId).usingMessage("token organizationId must be a UUID type").throwing(InvalidArgumentException.class).is(validUUID());
orgId = UUID.fromString(token.organizationId);
}
BatchStatement batch = new BatchStatement();
Statement insertIntoMainTable = QueryBuilder.insertInto(Tokens.TABLE_NAME).value(TOKEN_ID, tokenId).value(OWNER_ID, ownerId).value(ORG_ID, orgId).value(OWNER_NAME, token.ownerName).value(TIME_OF_EXPIRATION, token.timeOfExpiration).value(TIME_OF_CREATION, token.timeOfCreation).value(TOKEN_TYPE, tokenType).using(ttl((int) timeToLive));
batch.add(insertIntoMainTable);
Statement insertIntoOwnersTable = QueryBuilder.insertInto(Tokens.TABLE_NAME_BY_OWNER).value(OWNER_ID, ownerId).value(TOKEN_ID, tokenId).value(ORG_ID, orgId).value(OWNER_NAME, token.ownerName).value(TIME_OF_EXPIRATION, token.timeOfExpiration).value(TIME_OF_CREATION, token.timeOfCreation).value(TOKEN_TYPE, tokenType).using(ttl((int) timeToLive));
batch.add(insertIntoOwnersTable);
return batch;
}
Aggregations