コード例 #1
0
 @Override
 public void storeHeldForeignKey(Relationship relationship, RecordReference foreignKey) {
   if (!relationship.isHoldForeignRecord())
     throw new IllegalArgumentException(
         "This relationship is not allowed to hold on to foreign records");
   preferences
       .edit()
       .putString(getHeldForeignKeyPrefKey(relationship), foreignKey.serialise())
       .commit();
 }
コード例 #2
0
 @Override
 public RecordReference retrieveHeldForeignKey(Relationship relationship) {
   if (!relationship.isHoldForeignRecord())
     throw new IllegalArgumentException(
         "This relationship is not allowed to hold on to foreign records");
   String prefKey = getHeldForeignKeyPrefKey(relationship);
   String serialisedForeignKey = preferences.getString(prefKey, null);
   if (serialisedForeignKey != null)
     try {
       return relationship
           .getRelatedForm()
           .getSchema()
           .createRecordReference(serialisedForeignKey);
     } catch (Exception e) {
       deleteHeldForeignKey(relationship);
     }
   return null;
 }