@ Initialize ( distributed = false ) public void truncateIfNecesary ( ) { if ( truncateTable ) { final UpdateableDatastoreConnection con = datastore . openConnection ( ) ; try { final SchemaNavigator schemaNavigator = con . getSchemaNavigator ( ) ; final Table table = schemaNavigator . convertToTable ( schemaName , tableName ) ; final UpdateableDataContext dc = con . getUpdateableDataContext ( ) ; dc . executeUpdate ( new UpdateScript ( ) { @ Override public void run ( UpdateCallback callback ) { final RowDeletionBuilder delete = callback . deleteFrom ( table ) ; if ( logger . isInfoEnabled ( ) ) { logger . info ( "Executing truncating DELETE operation: {}" , delete . toSql ( ) ) ; } delete . execute ( ) ; } } ) ; } finally { con . close ( ) ; } } }
Truncates the database table if necesary . This is NOT a distributable initializer since it can only happen once .