Example usage for com.google.common.collect Multimaps forMap

List of usage examples for com.google.common.collect Multimaps forMap

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps forMap.

Prototype

public static <K, V> SetMultimap<K, V> forMap(Map<K, V> map) 

Source Link

Document

Returns a multimap view of the specified map.

Usage

From source file:com.palantir.atlasdb.keyvalue.rdbms.PostgresKeyValueService.java

@Override
@Idempotent//from w w  w.ja v a 2 s  .c  om
public void addGarbageCollectionSentinelValues(final String tableName, final Set<Cell> cells) {
    getDbi().inTransaction(new TransactionCallback<Void>() {
        @Override
        public Void inTransaction(Handle conn, TransactionStatus status) throws Exception {
            Map<Cell, byte[]> cellsWithInvalidValues = Maps2.createConstantValueMap(cells,
                    ArrayUtils.EMPTY_BYTE_ARRAY);
            Multimap<Cell, Long> cellsAsMultimap = Multimaps
                    .forMap(Maps2.createConstantValueMap(cells, Value.INVALID_VALUE_TIMESTAMP));
            deleteInTransaction(tableName, cellsAsMultimap, conn);
            putInTransaction(tableName, cellsWithInvalidValues, Value.INVALID_VALUE_TIMESTAMP, conn);
            return null;
        }
    });
}

From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java

/**
 * This will attempt to rollback the passed transactions.  If all are rolled back correctly this
 * method will also delete the values for the transactions that have been rolled back.
 * @return false if we cannot roll back the failed transactions because someone beat us to it.
 */// w w w  . j  a  v a  2  s . c  o m
private boolean rollbackFailedTransactions(String tableName, Map<Cell, Long> keysToDelete,
        Map<Long, Long> commitTimestamps, TransactionService transactionService) {
    for (long startTs : Sets.newHashSet(keysToDelete.values())) {
        if (commitTimestamps.get(startTs) == null) {
            log.warn("Rolling back transaction: " + startTs);
            if (!rollbackOtherTransaction(startTs, transactionService)) {
                return false;
            }
        } else {
            Validate.isTrue(commitTimestamps.get(startTs) == TransactionConstants.FAILED_COMMIT_TS);
        }
    }

    try {
        log.warn("For table: " + tableName + " we are deleting values of an uncommitted transaction: "
                + keysToDelete);
        keyValueService.delete(tableName, Multimaps.forMap(keysToDelete));
    } catch (RuntimeException e) {
        String msg = "This isn't a bug but it should be infrequent if all nodes of your KV service are running. "
                + "Delete has stronger consistency semantics than read/write and must talk to all nodes "
                + "instead of just talking to a quorum of nodes. " + "Failed to delete keys for table"
                + tableName + " from an uncommitted transaction: " + keysToDelete;
        log.error(msg, e);
    }

    return true;
}

From source file:com.sam.moca.server.exec.DefaultServerContext.java

private MocaResults _executeQuery(String query, Map<String, _StackArg> args, boolean keepContext)
        throws MocaException {
    // Make sure status is okay before executing the command.
    checkStatus();/*w w w .  j  a  v  a2  s  . c  o m*/
    _logger.debug("Parsing command... ");

    CommandSequence compiled;
    try {
        MocaParser parser = new MocaParser(query);
        compiled = parser.parse();
        _logger.debug("Parsed command");
    } catch (MocaParseException e) {
        _logger.debug(MocaUtils.concat("Parse Error: ", e));
        throw e;
    }

    _previousStatement.push(query);

    _DataStackElement[] tempStack = null;
    int tempStackLevel = 0;

    if (!keepContext) {
        try {
            _dataStackLock.lock();
            // We copy the stack level
            tempStackLevel = _dataStackLevel;
            _dataStackLevel = -1;
            // We copy the actual stack up to the stack level
            tempStack = Arrays.copyOf(_dataStack, tempStackLevel + 1);
            // We then have to fill the datastack with nulls, so that our
            // context is cleared
            Arrays.fill(_dataStack, 0, tempStackLevel + 1, null);
        } finally {
            _dataStackLock.unlock();
        }
    }
    pushStack();
    setCommand(compiled);
    try {
        if (args != null) {
            try {
                _dataStackLock.lock();
                _DataStackElement frame = _dataStack[_dataStackLevel];
                frame.args.putAll(Multimaps.forMap(args));
                frame.argList.addAll(args.values());
            } finally {
                _dataStackLock.unlock();
            }
        }
        _logger.debug("Executing...");
        return compiled.execute(this);
    } finally {
        popStack(false);
        _previousStatement.pop();
        if (!keepContext) {
            try {
                _dataStackLock.lock();
                // We copy the stack level back in
                _dataStackLevel = tempStackLevel;
                // We copy the actual stack up to the stack level back in
                System.arraycopy(tempStack, 0, _dataStack, 0, _dataStackLevel + 1);
            } finally {
                _dataStackLock.unlock();
            }
        }
    }
}