
com.rapleaf.jack.store.JsTable Maven / Gradle / Ivy
package com.rapleaf.jack.store;
import com.google.common.base.Preconditions;
import com.rapleaf.jack.queries.AbstractTable;
import com.rapleaf.jack.queries.Column;
import com.rapleaf.jack.queries.GenericTable;
public class JsTable extends GenericTable {
public final AbstractTable, ?> table;
public final Column scope;
public final Column type;
public final Column key;
public final Column value;
private JsTable(AbstractTable, ?> table, Column scope, Column type, Column key, Column value) {
super(table, JsTable.class, scope, type, key, value);
this.table = table;
this.scope = scope;
this.type = type;
this.key = key;
this.value = value;
}
@Override
public JsTable as(String alias) {
return JsTable.from(getAliasTable(alias)).create();
}
public static Builder from(AbstractTable, ?> table) {
return new Builder(table);
}
public static class Builder extends GenericTable.Builder {
private Column scope;
private Column type;
private Column key;
private Column value;
private Builder(AbstractTable, ?> table) {
super(table);
}
public Builder setScopeColumn(Column scopeColumn) {
checkColumn(scopeColumn);
this.scope = scopeColumn;
return this;
}
public Builder setTypeColumn(Column typeColumn) {
checkColumn(typeColumn);
this.type = typeColumn;
return this;
}
public Builder setKeyColumn(Column keyColumn) {
checkColumn(keyColumn);
this.key = keyColumn;
return this;
}
public Builder setValueColumn(Column valueColumn) {
checkColumn(valueColumn);
this.value = valueColumn;
return this;
}
@Override
public JsTable create() {
if (scope == null) {
Preconditions.checkArgument(allColumns.contains(JsConstants.DefaultTableField.entry_scope.name()));
scope = Column.fromField(table.getAlias(), JsConstants.DefaultTableField.entry_scope, Long.class);
}
if (type == null) {
Preconditions.checkArgument(allColumns.contains(JsConstants.DefaultTableField.entry_type.name()));
type = Column.fromField(table.getAlias(), JsConstants.DefaultTableField.entry_type, Integer.class);
}
if (key == null) {
Preconditions.checkArgument(allColumns.contains(JsConstants.DefaultTableField.entry_key.name()));
key = Column.fromField(table.getAlias(), JsConstants.DefaultTableField.entry_key, String.class);
}
if (value == null) {
Preconditions.checkArgument(allColumns.contains(JsConstants.DefaultTableField.entry_value.name()));
value = Column.fromField(table.getAlias(), JsConstants.DefaultTableField.entry_value, String.class);
}
return new JsTable(table, scope, type, key, value);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy