Search in sources :

Example 1 with UpdateException

use of com.torodb.core.exceptions.user.UpdateException in project torodb by torodb.

the class UpdateActionTranslator method translateMove.

private static void translateMove(CompositeUpdateAction.Builder builder, BsonDocument argument) throws UpdateException {
    for (Entry<?> entry : argument) {
        Collection<AttributeReference> attRefs = parseAttributeReference(entry.getKey());
        if (!entry.getValue().isString()) {
            throw new UpdateException("The 'to' field for $rename must " + "be a string, but " + entry.getValue() + " were found " + "with key " + entry.getKey());
        }
        AttributeReference newRef = parseAttributReferenceAsObjectReference(entry.getValue().asString().getValue());
        builder.add(new MoveUpdateAction(attRefs, newRef), false);
    }
}
Also used : AttributeReference(com.torodb.core.language.AttributeReference) MoveUpdateAction(com.torodb.mongodb.language.update.MoveUpdateAction) UpdateException(com.torodb.core.exceptions.user.UpdateException)

Example 2 with UpdateException

use of com.torodb.core.exceptions.user.UpdateException in project torodb by torodb.

the class UpdateActionTranslator method translateMultiply.

private static void translateMultiply(CompositeUpdateAction.Builder builder, BsonDocument argument) throws UpdateException {
    for (Entry<?> entry : argument) {
        Collection<AttributeReference> attRefs = parseAttributeReference(entry.getKey());
        KvValue<?> translatedValue = MongoWpConverter.translate(entry.getValue());
        if (!(translatedValue instanceof KvNumeric)) {
            throw new UpdateException("Cannot multiply with a " + "non-numeric argument");
        }
        builder.add(new MultiplyUpdateAction(attRefs, (KvNumeric<?>) translatedValue), false);
    }
}
Also used : KvNumeric(com.torodb.kvdocument.values.KvNumeric) AttributeReference(com.torodb.core.language.AttributeReference) UpdateException(com.torodb.core.exceptions.user.UpdateException) MultiplyUpdateAction(com.torodb.mongodb.language.update.MultiplyUpdateAction)

Example 3 with UpdateException

use of com.torodb.core.exceptions.user.UpdateException in project torodb by torodb.

the class UpdateActionTranslator method translateIncrement.

private static void translateIncrement(CompositeUpdateAction.Builder builder, BsonDocument argument) throws UpdateException {
    for (Entry<?> entry : argument) {
        Collection<AttributeReference> attRefs = parseAttributeReference(entry.getKey());
        KvValue<?> translatedValue = MongoWpConverter.translate(entry.getValue());
        if (!(translatedValue instanceof KvNumeric)) {
            throw new UpdateException("Cannot increment with a " + "non-numeric argument");
        }
        builder.add(new IncrementUpdateAction(attRefs, (KvNumeric<?>) translatedValue), false);
    }
}
Also used : KvNumeric(com.torodb.kvdocument.values.KvNumeric) AttributeReference(com.torodb.core.language.AttributeReference) IncrementUpdateAction(com.torodb.mongodb.language.update.IncrementUpdateAction) UpdateException(com.torodb.core.exceptions.user.UpdateException)

Aggregations

UpdateException (com.torodb.core.exceptions.user.UpdateException)3 AttributeReference (com.torodb.core.language.AttributeReference)3 KvNumeric (com.torodb.kvdocument.values.KvNumeric)2 IncrementUpdateAction (com.torodb.mongodb.language.update.IncrementUpdateAction)1 MoveUpdateAction (com.torodb.mongodb.language.update.MoveUpdateAction)1 MultiplyUpdateAction (com.torodb.mongodb.language.update.MultiplyUpdateAction)1