first commit
This commit is contained in:
80
src/main/java/com/andrewkydev/database/schema/TableSpec.java
Normal file
80
src/main/java/com/andrewkydev/database/schema/TableSpec.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package com.andrewkydev.database.schema;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class TableSpec {
|
||||
private final String name;
|
||||
private final List<ColumnSpec> columns;
|
||||
private final List<String> primaryKey;
|
||||
private final List<IndexSpec> indexes;
|
||||
|
||||
private TableSpec(Builder builder) {
|
||||
this.name = builder.name;
|
||||
this.columns = Collections.unmodifiableList(new ArrayList<>(builder.columns));
|
||||
this.primaryKey = Collections.unmodifiableList(new ArrayList<>(builder.primaryKey));
|
||||
this.indexes = Collections.unmodifiableList(new ArrayList<>(builder.indexes));
|
||||
}
|
||||
|
||||
public static Builder builder(String name) {
|
||||
return new Builder(name);
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<ColumnSpec> columns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public List<String> primaryKey() {
|
||||
return primaryKey;
|
||||
}
|
||||
|
||||
public List<IndexSpec> indexes() {
|
||||
return indexes;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String name;
|
||||
private final List<ColumnSpec> columns = new ArrayList<>();
|
||||
private final List<String> primaryKey = new ArrayList<>();
|
||||
private final List<IndexSpec> indexes = new ArrayList<>();
|
||||
|
||||
private Builder(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Builder column(ColumnSpec column) {
|
||||
this.columns.add(column);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder columns(List<ColumnSpec> columns) {
|
||||
this.columns.addAll(columns);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder primaryKey(List<String> columns) {
|
||||
this.primaryKey.clear();
|
||||
this.primaryKey.addAll(columns);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder index(IndexSpec index) {
|
||||
this.indexes.add(index);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder indexes(List<IndexSpec> indexes) {
|
||||
this.indexes.addAll(indexes);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TableSpec build() {
|
||||
return new TableSpec(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user