Skip to content

Commit

Permalink
docs: enhanve documentation to create table builder
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <[email protected]>
  • Loading branch information
otaviojava committed Nov 28, 2023
1 parent 449ca61 commit c15ef4c
Showing 1 changed file with 52 additions and 17 deletions.
69 changes: 52 additions & 17 deletions core/src/main/java/expert/os/harperdb/CreateTableBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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));
}
}
}
}

0 comments on commit c15ef4c

Please sign in to comment.