private void validateTableOptionShardingField ( TableDefinition tableDef , String optValue ) { // Verify that the sharding-field exists and is a timestamp field. FieldDefinition shardingFieldDef = tableDef . getFieldDef ( optValue ) ; Utils . require ( shardingFieldDef != null , "Sharding field has not been defined: " + optValue ) ; assert shardingFieldDef != null ; // Make FindBugs happy Utils . require ( shardingFieldDef . getType ( ) == FieldType . TIMESTAMP , "Sharding field must be a timestamp field: " + optValue ) ; Utils . require ( ! shardingFieldDef . isCollection ( ) , "Sharding field cannot be a collection: " + optValue ) ; // Default sharding-granularity to MONTH. if ( tableDef . getOption ( CommonDefs . OPT_SHARDING_GRANULARITY ) == null ) { tableDef . setOption ( CommonDefs . OPT_SHARDING_GRANULARITY , "MONTH" ) ; } // Default sharding-start to "tomorrow". if ( tableDef . getOption ( CommonDefs . OPT_SHARDING_START ) == null ) { GregorianCalendar startDate = new GregorianCalendar ( Utils . UTC_TIMEZONE ) ; startDate . add ( Calendar . DAY_OF_MONTH , 1 ) ; // adds 1 day String startOpt = String . format ( "%04d-%02d-%02d" , startDate . get ( Calendar . YEAR ) , startDate . get ( Calendar . MONTH ) + 1 , // 0-relative! startDate . get ( Calendar . DAY_OF_MONTH ) ) ; tableDef . setOption ( CommonDefs . OPT_SHARDING_START , startOpt ) ; } }
Validate the table option sharding - field .