From c15ef4cc13f03710032c1b28787c865ca1008075 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 28 Nov 2023 18:19:24 +0000 Subject: [PATCH] docs: enhanve documentation to create table builder Signed-off-by: Otavio Santana --- .../os/harperdb/CreateTableBuilder.java | 69 ++++++++++++++----- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/expert/os/harperdb/CreateTableBuilder.java b/core/src/main/java/expert/os/harperdb/CreateTableBuilder.java index f3b6277..26f84e8 100644 --- a/core/src/main/java/expert/os/harperdb/CreateTableBuilder.java +++ b/core/src/main/java/expert/os/harperdb/CreateTableBuilder.java @@ -3,6 +3,8 @@ import java.util.Objects; +import java.util.Objects; + /** * Builder class for constructing a "create table" operation in HarperDB. * This class facilitates the step-by-step configuration of a new table within a specific schema. @@ -27,46 +29,79 @@ public final class CreateTableBuilder { * Specifies the name of the table to be created. * * @param table The name of the table. - * @return A TableBuilder instance to continue configuring the table. + * @return A TableIdBuilder instance to continue configuring the table with an ID. * @throws NullPointerException if the provided table name is null. */ - public TableBuilder table(String table) { + public TableIdBuilder table(String table) { Objects.requireNonNull(table, "table is required"); - return new TableBuilder(schema, table, server); + return new TableIdBuilder(schema, table, server); } /** - * Builder class for configuring the details of the table to be created. + * Builder class for configuring the details of the table to be created, + * including specifying the ID for the table. */ - public static class TableBuilder { + public static class TableIdBuilder { private final String schema; private final String table; private final Server server; + private TableIdBuilder(String schema, String table, Server server) { + this.schema = schema; + this.table = table; + this.server = server; + } + /** - * Constructs a TableBuilder instance with the specified schema, table, and server. + * Specifies the ID (hash attribute) for the table. * - * @param schema The name of the schema for the new table. - * @param table The name of the table to be created. - * @param server The Server instance used for executing HarperDB operations. + * @param id The hash attribute for the table. + * @return A TableBuilder instance to continue configuring the table with additional details. + * @throws NullPointerException if the provided id is null. */ - private TableBuilder(String schema, String table, Server server) { + public TableBuilder id(String id) { + Objects.requireNonNull(id, "id is required"); + return new TableBuilder(schema, table, server, id); + } + } + + /** + * Builder class for configuring additional details of the table to be created + * and executing the "create table" operation. + */ + public static class TableBuilder { + private final String schema; + private final String table; + private final Server server; + private final String id; + + private TableBuilder(String schema, String table, Server server, String id) { this.schema = schema; this.table = table; this.server = server; + this.id = id; } /** - * Specifies the hash attribute (id) for the table. + * Executes the "create table" operation with default data attribute. * - * @param id The hash attribute for the table. * @return true if the table creation is successful; false otherwise. - * @throws NullPointerException if the provided id is null. */ - public boolean id(String id) { - Objects.requireNonNull(id, "id is required"); - return this.server.executeTableCreation(new CreateTable(schema, table, id)); + public boolean execute() { + return server.executeTableCreation(new CreateTable(schema, table, id, "data")); + } + + /** + * Executes the "create table" operation with a specified database attribute. + * + * @param database The database attribute for the table. + * @return true if the table creation is successful; false otherwise. + * @throws NullPointerException if the provided database is null. + */ + public boolean execute(String database) { + Objects.requireNonNull(database, "database is required"); + return server.executeTableCreation(new CreateTable(schema, table, id, database)); } } -} +} \ No newline at end of file