MapInfo

public abstract @interface MapInfo
implements Annotation

androidx.room.MapInfo


Declares which column(s) are used to build a map or multimap return value in a Dao query method.

This annotation is required when the key or value of the Map is a single column of one of the built in types (primitives, boxed primitives, enum, String, byte[], ByteBuffer) or a type with a converter (e.g. Date, UUID, etc).

The use of this annotation provides clarity on which column should be used in retrieving information required by the return type.

Example:

   @MapInfo(keyColumn = "artistName", valueColumn = "songName")
   @Query("SELECT * FROM Artist JOIN Song ON Artist.artistName = Song.artist")
    Map<String, List<String>> getArtistNameToSongNames();

   @MapInfo(valueColumn = "songCount")
   @Query("SELECT *, COUNT(mSongId) as songCount FROM Artist JOIN Song ON
   Artist.artistName = Song.artist GROUP BY artistName")
    Map<Artist, Integer> getArtistAndSongCounts();
 

To use the @MapInfo annotation, you must provide either the key column name, value column name, or both, based on the Dao's method return type. Column(s) specified in the provided @MapInfo annotation must be present in the query result.

Summary

Public methods

String keyColumn()

The name of the column to be used for the map's keys.

String valueColumn()

The name of the column to be used for the map's values.

Inherited methods

Public methods

keyColumn

public String keyColumn ()

The name of the column to be used for the map's keys.

Returns
String The key column name.

valueColumn

public String valueColumn ()

The name of the column to be used for the map's values.

Returns
String The value column name.