- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Room 的新手,@Relation 对我来说不是很清楚。如果我理解正确,我有实体,例如(RSS)ChannelEntity, channel 具有名为 ItemEntity 的项目。这些是带有@Entity 注释的类。我还有一个 POJO 来“连接”我的实体。我的意思是我必须像这样写一个 POJO:
public class Channel {
@Embedded
private ChannelEntity channel;
// Link is the primary key in ChannelyEntity
@Relation (parentColumn = "link", entityColumn = "channel_link")
private ArrayList<ItemEntity> items;
// Getters and Setters are here
}
然后我必须编写一个 dao 接口(interface),我可以像这样获取 Channel(不是 ChannelEntity):
public interface ChannelDao {
@Query("SELECT * FROM channels WHERE link = :link LIMIT 1")
Channel getChannelById(String link);
@Query("SELECT * FROM channels")
ArrayList<Channel> getAllChannels();
}
有了这些实体、DAO 和 POJO,我可以获得 Channel 对象,其中包含具有相应链接 (id) 的 Items 列表。是吗?
我的另一个问题是关于其余的 CRUD。例如。如果我想保存一个新 channel ,我可以将此语句添加到我的 ChannelDao 中吗?
@Insert(onConflict = OnConflictStrategy.REPLACE)
void createChannels(Channel... channels);
删除
@Delete
void deleteChannels(Channel... channels);
等等。那么它会从传递的 Channel 对象中创建和删除 ChannelEntities 和 ItemEntities 吗?
最佳答案
我按照@CommonsWare 的建议更新了我的类(class)。现在我有了带有@Embedded 对象的实体类:
@Entity (tableName = "channels")
public class ChannelEntity {
// Required channel elements
// The name of the channel. It's how people refer to your service.
private String title;
// The URL of the HTML website corresponding to the channel
@PrimaryKey
private String link;
//other fileds
@Embedded
private TextInputEntity textInputEntity;
@Embedded
private ImageEntity imageEntity;
//getters and setters
}
嵌入类之一:
// Specifies a text input box displayed with the channel.
// Embedded in ChannelEntity
public class TextInputEntity {
// Required elements
// The label of the Submit button in the text input area.
private String title;
// Explains the text input aera.
private String description;
// The name of the text object int hte text input area.
private String name;
// The URL of the CGI script that processes the text input request
private String link;
@ColumnInfo (name = "channel_link")
private String channelLink;
}
我为所有带有@Entity 注释的类编写了 daos(我将嵌入式类称为实体,即使它们不是实体,但我有 View 的模型类,我不想以后混淆它们)。
我这样映射关系:
// All items are optional, but at least one of title or description must be presented.
@Entity (tableName = "items"
, foreignKeys = @ForeignKey (entity = Channel.class
, parentColumns = "link"
, childColumns = "channel_link"))
public class ItemEntity {
@PrimaryKey (autoGenerate = true)
private int id;
// Title of the item
private String title;
// Other fileds
@ColumnInfo (name = "channel_link")
private String channelLink;
// Getters and setters
当我想获得一个包含项目列表的 channel 时,我是这样得到的:
public class Channel {
@Embedded
private ChannelEntity channel;
@Relation (parentColumn = "link", entityColumn = "channel_link")
private ArrayList<ItemEntity> items;
@Relation (parentColumn = "link", entityColumn = "channel_link")
private ArrayList<SkipDayEntity> skipDays;
@Relation (parentColumn = "link", entityColumn = "channel_link")
private ArrayList<SkipHourEntity> skipHours;
//Setters and getters
}
这是 Channel 的 dao:
@Dao
public interface ChannelDao {
@Insert (onConflict = OnConflictStrategy.REPLACE)
void insertChannel(ChannelEntity channel);
@Update
void updateChannel(ChannelEntity channel);
@Delete
void deleteChannel(ChannelEntity channel);
@Query ("SELECT * FROM channles WHERE link = :link LIMIT 1")
Channel getChannelByLink(String link);
@Query ("SELECT * FROM channels")
LiveData<ArrayList<Channel>> getAllChannels();
}
关于Android 房间持久性库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45172455/
我想知道将内存中的树结构存储为用于持久性目的的目录树的实用性。在我的例子中,他的目标文件系统将是 ZFS,一旦创建了结构,它将很少被多个进程访问。 使用目录树作为数据树持久化机制的性能如何? 最佳答案
我已经创建了 docker private registry 并且能够从同一网络中的其他 raspi 推送和拉取(将 registry ip 添加到 insecure-registry 选项) doc
我正在尝试构建我的第一个“真正的”Haskell 应用程序,一个使用 Servant 的 API,我在其中使用 Persistent 作为数据库后端。但是我在尝试使用 Persistent 进行某种类
我已经在 stackoverflow 上看到了 ASP.NET MVC C# 中的持久性 cookie 示例。但我不明白为什么下面的代码不起作用。 首先我写入cookie: HttpCookie co
我是 Java Persistence API 的新手.我刚学会它,现在想在我的 Java 桌面应用程序中使用它。但我有以下问题: Q1。哪个 JPA 实现的大小最小(因为我希望我的应用程序的大小尽可
我正在尝试按照 android 蓝图指南将 MVP 模式实现到我的项目中。目前,我将用户(实体数据)保存在我的 Presenter 中,我真的不喜欢这样做,因为在每次配置更改时,presenter 都
我需要一个类似 map 的数据结构(在 C++ 中)来存储具有以下功能的对 (Key,T): 可以在当前结构中插入新元素(Key,T) 可以在当前结构中根据Key搜索元素 您可以制作当前版本结构的“快
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我的配置 MBean 的持久性存在问题。我的配置: @ManagedResource(objectName = "pl.mobile
docker 中的 RabbitMQ 在删除没有卷的容器后丢失数据。 我的 Dockerfile: FROM rabbitmq:3-management ENV RABBITMQ_HIPE_COMPI
我正在尝试编写一个类型类,以简化使用持久性、aeson 和 scotty 编写 CRUD 后端 这是我的想法: runDB x = liftIO $ do info CRUD a where
当我尝试使用 持久化对象时遇到问题多线程 . 详情: 假设我有一个对象 PaymentOrder其中有一个列表 PaymentGroup (一对多关系)和 PaymentGroup包含 CreditT
我想使用纯功能数据结构和以下操作来实现环形缓冲区 通过索引进行高效随机访问 添加到前面 从背面移除 使用持久数据结构的原因是因为我有一个写入器线程和多个读取器线程,并且我想避免读取器阻塞写入器。 这可
persistence.xml 中关于 derby 客户端驱动程序的属性声明应该是什么?例如: 当我想从 Java 更新数据库时,我不断收到下面的异常。 实际上我需要客户端驱动程序而不是 Embed
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我希望用户即使关闭浏览器也不必登录。我的 cookie 将在一个月后过期。 用户登录成功 $session = CGI::Session->new (undef, undef, {Directory
我正在与 JBOss 作斗争,并且遇到了一个似乎很难解决的问题,但事实证明我不能。当我尝试部署一个简单的 Java Web 应用程序时,遇到异常: org.hibernate.ejb.Hibernat
当使用具有持久性的 Workflow Foundation 时,我们想删除一些(或全部)工作流,这些工作流不再应该被持久化/运行。 我可以使用任何脚本/工具吗? 最佳答案 没有可用于执行此操作的标准
我正在使用 JPA,并且我正在为所有引用实体使用二级缓存。一切正常,我可以从二级缓存中获取实体,因为它们之前已经被选中。 现在,我有两个应用程序,它们都使用相同的数据库(因此它们都使用相同的表、值等)
所以我正在制作一个 spring-boot 应用程序,并且从外部库导入一些数据模型(通过 maven 导入)。我有一些模型,它有一个外部库类型的字段,我希望能够保留它。像这样的东西: package
我是一名优秀的程序员,十分优秀!