private void updateIdleTask ( final Task orig , Task mods ) { // only allow transition to "starting" state String newState = StringUtil . normalize ( mods . getState ( ) ) ; if ( newState != null && ! newState . equals ( Task . IDLE ) && ! newState . equals ( Task . STARTING ) ) { throw new IllegalArgumentException ( "Illegal state transition: " + Task . IDLE + " -> " + newState ) ; } if ( newState != null ) { orig . setState ( newState ) ; } // At this point, id, activeLogId, and state have been validated/set. // Now we need to validate/set name, type, schedule, and data. if ( StringUtil . normalize ( mods . getName ( ) ) != null ) { orig . setName ( StringUtil . validate ( "name" , mods . getName ( ) , 256 ) ) ; } if ( StringUtil . normalize ( mods . getType ( ) ) != null ) { orig . setType ( StringUtil . validate ( "type" , mods . getType ( ) , 32 ) ) ; } if ( StringUtil . normalize ( mods . getSchedule ( ) ) != null ) { orig . setSchedule ( StringUtil . validate ( "schedule" , mods . getType ( ) , 1024 ) ) ; } if ( StringUtil . normalize ( mods . getData ( ) ) != null ) { orig . setData ( StringUtil . validate ( "data" , mods . getData ( ) , 32672 ) ) ; } // Validate schedule content, type-specific data, // and do dependency determination final TaskRunner runner = TaskRunner . getInstance ( orig , this , objectSetDao , objectStoreDao , null , null , new HttpClientConfig ( ) ) ; // Finally, update the necessary tables in a transaction final int taskId = Integer . parseInt ( orig . getId ( ) ) ; tt . execute ( new TransactionCallbackWithoutResult ( ) { public void doInTransactionWithoutResult ( TransactionStatus status ) { boolean success = false ; try { db . update ( UPDATE_SQL , orig . getName ( ) , orig . getType ( ) , orig . getState ( ) , orig . getSchedule ( ) , orig . getData ( ) , taskId ) ; db . update ( "DELETE FROM TaskSetDeps WHERE taskId = ?" , taskId ) ; db . update ( "DELETE FROM TaskStoreDeps WHERE taskId = ?" , taskId ) ; for ( String setId : runner . getRelatedSetIds ( ) ) { db . update ( INSERT_SQL2 , taskId , Integer . parseInt ( setId ) ) ; } for ( String storeId : runner . getRelatedStoreIds ( ) ) { db . update ( INSERT_SQL3 , taskId , Integer . parseInt ( storeId ) ) ; } success = true ; } finally { if ( ! success ) { status . setRollbackOnly ( ) ; } } } } ) ; }
allow prop changes and state transition to starting