private void generateDelete ( SQLiteDatabaseSchema schema ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "delete" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( Override . class ) . returns ( Integer . TYPE ) ; methodBuilder . addParameter ( Uri . class , "uri" ) ; methodBuilder . addParameter ( String . class , "selection" ) ; methodBuilder . addParameter ( ParameterSpec . builder ( TypeUtility . arrayTypeName ( String . class ) , "selectionArgs" ) . build ( ) ) ; boolean hasOperation = hasOperationOfType ( schema , methodBuilder , JQLType . DELETE ) ; if ( ! hasOperation ) { methodBuilder . addStatement ( "throw new $T(\"Unknown URI for $L operation: \" + uri)" , IllegalArgumentException . class , JQLType . DELETE ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; return ; } methodBuilder . addStatement ( "int returnRowDeleted=-1" ) ; methodBuilder . beginControlFlow ( "switch (sURIMatcher.match(uri))" ) ; defineJavadocHeaderForContentOperation ( methodBuilder , "delete" ) ; for ( Entry < String , ContentEntry > item : uriSet . entrySet ( ) ) { if ( item . getValue ( ) . delete == null ) continue ; defineJavadocForContentUri ( methodBuilder , item . getValue ( ) . delete ) ; // methodBuilder.addJavadoc("uri $L\n", item.getKey()); methodBuilder . beginControlFlow ( "case $L:" , item . getValue ( ) . pathIndex ) ; methodBuilder . addCode ( "// URI: $L\n" , item . getValue ( ) . delete . contentProviderUri ( ) ) ; methodBuilder . addStatement ( "returnRowDeleted=dataSource.get$L().$L(uri, selection, selectionArgs)" , item . getValue ( ) . delete . getParent ( ) . getName ( ) , item . getValue ( ) . delete . contentProviderMethodName ) ; methodBuilder . addStatement ( "break" ) ; methodBuilder . endControlFlow ( ) ; } defineJavadocFooterForContentOperation ( methodBuilder ) ; methodBuilder . beginControlFlow ( "default:" ) ; methodBuilder . addStatement ( "throw new $T(\"Unknown URI for $L operation: \" + uri)" , IllegalArgumentException . class , JQLType . DELETE ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . endControlFlow ( ) ; if ( hasOperation ) { if ( schema . generateLog ) { // generate log section - BEGIN methodBuilder . addComment ( "log section for content provider delete BEGIN" ) ; methodBuilder . beginControlFlow ( "if (dataSource.isLogEnabled())" ) ; methodBuilder . addStatement ( "$T.info(\"Changes are notified for URI %s\", uri)" , Logger . class ) ; // generate log section - END methodBuilder . endControlFlow ( ) ; methodBuilder . addComment ( "log section for content provider delete END" ) ; } methodBuilder . addStatement ( "getContext().getContentResolver().notifyChange(uri, null)" ) ; } methodBuilder . addCode ( "return returnRowDeleted;\n" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Generate delete .