If you think the Android project android-sqlite-helper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package net.ichigotake.sqlitehelper.schema;
//www.java2s.comimport java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
publicclass TableSchemaBuilder {
privatefinal String tableName;
privatefinal List<TableField> fields;
privatefinal List<Index> indexes;
privatefinal List<UniqueField> uniqueFields;
public TableSchemaBuilder(String tableName) {
this.tableName = tableName;
this.fields = new ArrayList<>();
this.indexes = new ArrayList<>();
this.uniqueFields = new ArrayList<>();
}
public TableSchema build() {
returnnew TableSchema(tableName, fields, indexes, uniqueFields);
}
public TableSchemaBuilder field(TableField[] fields) {
return field(Arrays.asList(fields));
}
public TableSchemaBuilder field(List<TableField> fields) {
for (TableField field : fields) {
this.fields.add(field);
if (field.getAttributes().contains(FieldAttribute.UNIQUE)) {
unique(field);
}
}
returnthis;
}
public TableSchemaBuilder index(TableField field, TableField... pair) {
List<TableField> targets = new ArrayList<>();
targets.add(field);
targets.addAll(Arrays.asList(pair));
indexes.add(new Index(tableName, targets));
returnthis;
}
public TableSchemaBuilder unique(TableField field, TableField... pair) {
uniqueFields.add(new UniqueField(field, pair));
returnthis;
}
}