OrientDB。设置ConflictStrategy抛出异常

时间:2016-07-29 03:28:07

标签: java orientdb

我有OObjectDatabaseTx。我想用api设置我自己的冲突策略。

OObjectDatabaseTx db;
db.setConflictStrategy(new ORecordConflictStrategy() {
            @Override
            public byte[] onUpdate(OStorage storage, byte iRecordType, ORecordId rid, ORecordVersion iRecordVersion, byte[] iRecordContent, ORecordVersion iDatabaseVersion) {
                <implementation>;
            }

            @Override
            public String getName() {
                return "SOME NAME";
            }
        });

在执行时,我得到一个例外,不支持该操作。

10:40:48,718 INFO  [com.ats.vis.services.transaction.TransactionManager] (TransactionExecutor[UML]) [__MAIN_WS__] ERROR:: java.lang.UnsupportedOperationException: setConflictStrategy
at com.orientechnologies.orient.client.remote.OStorageRemoteThread.setConflictStrategy(OStorageRemoteThread.java:318) [orientdb-client-2.1.19.jar:2.1.19]
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.setConflictStrategy(ODatabaseDocumentTx.java:1122) [orientdb-core-2.1.19.jar:2.1.19]
at com.orientechnologies.orient.object.db.OObjectDatabaseTx.setConflictStrategy(OObjectDatabaseTx.java:760) [orientdb-object-2.1.19.jar:2.1.19]

有没有办法设定冲突策略?

1 个答案:

答案 0 :(得分:1)

您在客户端设置它,但这是不可能的,因为它是使用它的服务器。如果您使用带有“远程”协议的OrientDB,则应该将其安装在服务器中。怎么做?

这很容易,写一个Server Pluginprivate void OpenNumberPickerDailog() { final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.timer_dailog); dialog.setCancelable(false); final NumberPicker numberPicker = (NumberPicker) dialog.findViewById(R.id.numberPicker); numberPicker.setMinValue(2); numberPicker.setMaxValue(15); numberPicker.setWrapSelectorWheel(true); Button ok = (Button) dialog.findViewById(R.id.button_ok); ok.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int a = numberPicker.getValue(); //int PickedNumber= as * 1000; } dialog.dismiss(); } }); Button cancel = (Button) dialog.findViewById(R.id.button2_cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } 注册它自己作为数据库监听器。这样,一旦实施了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="wrap_content" android:background="@mipmap/footer" android:orientation="vertical" android:padding="10dp"> <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:gravity="left" android:paddingBottom="15dp" android:paddingTop="5dp" android:text="Select time. " android:textColor="#ffffff" android:textStyle="bold" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <NumberPicker android:id="@+id/numberPicker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginTop="15dp" android:orientation="horizontal"> <Button android:id="@+id/button_ok" android:layout_width="0dip" android:layout_height="match_parent" android:layout_marginRight="10dp" android:layout_weight="1" android:background="#A76EA9" android:text="OK" android:textColor="#ffffff" /> <Button android:id="@+id/button2_cancel" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="1" android:background="#A76EA9" android:text="Cancel" android:textColor="#ffffff" /> </LinearLayout> </LinearLayout> startup()方法,就可以像以前一样安装冲突策略。示例(未尝试):

onOpen()

然后在onCreate()文件中将其注册为处理程序:

public class MyPlugin OServerPluginAbstract implements ODatabaseLifecycleListener {
  @Override
  public void startup() {
    Orient.instance().addDbLifecycleListener(this);
  }

  @Override
  public void onOpen(final ODatabaseInternal db) {
    db.setConflictStrategy(new ORecordConflictStrategy() {
        @Override
        public byte[] onUpdate(OStorage storage, byte iRecordType, ORecordId rid, ORecordVersion iRecordVersion, byte[] iRecordContent, ORecordVersion iDatabaseVersion) {
            <implementation>;
        }

        @Override
        public String getName() {
            return "SOME NAME";
        }
    });
  }

  @Override
  public void onOpen(final ODatabaseInternal db) {
    onOpen(db);
  }
  // BOILERPLATE CODE MISSING
}