Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change terminology from "database" to "namespace" #101

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/java/io/stargate/sgv2/jsonapi/StargateJsonApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
info = @Info(title = "", version = ""),
tags = {
@Tag(name = "General", description = "Executes general commands."),
@Tag(name = "Databases", description = "Executes database commands."),
@Tag(name = "Namespaces", description = "Executes namespace commands."),
@Tag(
name = "Documents",
description = "Executes document commands against a single collection."),
Expand All @@ -43,10 +43,10 @@
parameters = {
@Parameter(
in = ParameterIn.PATH,
name = "database",
name = "namespace",
required = true,
schema = @Schema(implementation = String.class, pattern = "\\w+"),
description = "The database where the collection is located.",
description = "The namespace where the collection is located.",
example = "cycling"),
@Parameter(
in = ParameterIn.PATH,
Expand Down Expand Up @@ -171,23 +171,23 @@
}
"""),
@ExampleObject(
name = "createDatabase",
summary = "`CreateDatabase` command",
name = "createNamespace",
summary = "`CreateNamespace` command",
value =
"""
{
"createDatabase": {
"createNamespace": {
"name": "cycling"
}
}
"""),
@ExampleObject(
name = "createDatabaseWithReplication",
summary = "`CreateDatabase` command with replication",
name = "createNamespaceWithReplication",
summary = "`CreateNamespace` command with replication",
value =
"""
{
"createDatabase": {
"createNamespace": {
"name": "cycling",
"options": {
"replication": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.stargate.sgv2.jsonapi.api.model.command;

/** Interface for all commands executed against a collection in a namespace (database). */
/** Interface for all commands executed against a collection in a namespace. */
public interface CollectionCommand extends Command {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateCollectionCommand;
import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateDatabaseCommand;
import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateNamespaceCommand;
import io.stargate.sgv2.jsonapi.api.model.command.impl.DeleteOneCommand;
import io.stargate.sgv2.jsonapi.api.model.command.impl.FindCommand;
import io.stargate.sgv2.jsonapi.api.model.command.impl.FindOneAndUpdateCommand;
Expand Down Expand Up @@ -34,7 +34,7 @@
include = JsonTypeInfo.As.WRAPPER_OBJECT,
property = "commandName")
@JsonSubTypes({
@JsonSubTypes.Type(value = CreateDatabaseCommand.class),
@JsonSubTypes.Type(value = CreateNamespaceCommand.class),
@JsonSubTypes.Type(value = CreateCollectionCommand.class),
@JsonSubTypes.Type(value = DeleteOneCommand.class),
@JsonSubTypes.Type(value = FindCommand.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
/**
* Defines the context in which to execute the command.
*
* @param database The name of the database.
* @param namespace The name of the namespace.
* @param collection The name of the collection.
*/
public record CommandContext(String database, String collection) {
public record CommandContext(String namespace, String collection) {

private static final CommandContext EMPTY = new CommandContext(null, null);

/**
* @return Returns empty command context, having both {@link #database} and {@link #collection} as
* <code>null</code>.
* @return Returns empty command context, having both {@link #namespace} and {@link #collection}
* as <code>null</code>.
*/
public static CommandContext empty() {
return EMPTY;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.stargate.sgv2.jsonapi.api.model.command;

/**
* Interface for all general commands, that are not executed against a namespace (database) nor a
* collection .
* Interface for all general commands, that are not executed against a namespace nor a collection .
*/
public interface GeneralCommand extends Command {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.stargate.sgv2.jsonapi.api.model.command;

/** Interface for all commands executed against a namespace. */
public interface NamespaceCommand extends Command {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.stargate.sgv2.jsonapi.api.model.command.impl;

import com.fasterxml.jackson.annotation.JsonTypeName;
import io.stargate.sgv2.jsonapi.api.model.command.DatabaseCommand;
import io.stargate.sgv2.jsonapi.api.model.command.NamespaceCommand;
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
Expand All @@ -17,6 +17,6 @@ public record CreateCollectionCommand(
type = SchemaType.OBJECT)
String name,
@Nullable Options options)
implements DatabaseCommand {
implements NamespaceCommand {
public record Options() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import javax.validation.constraints.Size;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

@Schema(description = "Command that creates a namespace (database).")
@JsonTypeName("createDatabase")
public record CreateDatabaseCommand(
@NotBlank @Size(min = 1, max = 48) @Schema(description = "Name of the database") String name,
@Nullable @Valid CreateDatabaseCommand.Options options)
@Schema(description = "Command that creates a namespace.")
@JsonTypeName("createNamespace")
public record CreateNamespaceCommand(
@NotBlank @Size(min = 1, max = 48) @Schema(description = "Name of the namespace") String name,
@Nullable @Valid CreateNamespaceCommand.Options options)
implements GeneralCommand {

@Schema(
name = "CreateDatabaseCommand.Options",
description = "Options for creating a new database.")
name = "CreateNamespaceCommand.Options",
description = "Options for creating a new namespace.")
public record Options(@Nullable @Valid Replication replication) {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@Tag(ref = "Documents")
public class CollectionResource {

public static final String BASE_PATH = "/v1/{database}/{collection}";
public static final String BASE_PATH = "/v1/{namespace}/{collection}";

private final CommandProcessor commandProcessor;

Expand All @@ -56,7 +56,7 @@ public CollectionResource(CommandProcessor commandProcessor) {
description = "Executes a single command against a collection.")
@Parameters(
value = {
@Parameter(name = "database", ref = "database"),
@Parameter(name = "namespace", ref = "namespace"),
@Parameter(name = "collection", ref = "collection")
})
@RequestBody(
Expand Down Expand Up @@ -103,11 +103,11 @@ public CollectionResource(CommandProcessor commandProcessor) {
@POST
public Uni<RestResponse<CommandResult>> postCommand(
@NotNull @Valid CollectionCommand command,
@PathParam("database") String database,
@PathParam("namespace") String namespace,
@PathParam("collection") String collection) {

// create context
CommandContext commandContext = new CommandContext(database, collection);
CommandContext commandContext = new CommandContext(namespace, collection);

// call processor
return commandProcessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.stargate.sgv2.jsonapi.api.model.command.CommandContext;
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult;
import io.stargate.sgv2.jsonapi.api.model.command.GeneralCommand;
import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateDatabaseCommand;
import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateNamespaceCommand;
import io.stargate.sgv2.jsonapi.config.constants.OpenApiConstants;
import io.stargate.sgv2.jsonapi.service.processor.CommandProcessor;
import javax.inject.Inject;
Expand Down Expand Up @@ -47,10 +47,10 @@ public GeneralResource(CommandProcessor commandProcessor) {
content =
@Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(anyOf = {CreateDatabaseCommand.class}),
schema = @Schema(anyOf = {CreateNamespaceCommand.class}),
examples = {
@ExampleObject(ref = "createDatabase"),
@ExampleObject(ref = "createDatabaseWithReplication"),
@ExampleObject(ref = "createNamespace"),
@ExampleObject(ref = "createNamespaceWithReplication"),
}))
@APIResponses(
@APIResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.smallrye.mutiny.Uni;
import io.stargate.sgv2.jsonapi.api.model.command.CommandContext;
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult;
import io.stargate.sgv2.jsonapi.api.model.command.DatabaseCommand;
import io.stargate.sgv2.jsonapi.api.model.command.NamespaceCommand;
import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateCollectionCommand;
import io.stargate.sgv2.jsonapi.config.constants.OpenApiConstants;
import io.stargate.sgv2.jsonapi.service.processor.CommandProcessor;
Expand All @@ -29,26 +29,26 @@
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.jboss.resteasy.reactive.RestResponse;

@Path(DatabaseResource.BASE_PATH)
@Path(NamespaceResource.BASE_PATH)
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@SecurityRequirement(name = OpenApiConstants.SecuritySchemes.TOKEN)
@Tag(ref = "Databases")
public class DatabaseResource {
@Tag(ref = "Namespaces")
public class NamespaceResource {

public static final String BASE_PATH = "/v1/{database}";
public static final String BASE_PATH = "/v1/{namespace}";

private final CommandProcessor commandProcessor;

@Inject
public DatabaseResource(CommandProcessor commandProcessor) {
public NamespaceResource(CommandProcessor commandProcessor) {
this.commandProcessor = commandProcessor;
}

@Operation(
summary = "Execute command",
description = "Executes a single command against a collection.")
@Parameters(value = {@Parameter(name = "database", ref = "database")})
@Parameters(value = {@Parameter(name = "namespace", ref = "namespace")})
@RequestBody(
content =
@Content(
Expand All @@ -72,10 +72,10 @@ public DatabaseResource(CommandProcessor commandProcessor) {
})))
@POST
public Uni<RestResponse<CommandResult>> postCommand(
@NotNull @Valid DatabaseCommand command, @PathParam("database") String database) {
@NotNull @Valid NamespaceCommand command, @PathParam("namespace") String namespace) {

// create context
CommandContext commandContext = new CommandContext(database, null);
CommandContext commandContext = new CommandContext(namespace, null);

// call processor
return commandProcessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public record CreateCollectionOperation(CommandContext commandContext, String na
@Override
public Uni<Supplier<CommandResult>> execute(QueryExecutor queryExecutor) {
final Uni<QueryOuterClass.ResultSet> execute =
queryExecutor.executeSchemaChange(getCreateTable(commandContext.database(), name));
queryExecutor.executeSchemaChange(getCreateTable(commandContext.namespace(), name));
final Uni<Boolean> indexResult =
execute
.onItem()
.transformToUni(
res -> {
final List<QueryOuterClass.Query> indexStatements =
getIndexStatements(commandContext.database(), name);
getIndexStatements(commandContext.namespace(), name);
List<Uni<QueryOuterClass.ResultSet>> indexes = new ArrayList<>(10);
indexStatements.stream()
.forEach(index -> indexes.add(queryExecutor.executeSchemaChange(index)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import java.util.function.Supplier;

/**
* Operation that creates a new Cassandra keyspace that serves as a namespace (database) for the
* JSON API.
* Operation that creates a new Cassandra keyspace that serves as a namespace for the JSON API.
*
* @param name Name of the namespace to create.
* @param replicationMap A replication json, see
* https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/cqlCreateKeyspace.html#Table2.Replicationstrategyclassandfactorsettings.
*/
public record CreateDatabaseOperation(String name, String replicationMap) implements Operation {
public record CreateNamespaceOperation(String name, String replicationMap) implements Operation {

// simple pattern for the cql
private static final String CREATE_KEYSPACE_CQL =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Uni<Supplier<CommandResult>> execute(QueryExecutor queryExecutor) {
private QueryOuterClass.Query buildDeleteQuery() {
String delete = "DELETE FROM \"%s\".\"%s\" WHERE key = ? IF tx_id = ?";
return QueryOuterClass.Query.newBuilder()
.setCql(String.format(delete, commandContext.database(), commandContext.collection()))
.setCql(String.format(delete, commandContext.namespace(), commandContext.collection()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private QueryOuterClass.Query buildSelectQuery() {
return new QueryBuilder()
.select()
.column(readDocument ? documentColumns : documentKeyColumns)
.from(commandContext.database(), commandContext.collection())
.from(commandContext.namespace(), commandContext.collection())
.where(conditions)
.limit(limit)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private QueryOuterClass.Query buildInsertQuery() {
+ " VALUES"
+ " (?, now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
return QueryOuterClass.Query.newBuilder()
.setCql(String.format(insert, commandContext.database(), commandContext.collection()))
.setCql(String.format(insert, commandContext.namespace(), commandContext.collection()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private QueryOuterClass.Query buildUpdateQuery() {
+ " IF "
+ " tx_id = ?";
return QueryOuterClass.Query.newBuilder()
.setCql(String.format(update, commandContext.database(), commandContext.collection()))
.setCql(String.format(update, commandContext.namespace(), commandContext.collection()))
.build();
}

Expand Down
Loading