Search in sources :

Example 1 with LibraryEntry

use of com.eightkdata.mongowp.server.api.CommandsLibrary.LibraryEntry in project torodb by torodb.

the class OplogOperationApplier method applyCmd.

@SuppressWarnings("unchecked")
private void applyCmd(DbCmdOplogOperation op, ExclusiveWriteMongodTransaction trans, ApplierContext applierContext) throws OplogApplyingException {
    LibraryEntry librayEntry = library.find(op.getRequest());
    if (librayEntry == null) {
        throw new OplogApplyingException(new CommandNotFoundException(op.getRequest().isEmpty() ? "?" : op.getRequest().getFirstEntry().getKey()));
    }
    Command command = librayEntry.getCommand();
    if (command == null) {
        BsonDocument document = op.getRequest();
        if (document.isEmpty()) {
            throw new OplogApplyingException(new CommandNotFoundException("Empty document query"));
        }
        String firstKey = document.getFirstEntry().getKey();
        throw new OplogApplyingException(new CommandNotFoundException(firstKey));
    }
    Object arg;
    try {
        arg = command.unmarshallArg(op.getRequest(), librayEntry.getAlias());
    } catch (MongoException ex) {
        throw new OplogApplyingException(ex);
    }
    Status executionResult = executeReplCommand(op.getDatabase(), command, arg, trans.getTorodTransaction());
    if (!executionResult.isOk()) {
        throw new OplogApplyingException(new MongoException(executionResult));
    }
}
Also used : Status(com.eightkdata.mongowp.Status) LibraryEntry(com.eightkdata.mongowp.server.api.CommandsLibrary.LibraryEntry) MongoException(com.eightkdata.mongowp.exceptions.MongoException) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) DeleteCommand(com.torodb.mongodb.commands.signatures.general.DeleteCommand) Command(com.eightkdata.mongowp.server.api.Command) UpdateCommand(com.torodb.mongodb.commands.signatures.general.UpdateCommand) CreateIndexesCommand(com.torodb.mongodb.commands.signatures.admin.CreateIndexesCommand) InsertCommand(com.torodb.mongodb.commands.signatures.general.InsertCommand) CommandNotFoundException(com.eightkdata.mongowp.exceptions.CommandNotFoundException)

Aggregations

Status (com.eightkdata.mongowp.Status)1 BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)1 CommandNotFoundException (com.eightkdata.mongowp.exceptions.CommandNotFoundException)1 MongoException (com.eightkdata.mongowp.exceptions.MongoException)1 Command (com.eightkdata.mongowp.server.api.Command)1 LibraryEntry (com.eightkdata.mongowp.server.api.CommandsLibrary.LibraryEntry)1 CreateIndexesCommand (com.torodb.mongodb.commands.signatures.admin.CreateIndexesCommand)1 DeleteCommand (com.torodb.mongodb.commands.signatures.general.DeleteCommand)1 InsertCommand (com.torodb.mongodb.commands.signatures.general.InsertCommand)1 UpdateCommand (com.torodb.mongodb.commands.signatures.general.UpdateCommand)1