Fixed
Status Update
Comments
yb...@google.com <yb...@google.com> #2
we've considered this, just didn't have time to implement.
Btw, we cannot just use name() because it might be proguarded away. so we need to generate the code that matches enums to hardcoded string values.
If you are using name(), be careful about migrations since 2 different compilations might have different names for the enum values.
Btw, we cannot just use name() because it might be proguarded away. so we need to generate the code that matches enums to hardcoded string values.
If you are using name(), be careful about migrations since 2 different compilations might have different names for the enum values.
t....@gmail.com <t....@gmail.com> #3
True. Even though this could be fixed by using proguard rules.
Would be great to see this in the future, it's really lots of code here ;)
Would be great to see this in the future, it's really lots of code here ;)
bu...@gmail.com <bu...@gmail.com> #4
What about the idea of using a more generic adapter which can handle all of the enums in your app? That way you could decide to persist them all with one "stone". You could choose to save them as strings, ordinals or even some other way of your choosing. But you would not have to add an adapter for every enum type in your app. You just have to add the one special enum adapter and Room would know how to use it for all enums.
yb...@google.com <yb...@google.com>
yb...@google.com <yb...@google.com> #5
This seems like a possible candidate for external contributions so moving it to the bug bounty hotlist.
We still need a proper design here hence not super straightforward.
Such design should ensure we are:
- safe for proguard (in case we go w/ name)
- have some logic for defaults (in case an enum is removed or renamed)
- possibly support ordinals (though that might be a case where we can require a type converter)
- possibly make it opt-in so that developer explicitly picks an option (e.g. some annotation on the enum to enable this)
si...@gmail.com <si...@gmail.com> #6
Project: platform/frameworks/support
Branch: androidx-master-dev
commit ae093dec7bfdc578cf0d7cd2ee6c8563ddd4f5ed
Author: Elif Bilgin <elifbilgin@google.com>
Date: Wed Oct 21 11:50:07 2020
Optimization for storing enums in databases.
Creating a default type adapter to persist Enums in Room. Changes made in logic of the findQueryParameterAdapter(...) function where we now try to find a TypeConverter for the collection of an object first, and if not, then try to find one for the type arg.
Test: Baseline tests replicate compiler errors in EnumColumnTypeAdapterTest.java
Bug: 73132006
Change-Id: Ia212097c16fde4302bc7c20cbad1604a996090ad
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspArrayType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspDeclaredType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
A room/compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
M room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/EnumColumnTypeAdapterTest.java
https://android-review.googlesource.com/1469447
Branch: androidx-master-dev
commit ae093dec7bfdc578cf0d7cd2ee6c8563ddd4f5ed
Author: Elif Bilgin <elifbilgin@google.com>
Date: Wed Oct 21 11:50:07 2020
Optimization for storing enums in databases.
Creating a default type adapter to persist Enums in Room. Changes made in logic of the findQueryParameterAdapter(...) function where we now try to find a TypeConverter for the collection of an object first, and if not, then try to find one for the type arg.
Test: Baseline tests replicate compiler errors in EnumColumnTypeAdapterTest.java
Bug: 73132006
Change-Id: Ia212097c16fde4302bc7c20cbad1604a996090ad
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspArrayType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspDeclaredType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
A room/compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
M room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/EnumColumnTypeAdapterTest.java
yb...@google.com <yb...@google.com> #7
Project: platform/frameworks/support
Branch: androidx-master-dev
commit ed8d4acdb13cba24fcb1a392b36952ddfe790776
Author: Elif Bilgin <elifbilgin@google.com>
Date: Wed Oct 21 11:50:07 2020
Optimization for storing enums in databases.
Creating a default type adapter to persist Enums in Room. Changes made in logic of the findQueryParameterAdapter(...) function where we now try to find a TypeConverter for the collection of an object first, and if not, then try to find one for the type arg.
Test: Baseline tests replicate compiler errors in EnumColumnTypeAdapterTest.java
Bug: 73132006
Change-Id: I4cfa8c7f9ac3dc97ec4591ceef6f97b4cba7a6ad
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
A room/compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
M room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/EnumColumnTypeAdapterTest.java
https://android-review.googlesource.com/1500819
Branch: androidx-master-dev
commit ed8d4acdb13cba24fcb1a392b36952ddfe790776
Author: Elif Bilgin <elifbilgin@google.com>
Date: Wed Oct 21 11:50:07 2020
Optimization for storing enums in databases.
Creating a default type adapter to persist Enums in Room. Changes made in logic of the findQueryParameterAdapter(...) function where we now try to find a TypeConverter for the collection of an object first, and if not, then try to find one for the type arg.
Test: Baseline tests replicate compiler errors in EnumColumnTypeAdapterTest.java
Bug: 73132006
Change-Id: I4cfa8c7f9ac3dc97ec4591ceef6f97b4cba7a6ad
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
M room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
A room/compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
M room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/EnumColumnTypeAdapterTest.java
da...@google.com <da...@google.com> #8
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 4eb2d133f3084759df737bc78b07a4ec8594d089
Author: Elif Bilgin <elifbilgin@google.com>
Date: Thu Nov 12 10:09:28 2020
Adding functionality to handle proguard when storing enums in databases.
Test: Baseline tests replicate compiler errors in EnumColumnTypeAdapterTest.java
Bug: 73132006
Change-Id: Ifa0a0bc496d63467a6b54c2c4d264c97a4bde0cd
M room/compiler/src/main/kotlin/androidx/room/ext/javapoet_ext.kt
M room/compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/EnumColumnTypeAdapterTest.java
https://android-review.googlesource.com/1497443
Branch: androidx-master-dev
commit 4eb2d133f3084759df737bc78b07a4ec8594d089
Author: Elif Bilgin <elifbilgin@google.com>
Date: Thu Nov 12 10:09:28 2020
Adding functionality to handle proguard when storing enums in databases.
Test: Baseline tests replicate compiler errors in EnumColumnTypeAdapterTest.java
Bug: 73132006
Change-Id: Ifa0a0bc496d63467a6b54c2c4d264c97a4bde0cd
M room/compiler/src/main/kotlin/androidx/room/ext/javapoet_ext.kt
M room/compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/EnumColumnTypeAdapterTest.java
ap...@google.com <ap...@google.com> #9
Is there a way we can disable this default TypeConverter altogether? Our room DB is quite big and with Room 2.3, we noticed that sometimes we forgot to add our custom Enum converters to @TypeConverters in Room and the default one got picked up which causes unexpected crash. And with the Room default Enum TypeConverter, we are unable to detect such mistake (forgetting to add our custom Enum converters to @TypeConverters ) at compile time.
It would be nice if we can configure our Room DB which just disables Room build-in type converter
It would be nice if we can configure our Room DB which just disables Room build-in type converter
Description
Version used: 1.0.0-rc1
Devices/Android versions reproduced on: compile
These are my entity and dao classes.
----------------------------------------------------------------------------------------------------------
@Entity
public class Playlist {
@PrimaryKey(autoGenerate = true) private int id;
private String name;
private String path;
@ColumnInfo(name = "icon_path") private String iconPath;
private int type;
@ColumnInfo(name = "date_created") private long dateCreated;
@ColumnInfo(name = "date_last_opened") private long dateLastOpened;
public int getId() {
return id;
}
public void setId(int id) {
}
public String getName() {
return name;
}
public void setName(String name) {
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getIconPath() {
return iconPath;
}
public void setIconPath(String iconPath) {
this.iconPath = iconPath;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public long getDateCreated() {
return dateCreated;
}
public void setDateCreated(long dateCreated) {
this.dateCreated = dateCreated;
}
public long getDateLastOpened() {
return dateLastOpened;
}
public void setDateLastOpened(long dateLastOpened) {
this.dateLastOpened = dateLastOpened;
}
}
----------------------------------------------------------------------------------------------------------
@Dao
public interface PlaylistDao {
@Query("SELECT * FROM playlist")
List<Playlist> getAll();
@Insert
void insert(Playlist playlist);
@Delete
void delete(Playlist playlist);
}
----------------------------------------------------------------------------------------------------------
I'm getting compile time error that cannot find getter for id and iconPath field.
----------------------------------------------------------------------------------------------------------
Playlist.java:15: error: Cannot find getter for field.
@PrimaryKey(autoGenerate = true) private int id;
^
Playlist.java:18: error: Cannot find getter for field.
@ColumnInfo(name = "icon_path") private String iconPath;
^
----------------------------------------------------------------------------------------------------------
While I looked into generated PlaylistDao implementation class, i saw that 'İ' is used as uppercase of 'i'.
----------------------------------------------------------------------------------------------------------
public List<Playlist> getAll() {
final String _sql = "SELECT * FROM playlist";
final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
final Cursor _cursor = __db.query(_statement);
try {
final int _cursorIndexOfİd = _cursor.getColumnIndexOrThrow("id");
final int _cursorIndexOfName = _cursor.getColumnIndexOrThrow("name");
final int _cursorIndexOfPath = _cursor.getColumnIndexOrThrow("path");
final int _cursorIndexOfİconPath = _cursor.getColumnIndexOrThrow("icon_path");
final int _cursorIndexOfType = _cursor.getColumnIndexOrThrow("type");
final int _cursorIndexOfDateCreated = _cursor.getColumnIndexOrThrow("date_created");
final int _cursorIndexOfDateLastOpened = _cursor.getColumnIndexOrThrow("date_last_opened");
final List<Playlist> _result = new ArrayList<Playlist>(_cursor.getCount());
while(_cursor.moveToNext()) {
final Playlist _item;
_item = new Playlist();
_
final String _tmpName;
_tmpName = _cursor.getString(_cursorIndexOfName);
_item.setName(_tmpName);
final String _tmpPath;
_tmpPath = _cursor.getString(_cursorIndexOfPath);
_item.setPath(_tmpPath);
_item.iconPath = _cursor.getString(_cursorIndexOfİconPath);
final int _tmpType;
_tmpType = (int) _cursor.getInt(_cursorIndexOfType);
_item.setType(_tmpType);
final long _tmpDateCreated;
_tmpDateCreated = _cursor.getLong(_cursorIndexOfDateCreated);
_item.setDateCreated(_tmpDateCreated);
final long _tmpDateLastOpened;
_tmpDateLastOpened = _cursor.getLong(_cursorIndexOfDateLastOpened);
_item.setDateLastOpened(_tmpDateLastOpened);
_result.add(_item);
}
return _result;
} finally {
_cursor.close();
_statement.release();
}
}
----------------------------------------------------------------------------------------------------------
I'm using Turkish keyboard. I tried changing my keyboard input as English and wrote entity class again. I also tried convert file encoding of playlist class but the problem was not solved.
It only compile without error when i change getters with getİd and getİconPath.