Search in sources :

Example 6 with Command

use of com.ramussoft.common.journal.command.Command in project ramus by Vitaliy-Yakovchuk.

the class Journal method redoUserTransaction.

@Override
public void redoUserTransaction() {
    int counter = 0;
    try {
        Command command = redo();
        counter++;
        if (!(command instanceof StartUserTransactionCommand)) {
            throw new Exception("Command is not user transaction");
        }
        while (!(redo() instanceof EndUserTransactionCommand)) {
            counter++;
        }
    } catch (Exception e) {
        e.printStackTrace();
        while (counter > 0) {
            counter--;
            undo();
        }
    }
}
Also used : CreateAttributeCommand(com.ramussoft.common.journal.command.CreateAttributeCommand) UpdateAttributeCommand(com.ramussoft.common.journal.command.UpdateAttributeCommand) DeleteElementCommand(com.ramussoft.common.journal.command.DeleteElementCommand) SetElementQualifierCommand(com.ramussoft.common.journal.command.SetElementQualifierCommand) CreateQualifierCommand(com.ramussoft.common.journal.command.CreateQualifierCommand) DeleteQualifierCommand(com.ramussoft.common.journal.command.DeleteQualifierCommand) TransactionStorageCommand(com.ramussoft.common.journal.command.TransactionStorageCommand) Command(com.ramussoft.common.journal.command.Command) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) DeleteAttributeCommand(com.ramussoft.common.journal.command.DeleteAttributeCommand) FormulaCommand(com.ramussoft.common.journal.command.FormulaCommand) NewBranchCommand(com.ramussoft.common.journal.command.NewBranchCommand) UpdateQualifierCommand(com.ramussoft.common.journal.command.UpdateQualifierCommand) CreateElementCommand(com.ramussoft.common.journal.command.CreateElementCommand) SetStreamCommand(com.ramussoft.common.journal.command.SetStreamCommand) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) NextCommand(com.ramussoft.common.journal.command.NextCommand) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand)

Example 7 with Command

use of com.ramussoft.common.journal.command.Command in project ramus by Vitaliy-Yakovchuk.

the class Journal method readPrev.

private Command readPrev() throws IOException {
    Command.moveCommandStart(accessFile);
    long pos = accessFile.getFilePointer();
    Command res = readCommand();
    accessFile.seek(pos);
    return res;
}
Also used : CreateAttributeCommand(com.ramussoft.common.journal.command.CreateAttributeCommand) UpdateAttributeCommand(com.ramussoft.common.journal.command.UpdateAttributeCommand) DeleteElementCommand(com.ramussoft.common.journal.command.DeleteElementCommand) SetElementQualifierCommand(com.ramussoft.common.journal.command.SetElementQualifierCommand) CreateQualifierCommand(com.ramussoft.common.journal.command.CreateQualifierCommand) DeleteQualifierCommand(com.ramussoft.common.journal.command.DeleteQualifierCommand) TransactionStorageCommand(com.ramussoft.common.journal.command.TransactionStorageCommand) Command(com.ramussoft.common.journal.command.Command) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) DeleteAttributeCommand(com.ramussoft.common.journal.command.DeleteAttributeCommand) FormulaCommand(com.ramussoft.common.journal.command.FormulaCommand) NewBranchCommand(com.ramussoft.common.journal.command.NewBranchCommand) UpdateQualifierCommand(com.ramussoft.common.journal.command.UpdateQualifierCommand) CreateElementCommand(com.ramussoft.common.journal.command.CreateElementCommand) SetStreamCommand(com.ramussoft.common.journal.command.SetStreamCommand) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) NextCommand(com.ramussoft.common.journal.command.NextCommand)

Example 8 with Command

use of com.ramussoft.common.journal.command.Command in project ramus by Vitaliy-Yakovchuk.

the class Journal method undoUserTransaction.

@Override
public void undoUserTransaction() {
    int counter = 0;
    try {
        Command command = undo();
        counter++;
        if (!(command instanceof EndUserTransactionCommand)) {
            throw new Exception("Command is not user transaction");
        }
        while (!((command = undo()) instanceof StartUserTransactionCommand)) {
            counter++;
        }
    } catch (Exception e) {
        e.printStackTrace();
        while (counter > 0) {
            counter--;
            redo();
        }
    }
}
Also used : CreateAttributeCommand(com.ramussoft.common.journal.command.CreateAttributeCommand) UpdateAttributeCommand(com.ramussoft.common.journal.command.UpdateAttributeCommand) DeleteElementCommand(com.ramussoft.common.journal.command.DeleteElementCommand) SetElementQualifierCommand(com.ramussoft.common.journal.command.SetElementQualifierCommand) CreateQualifierCommand(com.ramussoft.common.journal.command.CreateQualifierCommand) DeleteQualifierCommand(com.ramussoft.common.journal.command.DeleteQualifierCommand) TransactionStorageCommand(com.ramussoft.common.journal.command.TransactionStorageCommand) Command(com.ramussoft.common.journal.command.Command) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) DeleteAttributeCommand(com.ramussoft.common.journal.command.DeleteAttributeCommand) FormulaCommand(com.ramussoft.common.journal.command.FormulaCommand) NewBranchCommand(com.ramussoft.common.journal.command.NewBranchCommand) UpdateQualifierCommand(com.ramussoft.common.journal.command.UpdateQualifierCommand) CreateElementCommand(com.ramussoft.common.journal.command.CreateElementCommand) SetStreamCommand(com.ramussoft.common.journal.command.SetStreamCommand) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) NextCommand(com.ramussoft.common.journal.command.NextCommand) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand)

Example 9 with Command

use of com.ramussoft.common.journal.command.Command in project ramus by Vitaliy-Yakovchuk.

the class InternetHookJournal method redo.

@Override
public Command redo() {
    Command command = super.redo();
    onRepeat(command);
    return command;
}
Also used : Command(com.ramussoft.common.journal.command.Command) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand)

Example 10 with Command

use of com.ramussoft.common.journal.command.Command in project ramus by Vitaliy-Yakovchuk.

the class InternetHookJournal method undo.

@Override
public Command undo() {
    Command undo = super.undo();
    if (undo instanceof StartUserTransactionCommand) {
        try {
            long cursor = getPointer();
            byte[] bs = new byte[(int) (this.cursor - cursor)];
            accessFile.read(bs);
            accessFile.seek(cursor);
            this.cursor = cursor;
            onUndo(bs);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return undo;
}
Also used : Command(com.ramussoft.common.journal.command.Command) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand)

Aggregations

Command (com.ramussoft.common.journal.command.Command)10 EndUserTransactionCommand (com.ramussoft.common.journal.command.EndUserTransactionCommand)10 StartUserTransactionCommand (com.ramussoft.common.journal.command.StartUserTransactionCommand)10 CreateAttributeCommand (com.ramussoft.common.journal.command.CreateAttributeCommand)7 CreateElementCommand (com.ramussoft.common.journal.command.CreateElementCommand)7 CreateQualifierCommand (com.ramussoft.common.journal.command.CreateQualifierCommand)7 DeleteAttributeCommand (com.ramussoft.common.journal.command.DeleteAttributeCommand)7 DeleteElementCommand (com.ramussoft.common.journal.command.DeleteElementCommand)7 DeleteQualifierCommand (com.ramussoft.common.journal.command.DeleteQualifierCommand)7 FormulaCommand (com.ramussoft.common.journal.command.FormulaCommand)7 NewBranchCommand (com.ramussoft.common.journal.command.NewBranchCommand)7 NextCommand (com.ramussoft.common.journal.command.NextCommand)7 SetElementQualifierCommand (com.ramussoft.common.journal.command.SetElementQualifierCommand)7 SetStreamCommand (com.ramussoft.common.journal.command.SetStreamCommand)7 TransactionStorageCommand (com.ramussoft.common.journal.command.TransactionStorageCommand)7 UpdateAttributeCommand (com.ramussoft.common.journal.command.UpdateAttributeCommand)7 UpdateQualifierCommand (com.ramussoft.common.journal.command.UpdateQualifierCommand)7 IOException (java.io.IOException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IEngine (com.ramussoft.common.IEngine)2