use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.
the class Verify method isValidIndexSchema.
/**
* Verifies that the index schema only index columns for columns that are available
* @param indices A mapping of the index details, not null
* @param columns A mapping of column details, not null
* @throws NullPointerException Thrown if the indices or columns container is null
* @throws IllegalArgumentException Thrown if a {@link IndexSchema} indexes
* a column that is not an available column
*/
public static void isValidIndexSchema(final Collection<IndexSchema> indices, final Collection<ColumnSchema> columns) {
checkNotNull(indices);
checkNotNull(columns);
Set<String> columnNames = Sets.newHashSet();
for (ColumnSchema column : columns) {
columnNames.add(column.getColumnName());
}
for (final IndexSchema index : indices) {
for (final String column : index.getColumns()) {
if (!columnNames.contains(column)) {
throw new IllegalArgumentException("Only columns in the table may be indexed.");
}
}
}
}
use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.
the class ColumnSchemaGenerator method next.
@Override
public ColumnSchema next() {
ColumnType type = typeGen.next();
ColumnSchema.Builder builder = ColumnSchema.builder(MYSQL_NAME_GEN.next(), type);
switch(type) {
case STRING:
case BINARY:
builder.setMaxLength(lengthGen.next());
break;
case LONG:
case ULONG:
case DOUBLE:
builder.setIsAutoIncrement(RAND.nextBoolean());
break;
case DECIMAL:
int precision = RAND.nextInt(66);
int scale = RAND.nextInt(Math.max(31, precision));
builder.setPrecision(precision).setScale(scale);
break;
default:
break;
}
return builder.build();
}
use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.
the class TableSchemaGenerator method next.
@Override
public TableSchema next() {
final List<ColumnSchema> columnSchemas = COLUMNS_GEN.next();
ImmutableList.Builder<String> columns = ImmutableList.builder();
for (ColumnSchema columnSchema : columnSchemas) {
columns.add(columnSchema.getColumnName());
}
final Generator<List<IndexSchema>> indexGen = CombinedGenerators.lists(new IndexSchemaGenerator(columns.build()), numIndicesGen);
return new TableSchema(columnSchemas, indexGen.next());
}
use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.
the class VerifyTest method testIsValidTableSchemaValidSchema.
@Test
public void testIsValidTableSchemaValidSchema() {
final List<ColumnSchema> columns = ImmutableList.<ColumnSchema>of(ColumnSchema.builder(COLUMN_B, ColumnType.LONG).setIsAutoIncrement(true).build());
Verify.isValidTableSchema(new TableSchema(columns, ImmutableList.<IndexSchema>of()));
}
use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.
the class VerifyTest method testHasAutoIncrementColumn.
@Test
public void testHasAutoIncrementColumn() {
final List<ColumnSchema> columns = ImmutableList.<ColumnSchema>of(ColumnSchema.builder(COLUMN_B, ColumnType.LONG).setIsAutoIncrement(true).build());
final TableSchema tableSchema = new TableSchema(columns, ImmutableList.<IndexSchema>of());
Verify.hasAutoIncrementColumn(tableSchema);
}
Aggregations