public static void deleteAllFromSharedTable ( String appid ) { if ( StringUtils . isBlank ( appid ) || ! isSharedAppid ( appid ) ) { return ; } Pager pager = new Pager ( 25 ) ; PageIterable < Item , QueryOutcome > pages ; Map < String , AttributeValue > lastKey = null ; do { // read all phase pages = queryGSI ( appid , pager ) ; if ( pages == null ) { break ; } List < WriteRequest > deletePage = new LinkedList <> ( ) ; for ( Page < Item , QueryOutcome > page : pages ) { for ( Item item : page ) { String key = item . getString ( Config . _KEY ) ; // only delete rows which belong to the given appid if ( StringUtils . startsWith ( key , appid . trim ( ) ) ) { logger . debug ( "Preparing to delete '{}' from shared table, appid: '{}'." , key , appid ) ; pager . setLastKey ( item . getString ( Config . _ID ) ) ; deletePage . add ( new WriteRequest ( ) . withDeleteRequest ( new DeleteRequest ( ) . withKey ( Collections . singletonMap ( Config . _KEY , new AttributeValue ( key ) ) ) ) ) ; } } lastKey = page . getLowLevelResult ( ) . getQueryResult ( ) . getLastEvaluatedKey ( ) ; } // delete all phase logger . info ( "Deleting {} items belonging to app '{}', from shared table..." , deletePage . size ( ) , appid ) ; if ( ! deletePage . isEmpty ( ) ) { batchWrite ( Collections . singletonMap ( getTableNameForAppid ( appid ) , deletePage ) , 1 ) ; } } while ( lastKey != null && ! lastKey . isEmpty ( ) ) ; }
Deletes all objects in a shared table which belong to a given appid by scanning the GSI .