Android的Room持久性库慷慨地包含适用于对象或集合的@Insert和@Update注释.然而,我有一个用例(包含模型的推送通知)需要UPSERT,因为数据可能存在或可能不存在于数据库中.
Sqlite本身没有upsert,并且在这个SO问题中描述了变通方法.鉴于那里的解决方案,如何将它们应用于房间?
更具体地说,如何在Room中实现不会破坏任何外键约束的插入或更新?使用带onConflict = REPLACE的insert将导致onDelete调用该行的任何外键.在我的情况下,onDelete导致级联,重新插入行将导致其他表中的行与外键被删除.这不是预期的行为.
我最近决定将我的应用程序移动到使用新的支持设计库,最近发现了一个非常讨厌的bug.
假设我有一个CoordinatorLayout托管AppBarLayout和任何可滚动的视图,无论是ViewPager,NestedScrollView,还是具有所需滚动行为的RecyclerView; 选择显示一个显示键盘的对话框片段会导致AppBarLayout与滚动视图断开连接,并且它们不再滚动在一起.
此外,滚动视图被强制调整到底部屏幕的一半,而AppBar布局占据了上半部分,尽管它不需要它.
这个bug的视频在这里: Youtube Link
编辑:
将Activity中键盘的softInputMode设置为"adjustPan"可以解决问题.显然,CoordinatorLayout不喜欢通过键盘动态调整大小.
违规的XML看起来像这样,但我有多个XML变体表现出这种行为,其中的共同元素都是他们使用的是CollapsingToolbarLayout:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="192dp"
android:background="@color/transparent">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="144dp"
android:elevation="4dp"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="@dimen/quadruple_margin"
app:layout_collapseParallaxMultiplier="0.7"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@color/primary"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/ranking_background" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_gravity="bottom"
android:background="@color/black_40" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_picture"
android:layout_width="@dimen/double_margin"
android:layout_height="@dimen/double_margin"
android:layout_alignBottom="@+id/text"
android:layout_marginLeft="@dimen/double_margin"
android:layout_marginStart="@dimen/double_margin"
android:src="@drawable/image_placeholder"
android:visibility="gone" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_marginLeft="@dimen/single_margin"
android:layout_marginStart="@dimen/single_margin"
android:layout_marginTop="@dimen/quadruple_margin"
android:layout_toRightOf="@+id/profile_picture"
android:text="@string/my_places_for"
android:textColor="@color/white"
android:textSize="20sp"
android:visibility="gone" …Run Code Online (Sandbox Code Playgroud) android android-keypad android-dialogfragment android-support-library android-coordinatorlayout
我有一个在CoordinatorLayout中托管的垂直RecyclerView,具有折叠工具栏布局.此RecyclerView的ViewHolder包含另一个带有GridLayoutManager的RecyclerView.
这种嵌套的原因是内部RecyclerView显示的图片集合可以包含1-20张图片.我不知道会有多少张图片,但Grid的跨度必须始终为3.每次绑定ViewHolder时,我都会调整RecyclerView的布局参数以容纳内容.
如果没有CollapsingToolBarLayout,这很有效.但是,如果有一个折叠的工具栏,用我的手指在内部RecyclerView上滚动不会滚动折叠工具栏,但滚动另一个项目却会.
要重新强调,在绑定的ViewHolder中,如果我开始滚动除嵌套的RecyclerView之外的任何其他项目,滚动工作正常.但是,如果我在嵌套的RecyclerView上开始滚动,那么它会中断.
是否可以阻止内部RecyclerView上的滚动拦截,只允许父滚动?我希望内部的RecyclerView仍能处理点击.
以下是该现象的YouTube链接:https://youtu.be/fzj7HmqskzU
以下是父RecyclerView的XML:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivityFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
app:contentScrim="?attr/colorPrimary"
app:layout_collapseParallaxMultiplier="0.7"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<View
android:id="@+id/header_view"
android:layout_width="match_parent"
android:layout_height="192dp"
android:animateLayoutChanges="true"
android:background="@color/primary" />
<android.support.v7.widget.Toolbar
android:id="@+id/action_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:elevation="4dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/Theme.AppCompat.NoActionBar"
app:theme="@style/Theme.AppCompat.NoActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
这是托管嵌套RecyclerView的主要ViewHolder:
public class SimpleAdapter extends RecyclerView.Adapter<SimpleAdapter.ViewHolder> {
private static final int MODEL_OBJECT = 1;
private List<ModelObject> modelObjects;
private Context context;
private int imageSize;
public SimpleAdapter(List<ModelObject> modelObjects) …Run Code Online (Sandbox Code Playgroud) android-recyclerview androiddesignsupport android-collapsingtoolbarlayout android-appbarlayout
我已成功在Google App引擎引擎上部署了自定义Node.js应用程序.但是我在启动应用程序时遇到问题,因为尝试连接时mongoose超时.令人沮丧的是,猫鼬在我的本地机器上与完全相同的参数连接得很好.
我的MongoDb URI的形式如下:
mongodb://<dbuser>:<dbpassword>@xxxx.mlab.com:<portNumber>/d??b-name
Run Code Online (Sandbox Code Playgroud)
正如URI所暗示的那样,db由mlab托管.它是Google Cloud Platform上的沙箱实例.但是我没有使用Google Compute Engine部署数据库.在mlab上完成设置过程时,我只是选择在GCP上主持.
我在SO上遇到过类似的问题,但大多数都没有接受.只是在评论中不同的话语,没有公认的解决方案.
因此,我的问题是,在尝试连接上述URI时,我的App Engine实例与本地计算机有何不同?我选择让mlab在GCP上托管它的事实是什么?如果我选择在亚马逊AWS上托管它会有什么不同吗?问题的根本原因究竟是什么?
作为参考,以下是我发现的类似问题:
另外,如果有帮助,MongoDB是作为分贝的商业模式中,数据存储的应用程序的快速会话,并从socket.io存储临时数据.
部署后从App Engine发生错误堆栈跟踪:
2017-10-18 02:13:46 default[20171017t215757] npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
2017-10-18 02:13:46 default[20171017t215757] npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
2017-10-18 02:13:46 default[20171017t215757] npm ERR! enoent This is most likely not a problem with npm itself
2017-10-18 02:13:46 default[20171017t215757] npm ERR! enoent and is related to npm not being able to find …Run Code Online (Sandbox Code Playgroud) google-app-engine mongoose mongodb node.js google-compute-engine
android ×3
android-architecture-components ×1
android-collapsingtoolbarlayout ×1
android-room ×1
mongodb ×1
mongoose ×1
node.js ×1
sqlite ×1