Skip to content

Commit

Permalink
feat: create create table operatioN
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 6fc3bd8 commit 1302874
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
29 changes: 29 additions & 0 deletions core/src/main/java/expert/os/harperdb/CreateTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

/**
* Represents the "create table" operation in HarperDB.
*/
Expand Down Expand Up @@ -56,4 +58,31 @@ public String table() {
public String id() {
return id;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}
CreateTable that = (CreateTable) object;
return Objects.equals(schema, that.schema) && Objects.equals(table, that.table)
&& Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hash(schema, table, id);
}

@Override
public String toString() {
return "CreateTable{" +
"schema='" + schema + '\'' +
", table='" + table + '\'' +
", id='" + id + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ private TableBuilder(String schema, String table, Server server) {
}
public boolean id(String id) {
Objects.requireNonNull(id, "id is required");
HttpRequest request = this.server.createRequest()
.POST(ofByteArray(INSTANCE.writeValueAsBytes(new CreateSchema(schema))))
.build();
return false;
return this.server.createTable(new CreateTable(schema, table, id));
}
}

Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/expert/os/harperdb/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ public CreateTableBuilder table(String schema){
return new CreateTableBuilder(schema, this);
}

boolean createTable(CreateTable operation) {
HttpRequest request = createRequest()
.POST(ofByteArray(INSTANCE.writeValueAsBytes(operation)))
.build();
try {
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
return HttpStatus.OK.isEquals(response);
} catch (IOException| InterruptedException e) {
throw new HarperDBException("There is an issue to create the table: " + operation, e);
}
}


HttpRequest.Builder createRequest() {
return HttpRequest.newBuilder()
Expand All @@ -71,4 +83,5 @@ HttpRequest.Builder createRequest() {

}


}

0 comments on commit 1302874

Please sign in to comment.