Fixed
Status Update
Comments
ya...@google.com <ya...@google.com>
da...@google.com <da...@google.com> #2
I'll take this one, have a draft CL (aosp/975603) since we also need this for enabling relationship inserts.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 02684f53abe601dc8b863638bf4ae38a3d54c029
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Mon Jun 03 09:58:57 2019
Allow using POJOs in @Insert, @Update and @Delete method parameters.
Add a new method to @Insert, @Update and @Delete called 'entity', that
allows declaring the target entity the method is meant to affect. The
method will interpret the POJO parameters as partial entities.
If the method is an INSERT, we allow any POJO with a subset of columns
that will not cause a NOT NULL constraint. If the real entity has a
auto generated primary key, then that column is optional too.
If the method is an UPDATE or DELETE then we allow any POJO with a
subset of columns regardless of the schema default values. For UPDATE
the only requirement is that the POJO must have fields matching the
primary keys of the entity.
Bug: 127549506
Test: ./gradlew room:room-compiler:test \
room:integration-tests:room-testapp:cC
Change-Id: Ie0477d91bb92f799486ff672b20d4564769903d2
M room/common/api/2.2.0-alpha01.ignore
M room/common/api/2.2.0-alpha01.txt
M room/common/api/current.txt
M room/common/src/main/java/androidx/room/Delete.java
M room/common/src/main/java/androidx/room/Insert.java
M room/common/src/main/java/androidx/room/Update.java
M room/compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/DeletionMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/InsertionMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ShortcutMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ShortcutParameterProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/UpdateMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/vo/DeletionMethod.kt
M room/compiler/src/main/kotlin/androidx/room/vo/InsertionMethod.kt
A room/compiler/src/main/kotlin/androidx/room/vo/ShortcutEntity.kt
M room/compiler/src/main/kotlin/androidx/room/vo/ShortcutMethod.kt
M room/compiler/src/main/kotlin/androidx/room/vo/ShortcutQueryParameter.kt
M room/compiler/src/main/kotlin/androidx/room/vo/UpdateMethod.kt
M room/compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
M room/compiler/src/main/kotlin/androidx/room/writer/EntityDeletionAdapterWriter.kt
M room/compiler/src/main/kotlin/androidx/room/writer/EntityInsertionAdapterWriter.kt
M room/compiler/src/main/kotlin/androidx/room/writer/EntityUpdateAdapterWriter.kt
M room/compiler/src/test/data/daoWriter/output/WriterDao.java
M room/compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/processor/UpdateMethodProcessorTest.kt
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/dao/UserDao.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/DefaultValueTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/SimpleEntityReadWriteTest.java
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/vo/IdUsername.java
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/vo/Username.java
https://android-review.googlesource.com/975603
https://goto.google.com/android-sha1/02684f53abe601dc8b863638bf4ae38a3d54c029
Branch: androidx-master-dev
commit 02684f53abe601dc8b863638bf4ae38a3d54c029
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Mon Jun 03 09:58:57 2019
Allow using POJOs in @Insert, @Update and @Delete method parameters.
Add a new method to @Insert, @Update and @Delete called 'entity', that
allows declaring the target entity the method is meant to affect. The
method will interpret the POJO parameters as partial entities.
If the method is an INSERT, we allow any POJO with a subset of columns
that will not cause a NOT NULL constraint. If the real entity has a
auto generated primary key, then that column is optional too.
If the method is an UPDATE or DELETE then we allow any POJO with a
subset of columns regardless of the schema default values. For UPDATE
the only requirement is that the POJO must have fields matching the
primary keys of the entity.
Bug: 127549506
Test: ./gradlew room:room-compiler:test \
room:integration-tests:room-testapp:cC
Change-Id: Ie0477d91bb92f799486ff672b20d4564769903d2
M room/common/api/2.2.0-alpha01.ignore
M room/common/api/2.2.0-alpha01.txt
M room/common/api/current.txt
M room/common/src/main/java/androidx/room/Delete.java
M room/common/src/main/java/androidx/room/Insert.java
M room/common/src/main/java/androidx/room/Update.java
M room/compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/DeletionMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/InsertionMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ShortcutMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ShortcutParameterProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/UpdateMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/vo/DeletionMethod.kt
M room/compiler/src/main/kotlin/androidx/room/vo/InsertionMethod.kt
A room/compiler/src/main/kotlin/androidx/room/vo/ShortcutEntity.kt
M room/compiler/src/main/kotlin/androidx/room/vo/ShortcutMethod.kt
M room/compiler/src/main/kotlin/androidx/room/vo/ShortcutQueryParameter.kt
M room/compiler/src/main/kotlin/androidx/room/vo/UpdateMethod.kt
M room/compiler/src/main/kotlin/androidx/room/writer/DaoWriter.kt
M room/compiler/src/main/kotlin/androidx/room/writer/EntityDeletionAdapterWriter.kt
M room/compiler/src/main/kotlin/androidx/room/writer/EntityInsertionAdapterWriter.kt
M room/compiler/src/main/kotlin/androidx/room/writer/EntityUpdateAdapterWriter.kt
M room/compiler/src/test/data/daoWriter/output/WriterDao.java
M room/compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/processor/InsertionMethodProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/processor/ShortcutMethodProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/processor/UpdateMethodProcessorTest.kt
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/dao/UserDao.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/DefaultValueTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/SimpleEntityReadWriteTest.java
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/vo/IdUsername.java
A room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/vo/Username.java
da...@google.com <da...@google.com>
ys...@gmail.com <ys...@gmail.com> #4
Nice feature.
nn...@gmail.com <nn...@gmail.com> #5
i dont understand this example above . how do you target a specific field and update it
Description
@Entity
data class User(
@PrimaryKey id: Long,
name: String,
email: String?
)
data class UserName(id: Long, name: String)
data class UserEmail(id: Long, email: String)
@Dao
interface UserDao {
@Insert(entity = User::class)
insertWithoutEmail(userName: UserName)
@Update(entities = User::class)
updateEmail(userEmail: UserEmail)
}
- The @Insert example above is a bit silly, but it makes sense when you want to leave out columns with default values (
- We probably need a better API to support insertion/update of multiple entities/pojos.