public static void migratePendingCommands(SQLiteDatabase db) { List<PendingCommand> pendingCommands = new ArrayList<>(); if (columnExists(db, "pending_commands", "arguments")) { for (OldPendingCommand oldPendingCommand : getPendingCommands(db)) { PendingCommand newPendingCommand = migratePendingCommand(oldPendingCommand); pendingCommands.add(newPendingCommand); } db.execSQL("DROP TABLE IF EXISTS pending_commands"); db.execSQL("CREATE TABLE pending_commands (" + "id INTEGER PRIMARY KEY, " + "command TEXT, " + "data TEXT" + ")"); PendingCommandSerializer pendingCommandSerializer = PendingCommandSerializer.getInstance(); for (PendingCommand pendingCommand : pendingCommands) { ContentValues cv = new ContentValues(); cv.put("command", pendingCommand.getCommandName()); cv.put("data", pendingCommandSerializer.serialize(pendingCommand)); db.insert("pending_commands", "command", cv); } } }
l.pendingCommandStarted(account, command.getCommandName()); command.execute(this, account); for (MessagingListener l : getListeners()) { l.synchronizeMailboxProgress(account, null, progress, todo); l.pendingCommandCompleted(account, command.getCommandName());
@Test public void testSerializeDeserialize__withArguments() { PendingCommand pendingCommand = PendingAppend.create(SOURCE_FOLDER, UID); String serializedCommand = pendingCommandSerializer.serialize(pendingCommand); PendingAppend unserializedCommand = (PendingAppend) pendingCommandSerializer.unserialize( DATABASE_ID, pendingCommand.getCommandName(), serializedCommand); assertEquals(DATABASE_ID, unserializedCommand.databaseId); assertEquals(SOURCE_FOLDER, unserializedCommand.folder); assertEquals(UID, unserializedCommand.uid); }
@Test public void testSerializeDeserialize__withoutArguments() { PendingCommand pendingCommand = PendingEmptyTrash.create(); String serializedCommand = pendingCommandSerializer.serialize(pendingCommand); PendingEmptyTrash unserializedCommand = (PendingEmptyTrash) pendingCommandSerializer.unserialize( DATABASE_ID, pendingCommand.getCommandName(), serializedCommand); assertEquals(DATABASE_ID, unserializedCommand.databaseId); }
public <T extends PendingCommand> String serialize(T command) { // noinspection unchecked, we know the map has correctly matching adapters JsonAdapter<T> adapter = (JsonAdapter<T>) adapters.get(command.getCommandName()); if (adapter == null) { throw new IllegalArgumentException("Unsupported pending command type!"); } return adapter.toJson(command); }
public void addPendingCommand(PendingCommand command) throws MessagingException { final ContentValues cv = new ContentValues(); cv.put("command", command.getCommandName()); cv.put("data", pendingCommandSerializer.serialize(command)); database.execute(false, new DbCallback<Void>() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException { db.insert("pending_commands", "command", cv); return null; } }); }
@Test public void testSerializeDeserialize__withComplexArguments() { PendingCommand pendingCommand = PendingMoveOrCopy.create( SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_MAP); String serializedCommand = pendingCommandSerializer.serialize(pendingCommand); PendingMoveOrCopy unserializedCommand = (PendingMoveOrCopy) pendingCommandSerializer.unserialize( DATABASE_ID, pendingCommand.getCommandName(), serializedCommand); assertEquals(DATABASE_ID, unserializedCommand.databaseId); assertEquals(SOURCE_FOLDER, unserializedCommand.srcFolder); assertEquals(DEST_FOLDER, unserializedCommand.destFolder); assertEquals(UID_MAP, unserializedCommand.newUidMap); }