/* (non-Javadoc) * @see org.javarosa.core.services.storage.IStorageUtility#write(org.javarosa.core.services.storage.Persistable) */ public void write(Persistable p) throws StorageFullException { if (p.getID() != -1) { this.data.put(DataUtil.integer(p.getID()), (T) p); syncMeta(); } else { p.setID(curCount); this.add((T) p); } }
public static void importRMS(FormInstance dm, IStorageUtility storage, Class type, String path) { if (!Externalizable.class.isAssignableFrom(type) || !Restorable.class.isAssignableFrom(type)) { return; } boolean idMatters = Persistable.class.isAssignableFrom(type); String childName = ((Restorable) PrototypeFactory.getInstance(type)).getRestorableType(); TreeElement e = dm.resolveReference(absRef(path, dm)); Vector children = e.getChildrenWithName(childName); for (int i = 0; i < children.size(); i++) { FormInstance child = subDataModel((TreeElement) children.elementAt(i)); Restorable inst = (Restorable) PrototypeFactory.getInstance(type); // restore record id first so 'importData' has access to it int recID = -1; if (idMatters) { recID = ((Integer) getValue(RECORD_ID_TAG, child)).intValue(); ((Persistable) inst).setID(recID); } inst.importData(child); try { if (idMatters) { storage.write((Persistable) inst); } else { storage.add((Externalizable) inst); } } catch (Exception ex) { throw new RuntimeException( "Error importing RMS during restore! [" + type.getName() + ":" + recID + "]; " + ex.getMessage()); } } }