81 lines
2.1 KiB
Java
81 lines
2.1 KiB
Java
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);
|
|
}
|
|
}
|
|
}
|