All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bronto.api.operation.BrontoWritePager Maven / Gradle / Ivy

There is a newer version: 1.0.9
Show newest version
package com.bronto.api.operation;

import java.util.Iterator;

import com.bronto.api.BrontoApi;
import com.bronto.api.BrontoWriteException;
import com.bronto.api.BrontoWriteExceptionTransform;
import com.bronto.api.model.WriteResult;
import com.bronto.api.reflect.ApiReflection;
import com.bronto.api.request.BrontoClientRequest;

public class BrontoWritePager implements Iterator {
    private final BrontoApi client;
    private final ApiReflection reflect;
    private final BrontoWriteBatch batches;
    private final BrontoWriteExceptionTransform handle;

    public BrontoWritePager(BrontoApi client, ApiReflection reflect, BrontoWriteBatch batches, BrontoWriteExceptionTransform handle) {
        this.client = client;
        this.reflect = reflect;
        this.batches = batches;
        this.handle = handle;
    }

    public BrontoWritePager(BrontoApi client, ApiReflection reflect, BrontoWriteBatch batches) {
        this(client, reflect, batches, new DefaultWriteExceptionTransform(client, reflect, batches));
    }

    public BrontoApi getClient() {
        return client;
    }

    public ApiReflection getReflect() {
        return reflect;
    }

    public BrontoWriteBatch getBatches() {
        return batches;
    }

    @Override
    public boolean hasNext() {
        return batches.hasNext();
    }

    @Override
    public WriteResult next() {
        String methodName = batches.getMethod();
        final Object call = reflect.fillMethodCall(methodName, batches.next());
        BrontoClientRequest request = reflect.createMethodRequest(methodName, call);
        try {
            return client.invoke(request);
        } catch (BrontoWriteException bwe) {
            return handle.transform(bwe);
        }
    }

    @Override
    public void remove() {
        batches.remove();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy